-
- Downloads
[FIX] stock: enable index/bitmap scan in report_stock_quantity
The report_stock_quantity model defines a view in its init method to compute quantity information related to stock. This view is made of two CTEs and a three-part query separated by UNION ALL. The first CTE, existing_sm, retrieves the stock_move data from the database that are later used by the remaining of the query. One of the where conditions of existing_sm is (m.state != 'done' or m.date >= ((now() at time zone 'utc')::date - interval '3month')). m.state != 'done' is translated to m.state <> 'done' by the query planner. This type of operator has the side-effect of turning off index scan. Therefore, the scanning of the existing_sm CTE performs a Seq Scan and applies the where conditions in a Filter node. This can be quite ineffecient if the stock_move table is big, and if the selectivity of the m.state != 'done' condition is high enough to theoretically justify an IndexScan. To fix that, we take the inverse of m.state != 'done', i.e. an IN cond. This allows postgres to use Bitmap Scan, which is usually better under these specific conditions. E.g. speedup: db with 7M stock_moves, select from report_stock_quantity with conds for state, date, product_id, warehouse_id, company_id 4.5s -> 2.5s opw-3288364 closes odoo/odoo#122911 X-original-commit: aad458e5 Signed-off-by:William Henrotin (whe) <whe@odoo.com> Signed-off-by:
Van Delft Aurélien (avd) <avd@odoo.com>
Please register or sign in to comment