简体   繁体   中英

DB2 bulk update take long time

We have 3 million record in our database. We need to update postalcode column with same postalcode column by removing first letter 0.

identifyno,addresstypecode is composite primary column in addresss table.

We used below query 300 times(300*10000=3000000)

UPDATE db2inst1.address SET postalcode = SUBSTR(postalcode,2) WHERE (identifyno,addresstypecode) IN (SELECT identifyno,addresstypecode FROM db2inst1.address WHERE countrycode='IN' AND SUBSTR(postalcode,1,1)='0' FETCH FIRST 10000 rows only ); commit;

It is taking long time ( almost 1 day) to execute.

Please help me to improve the performance of the query.

I think the problem is that your query touches the same table twice. You can simplify it to:

UPDATE db2inst1.address 
SET postalcode = SUBSTR(postalcode,2) 
WHERE countrycode='IN' AND SUBSTR(postalcode,1,1)='0'

I don't understand why you are only updating the first 1000 records, especially since you do not have an ORDER BY clause, so the order is arbitrarily assigned by the database engine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM