Search code examples
javaprepared-statementspring-jdbc

Update query inside the Batch update execution is taking long time


System.out.println("multipleBatchUpdateCheckErroreValues.update starting time------"+ new DateTime());     
multipleBatchUpdateCheckError(
            vSql.toString(),  //sql query
            pPriceMap.toList(), //rows
            50, //batch size
            new ObjectPreparedStatementSetter() {
              public void setValues(Object row, PreparedStatement ps, int rowNo) throws SQLException {
                Price vPrice = (Price) row;
                prepareValues(vPrice, ps, UPDATE);
              }
            });
        }
System.out.println("multipleBatchUpdateCheckErroreValues.update ending time------"
            + new DateTime());

In the above code, Update is taking too much time to finish. How to optimize the below code execution time?

SQL Query is

UPDATE PRICE_T
   SET TO_TIME = ?,
       PRICE_EXCLUDING_TAX = ?,
       PRICE_INCLUDING_TAX = ?,
       REASON = ?,
       PRIORITY_TYPE = ?,
       TRANS_TIME = ?,
       DEL_TIME = ?,
       UPD_TIME = ?
 WHERE CLASS = ?
   and CLASS_TYPE = ?
   and COUNTRY_CODE = ?
   and ITEM_NO = ?
   and ITEM_TYPE = ?
   and CURRENCY_CODE = ?
   and PRICE_TYPE = ?
   and FROM_TIME = ?

Total rows 10k, columns 14, time taking to process is 35 mins.


Solution

  • After creating the indexes on all the 8 columns of where clause , the execution time decreased to 1 second.