Skip to content
  • Nisha Gopalakrishnan's avatar
    baf15573
    BUG#25385334: MYSQL 5.7 ERROR WITH ALTER TABLE MODIFY SYNTAX · baf15573
    Nisha Gopalakrishnan authored
                  AND DATETIME TYPE.
    
    Analysis:
    ========
    The problem reported in the bug is:
    ALTER TABLE MODIFY operation with FIRST/AFTER clause for
    DATE/DATETIME and GEOMETRIC types to modify the position
    of columns failed with an error.
    
    ALTER TABLE operations for DATE/DATETIME and GEOMETRIC
    types require additional handling. The cases where
    an error should be reported is discussed below:
    
    a) When a new NOT NULL column of type DATE/DATETIME/GEOMETRIC
       without a default value is added to a table which is not
       empty, a zero date and empty string is used. Under
       NO_ZERO_DATE and STRICT SQL mode, zero date is not allowed.
       An empty string is an invalid value for GEOMETRIC type.
    b) When a column of different data type which can hold NULL
       value is changed/modified to GEOMETRIC NOT NULL type,
       the NULL value is converted to a empty string which is
       invalid value for GEOMETRIC types. Note that data type
       conversion of existing columns is possible only using
       COPY algorithm. Attempt to change/modify datatypes of
       existing columns using INPLACE algorithm is not supported
       and will fail with an error.
    c) GEOMETRIC/DATE/DATETIME can be modified from NULLABLE
       columns to NOT NULL using COPY and INPLACE algorithm.
       When the table holds NULL value, an error is reported
       at SQL layer for COPY algorithm, while the SE enforces
       the restriction for INPLACE algorithm.
    
    Patch for bug19880316 utilized the flag 'error_if_not_empty'
    to enforce the restrictions for GEOMETRIC types listed above
    for COPY algorithm and also handled the case of ALTER TABLE,
    ADD column for INPLACE algorithm.
    
    The patch for bug19880316 introduced a bug-ALTER TABLE MODIFY/
    CHANGE operation with FIRST/AFTER clause for GEOMETRIC types
    using COPY/INPLACE algorithm to modify the position of columns
    failed with an error. The scope of the bug was extended to
    DATE/DATETIME types with the bug fix for bug16888677 which is
    now raised in the current bug report.
    
    The flag 'error_if_not_empty' is set in 'mysql_prepare_alter_table()'
    when:
    * Field is DATE/DATETIME or GEOMETRIC.
    * Field is NOT NULL and DEFAULT value is not supplied.
    
    The flag is later utilized to report error "Invalid use of NULL
    value" in mysql_inplace_alter_table() if:
    * The MDL lock is not upgraded from SU to block writes.
    * Table is not empty.
    
    The ALTER operation reported in the bug report can be performed
    using INPLACE algorithm which does not require the SE to block writes.
    Hence the MDL lock is not upgraded. The flag was incorrectly set for
    the above ALTER operation which triggered the error.
    
    Fix:
    ====
    a) The flag 'error_if_not_empty' is set when new NOT NULL columns
       of DATE/DATETIME/GEOMETRIC types are added.(Note that the other
       case where the flag is set when datatype is modified/changed to
       GEOMETRIC NOT NULL from NON-GEOMETRIC types using COPY algorithm
       introduced by patch for bug 19880316).
    
    b) Also the check to ensure that MDL lock is upgraded
       from SU is removed from 'mysql_inplace_alter_table()'.
       ALTER TABLE, INPLACE algorithm does not support
       changing/modifying data type. So, the flag
       'error_if_not_empty' is set only for ALTER TABLE,
       ADD which takes an exclusive lock.
    
    c) ALTER TABLE, MODIFY/CHANGE using INPLACE algorithm to change
       columns from NULL to NOT NULL, the validation is pushed down
       to SE.
    
    d) Change in error message is recorded for the test
       'alter_spatial_index.test' in innodb_gis since the fix
       pushes the check during the data validation.
    baf15573
    BUG#25385334: MYSQL 5.7 ERROR WITH ALTER TABLE MODIFY SYNTAX
    Nisha Gopalakrishnan authored
                  AND DATETIME TYPE.
    
    Analysis:
    ========
    The problem reported in the bug is:
    ALTER TABLE MODIFY operation with FIRST/AFTER clause for
    DATE/DATETIME and GEOMETRIC types to modify the position
    of columns failed with an error.
    
    ALTER TABLE operations for DATE/DATETIME and GEOMETRIC
    types require additional handling. The cases where
    an error should be reported is discussed below:
    
    a) When a new NOT NULL column of type DATE/DATETIME/GEOMETRIC
       without a default value is added to a table which is not
       empty, a zero date and empty string is used. Under
       NO_ZERO_DATE and STRICT SQL mode, zero date is not allowed.
       An empty string is an invalid value for GEOMETRIC type.
    b) When a column of different data type which can hold NULL
       value is changed/modified to GEOMETRIC NOT NULL type,
       the NULL value is converted to a empty string which is
       invalid value for GEOMETRIC types. Note that data type
       conversion of existing columns is possible only using
       COPY algorithm. Attempt to change/modify datatypes of
       existing columns using INPLACE algorithm is not supported
       and will fail with an error.
    c) GEOMETRIC/DATE/DATETIME can be modified from NULLABLE
       columns to NOT NULL using COPY and INPLACE algorithm.
       When the table holds NULL value, an error is reported
       at SQL layer for COPY algorithm, while the SE enforces
       the restriction for INPLACE algorithm.
    
    Patch for bug19880316 utilized the flag 'error_if_not_empty'
    to enforce the restrictions for GEOMETRIC types listed above
    for COPY algorithm and also handled the case of ALTER TABLE,
    ADD column for INPLACE algorithm.
    
    The patch for bug19880316 introduced a bug-ALTER TABLE MODIFY/
    CHANGE operation with FIRST/AFTER clause for GEOMETRIC types
    using COPY/INPLACE algorithm to modify the position of columns
    failed with an error. The scope of the bug was extended to
    DATE/DATETIME types with the bug fix for bug16888677 which is
    now raised in the current bug report.
    
    The flag 'error_if_not_empty' is set in 'mysql_prepare_alter_table()'
    when:
    * Field is DATE/DATETIME or GEOMETRIC.
    * Field is NOT NULL and DEFAULT value is not supplied.
    
    The flag is later utilized to report error "Invalid use of NULL
    value" in mysql_inplace_alter_table() if:
    * The MDL lock is not upgraded from SU to block writes.
    * Table is not empty.
    
    The ALTER operation reported in the bug report can be performed
    using INPLACE algorithm which does not require the SE to block writes.
    Hence the MDL lock is not upgraded. The flag was incorrectly set for
    the above ALTER operation which triggered the error.
    
    Fix:
    ====
    a) The flag 'error_if_not_empty' is set when new NOT NULL columns
       of DATE/DATETIME/GEOMETRIC types are added.(Note that the other
       case where the flag is set when datatype is modified/changed to
       GEOMETRIC NOT NULL from NON-GEOMETRIC types using COPY algorithm
       introduced by patch for bug 19880316).
    
    b) Also the check to ensure that MDL lock is upgraded
       from SU is removed from 'mysql_inplace_alter_table()'.
       ALTER TABLE, INPLACE algorithm does not support
       changing/modifying data type. So, the flag
       'error_if_not_empty' is set only for ALTER TABLE,
       ADD which takes an exclusive lock.
    
    c) ALTER TABLE, MODIFY/CHANGE using INPLACE algorithm to change
       columns from NULL to NOT NULL, the validation is pushed down
       to SE.
    
    d) Change in error message is recorded for the test
       'alter_spatial_index.test' in innodb_gis since the fix
       pushes the check during the data validation.
Loading