10.6.2 Bulk Data Loading for MyISAM Tables (original) (raw)

10.6.2 Bulk Data Loading for MyISAM Tables

These performance tips supplement the general guidelines for fast inserts in Section 10.2.5.1, “Optimizing INSERT Statements”.

ALTER TABLE tbl_name DISABLE KEYS;  
ALTER TABLE tbl_name ENABLE KEYS;  
LOCK TABLES a WRITE;  
INSERT INTO a VALUES (1,23),(2,34),(4,33);  
INSERT INTO a VALUES (8,26),(6,29);  
...  
UNLOCK TABLES;  

This benefits performance because the index buffer is flushed to disk only once, after allINSERT statements have completed. Normally, there would be as many index buffer flushes as there are INSERT statements. Explicit locking statements are not needed if you can insert all rows with a singleINSERT.
Locking also lowers the total time for multiple-connection tests, although the maximum wait time for individual connections might go up because they wait for locks. Suppose that five clients attempt to perform inserts simultaneously as follows: