Bug #80832 ALTER TABLE MODYIFY COLUMN does not set ALTER_CHANGE_COLUMN_DEFAULT flag
Submitted: 23 Mar 2016 8:46 Modified: 16 Nov 2016 19:19
Reporter: Olav Sandstå Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:5.7.13 OS:Any
Assigned to: CPU Architecture:Any

[23 Mar 2016 8:46] Olav Sandstå
Description:
It would be good if all ALTER statements that change the DEFAULT value for a column could set the Alter_info::ALTER_CHANGE_COLUMN_DEFAULT flag in the Alter_info structure. This would make it easier to check if a default value has been changed, eg. when needing to test for this in is_inplace_alter_impossible(). 

For instance, the following statement:

  ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7;

will set the ALTER_CHANGE_COLUMN_DEFAULT flag. But this statement:

  ALTER TABLE t1 MODIFY COLUMN a INTEGER DEFAULT 7;

does not set it. Instead it set ALTER_CHANGE_COLUMN (which is correct). But in the above case, only the DEFAULT value is changed (assuming the column already was of type INTEGER), so it would be good if also the ALTER_CHANGE_COLUMN_DEFAULT flag was set. 

How to repeat:
CREATE TABLE t1 (
  a INTEGER DEFAULT 5
);

INSERT INTO t1 VALUES (DEFAULT);

# This sets the ALTER_CHANGE_COLUMN_DEFAULT flag
ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7;

# These two do not set the ALTER_CHANGE_COLUMN_DEFAULT flag, but only the ALTER_CHANGE_COLUMN flag
ALTER TABLE t1 MODIFY COLUMN a INTEGER DEFAULT 6;
ALTER TABLE t1 CHANGE COLUMN a a INTEGER DEFAULT 8;

DROP TABLE t1;
[16 Nov 2016 19:19] Paul DuBois
Posted by developer:
 
Noted in 8.0.1 changelog.

In-place ALTER TABLE operations are now possible for column
modifications of tables containing generated columns that depend on
columns with a DEFAULT value if the modified columns are not involved
in the generated column expressions. For example, changing the NULL
property of a separate column can be done in place without a table
rebuild.