Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does DB2 take so long to run a simple SQL logic?

Status
Not open for further replies.

pradchal1

Programmer
Nov 10, 2004
31
FR
I have a simple query that runs against a DB2 database table with 200,000 rows of data. The table has about 10 columns. But my SQL query takes too long to run almost filling up the log. It is a simple logic. Can anyone suggest me anything I can do to make this any faster?
My SQL is:

delete from B;
insert into B
select * from A source where effdt =
( select max(effdt) from A sub
where sub.TRNSFR_SRC_ID = source.TRNSFR_SRC_ID
and sub.COMP_SUBJECT_AREA = source.COMP_SUBJECT_AREA
and sub.TRNSFR_CMP_SEQ = source.TRNSFR_CMP_SEQ
and sub.TRNSFR_EQVLNCY_CMP = source.TRNSFR_EQVLNCY_CMP
and effdt <= CURRENT DATE);

Basically, I want the highest effective dated row where the keys (TRNSFR_SRC_ID, COMP_SUBJECT_AREA, TRNSFR_CMP_SEQ AND TRNSFR_EQVLNCY_CMP) match.

Any suggestion or help would be greatly appreciated.
 
I don't know if DB2 allows you to Truncate a table versus delete. In SQL it's faster with less logging and you might try that.

If you are on an IBM mainframe try posting this on Your first few posts are free but after that you have to pay.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top