Question : Performance Changes in a DB2 program

Hi All,

We have been using an archive program where we had identified a list of tables that needed archiving. The older approach was:

1) Had a COBOL program which deleted from tables one table at a time.
2) The tables with fewer records were deleted using a single delete. E.g. DELETE FROM TABLE_FIRST WHERE DATE < CURRENT DATE
3) For tables with significant number of records we had a cursor that fetched records. For every record fetched we were running a delete query.
4) When the FETCH for the cursor was run, we fetched 5000 rows at a time e.g. FETCH CSR_CURSOR FOR 5000 ROWS. The data was stored in an array with 5000 rows. Records were read from the array one at a time and the delete was performed using these values. After the first 5000 rows are deleted, we fetch the next block of 5000 for this table.

This year we have a requirement in which we have been asked to remove the table specific hard coding from the program. We are to create a list file that contains a list of table to be deleted and the criteria to be used for deletion. This required an overhaul to our program. This is the approach that we have for now:

1) We perform the delete on the tables in parallel. A CL program is run to read from the list file and for every table listed a delete program is submitted.
2) The delete program is a dynamic DB2 COBOL program in which we first find out the primary key for a table.
3) A SELECT query is PREPARED using the fields in the primary key.
4) We use SQLDA to load storage address for the different set of primary keys that can occur.
5) For every record that is fetched (using th primary key values), we run a DELETE statement. The FETCH statement is FETCH CSR_CURSOR USING DESCRIPTOR :SQLDA.

What I am not able to achieve using the FETCH statement in point# 5 is to FETCH for 5000 ROWS. It is my understanding that  I will get better performance if i FETCH in blocks of 5000 (this is just a random number we chose) and run DELETE for each of the 5000 records fetched than running a simple FETCH and running a DELETE for every record that is returned by the FETCH.
Please advise if I am correct in assuming that "FETCH in block of 5000 and DELETE" will be faster that "FETCH ALL and DELETE". If yes, how what is the syntax to fetch in blocks when using the SQLDA descriptor.

Thanks for the help in advance.

Regards
Ali.

Answer : Performance Changes in a DB2 program

I think this might be a littlle easier than you realized -- you can do a union between the two temp tables and call it done:
-- Here is the contents of your final table ...
Select Col1      Col2      Col3      Col4      Col5      Col6      Col7      DSTRecID      Country
from DBO.PROC1_TBL
union
select Col1      Col2      Col3      Col4      Col5      Col6      Col7      DSTRecID      Country
from DBO.PROC2_TBL

-- You can insert it into your final table as:
Insert into dbo.final_table (Col1      Col2      Col3      Col4      Col5      Col6      Col7      DSTRecID      Country )
Select Col1      Col2      Col3      Col4      Col5      Col6      Col7      DSTRecID      Country
from DBO.PROC1_TBL
union
select Col1      Col2      Col3      Col4      Col5      Col6      Col7      DSTRecID      Country
from DBO.PROC2_TBL


Random Solutions  
 
programming4us programming4us