From 7e1627d085089d1330a408c810c78bebef04278d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Mar 2006 05:01:11 -0800 Subject: [PATCH] Bug #17097: Partitions: failing ADD PRIMARY KEY leads to temporary rotten metadata,crash When doing an ALTER TABLE on a table using partitioning, force the table definition to get reloaded, since it may become invalid whenever the ALTER TABLE fails (even for an ALTER TABLE without specific partitioning changes). mysql-test/r/partition.result: New results mysql-test/t/partition.test: New regression test sql/sql_partition.cc: Always force table to get reloaded when we ALTER a partitioned table --- mysql-test/r/partition.result | 11 +++++++++++ mysql-test/t/partition.test | 11 +++++++++++ sql/sql_partition.cc | 18 ++++++++++-------- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 59e29046d90..4e4dc312887 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -422,4 +422,15 @@ partition_name partition_description table_rows x123 11,12 1 x234 NULL,1 1 drop table t1; +create table t1 (a int, b int) partition by list (a) +(partition p1 values in (1), partition p2 values in (2)); +alter table t1 add primary key (b); +ERROR HY000: A PRIMARY KEY need to include all fields in the partition function +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY LIST (a) (PARTITION p1 VALUES IN (1) ENGINE = MyISAM, PARTITION p2 VALUES IN (2) ENGINE = MyISAM) +drop table t1; End of 5.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index f22edb54756..d7fb109908a 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -540,4 +540,15 @@ select partition_name, partition_description, table_rows from information_schema.partitions where table_schema ='test'; drop table t1; +# +# Bug #17097: Partitions: failing ADD PRIMARY KEY leads to temporary rotten +# metadata,crash +# +create table t1 (a int, b int) partition by list (a) + (partition p1 values in (1), partition p2 values in (2)); +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +alter table t1 add primary key (b); +show create table t1; +drop table t1; + --echo End of 5.1 tests diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 257c1988cbd..1e1365f67a6 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4060,6 +4060,15 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, { DBUG_ENTER("prep_alter_part_table"); + /* + We are going to manipulate the partition info on the table object + so we need to ensure that the data structure of the table object + is freed by setting version to 0. table->s->version= 0 forces a + flush of the table object in close_thread_tables(). + */ + if (table->part_info) + table->s->version= 0L; + if (alter_info->flags & (ALTER_ADD_PARTITION | ALTER_DROP_PARTITION | ALTER_COALESCE_PARTITION | ALTER_REORGANIZE_PARTITION | @@ -4068,19 +4077,12 @@ uint prep_alter_part_table(THD *thd, TABLE *table, ALTER_INFO *alter_info, ALTER_REPAIR_PARTITION | ALTER_REBUILD_PARTITION)) { partition_info *tab_part_info= table->part_info; + uint flags= 0; if (!tab_part_info) { my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0)); DBUG_RETURN(TRUE); } - /* - We are going to manipulate the partition info on the table object - so we need to ensure that the data structure of the table object - is freed by setting version to 0. table->s->version= 0 forces a - flush of the table object in close_thread_tables(). - */ - uint flags= 0; - table->s->version= 0L; if (alter_info->flags == ALTER_TABLE_REORG) { uint new_part_no, curr_part_no;