Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW] 15.0 perf mrp whe #109182

Closed

Conversation

fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Jan 5, 2023

Scenario: read a production order's component move
context: 4M stock move in the database, 25k not done nor cancelled on the current product

Before :
2022-12-02_16-32

After :
2022-12-02_16-31

The block 1 is improved by the indexes on stock move (db07e39)

The read request time is roughly divided by 2

The second commit (b03f932) speedup the following query

outs = self.env['stock.move'].search(out_domain, order='reservation_date, priority desc, date, id')
by giving a domain that use the index on state. In the following query plan:

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| QUERY PLAN                                                                                                                                                                                 |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Sort  (cost=108554.14..108554.38 rows=93 width=18) (actual time=467.823..468.663 rows=25508 loops=1)                                                                                       |
|   Sort Key: stock_move.reservation_date, stock_move.priority DESC, stock_move.date, stock_move.id                                                                                          |
|   Sort Method: quicksort  Memory: 2020kB                                                                                                                                                   |
|   ->  Nested Loop  (cost=1659.68..108551.10 rows=93 width=18) (actual time=65.206..442.291 rows=25508 loops=1)                                                                             |
|         ->  Seq Scan on stock_location  (cost=0.00..16.44 rows=1 width=4) (actual time=18.401..18.488 rows=5 loops=1)                                                                      |
|               Filter: (active AND (unaccent((parent_path)::text) ~~ '1/11/%'::text))                                                                                                       |
|               Rows Removed by Filter: 50                                                                                                                                                   |
|         ->  Bitmap Heap Scan on stock_move  (cost=1659.68..108531.83 rows=284 width=22) (actual time=30.365..83.770 rows=5102 loops=5)                                                     |
|               Recheck Cond: ((product_id = ANY ('{87960,87937,100482,87968,87944,4596,87941,87940,94968,87966,87934,87942,102479}'::integer[])) AND (location_id = stock_location.id))     |
|               Filter: ((product_uom_qty <> 0.0000) AND (NOT (hashed SubPlan 1)) AND (((state)::text <> ALL ('{draft,cancel,done}'::text[])) OR (state IS NULL)))                           |
|               Rows Removed by Filter: 189567                                                                                                                                               |
|               Heap Blocks: exact=74414                                                                                                                                                     |
|               ->  Bitmap Index Scan on stock_move_product_location_index  (cost=0.00..1643.16 rows=54797 width=0) (actual time=8.396..8.396 rows=194668 loops=5)                           |
|                     Index Cond: ((product_id = ANY ('{87960,87937,100482,87968,87944,4596,87941,87940,94968,87966,87934,87942,102479}'::integer[])) AND (location_id = stock_location.id)) |
|               SubPlan 1                                                                                                                                                                    |
|                 ->  Seq Scan on stock_location stock_location_1  (cost=0.00..16.44 rows=1 width=4) (actual time=2.301..2.321 rows=5 loops=1)                                               |
|                       Filter: (active AND (unaccent((parent_path)::text) ~~ '1/11/%'::text))                                                                                               |
|                       Rows Removed by Filter: 50                                                                                                                                           |
| Planning Time: 0.377 ms                                                                                                                                                                    |
| JIT:                                                                                                                                                                                       |
|   Functions: 26                                                                                                                                                                            |
|   Options: Inlining false, Optimization false, Expressions true, Deforming true                                                                                                            |
|   Timing: Generation 4.186 ms, Inlining 0.000 ms, Optimization 1.857 ms, Emission 18.412 ms, Total 24.455 ms                                                                               |
| Execution Time: 473.597 ms                                                                                                                                                                 |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

We can see Bitmap index scan found 5102 records but filter out 189567 (which is ~97% useless)


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

Forward-Port-Of: #106740

in sale_mrp module, the method `get_sale_order_count` get all stock move
with created_production_id = the current production order. Without
index, this request is significantly slow.

X-original-commit: 4c17020
'State' field on stock move is indexed. Some domains on stock move state
are expressed like (state, not in, ('a', 'b', 'c')) instead of (state,
in, ('d', 'e', 'f', NULL)). The 'not in' domain won't the index and thus
will be relatively slower

X-original-commit: 96f8321
@robodoo
Copy link
Contributor

robodoo commented Jan 5, 2023

@fw-bot
Copy link
Contributor Author

fw-bot commented Jan 5, 2023

This PR targets saas-15.3 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added the forwardport This PR was created by @fw-bot label Jan 5, 2023
@C3POdoo C3POdoo added the RD research & development, internal work label Jan 5, 2023
@fw-bot fw-bot mentioned this pull request Jan 5, 2023
robodoo pushed a commit that referenced this pull request Jan 6, 2023
in sale_mrp module, the method `get_sale_order_count` get all stock move
with created_production_id = the current production order. Without
index, this request is significantly slow.

X-original-commit: 4c17020
Part-of: #109182
robodoo pushed a commit that referenced this pull request Jan 6, 2023
'State' field on stock move is indexed. Some domains on stock move state
are expressed like (state, not in, ('a', 'b', 'c')) instead of (state,
in, ('d', 'e', 'f', NULL)). The 'not in' domain won't the index and thus
will be relatively slower

closes #109182

X-original-commit: 96f8321
Signed-off-by: Rémy Voet <ryv@odoo.com>
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
@robodoo robodoo temporarily deployed to merge January 6, 2023 12:24 Inactive
@robodoo robodoo closed this Jan 6, 2023
@fw-bot fw-bot deleted the saas-15.3-15.0-perf-mrp-whe-5Ws0-fw branch January 20, 2023 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwardport This PR was created by @fw-bot RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants