Académique Documents
Professionnel Documents
Culture Documents
#nde$
%urrent approach &sum o' entries(
%urrent approach e$plained! Per'ormance anal)sis! Alternati,e -: Accumulated ,alues using triggers
Allo s to do comple$ 'ilters6 .ut usuall) loo" li"e *include non;dra't entries 'rom these periods 'or these accounts+!
__compute() sums: uses the 'ilter to :uer) 'or the sums o' de.it/credit/.alance 'or the current account and its children!
<oes just one S9L :uer) 'or all the accounts! (nice!) 8as to aggregate the children ,alues on p)thon!
WHERE l.account_id ! (2, 3, 4, 5, 6, ..., 1648, 1649, 1650, 1651) A!" l.state #$ %dra&t% A!" l.'eriod_id ! (SELEC( id )*OM account_'eriod +,E*E &iscal-ear_id ! (.)) A!" l.move_id ! (SELEC( id )*OM account_move +,E*E account_move.state / %'osted%) GROUP BY l.account_id
:oin )ilter= (l.'eriod_id / account_'eriod.id) -$ !ested Loo' -$ (cost/;5.00..56.5< ro9s/. 9idt3/<<) (cost/;5.00..;5.0. ro9s/. 9idt3/;)
@gh?6 se:uential scan on a ta.le ith &potentiall)( lots o' records!!! :&
,as3A44re4ate -$
)ilter= ((state)==te>t / %'osted%==te>t) -$ nde> Scan usin4 account_move_line_move_id_inde> on account_move_line l nde> Cond= (l.move_id / account_move.id) )ilter= (((l.state)==te>t #$ %dra&t%==te>t) A!" (l.account_id / A!1 (%A<,8,;,5, ..., .@;?,.@50,.@5.B%==inte4erCD))) -$ nde> Scan usin4 account_'eriod_&iscal-ear_id_inde> on account_'eriod nde> Cond= (account_'eriod.&iscal-ear_id / .) (cost/0.00..0.<? ro9s/. 9idt3/;) (cost/0.00...<.;? ro9s/. 9idt3/<@)
Le,el E F GHDDDD &lea' account( Le,el G ; GHDD Le,el H ; GHD Le,el 1 ; GH Le,el - ; G Le,el D F D &root account(
5o get the .alance o' account *G+ e need to sum the .alance o' -I1 accounts?
O"6 loo"s li"e the num.er o' children c has a lot o' in'luence6 and the num.er o' mo,es l has little or zero in'luence6 4(c) $$ &(l) Lets split them!!!
4o it is clear that 4(c) is linear? ¬e: the nL o' children gro s e$ponentiall)( O(4(c)) = O(c)
Big O ; %onclusion
O(__compute) = O(l) + O(c) c has an une$pectedl) .ig in'luence on the results >M Bad per'ormance on comple$ charts o' accounts? c does not gro ith time6 .ut l does!!! >M OpenERP accounting .ecomes slo er and slo er ith time? &though itBs not that .ad as e$pected(
Reading the de.it/credit/.alance .ecomes much 'aster! !!!and reading is much more data intensi,e than riting:
Accounting reports read lots o' times lots o' accounts! Accountants onl) update a 'e accounts at a time!
O('):uer) &get the de.it/credit/.alance o' each period 'or that account( instead o' O(l):uer)6 ith ' .eing the num.er o' periods6 ' ## l. @sing opening entries6 or cumulati,e totals6 ' .ecomes constant >M O(.) #' aggregated sums & ith children ,alues( are also precalculated6 e donBt ha,e to do one O(c)aggregation per read!
4e o.ject to store the accumulated de.it/credit/.alance per account and period &letBs call it account.period.sum(!
Opening 2o,e line ,alues in period Nalue in ta.le GDD GDD -st =1DD6 =ED CED 1nd =1E CJE Hrd ;GDD 1JE Gth =1E6 =1DD EDD
5riggers on Postgres &#$!pg%&$( update the account_period_sum ta.le each time an account mo,e line is created/updated/deleted!
5he data is calculated accumulating the ,alues 'rom pre,ious periods! &/erdinand protot)pe re:uires an special naming o'
periods 'or this(!
%reates S9L ,ie s .ased on the account account_period_sum ta.le! /or reports that sho data aggregated .) period:
4e reports can .e created that either directl) use the S9L ,ie s6 or use the account!period!sum o.ject!
5he account.account.__compute() method could .e e$tended to optimize :ueries &modi'ied to ma"e use o' the account_period_sum hen possi.le( in the 'uture!
Bad points
<ata.ase dependent triggers! 5riggers are harder to maintain than P)thon code! 2a"es some assumptions on period names!
&as OpenERP currentl) does not 'lag opening periods apart 'rom closing ones(
4e o.ject to store the de.it/credit/.alance sums per account and period (and state)+
Opening 2o,e line ,alues in period Nalue in ta.le GDD GDD -st =1DD6 =ED 1ED 1nd =1E 1E Hrd ;GDD ;GDD Gth =1E6 =1DD 11E
E$tends the account.move.line open o.ject to update the account.sum o.jects each time a line is created/updated/deleted!
#' the :uer) 'ilters onl) .) period/'iscal )ear/state6 the data is retrie,ed 'rom the account.sum o.ject! #' the :uer) 'ilters .) dates6 and one ore more 'iscal periods are 'ull) included on that range6 the data is retrie,ed 'rom 'or the account.sum o.jects &'or the range co,ered .) the periods( plus the account.move.lines &the range not co,ered .) periods(! /iltering .) e,er) other 'ield &'or e$ample partner_id( causes a 'all.ac" into the normal __compute method!
/ast6 al a)s! <rill;do n na,igation! 4eed to "eep sums in s)nc ith mo,e lines! 2ore comple$ &__compute( or speci'ic :ueries to ma"e use o' the precalculated sums!
%ons
%ons