summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuewen Baconnier <guewen.baconnier@camptocamp.com>2015-07-02 20:59:26 +0200
committerOlivier Dony <odo@openerp.com>2015-07-08 13:56:20 +0200
commit4fe0c6bd60d3d092f69a1fec213ddcb9d5eeb8a6 (patch)
treed8e917d3b15622ebd54462ac938094fe11d6bc70
parent166839fb461ffa6ebb3969643f9231cc8d922dba (diff)
[IMP] account: updated index to optimize _default_get of account.move.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: https://github.com/odoo/odoo/pull/7430#issuecomment-119521031 Closes #7430
-rw-r--r--addons/account/account_move_line.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index 230626d0b9a..df6cd1dc8d9 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -575,7 +575,8 @@ class account_move_line(osv.osv):
res = super(account_move_line, self)._auto_init(cr, context=context)
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'account_move_line_journal_id_period_id_index\'')
if not cr.fetchone():
- cr.execute('CREATE INDEX account_move_line_journal_id_period_id_index ON account_move_line (journal_id, period_id)')
+ cr.execute('CREATE INDEX account_move_line_journal_id_period_id_index '
+ 'ON account_move_line (journal_id, period_id, state, create_uid, id DESC)')
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('account_move_line_date_id_index',))
if not cr.fetchone():
cr.execute('CREATE INDEX account_move_line_date_id_index ON account_move_line (date DESC, id desc)')