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
Add a partial index on account move line #7430
Conversation
👍 It would be good to have a |
👍 |
Thanks, improving the performance of this query is a good idea, but we should refrain from adding more indexes on that table, especially a partial one that would only be useful in a few limited cases. Instead we could improve an existing index (e.g. If we extend it to include the CREATE INDEX account_move_line_journal_id_period_id_index
ON account_move_line (journal_id, period_id, state, create_uid, id DESC) This is the result of your benchmark:
Changing this in 7.0 is a bit borderline, and the performance boost will not affect many operations, but if it only involves adding a few extra columns in the existing index I think it is acceptable. Users who would like to benefit from the improvement will have to drop (and recreate) the index manually, which is safer. What do you think? |
An log analysis showed that the normalized query below was executed very often with a slow explain plan using a seq scan. SELECT move_id, date FROM account_move_line WHERE journal_id = 0 AND period_id = 0 AND create_uid = 0 AND state = '' ORDER BY id DESC LIMIT 0; This query is called in the _default_get of account_move_line to find the last unbalanced move line. The existing index can be improved to cover this query as well, showing a Impressive improvement of the explain plan as explained here: odoo#7430 (comment)
cfc7eb7
to
555a595
Compare
Thanks a lot @odony for this very detailed analysis and feedback. I'm always delighted when I get a review from you because I know that I will learn and that you will raise the good questions or improvements. ⭐ I updated my commit according to your comment. |
….line A log analysis showed that the normalized query below was executed very often with a slow explain plan using a seq scan. ```sql SELECT move_id, date FROM account_move_line WHERE journal_id = <journal_id> AND period_id = <period_id> AND create_uid = <user_id> AND state = 'draft' ORDER BY id DESC LIMIT 0; ``` This query is called in the _default_get of account.move.line to find the last unbalanced move line. The existing index can be improved to cover this query as well, showing an impressive improvement of the explain plan as explained here: #7430 (comment) Closes #7430
Thanks for the quick update of the PR, just merged in 7.0 at 4fe0c6b :-) |
A log analysis showed that the normalized query below was executed very often
with a slow explain plan using a seq scan.
This query is called in the _default_get of account_move_line to find the last
unbalanced move line. The state is always 'draft' and the fields always
journal_id, period_id and create_uid so it is a good candidate for a partial
index with combined fields.
The explain plan shows an impressive improvement, dropping from ~800ms to
~0.030 ms for a table with 3906500 records. This query was called 7700 times in
a working day for a cumulated duration of 25m32s.
Example of explain plan before:
And after:
The query is called here: https://github.com/guewen/odoo/blob/7.0-account_move_line-join-index/addons/account/account_move_line.py#L268-L271