Aron Solberg
Aron Solberg

Reputation: 6878

In MySQL 5.6 "Alter Table Add Columns" not allowing DML concurrency

MySQL 5.6 claims that DDL operations will be run with the maximum possible concurrency. http://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html

The “Allows Concurrent DML?” column shows which operations can be performed fully online; the preferred value is “Yes”. You can specify LOCK=NONE to assert that full concurrency is allowed during the DDL, but MySQL automatically allows this level of concurrency when possible. When concurrent DML is allowed, concurrent queries are also always allowed.

However I just tried an "ALTER TABLE ADD COLUMN... " statement and the table appeared locked during this operation. When I reran the statement and appended ",ALGORITHM=inplace, LOCK=none" then it took longer, but the table remained available to be used. I thought MySQL would use the highest level of concurrency available for a particular statement so why did I have to specify them explicitly?

Upvotes: 4

Views: 1907

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562661

The fact that Online DDL allows concurrent DML does not necessarily mean that it takes every opportunity to do so by default.

The language about "allows this level of concurrency when possible" is a little bit hard to interpret. You may assume that MySQL always uses the inplace algorithm when it is possible, but think of it in the reverse: it really means that it does not allow the inplace algorithm when it is not possible. If inplace DDL is possible, it allows it, but does not actually use that algorithm unless you request it.

You observed yourself that Online DDL is slower. Is it not a reasonable default to use the faster method (since most people want things to be faster)? After all, the table may be small enough that a non-inplace ALTER will take less than 1 second, and so it's not much of an interruption. Enabling inplace ALTER in all cases where it is possible would make them take longer by default.

Upvotes: 3

Related Questions