With MySQL, how long does an "ALTER TABLE ... DISABLE KEYS;" statement last?
Solution 1
The Fine Manual (which is well worth Reading) suggests that the effect of that statement lasts until a corresponding ALTER TABLE ... ENABLE KEYS
statement is executed.
Solution 2
ALTER TABLE ... DISABLE KEYS and ALTER TABLE ... ENABLE KEYS do not work for InnoDB.
I addressed this back in February 13, 2011.
UPDATE 2011-07-18 12:35 EDT
This is a very good question because it expose an evil that was left over in MySQL. The mysqldump program blindly drops DISABLE KEYS and ENABLE KEYS around the creation and load over every table without regard to storage engine. Since DISABLE KEYS and ENABLE KEYS do not work (in the best case has no effect) on InnoDB tables as it works properly for MyISAM, this unknown fact should be better documented by the MySQL community. Oh yea, MySQL is in the middle of the Galactic Empire known as Oracle. I will not be holding my breath on documentation changes forthcoming.
Related videos on Youtube
Daniel Beardsley
Updated on September 18, 2022Comments
-
Daniel Beardsley over 1 year
If you disable the keys (suspending indexing) on a mysql INNODB table, how long does that setting last?
For a query like:
ALTER TABLE users DISABLE KEYS;
Do the keys get re-enabled at the end of the script? or do they last until you explicitly turn indexing back on?
-
John Gardeniers almost 13 yearsMaking a statement is one thing. Yelling it out by using both caps and bold is somewhat excessive and completely unnecessary.
-
RolandoMySQLDBA almost 13 years@John : I am sorry I seem overly enthusiastic. I am not angry with anyone. ALTER TABLE DISABLE/ENABLE KEYS against InnoDB is not well documented. Oracle is not going to improve things either.
-
pahnin about 7 years@RolandoMySQLDBA is there any workaround to avoid mysqldump putting DISABLE KEYS and ENABLE KEYS in the dump file?