Mar 2, 2010 8:20 AM
slow insert in stored procedure
-
Like (0)
Hi,
i have table t1(with n columns) and t2 (with n+1 columns) and t3(PK_T1, GEN_KEY) .
for loop read data from t1
if PK_T1 in T3
take GEN_KEY from T3
else
next val from seque -> GEN_KEY.
end if
write GEN_KEY + all data from T1 to T2
end loop
This is very slow 9mins form 1000 record.
What did a do wrong ????
thanks, bye
d
Why are you doing this as 'record at a time' processing in a stored procedure? This may be appropriate on older transaction-based DBMS, but not for Netezza.
Better to use standard SQL to do this processing in 'bulk mode'
D.
single row inserts are extremely slow in Netezza. You'll have to rewrite the stored procedure to use SQL to break the data into sets, then use SQL to perform whatever operation it is you want to do on the entire set of data in a single pass
did you try something like below?
insert into t2
select t3.gen_key, t1.*
from t2 , t3
where t2.pk_1 =t3.pk_1
union all
select next value for s, t1.*
from t2 a
where not exists ( select 1 from t3 b where a.pk_1 = b.pk_1)
as you might notice, sequences behaviour is not identical to oracle sequences.
Thank you so much for the post. It's really informative!
__________________
http://moviesonlineworld.com

