diff --git a/mysql-test/main/partition_innodb.result b/mysql-test/main/partition_innodb.result index ed79bbbe48d..605ac38384e 100644 --- a/mysql-test/main/partition_innodb.result +++ b/mysql-test/main/partition_innodb.result @@ -580,6 +580,33 @@ DROP TABLE t1; # Bug#57985 "ONLINE/FAST ALTER PARTITION can fail and leave the # table unusable". # +CREATE TABLE t1 (a bigint not null, b int not null, PRIMARY KEY (a)) +ENGINE = InnoDB PARTITION BY KEY(a) PARTITIONS 2; +INSERT INTO t1 values (0,1), (1,2); +# The below ALTER should fail. It should leave the +# table in its original, non-corrupted, usable state. +ALTER TABLE t1 ADD UNIQUE KEY (b); +ERROR HY000: A UNIQUE INDEX must include all columns in the table's partitioning function +# The below statements should succeed, as ALTER should +# have left table intact. +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` bigint(20) NOT NULL, + `b` int(11) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 + PARTITION BY KEY (`a`) +PARTITIONS 2 +SELECT * FROM t1; +a b +1 2 +0 1 +DROP TABLE t1; +# +# Bug#57985 "ONLINE/FAST ALTER PARTITION can fail and leave the +# table unusable". +# DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a bigint not null, b int not null, PRIMARY KEY (a)) ENGINE = InnoDB PARTITION BY KEY(a) PARTITIONS 2; diff --git a/mysql-test/main/partition_innodb.test b/mysql-test/main/partition_innodb.test index e09a2b4f9d3..ae0ce59fabc 100644 --- a/mysql-test/main/partition_innodb.test +++ b/mysql-test/main/partition_innodb.test @@ -665,6 +665,25 @@ OPTIMIZE TABLE t1; SET SESSION sql_mode = @old_mode; DROP TABLE t1; + +--echo # +--echo # Bug#57985 "ONLINE/FAST ALTER PARTITION can fail and leave the +--echo # table unusable". +--echo # +CREATE TABLE t1 (a bigint not null, b int not null, PRIMARY KEY (a)) + ENGINE = InnoDB PARTITION BY KEY(a) PARTITIONS 2; +INSERT INTO t1 values (0,1), (1,2); +--echo # The below ALTER should fail. It should leave the +--echo # table in its original, non-corrupted, usable state. +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +ALTER TABLE t1 ADD UNIQUE KEY (b); +--echo # The below statements should succeed, as ALTER should +--echo # have left table intact. +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + + --echo # --echo # Bug#57985 "ONLINE/FAST ALTER PARTITION can fail and leave the --echo # table unusable". diff --git a/mysql-test/suite/versioning/r/partition_innodb.result b/mysql-test/suite/versioning/r/partition_innodb.result index de3521b6aa3..f5945304899 100644 --- a/mysql-test/suite/versioning/r/partition_innodb.result +++ b/mysql-test/suite/versioning/r/partition_innodb.result @@ -20,7 +20,7 @@ alter table t1 partition by system_time ( partition p0 history, partition pn current ); -ERROR HY000: `row_start` must be of type TIMESTAMP(6) for system-versioned table `#sql-temporary` +ERROR HY000: `row_start` must be of type TIMESTAMP(6) for system-versioned table `t1` create or replace table t ( a int primary key, row_start bigint unsigned as row start invisible, diff --git a/mysql-test/suite/versioning/t/partition_innodb.test b/mysql-test/suite/versioning/t/partition_innodb.test index bb4fe50ce91..d7527ff7410 100644 --- a/mysql-test/suite/versioning/t/partition_innodb.test +++ b/mysql-test/suite/versioning/t/partition_innodb.test @@ -21,7 +21,6 @@ create or replace table t1( period for system_time(row_start, row_end) ) engine=InnoDB with system versioning; ---replace_regex /#sql-[0-9a-f_]*/#sql-temporary/ --error ER_VERS_FIELD_WRONG_TYPE alter table t1 partition by system_time ( partition p0 history, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index ba44972e88a..ca26c7149e5 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5055,43 +5055,7 @@ int create_table_impl(THD *thd, const LEX_CSTRING &orig_db, thd->thread_specific_used= TRUE; create_info->table= table; // Store pointer to table } -#ifdef WITH_PARTITION_STORAGE_ENGINE - else if (thd->work_part_info && frm_only) - { - /* - For partitioned tables we can't find some problems with table - until table is opened. Therefore in order to disallow creation - of corrupted tables we have to try to open table as the part - of its creation process. - In cases when both .FRM and SE part of table are created table - is implicitly open in ha_create_table() call. - In cases when we create .FRM without SE part we have to open - table explicitly. - */ - TABLE table; - TABLE_SHARE share; - init_tmp_table_share(thd, &share, db.str, 0, table_name.str, path); - - bool result= (open_table_def(thd, &share, GTS_TABLE) || - open_table_from_share(thd, &share, &empty_clex_str, 0, - (uint) READ_ALL, 0, &table, true)); - if (!result) - (void) closefrm(&table); - - free_table_share(&share); - - if (result) - { - char frm_name[FN_REFLEN]; - strxnmov(frm_name, sizeof(frm_name), path, reg_ext, NullS); - (void) mysql_file_delete(key_file_frm, frm_name, MYF(0)); - (void) file->ha_create_partitioning_metadata(path, NULL, CHF_DELETE_FLAG); - goto err; - } - } -#endif - error= 0; err: THD_STAGE_INFO(thd, stage_after_create);