0

If I initiate a TRUNCATE on a table, what happens to INSERTs executed against that table? Are they queued until the TRUNCATE completes, or are they simply discarded? I know this condition is quite rare but it's possible.

I'm using PDO transactions with MySQL, however I have to TRUNCATE the table after the transaction. I don't want to use DELETE from within the transaction as it's slower than TRUNCATE. This is for a stats logger on a website, so concurrent requests to the same table are easily possible.

The queries executed are (from the query log):

SHOW PROCESSLIST
SELECT COUNT(*) AS Counter FROM stats_current
START TRANSACTION
LOCK TABLES stats_current WRITE, stats WRITE
UNLOCK TABLES
LOCK TABLES stats_customer_current WRITE, stats_customer WRITE
UNLOCK TABLES
LOCK TABLES stats_update_queue WRITE, stats_customer_current WRITE, stats_customer WRITE
UNLOCK TABLES
TRUNCATE stats_update_queue
commit
Bojangles
  • 99,427
  • 50
  • 170
  • 208

0 Answers0