I have temp table with 14k records and main table with 5 million records, I am updating main table from temp table using below SQL
UPDATE customPricing t1
INNER JOIN customPricingIncremental t2 ON (t1.customerClass=t2.customerClass and t1.customerName=t2.customerName and t1.svcType=t2.svcType and t1.svcDuration=t2.svcDuration and t1.durationPeriod=t2.durationPeriod and t1.partNumberSKU=t2.partNumberSKU)
SET t1.customerId= t2.customerId, t1.customerNumber= t2.customerNumber, t1.custPartNumber=t2.custPartNumber, t1.sppl= t2.sppl ,t1.priceMSRP= t2.priceMSRP, t1.partnerPriceDistiDvarOEM= t2.partnerPriceDistiDvarOEM, t1.msrpSvcPrice=t2.msrpSvcPrice, t1.partnerSvcPrice=t2.partnerSvcPrice, t1.msrpBundlePrice=t2.msrpBundlePrice, t1.partnerBundlePrice=t2.partnerBundlePrice, t1.startDate=t2.startDate, t1.endDate=t2.endDate, t1.currency=t2.currency, t1.countryCode=t2.countryCode, t1.inventoryItemId=t2.inventoryItemId, t1.flexField1=t2.flexField1, t1.flexField2=t2.flexField2, t1.flexField3=t2.flexField3, t1.flexField4=t2.flexField4, t1.flexField5=t2.flexField5
CustomerClass, customerName, durationPeriod, svcDuration & partNumberSKU
all are indexes on both tables with length of 10 only, there is no primary key/unique indexes for both.
It takes forever to update the table, and I get timedout in the end.
What I am doing wrong ?
Nitesh
Try to disable nonunique keys temporarily: ALTER TABLE customPricing DISABLE KEYS
Now run your query, and then enable them again:
ALTER TABLE customPricing ENABLE KEYS
Do this from the mysql client or a script instead of phpmyadmin as the queries might only apply to the current session.
Also, watch out for any triggers in the target table.
Read more about
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.