How to improve INSERT INTO ... SELECT locking behavior
Posted
by Artem
on Stack Overflow
See other posts from Stack Overflow
or by Artem
Published on 2010-04-14T20:44:12Z
Indexed on
2010/04/24
5:53 UTC
Read the original article
Hit count: 368
In our production database, we ran the following pseudo-code SQL batch query running every hour:
INSERT INTO TemporaryTable (SELECT FROM HighlyContentiousTableInInnoDb WHERE allKindsOfComplexConditions are true)
Now this query itself does not need to be fast, but I noticed it was locking up HighlyContentiousTableInInnoDb, even though it was just reading from it. Which was making some other very simple queries take ~25 seconds (that's how long that other query takes).
Then I discovered that InnoDB tables in such a case are actually locked by a SELECT! http://www.mysqlperformanceblog.com/2006/07/12/insert-into-select-performance-with-innodb-tables/
But I don't really like the solution in the article of selecting into an OUTFILE, it seems like a hack (temporary files on filesystem seem sucky). Any other ideas? Is there a way to make a full copy of an InnoDB table without locking it in this way during the copy. Then I could just copy the HighlyContentiousTable to another table and do the query there.
© Stack Overflow or respective owner