开发者

Insert Into one duplicate update xx - Does it also update the INDEXes of the table?

I have a table with 30M+ rows, and each index update is expensive. I sometimes have to update and/or add 5000+ rows in a single insert.开发者_如何学运维 Sometimes all rows are new, sometimes some are new.

I cannot use update - since I don't know which is already in the table, so I use INSERT .. ON DUPLICATE KEY UPDATE for a single column.

This sometimes take a lot of time >5 sec.

Is there a better way to do it? maybe I did not explain myself clear enough :)


Are you issuing 5000+ separate insert statements? If so, lock the table while doing the inserts; it'll go a lot faster.


I added BEGIN TRANSACTION and COMMIT to perform the insert, and it enhanced performance by x4 to x10.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜