Skip to content

Conversation

@AdrianaSaiz
Copy link

@AdrianaSaiz AdrianaSaiz commented Nov 12, 2025

Add index for first_move_id to improve performance

Without indexing first_move_id field, when trying to execute write method on a stock move, for example when we confirm a sale order. The query lasts for at least more than 7 seconds.

This slows down the system and can even cause PostgreSQL blocks.

As we can see in this profiler, the query:

sql('SELECT "stock_move".id FROM "stock_move" WHERE ("stock_move"."first_move_id" in %s) ORDER BY "stock_move"."id" ') (SELECT "stock_move".id FROM "stock_move" WHERE ("stock_move"."first_move_id" in (25199374)) ORDER BY "stock_move"."id" )

The query is consuming more than 70% of the order confirmation time, when making a return.

image

Whereas if we index the field first_move_id, the query lasts less than a second and all the process is finished in only 1 second

image

@AdrianaSaiz AdrianaSaiz force-pushed the 16.0-fix-stock_move_propagate_first_move branch from e1df3d7 to f7bfe8d Compare November 13, 2025 08:46
Copy link

@xAdrianCif xAdrianCif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great analysis and I think very useful, thanks for the work!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants