Bug #76498 Online DDL "Make column NOT NULL" doesn't allow concurrent DML
Submitted: 27 Mar 2015 0:35 Modified: 18 Dec 2015 17:53
Reporter: Peiran Song Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:5.6.22, 5.6.25, 5.7.8 OS:Any
Assigned to: CPU Architecture:Any

[27 Mar 2015 0:35] Peiran Song
Description:
Per documentation at http://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html, "Make column NOT NULL" should

1) allow ALGORITHM=INPLACE if no columns contains NULL, and/or SQL_MODE doesn't include strick_all_tables

2) allow concurrent DML

But tests on 5.6.22 showed that both seem not true. 

How to repeat:
Server version: 5.6.22 MySQL Community Server (GPL)

mysql> CREATE TABLE `t_alter` (   `a` int(11) NOT NULL AUTO_INCREMENT,   `b` varchar(10), PRIMARY KEY (`a`),   KEY `idx_b` (`b`) ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t_alter values (1, "hi"), (2,"hello");
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

1) There is NO null values, but ALGORITHM=INPLACE is not allowed 

mysql> alter table t_alter modify `b` varchar(10) not null default '', lock=none, algorithm=inplace;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: cannot silently convert NULL values, as required in this SQL_MODE. Try ALGORITHM=COPY.

2) Tried empty SQL_MODE, no difference. 

mysql> show global variables like 'sql_mode';
+---------------+------------------------+
| Variable_name | Value                  |
+---------------+------------------------+
| sql_mode      | NO_ENGINE_SUBSTITUTION |
+---------------+------------------------+
1 row in set (0.00 sec)

mysql> set sql_mode = '';
Query OK, 0 rows affected (0.00 sec)

mysql> alter table t_alter modify `b` varchar(10) not null default '', lock=none, algorithm=inplace;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: cannot silently convert NULL values, as required in this SQL_MODE. Try ALGORITHM=COPY.

3)  algorithm=copy doesn't allow lock=none, basically lock=none is not supported for this alter.

mysql> alter table t_alter modify `b` varchar(10) not null default '', lock=none, algorithm=copy;
ERROR 1846 (0A000): LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED.
mysql> 
mysql> alter table t_alter modify `b` varchar(10) not null default '', lock=none;
ERROR 1846 (0A000): LOCK=NONE is not supported. Reason: cannot silently convert NULL values, as required in this SQL_MODE. Try LOCK=SHARED.

Suggested fix:
Either a code bug or documentation bug.
[27 Mar 2015 9:20] MySQL Verification Team
Hello Peiran Song,

Thank you for the report and test case.

Thanks,
Umesh
[18 Dec 2015 17:53] Daniel Price
Posted by developer:
 
The content has been revised as follows for "Make column NOT NULL":

STRICT_ALL_TABLES or STRICT_TRANS_TABLES SQL_MODE is required for the
operation to succeed. The operation fails if the column contains NULL
values.

http://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html

Thank you for the bug report.