开发者

how to optimize a slow batch INSERT IGNORE in MySQL

开发者 https://www.devze.com 2023-02-28 09:10 出处:网络
Just finished rewriting many queries as batch queries - no more DB calls inside of foreach loops! One of these new batch开发者_运维问答 queries, and insert ignore into a pivot table, is taking 1-4 se

Just finished rewriting many queries as batch queries - no more DB calls inside of foreach loops!

One of these new batch开发者_运维问答 queries, and insert ignore into a pivot table, is taking 1-4 seconds each time. It is fairly large (~100 rows per call) and the table is also > 2 million rows.

This is the current bottleneck in my program. Should I consider something like locking the table (never done this before, but I have heard it is ... dangerous) or are there other options I should look at first.

As it is a pivot table, there is a unique key comprised of both the rows I am updating.


Are you using indexes? Indexing the correct columns speeds things up immensely. If you are doing a lot of updating and inserting, sometimes it makes sense to disable indexes until finished, since re-indexing takes time. I don't understand how locking the table would help. Is this table in user by other users or applications? That would be the main reason locking would increase speed.

0

精彩评论

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