From 139b653e14bc4f0c0343061582fe015779f062a7 Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Fri, 21 Aug 2015 10:26:23 +0200 Subject: [PATCH] Remove un-optimized "LIMIT 1" from SQL request --- account_financial_report_webkit/account_move_line.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/account_financial_report_webkit/account_move_line.py b/account_financial_report_webkit/account_move_line.py index f8671f99..882ce99f 100644 --- a/account_financial_report_webkit/account_move_line.py +++ b/account_financial_report_webkit/account_move_line.py @@ -47,11 +47,14 @@ class AccountMoveLine(orm.Model): res[line.id] = {'last_rec_date': False} rec = line.reconcile_id or line.reconcile_partial_id or False if rec: - # we use cursor in order to gain some perfs + # we use cursor in order to gain some perfs. + # also, important point: LIMIT 1 is not used due to + # performance issues when in conjonction with "OR" + # (one backwards index scan instead of 2 scans and a sort) cursor.execute('SELECT date from account_move_line' ' WHERE reconcile_id = %s' ' OR reconcile_partial_id = %s' - ' ORDER BY date DESC LIMIT 1 ', + ' ORDER BY date DESC', (rec.id, rec.id)) res_set = cursor.fetchone() if res_set: