Quote:
|
Originally Posted by sidkolia
Hi
We have a Java application that inserts a certain amount of data into a set of tables.
After the insert the data is processed one row a a time and inserts are made into the main tables...
Our problem is that on a mySQL DB this takes about 1 1/2 hours and
on our DB2 about 14 hours! It seems that the problem is that the indexes
on the first set of tables are not updated efter the insert therefore the
updates takes too long to perform.
We guess that this could be fixed by running a reorg or update statistics but we cant figure out how to do it between the two jobs!
The JDBC-driver does'nt accept the reorg commands so we cant do it through
the application.
Does anone have any ideas???
Sincerely
Stefan Sidholm
Sweden
|
JDBC - set autocommit off, then do commits ever N records.
Better still - use the batch capabilities:
PreparedStatement pstmt =
con.prepareStatement("INSERT INTO XXX values (?, ?)");
for (int i=0; i<ITER; i++) {
pstmt.setString(1, "STRING" + i);
pstmt.setString(2, "another string");
pstmt.addBatch();
}
int[] res = pstmt.executeBatch();
con.commit();
Keep the batch sizes reasonable, 1000 rows for small ones, less if the rows are big... but I've found a big performance gain, especially if the app is running remotely.