Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-13851

Always check table options in ALTER TABLE…ALGORITHM=INPLACE

Details

    Description

      The test encryption.innodb-spatial-index creates a table with ENCRYPTED=YES, and then expects an ADD SPATIAL INDEX, ALGORITHM=COPY operation to fail. However, an operation with FORCE, ALGORITHM=COPY is just fine (in both 10.1 and 10.2):

      --source include/have_innodb.inc
      --source include/have_file_key_management_plugin.inc
       
      CREATE TABLE t1 (pk INT PRIMARY KEY AUTO_INCREMENT,
      c VARCHAR(256), coordinate POINT NOT NULL) ENCRYPTED=YES ENGINE=INNODB;
      ALTER TABLE t1 FORCE, ALGORITHM=COPY;
      ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
      DROP TABLE t1;
      

      In my opinion, ALTER TABLE...ALGORITHM=COPY must always succeed, and it must always preserve those table attributes that were not specified in the ALTER.

      Attachments

        Issue Links

          Activity

            MDEV-11974 disallows the creation of encrypted tables with SPATIAL INDEX, because encryption uses a field that is used for something else (SSN, split sequence number) in the InnoDB 5.7 R-tree index implementation.

            So, the bug is not that ADD SPATIAL INDEX, ALGORITHM=COPY is refused, but it is that ADD SPATIAL INDEX, ALGORITHM=INPLACE is not refused when the table is encrypted.

            marko Marko Mäkelä added a comment - MDEV-11974 disallows the creation of encrypted tables with SPATIAL INDEX, because encryption uses a field that is used for something else (SSN, split sequence number) in the InnoDB 5.7 R-tree index implementation. So, the bug is not that ADD SPATIAL INDEX, ALGORITHM=COPY is refused, but it is that ADD SPATIAL INDEX, ALGORITHM=INPLACE is not refused when the table is encrypted.

            This (so far untested) fix should take care of it:

            diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
            index 186665b8c8e..ee8e06ea19f 100644
            --- a/storage/innobase/handler/handler0alter.cc
            +++ b/storage/innobase/handler/handler0alter.cc
            @@ -5606,10 +5606,7 @@ ha_innobase::prepare_inplace_alter_table(
             		/* The clustered index is corrupted. */
             		my_error(ER_CHECK_NO_SUCH_TABLE, MYF(0));
             		DBUG_RETURN(true);
            -	}
            -
            -	if (ha_alter_info->handler_flags
            -	    & Alter_inplace_info::CHANGE_CREATE_OPTION) {
            +	} else {
             		const char* invalid_opt = info.create_options_are_invalid();
             
             		/* Check engine specific table options */
            

            marko Marko Mäkelä added a comment - This (so far untested) fix should take care of it: diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 186665b8c8e..ee8e06ea19f 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -5606,10 +5606,7 @@ ha_innobase::prepare_inplace_alter_table( /* The clustered index is corrupted. */ my_error(ER_CHECK_NO_SUCH_TABLE, MYF(0)); DBUG_RETURN(true); - } - - if (ha_alter_info->handler_flags - & Alter_inplace_info::CHANGE_CREATE_OPTION) { + } else { const char* invalid_opt = info.create_options_are_invalid(); /* Check engine specific table options */

            With the above patch, we do get one test failure:

            CURRENT_TEST: innodb_zip.create_options
            mysqltest: At line 252: query 'ALTER TABLE t1 ADD COLUMN f1 INT' failed: 1478: Table storage engine 'InnoDB' does not support the create option 'ROW_FORMAT'
            

            I think that this is the proper thing to do. The context:

            CREATE TABLE t1 ( i INT ) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
            SET GLOBAL innodb_file_format=Antelope;
            ALTER TABLE t1 ADD COLUMN f1 INT;
            

            This would even force a table rebuild, creating a new .ibd file.
            However, the create options would be validated for any form of ALTER TABLE, such as renaming columns or changing default values. That may feel a bit excessive.

            marko Marko Mäkelä added a comment - With the above patch, we do get one test failure: CURRENT_TEST: innodb_zip.create_options mysqltest: At line 252: query 'ALTER TABLE t1 ADD COLUMN f1 INT' failed: 1478: Table storage engine 'InnoDB' does not support the create option 'ROW_FORMAT' I think that this is the proper thing to do. The context: CREATE TABLE t1 ( i INT ) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4; SET GLOBAL innodb_file_format=Antelope; ALTER TABLE t1 ADD COLUMN f1 INT ; This would even force a table rebuild, creating a new .ibd file. However, the create options would be validated for any form of ALTER TABLE, such as renaming columns or changing default values. That may feel a bit excessive.

            People

              marko Marko Mäkelä
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.