Skip to content

[Bug]: Items Performance after php8 upgrade #4519

Closed

Description

@giskardors

🐛 Bug Description

I have upgraded from 3.3.7 to 3.4.1, Im using mariadb 11.8.6. Everytime I try the Items page, it takes a lot to load, but didnt happend on version 3.3.7. Ive tried to optimize every table on mariadb, without success.
Im using php 8.4

What else should I try?

Thanks in advance

📋 Steps to Reproduce

Go to Items page, let it load

✅ Expected Behavior

Load in less than 2 seconds

📦 OpenSourcePOS Version

OpenSourcePOS 3.4.1

🔧 PHP Version

PHP 8.4

🌐 Browser(s)

Firefox

🖥️ Server Operating System

Fedora 43

🗄️ Database

Mariadb 11.8.6

🌍 Web Server

Apache 2.4

📊 System Information Report

General Info

User Setup

Permissions

Información de instalación OSPOS: 3.4.1 - 5f395d
Language Code: es-MX

Extensions & Modules:
» GD: Enabled ✓
» BC Math: Enabled ✓
» INTL: Enabled ✓
» OpenSSL: Enabled ✓
» MBString: Enabled ✓
» Curl: Enabled ✓
» Json: Enabled ✓

» Xml: Enabled ✓

User Configuration:
.Browser: Firefox 149.0
Server Software: Apache/2.4.66 (Fedora Linux)
PHP Version: 8.4.20
DB Version: 11.8.6-MariaDB
Server Port: 80
OS: Linux 6.19.12-200.fc43.x86_64

📜 Relevant Log Output

📸 Screenshots

No response

✓ Confirmation

  • I certify that this is an unmodified copy of OpenSourcePOS
  • I have searched existing issues to ensure this bug has not already been reported
  • I have provided all the information requested above

Activity

  1. jekkos commented on Apr 19, 2026

    @jekkos
    Member

    We've identified the likely root cause and opened a fix in PR #4520.

    Root Cause

    PR #4250 (commit 29c3c55) added orWhere clauses to Item::exists() and Item::get_item_id() to support barcode lookup, but these OR conditions were not wrapped in parentheses (groupStart()/groupEnd()). This causes:

    1. Wrong SQL semantics — generates WHERE item_id = ? OR item_number = ? AND deleted = 0 instead of WHERE (item_id = ? OR item_number = ?) AND deleted = 0. Due to SQL operator precedence, AND binds tighter than OR, so the deleted filter only applies to the item_number branch. Deleted items can still match via item_id, causing extra row returns and index bypass.

    2. Performance regression — The unscoped OR causes MySQL/MariaDB's optimizer to bypass the item_id primary key index and fall back to full table scans, particularly when comparing a VARCHAR item_number column against a numeric parameter.

    Fix

    PR #4520 wraps the orWhere conditions in groupStart()/groupEnd() for proper SQL parenthesization in both exists() and get_item_id().

    In the meantime — to help us confirm the diagnosis

    Could you enable the slow query log so we can see exactly which queries are slow? This will tell us if the regression is from the orWhere issue or from something else (like missing optimization indices from the 3.4.1 migration).

    To enable slow query log on MariaDB:

    -- Run in your MariaDB console
    SET GLOBAL slow_query_log = 'ON';
    SET GLOBAL long_query_time = 2;
    SET GLOBAL log_queries_not_using_indexes = 'ON';
    SET GLOBAL slow_query_log_file = '/var/log/mysql/mysql-slow.log';

    Then load the Items page, and check the log:

    mysqldumpslow -s t /var/log/mysql/mysql-slow.log

    Disable when done:

    SET GLOBAL slow_query_log = 'OFF';
    SET GLOBAL log_queries_not_using_indexes = 'OFF';

    Also, please verify the optimization indices exist (these were added in a 3.4.1 migration and should be present if migrations ran successfully):

    SHOW INDEX FROM ospos_attribute_links WHERE Key_name = 'attribute_links_uq2';
    SHOW INDEX FROM ospos_inventory WHERE Key_name = 'trans_items_trans_date';

    If either returns no rows, the migration didn't run and you're missing indexes that were specifically added to fix items view timeouts on large databases (per PR #4230).

    Sharing the slow query log output would help us confirm the fix targets the right queries. Thanks!

  2. self-assigned this
    on Apr 19, 2026
  3. added this to the 3.4.3 milestone on Apr 19, 2026
  4. jekkos commented on Apr 20, 2026

    @jekkos
    Member

    Dears, a fix has been merged in master. There will soon be a new unstable zip that you can try to see if it resolves the issue. Mind that in case you have ospos setup using a reverse proxy that is not the apache ospos is running on that the install might break.

    Let me know if this works

  5. giskardors commented on Apr 26, 2026

    @giskardors
    Author

    Hi! Sorry for the late reply, I found both indexes, so no problem there.
    Im adding the log

    Count: 1 Time=0.00s (0s) Lock=0.00s (0s) Rows_sent=131.0 (131), Rows_examined=131.0 (131), Rows_affected=0.0 (0), root[root]@localhost useglams; SET timestamp=N; SELECT * FROM ospos_app_configORDER BYkey` ASC

    Count: 2 Time=0.00s (0s) Lock=0.00s (0s) Rows_sent=12.0 (24), Rows_examined=72.0 (144), Rows_affected=0.0 (0), root[root]@localhost
    SELECT *
    FROM ospos_modules
    JOIN ospos_permissions ON ospos_permissions.permission_id = ospos_modules.module_id
    JOIN ospos_grants ON ospos_permissions.permission_id = ospos_grants.permission_id
    WHERE person_id = N
    AND menu_group IN ('S','S')
    AND sort != N
    ORDER BY sort ASC

    Count: 1 Time=0.00s (0s) Lock=0.00s (0s) Rows_sent=2.0 (2), Rows_examined=6.0 (6), Rows_affected=0.0 (0), root[root]@localhost
    SELECT *
    FROM ospos_stock_locations
    JOIN ospos_permissions AS permissions ON permissions.location_id = ospos_stock_locations.location_id
    JOIN ospos_grants AS grants ON grants.permission_id = permissions.permission_id
    WHERE person_id = 'S'
    AND permissions.permission_id LIKE 'S' ESCAPE 'S'
    AND deleted = N

    Count: 2 Time=0.00s (0s) Lock=0.00s (0s) Rows_sent=1.0 (2), Rows_examined=41.0 (82), Rows_affected=0.0 (0), root[root]@localhost
    SELECT version
    FROM ospos_migrations
    ORDER BY version DESC
    LIMIT N

    Count: 1 Time=17.65s (17s) Lock=0.00s (0s) Rows_sent=25.0 (25), Rows_examined=724386.0 (724386), Rows_affected=0.0 (0), root[root]@localhost
    SELECT MAX(items.item_id) AS item_id, MAX(items.name) AS name, MAX(items.category) AS category, MAX(items.supplier_id) AS supplier_id, MAX(items.item_number) AS item_number, MAX(items.description) AS description, MAX(items.cost_price) AS cost_price, MAX(items.unit_price) AS unit_price, MAX(items.reorder_level) AS reorder_level, MAX(items.receiving_quantity) AS receiving_quantity, MAX(items.pic_filename) AS pic_filename, MAX(items.allow_alt_description) AS allow_alt_description, MAX(items.is_serialized) AS is_serialized, MAX(items.pack_name) AS pack_name, MAX(items.tax_category_id) AS tax_category_id, MAX(items.deleted) AS deleted, MAX(suppliers.person_id) AS person_id, MAX(suppliers.company_name) AS company_name, MAX(suppliers.agency_name) AS agency_name, MAX(suppliers.account_number) AS account_number, MAX(suppliers.deleted) AS deleted, MAX(inventory.trans_id) AS trans_id, MAX(inventory.trans_items) AS trans_items, MAX(inventory.trans_user) AS trans_user, MAX(inventory.trans_date) AS trans_date, MAX(inventory.trans_comment) AS trans_comment, MAX(inventory.trans_location) AS trans_location, MAX(inventory.trans_inventory) AS trans_inventory, MAX(item_quantities.item_id) AS qty_item_id, MAX(item_quantities.location_id) AS location_id, MAX(item_quantities.quantity) AS quantity
    FROM ospos_items AS items
    LEFT JOIN ospos_suppliers AS suppliers ON suppliers.person_id = items.supplier_id
    JOIN ospos_inventory AS inventory ON inventory.trans_items = items.item_id
    JOIN ospos_item_quantities AS item_quantities ON item_quantities.item_id = items.item_id
    WHERE location_id = 'S'
    AND DATE_FORMAT(trans_date, "S") BETWEEN 'S' AND 'S'
    AND items.deleted = N
    AND items.item_type IN (N,N,N)
    GROUP BY items.item_id
    ORDER BY item_id ASC
    LIMIT N

    `

    Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions