patternsqlMinor
Remove redundant disable/enable key statements from mysqldump
Viewed 0 times
enablestatementsdisablemysqldumpremoveredundantfromkey
Problem
A standard mysqldump will create a table, disable keys, insert the data, and re-enable keys. There are reasons for this. However, when a table is empty, the keys are still disabled and re-enabled.
This little block of code, repeated multiple times, is surely slowing down inserts for no good reason. Is there any way to remove it, or to prevent its creation in the first place? I imagine that it is no big deal, but I’m still curious.
LOCK TABLES `Brands` WRITE;
/*!40000 ALTER TABLE `Brands` DISABLE KEYS */;
/*!40000 ALTER TABLE `Brands` ENABLE KEYS */;
UNLOCK TABLES;This little block of code, repeated multiple times, is surely slowing down inserts for no good reason. Is there any way to remove it, or to prevent its creation in the first place? I imagine that it is no big deal, but I’m still curious.
Solution
Don't worry,
These commands,
I have written about this many times as far back as May 2011
See MySQL Documentation on this
You can create dumps without them with
DISABLE KEYS and ENABLE KEYS are artifacts from mysqldump of bygone daysThese commands,
DISABLE KEYS and ENABLE KEYS have absolutely no effect on InnoDB Tables (they were not implemented for the InnoDB Storage Engine). They were designed specifically for MyISAM tables. You will just get warnings.I have written about this many times as far back as May 2011
See MySQL Documentation on this
You can create dumps without them with
mysqldump ... | grep -v "ABLE KEYS" > dumpfile.sqlCode Snippets
mysqldump ... | grep -v "ABLE KEYS" > dumpfile.sqlContext
StackExchange Database Administrators Q#328298, answer score: 3
Revisions (0)
No revisions yet.