Question : Bulk updates in SYBASE using Java Batch Updates

I have to execute many updates on a table using java batch updates, but i when i try to execute my code on 22,000 records, it just hangs.

How can i optimize the updates to not use NOARCHIVELOG, as in Oracle database. How can i make my updates faster?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
String updateSql = "UPDATE AMF " +
                    " SET BLOCKED_CV = ?, " +
                    " BLOCKED_FC = ? " +
                    " WHERE BRANCH_CODE = ? " +
                    " AND CURRENCY_CODE = ? " +
                    " AND GL_CODE = ? " +
                    " AND CIF_SUB_NO = ? " +
                    " AND SL_NO = ? ";
            statement = conn.prepareStatement(updateSql);
            if (totalColumns > 0) {
                //Now writing records in csv file
                for (int r = 0; r < totalRows; r++) {
 
                    rowVector = (Vector) IADataVector.get(r);
                    // only update those blocked amounts which exists on imal side
                    if (rowVector.get(INDEX_PIBAS_ADDREF) != null &&
                            rowVector.get(INDEX_IMAL_ADDREF) != null) {
 
                        //System.out.println("updateRows= " + updateRows);
 
                        blockAmount = new Double(rowVector.get(INDEX_PIBAS_SHDWBALN).toString()).doubleValue();
                        branch = new Integer(rowVector.get(INDEX_IMAL_BRANCH).toString()).intValue();
                        currency = new Integer(rowVector.get(INDEX_IMAL_CURRENCY).toString()).intValue();
                        glCode = new Long(rowVector.get(INDEX_IMAL_GL).toString()).longValue();
                        cifNo = new Long(rowVector.get(INDEX_IMAL_CIF).toString()).longValue();
                        slNO = new Integer(rowVector.get(INDEX_IMAL_SL).toString()).intValue();
 
                        if (currency == 586) {
                            statement.setDouble(1, blockAmount);
                            statement.setLong(2, 0);
                        } else {
                            statement.setLong(1, 0);
                            statement.setDouble(2, blockAmount);
                        }
                        statement.setInt(3, branch);
                        statement.setInt(4, currency);
                        statement.setLong(5, glCode);
                        statement.setLong(6, cifNo);
                        statement.setInt(7, slNO);
 
                        statement.addBatch();
                    }
                    updateRows++;
                }
                statement.executeBatch();
            }
            statement.close();
            conn.commit();
Open in New Window Select All

Answer : Bulk updates in SYBASE using Java Batch Updates

Gosh no!!!  Those are correlated subqueries and performance will be incredibly bad.  The optimzer MIGHT try to flatten that out into a JOIN but I suspect that it will join to the work table twice at best and in the worst case, it will do two queries for every row in the table.  Not good.

The correct syntax is a JOIN between the driving and target tables...  As you can see in the code snippet, it can work for any number of columns and there is one, clean join.  The work table is the driver since it will have many fewer rows in it.  I would remove the primary key as it will not be needed and, in fact, will only slow things down while you try to load it.

BTW, all the documentation is available for download as PDFs for free from sybooks.sybase.com so you can have a ready reference to the syntax of the commands, statements, and functions.

Also, I am curious about one thing.  You say this is ASE and the code you have posted certainly looks like ASE however, this command is terminated with a semi-colon; a decidedly non-ASE thing to do.

One other thought I had about configuration of the server.  You are using a good chunk of the RAM (9+ out of 16GB), which in Windows may invite paging.  It ain't too smart that way.  There are two Sybase configuration parameters you want to make certain are set.  The first grabs all of the memory at startup and the second locks the shared mamory segment into RAM so it won't be paged.  Both of those options should be set.  You can find them in the server configuration section of Sybase Central.  Just right mouse click on the server icon and configuration will be one of the options.

Regards,
Bill
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
UPDATE AMF
   SET A.BLOCKED_CV = W.BLOCKED_CV,
       A.BLOCKED_FC = W.BLOCKED_FC
  FROM AMF_BLOCK_SYNC_MK W
  JOIN AMF A
    ON W.COMP_CODE = A.COMP_CODE
   AND W.BRANCH_CODE = A.BRANCH_CODE
   AND W.CURRENCY_CODE = A.CURRENCY_CODE
   AND W.GL_CODE = A.GL_CODE
   AND W.CIF_SUB_NO = A.CIF_SUB_NO
   AND W.SL_NO = A.SL_NO
Open in New Window Select All
Random Solutions  
 
programming4us programming4us