I am using MySQL, I have a dump file, the content of it are something like following
TRUNCATE TABLE cars;
ALTER TABLE cars DISABLE KEYS;
INSERT INTO cars ... ;
ALTER TABLE cars ENABLE KEYS;
OPTIMIZE TABLE cars
I am wondering what are the following statements(from the above dump) doing respectively:
1.
ALTER TABLE cars DISABLE KEYS;
2.
ALTER TABLE cars ENABLE KEYS;
3.
OPTIMIZE TABLE cars
DISABLE KEYStells mySQL not to update indexes while you are inserting.ENABLE KEYStells it to recreate and then begin updating indexes again. Lastly OPTIMIZE does a number of things including updating statistics and sorting index pages. This is important after large inserts/updates/deletes.The code above would typically be used for a bulk insert/update. Disabling indexes helps the performance of large insert/update/delete operations.