In our production database, we ran the following pseudo-code SQL batch query running every hour:
INSERT INTO TemporaryTable
(SELECT FROM HighlyContentiou
I was facing the same issue using CREATE TEMPORARY TABLE ... SELECT ...
with SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction
.
Based on your initial query, my problem was solved by locking the HighlyContentiousTableInInnoDb
before starting the query.
LOCK TABLES HighlyContentiousTableInInnoDb READ;
INSERT INTO TemporaryTable
(SELECT FROM HighlyContentiousTableInInnoDb
WHERE allKindsOfComplexConditions are true)
UNLOCK TABLES;