Ask To Optimize Looping

From: Otniel Michael <otnieltera(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Ask To Optimize Looping
Date: 2009-08-19 09:22:21
Message-ID: 1703cd180908190222n724f1efcyb8658a4ed0663c0e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi guys, can anyone help to optimize this loop :

for i in
select
kodedivisi,kodeseksi,kodewip,nobatch,ket1,ket2,ket3,ket4,NILAIPROP as
nilaiygdibagi
from EDP040_07_23
order by kodedivisi,kodeseksi,kodewip,nobatch,ket1,ket2,ket3,ket4
loop

jmlData2 = jmlData2 + 1;

if (jmlData2 = 500) then
jmlData3 = jmlData3 + jmlData2;
jmlData2 = 0;

Raise Notice '' 12 - 2 - EDP040_07_23 = %'', jmlData3;
end if;

Update EP_ES06_N_TEMP2
Set NilPakai = NilPakai + case when i.nilaiygdibagi > 0 then
VNilaiPembagi else -1*VNilaiPembagi end
Where
(THBLTR,DIVCOD,WIPCOD,NBATCH,SKSFOH,MAINAC,SUB_AC,BAGCOD,SLGIDC,DSRTRF,
JAMPAKAI,NILPAKAI,KodeHsl,NoBatchHsl) in
(Select
THBLTR,DIVCOD,WIPCOD,NBATCH,SKSFOH,MAINAC,SUB_AC,BAGCOD,SLGIDC,DSRTRF,
JAMPAKAI,NILPAKAI,KodeHsl,NoBatchHsl
From EP_ES06_N_TEMP2
Where DIVCOD = i.kodedivisi and
WIPCOD = i.kodewip and
NBATCH = i.nobatch and
SKSFOH = i.kodeseksi and
trim(MAINAC) = trim(i.ket1) and
trim(SUB_AC) = trim(i.ket2) and
trim(BAGCOD) = trim(i.ket3) and
trim(SLGIDC) = trim(i.ket4)
Order by thbltr desc,divcod desc,wipcod desc,nbatch desc,
SKSFOH desc,mainac desc,sub_ac desc,bagcod desc,slgidc
desc,dsrtrf desc,
jampakai desc,nilpakai desc,kodehsl desc,nobatchhsl desc

limit (abs(i.nilaiygdibagi) / VNilaiPembagi));
end loop;

This loop need 30 minutes (18.000 record data), and the raise notice will
show every 50 second (500 record data).
Thanks anyway.

--
-------------------------------------------------------------------
"He who is quick to become angry will commit folly, and a crafty man is
hated"

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Otniel Michael 2009-08-19 10:17:07 Ask About SQL
Previous Message Pierre Frédéric Caillaud 2009-08-19 06:27:52 Re: [SQL] SQL Query Performance - what gives?