summaryrefslogtreecommitdiff
path: root/addons/analytic_user_function
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2015-04-29 23:56:58 +0200
committerOlivier Dony <odo@openerp.com>2015-04-30 00:20:12 +0200
commitcaf333eb59d4dc2e2eca05a0d4e8cf271b7d52cb (patch)
treea131ea5b9c15262aac887f0c3e2c95b8d9bcd200 /addons/analytic_user_function
parent6e25d6e589e4aa79768c483bca5c5669aaf52376 (diff)
[FIX] account.invoice.report: performance problem in currency rate computation
The SQL view implementing the "Invoice Analysis" report JOINs the res.currency.rate table in order to obtain the correct currency rate to convert each invoice line amount in the same currency. The matching of the rate needs to be done on the date of that rate (`name` column) - the last rate preceding the invoice date is presumed to be the right one. However there is no simple way to make a direct JOIN between account.invoice.line and res.currency.rate with a single match, without using an ORDER BY clause and LIMIT 1. This requires a costly SUBSELECT query for each invoice line, quickly becoming prohibitive. Through the use of PostgreSQL's Common Table Expressions (CTE) it is possible to construct a temporary table with the rates' start and end date of application. This temporary table can then be used in a direct JOIN with account.invoice.line, delivering much better performance (no SUBSELECT needed for each invoice line) On a database with 50k invoice lines this makes invoice analysis return results in less than 800 ms instead of 10+ seconds.
Diffstat (limited to 'addons/analytic_user_function')
0 files changed, 0 insertions, 0 deletions