From b32237c3a74a2504db3c98f95502db6ac4f1549b Mon Sep 17 00:00:00 2001 From: "mikael@c-870ae253.1238-1-64736c10.cust.bredbandsbolaget.se" <> Date: Thu, 4 May 2006 13:18:55 -0400 Subject: [PATCH 1/4] BUG 19062: CREATE TABLE ... PARTITION BY ... AS SELECT don't create partitioned table --- mysql-test/r/partition.result | 9 +++++++++ mysql-test/t/partition.test | 10 ++++++++++ sql/sql_parse.cc | 20 +++++++++++--------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 0da071374ea..ba24f34c383 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -886,4 +886,13 @@ s1 2 3 drop table t1; +create table t1 (a varchar(1)) +partition by key (a) +as select 'a'; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(1) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY KEY (a) +drop table t1; End of 5.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 272cdc27af6..311289d8fbe 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -1009,4 +1009,14 @@ select auto_increment from information_schema.tables where table_name='t1'; select * from t1; drop table t1; +# +# BUG 19062 Partition clause ignored if CREATE TABLE ... AS SELECT ...; +# +create table t1 (a varchar(1)) +partition by key (a) +as select 'a'; + +show create table t1; +drop table t1; + --echo End of 5.1 tests diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b1b498b356d..e75d673d299 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2855,6 +2855,17 @@ mysql_execute_command(THD *thd) res= 1; goto end_with_restore_list; } +#ifdef WITH_PARTITION_STORAGE_ENGINE + { + partition_info *part_info= thd->lex->part_info; + if (part_info && !(part_info= thd->lex->part_info->get_clone())) + { + res= -1; + goto end_with_restore_list; + } + thd->work_part_info= part_info; + } +#endif if (select_lex->item_list.elements) // With select { select_result *result; @@ -2924,15 +2935,6 @@ mysql_execute_command(THD *thd) lex->like_name); else { -#ifdef WITH_PARTITION_STORAGE_ENGINE - partition_info *part_info= thd->lex->part_info; - if (part_info && !(part_info= thd->lex->part_info->get_clone())) - { - res= -1; - goto end_with_restore_list; - } - thd->work_part_info= part_info; -#endif res= mysql_create_table(thd, create_table->db, create_table->table_name, &lex->create_info, lex->create_list, From d9ca07a7153a1e024285ebe1648d8631474b1550 Mon Sep 17 00:00:00 2001 From: "mikael@c-870ae253.1238-1-64736c10.cust.bredbandsbolaget.se" <> Date: Thu, 4 May 2006 14:38:42 -0400 Subject: [PATCH 2/4] BUG#19501: Data_Free incorrectly handled for partitioned tables --- mysql-test/r/partition.result | 14 ++++++++++++++ mysql-test/t/partition.test | 15 +++++++++++++++ sql/ha_partition.cc | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 0da071374ea..83caa8fa0c4 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -886,4 +886,18 @@ s1 2 3 drop table t1; +CREATE TABLE t1 (a int) ENGINE = MYISAM PARTITION BY KEY(a); +INSERT into t1 values (1), (2); +SHOW TABLE STATUS; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 2 7 14 0 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +DELETE from t1 where a = 1; +SHOW TABLE STATUS; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 14 14 0 0 7 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +ALTER TABLE t1 OPTIMIZE PARTITION p0; +SHOW TABLE STATUS; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MyISAM 10 Fixed 1 7 7 0 1024 0 NULL NULL NULL NULL latin1_swedish_ci NULL partitioned +DROP TABLE t1; End of 5.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 272cdc27af6..f8ecd7dc0e7 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -1009,4 +1009,19 @@ select auto_increment from information_schema.tables where table_name='t1'; select * from t1; drop table t1; +# +# BUG 19501 Partitions: SHOW TABLE STATUS shows wrong Data_free +# +CREATE TABLE t1 (a int) ENGINE = MYISAM PARTITION BY KEY(a); +INSERT into t1 values (1), (2); +--replace_column 9 0 12 NULL 13 NULL 14 NULL +SHOW TABLE STATUS; +DELETE from t1 where a = 1; +--replace_column 9 0 12 NULL 13 NULL 14 NULL +SHOW TABLE STATUS; +ALTER TABLE t1 OPTIMIZE PARTITION p0; +--replace_column 12 NULL 13 NULL 14 NULL +SHOW TABLE STATUS; +DROP TABLE t1; + --echo End of 5.1 tests diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 1ab2c4270fd..c58df5b2d3c 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -4169,6 +4169,8 @@ void ha_partition::info(uint flag) index_file_length: Length of index file, in principle bytes in indexes in the table We report sum + delete_length: Length of free space easily used by new records in table + We report sum mean_record_length:Mean record length in the table We calculate this check_time: Time of last check (only applicable to MyISAM) @@ -4178,6 +4180,7 @@ void ha_partition::info(uint flag) deleted= 0; data_file_length= 0; index_file_length= 0; + delete_length= 0; check_time= 0; file_array= m_file; do @@ -4190,6 +4193,7 @@ void ha_partition::info(uint flag) deleted+= file->deleted; data_file_length+= file->data_file_length; index_file_length+= file->index_file_length; + delete_length+= file->delete_length; if (file->check_time > check_time) check_time= file->check_time; } From 8e4a875d8e88b575d5b99920126899d07bb52ccc Mon Sep 17 00:00:00 2001 From: "mikael@c-870ae253.1238-1-64736c10.cust.bredbandsbolaget.se" <> Date: Thu, 4 May 2006 15:15:25 -0400 Subject: [PATCH 3/4] BUG#19502: Enable/Disable index routines not working for partitioned handlers Implemented enable/disable index routines for partition handler --- mysql-test/r/partition.result | 4 ++ mysql-test/t/partition.test | 7 ++++ sql/ha_partition.cc | 76 +++++++++++++++++++++++++++++++++++ sql/ha_partition.h | 7 ++-- 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 0da071374ea..20ff85d10ac 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -886,4 +886,8 @@ s1 2 3 drop table t1; +CREATE TABLE t1 (a int, index(a)) PARTITION BY KEY(a); +ALTER TABLE t1 DISABLE KEYS; +ALTER TABLE t1 ENABLE KEYS; +DROP TABLE t1; End of 5.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 272cdc27af6..f32c55c7a9e 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -1009,4 +1009,11 @@ select auto_increment from information_schema.tables where table_name='t1'; select * from t1; drop table t1; +# +# BUG 19502: ENABLE/DISABLE Keys don't work for partitioned tables +# +CREATE TABLE t1 (a int, index(a)) PARTITION BY KEY(a); +ALTER TABLE t1 DISABLE KEYS; +ALTER TABLE t1 ENABLE KEYS; +DROP TABLE t1; --echo End of 5.1 tests diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 1ab2c4270fd..30a816e45a7 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -5318,6 +5318,82 @@ void ha_partition::init_table_handle_for_HANDLER() } +/**************************************************************************** + MODULE enable/disable indexes +****************************************************************************/ + +/* + Disable indexes for a while + SYNOPSIS + disable_indexes() + mode Mode + RETURN VALUES + 0 Success + != 0 Error +*/ + +int ha_partition::disable_indexes(uint mode) +{ + handler **file; + int error= 0; + + for (file= m_file; *file; file++) + { + if ((error= (*file)->disable_indexes(mode))) + break; + } + return error; +} + + +/* + Enable indexes again + SYNOPSIS + enable_indexes() + mode Mode + RETURN VALUES + 0 Success + != 0 Error +*/ + +int ha_partition::enable_indexes(uint mode) +{ + handler **file; + int error= 0; + + for (file= m_file; *file; file++) + { + if ((error= (*file)->enable_indexes(mode))) + break; + } + return error; +} + + +/* + Check if indexes are disabled + SYNOPSIS + indexes_are_disabled() + + RETURN VALUES + 0 Indexes are enabled + != 0 Indexes are disabled +*/ + +int ha_partition::indexes_are_disabled(void) +{ + handler **file; + int error= 0; + + for (file= m_file; *file; file++) + { + if ((error= (*file)->indexes_are_disabled())) + break; + } + return error; +} + + /**************************************************************************** MODULE Partition Share ****************************************************************************/ diff --git a/sql/ha_partition.h b/sql/ha_partition.h index b31b9af28a3..1443a20133c 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -938,17 +938,18 @@ public: virtual uint checksum() const; virtual bool is_crashed() const; virtual bool auto_repair() const; + */ + /* ------------------------------------------------------------------------- MODULE enable/disable indexes ------------------------------------------------------------------------- - Enable/Disable Indexes are not supported currently (Heap, MyISAM) - This means that the following methods are not implemented: + Enable/Disable Indexes are only supported by HEAP and MyISAM. ------------------------------------------------------------------------- + */ virtual int disable_indexes(uint mode); virtual int enable_indexes(uint mode); virtual int indexes_are_disabled(void); - */ /* ------------------------------------------------------------------------- From 56b97747dee9c299684d5a9084578093147edcef Mon Sep 17 00:00:00 2001 From: "mikael@c-870ae253.1238-1-64736c10.cust.bredbandsbolaget.se" <> Date: Wed, 10 May 2006 12:53:40 -0400 Subject: [PATCH 4/4] BUG#19010: Fix issues with that ALTER TABLE from auto-partitioned NDB table doesn't work unless primary key exists on table. --- mysql-test/r/ndb_bitfield.result | 2 +- mysql-test/r/ndb_dd_basic.result | 2 +- mysql-test/r/ndb_dd_disk2memory.result | 8 +++--- mysql-test/r/ndb_gis.result | 4 +-- mysql-test/r/ndb_partition_key.result | 39 +++++++++++++++++++++++++- mysql-test/r/rpl_ndb_UUID.result | 2 +- mysql-test/r/rpl_ndb_dd_advance.result | 12 ++++---- mysql-test/t/ndb_partition_key.test | 20 +++++++++++++ sql/partition_info.h | 2 ++ sql/sql_partition.cc | 25 ++++++++++++++++- sql/sql_show.cc | 1 + sql/sql_table.cc | 1 + sql/table.cc | 11 +++++++- sql/table.h | 1 + sql/unireg.cc | 18 ++++++++---- 15 files changed, 125 insertions(+), 23 deletions(-) diff --git a/mysql-test/r/ndb_bitfield.result b/mysql-test/r/ndb_bitfield.result index 9a8c571cfba..59c4d420b22 100644 --- a/mysql-test/r/ndb_bitfield.result +++ b/mysql-test/r/ndb_bitfield.result @@ -9,7 +9,7 @@ t1 CREATE TABLE `t1` ( `pk1` int(11) NOT NULL, `b` bit(64) DEFAULT NULL, PRIMARY KEY (`pk1`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 insert into t1 values (0,b'1111111111111111111111111111111111111111111111111111111111111111'), (1,b'1000000000000000000000000000000000000000000000000000000000000000'), diff --git a/mysql-test/r/ndb_dd_basic.result b/mysql-test/r/ndb_dd_basic.result index d5ac5071a8e..99d5dd62717 100644 --- a/mysql-test/r/ndb_dd_basic.result +++ b/mysql-test/r/ndb_dd_basic.result @@ -49,7 +49,7 @@ t1 CREATE TABLE `t1` ( `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`pk1`) -) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 INSERT INTO t1 VALUES (0, 0, 0); SELECT * FROM t1; pk1 b c diff --git a/mysql-test/r/ndb_dd_disk2memory.result b/mysql-test/r/ndb_dd_disk2memory.result index 80056b7269d..bd5bbda42f3 100644 --- a/mysql-test/r/ndb_dd_disk2memory.result +++ b/mysql-test/r/ndb_dd_disk2memory.result @@ -218,7 +218,7 @@ t2 CREATE TABLE `t2` ( `b2` int(11) NOT NULL, `c2` int(11) NOT NULL, PRIMARY KEY (`pk2`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SHOW CREATE TABLE test.t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -226,7 +226,7 @@ t1 CREATE TABLE `t1` ( `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`pk1`) -) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 ALTER TABLE test.t2 TABLESPACE table_space1 STORAGE DISK ENGINE=NDB; SHOW CREATE TABLE test.t2; @@ -236,7 +236,7 @@ t2 CREATE TABLE `t2` ( `b2` int(11) NOT NULL, `c2` int(11) NOT NULL, PRIMARY KEY (`pk2`) -) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) TABLESPACE table_space1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 ALTER TABLE test.t1 ENGINE=NDBCLUSTER; SHOW CREATE TABLE test.t1; Table Create Table @@ -245,7 +245,7 @@ t1 CREATE TABLE `t1` ( `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`pk1`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 DROP TABLE test.t1; DROP TABLE test.t2; diff --git a/mysql-test/r/ndb_gis.result b/mysql-test/r/ndb_gis.result index f9b9ceb76a5..67447a69242 100644 --- a/mysql-test/r/ndb_gis.result +++ b/mysql-test/r/ndb_gis.result @@ -14,7 +14,7 @@ gis_point CREATE TABLE `gis_point` ( `fid` int(11) NOT NULL AUTO_INCREMENT, `g` point DEFAULT NULL, PRIMARY KEY (`fid`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra fid int(11) NO PRI NULL auto_increment @@ -476,7 +476,7 @@ gis_point CREATE TABLE `gis_point` ( `fid` int(11) NOT NULL AUTO_INCREMENT, `g` point DEFAULT NULL, PRIMARY KEY (`fid`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SHOW FIELDS FROM gis_point; Field Type Null Key Default Extra fid int(11) NO PRI NULL auto_increment diff --git a/mysql-test/r/ndb_partition_key.result b/mysql-test/r/ndb_partition_key.result index 503283df532..b7bf64d8724 100644 --- a/mysql-test/r/ndb_partition_key.result +++ b/mysql-test/r/ndb_partition_key.result @@ -137,7 +137,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 alter table t1 partition by key(a) (partition p0 engine=ndb, partition p1); @@ -197,3 +197,40 @@ ENGINE=NDB PARTITION BY KEY(c3); ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1; DROP TABLE t1; +create table t1 (a int) engine = ndb; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 +alter table t1 add column b int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 +alter table t1 engine = myisam; +alter table t1 engine = ndb; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 +alter table t1 coalesce partition 1; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () PARTITIONS 1 +drop table t1 ; +create table t1 (a int) engine = ndb; +alter table t1 add partition partitions 1; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () PARTITIONS 3 +drop table t1; diff --git a/mysql-test/r/rpl_ndb_UUID.result b/mysql-test/r/rpl_ndb_UUID.result index c768779c49b..422379d4f55 100644 --- a/mysql-test/r/rpl_ndb_UUID.result +++ b/mysql-test/r/rpl_ndb_UUID.result @@ -33,7 +33,7 @@ t1 CREATE TABLE `t1` ( `blob_column` longblob, `vchar_column` varchar(100) DEFAULT NULL, PRIMARY KEY (`a`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 DROP PROCEDURE test.p1; DROP FUNCTION test.fn1; DROP TABLE test.t1; diff --git a/mysql-test/r/rpl_ndb_dd_advance.result b/mysql-test/r/rpl_ndb_dd_advance.result index ba89592b532..2cb1cce649b 100644 --- a/mysql-test/r/rpl_ndb_dd_advance.result +++ b/mysql-test/r/rpl_ndb_dd_advance.result @@ -69,7 +69,7 @@ t1 CREATE TABLE `t1` ( PRIMARY KEY (`c1`), KEY `t1_i` (`c2`,`c3`), KEY `c5` (`c5`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 **** Show first set of ALTERs on SLAVE **** SHOW CREATE TABLE t1; Table Create Table @@ -82,7 +82,7 @@ t1 CREATE TABLE `t1` ( PRIMARY KEY (`c1`), KEY `t1_i` (`c2`,`c3`), KEY `c5` (`c5`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 **** Second set of alters test 1 **** ALTER TABLE t1 RENAME t2; ALTER TABLE t2 DROP INDEX c5; @@ -101,7 +101,7 @@ t1 CREATE TABLE `t1` ( `c5` double DEFAULT NULL, PRIMARY KEY (`c1`), KEY `t1_i` (`c2`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 **** Show second set of ALTERs on SLAVE **** SHOW CREATE TABLE t1; Table Create Table @@ -113,7 +113,7 @@ t1 CREATE TABLE `t1` ( `c5` double DEFAULT NULL, PRIMARY KEY (`c1`), KEY `t1_i` (`c2`,`c3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 **** Third and last set of alters for test1 **** ALTER TABLE t1 CHANGE c1 c1 DOUBLE; ALTER TABLE t1 CHANGE c2 c2 DECIMAL(10,2); @@ -135,7 +135,7 @@ t1 CREATE TABLE `t1` ( `c5` double DEFAULT NULL, PRIMARY KEY (`c1`), KEY `t1_i` (`c2`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SELECT * FROM t1 ORDER BY c1 LIMIT 5; c1 c2 c3 c5 1 2.00 b1b1b1b1b1b1b1b1b1b1 NULL @@ -153,7 +153,7 @@ t1 CREATE TABLE `t1` ( `c5` double DEFAULT NULL, PRIMARY KEY (`c1`), KEY `t1_i` (`c2`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () +) ENGINE=ndbcluster DEFAULT CHARSET=latin1 SELECT * FROM t1 where c1 = 1; c1 c2 c3 c5 1 2.00 b1b1b1b1b1b1b1b1b1b1 NULL diff --git a/mysql-test/t/ndb_partition_key.test b/mysql-test/t/ndb_partition_key.test index ce939663ab8..9309dc7b36f 100644 --- a/mysql-test/t/ndb_partition_key.test +++ b/mysql-test/t/ndb_partition_key.test @@ -196,3 +196,23 @@ CREATE TABLE t1 ( ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1; DROP TABLE t1; + +# +# BUG 19010: ALTER TABLE from NDB to other engine without primary key +# doesn't work. +# +create table t1 (a int) engine = ndb; +show create table t1; +alter table t1 add column b int; +show create table t1; +alter table t1 engine = myisam; +alter table t1 engine = ndb; +show create table t1; +alter table t1 coalesce partition 1; +show create table t1; +drop table t1 ; +create table t1 (a int) engine = ndb; +alter table t1 add partition partitions 1; +show create table t1; +drop table t1; + diff --git a/sql/partition_info.h b/sql/partition_info.h index 3a1e6be4050..af43f7b7933 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -184,6 +184,7 @@ public: bool list_of_subpart_fields; bool linear_hash_ind; bool fixed; + bool is_auto_partitioned; bool from_openfrm; bool has_null_value; uint has_null_part_id; @@ -219,6 +220,7 @@ public: list_of_part_fields(FALSE), list_of_subpart_fields(FALSE), linear_hash_ind(FALSE), fixed(FALSE), + is_auto_partitioned(FALSE), from_openfrm(FALSE), has_null_value(FALSE), has_null_part_id(0) diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 0442ad724d2..cc580578c7e 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4075,6 +4075,7 @@ that are reorganised. tab_part_info->use_default_partitions= FALSE; } tab_part_info->use_default_no_partitions= FALSE; + tab_part_info->is_auto_partitioned= FALSE; } } else if (alter_info->flags == ALTER_DROP_PARTITION) @@ -4090,6 +4091,8 @@ that are reorganised. uint no_parts_dropped= alter_info->partition_names.elements; uint no_parts_found= 0; List_iterator part_it(tab_part_info->partitions); + + tab_part_info->is_auto_partitioned= FALSE; if (!(tab_part_info->part_type == RANGE_PARTITION || tab_part_info->part_type == LIST_PARTITION)) { @@ -4274,7 +4277,10 @@ state of p1. tab_part_info->no_parts= no_parts_remain; } if (!(alter_info->flags & ALTER_TABLE_REORG)) + { tab_part_info->use_default_no_partitions= FALSE; + tab_part_info->is_auto_partitioned= FALSE; + } } else if (alter_info->flags == ALTER_REORGANIZE_PARTITION) { @@ -4293,6 +4299,8 @@ state of p1. uint no_parts_new= thd->work_part_info->partitions.elements; partition_info *alt_part_info= thd->work_part_info; uint check_total_partitions; + + tab_part_info->is_auto_partitioned= FALSE; if (no_parts_reorged > tab_part_info->no_parts) { my_error(ER_REORG_PARTITION_NOT_EXIST, MYF(0)); @@ -4533,7 +4541,22 @@ the generated partition syntax in a correct manner. Make sure change of engine happens to all partitions. */ DBUG_PRINT("info", ("partition changed")); - set_engine_all_partitions(thd->work_part_info, create_info->db_type); + if (table->part_info->is_auto_partitioned) + { + /* + If the user originally didn't specify partitioning to be + used we can remove it now. + */ + thd->work_part_info= NULL; + } + else + { + /* + Ensure that all partitions have the proper engine set-up + */ + set_engine_all_partitions(thd->work_part_info, + create_info->db_type); + } *partition_changed= TRUE; } } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 5e54040f0ae..b23b53d117e 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1274,6 +1274,7 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, uint part_syntax_len; char *part_syntax; if (table->part_info && + (!table->part_info->is_auto_partitioned) && ((part_syntax= generate_partition_syntax(table->part_info, &part_syntax_len, FALSE,FALSE)))) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 412682fc3b0..4b8bf7bcf17 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3045,6 +3045,7 @@ bool mysql_create_table_internal(THD *thd, } file->set_auto_partitions(part_info); part_info->default_engine_type= create_info->db_type; + part_info->is_auto_partitioned= TRUE; } if (part_info) { diff --git a/sql/table.cc b/sql/table.cc index 6ba66569f5c..8227287df0f 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -655,7 +655,6 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, my_free(buff, MYF(0)); goto err; } - next_chunk++; } #else if (partition_info_len) @@ -679,7 +678,15 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, */ next_chunk+= 4; } + else if (share->mysql_version >= 50110) #endif + { + /* New auto_partitioned indicator introduced in 5.1.11 */ +#ifdef WITH_PARTITION_STORAGE_ENGINE + share->auto_partitioned= *next_chunk; +#endif + next_chunk++; + } keyinfo= share->key_info; for (i= 0; i < keys; i++, keyinfo++) { @@ -1469,6 +1476,8 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, Fix the partition functions and ensure they are not constant functions */ + outparam->part_info->is_auto_partitioned= share->auto_partitioned; + DBUG_PRINT("info", ("autopartitioned = %u", share->auto_partitioned)); if (fix_partition_func(thd, share->normalized_path.str, outparam, is_create_table)) goto err; diff --git a/sql/table.h b/sql/table.h index 85d49444b29..e1b496a8296 100644 --- a/sql/table.h +++ b/sql/table.h @@ -213,6 +213,7 @@ typedef struct st_table_share */ bool log_table; #ifdef WITH_PARTITION_STORAGE_ENGINE + bool auto_partitioned; const uchar *partition_info; uint partition_info_len; const uchar *part_state; diff --git a/sql/unireg.cc b/sql/unireg.cc index bbb4d970d37..58c8123c98e 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -130,8 +130,14 @@ bool mysql_create_frm(THD *thd, const char *file_name, /* str_db_type */ create_info->extra_size= (2 + str_db_type.length + 2 + create_info->connect_string.length); - /* Partition */ - create_info->extra_size+= 9; + /* + Partition: + Length of partition info = 4 byte + Potential NULL byte at end of partition info string = 1 byte + Indicator if auto-partitioned table = 1 byte + => Total 6 byte + */ + create_info->extra_size+= 6; #ifdef WITH_PARTITION_STORAGE_ENGINE if (part_info) { @@ -203,17 +209,19 @@ bool mysql_create_frm(THD *thd, const char *file_name, #ifdef WITH_PARTITION_STORAGE_ENGINE if (part_info) { + char auto_partitioned= part_info->is_auto_partitioned ? 1 : 0; int4store(buff, part_info->part_info_len); if (my_write(file, (const byte*)buff, 4, MYF_RW) || my_write(file, (const byte*)part_info->part_info_string, - part_info->part_info_len + 1, MYF_RW)) + part_info->part_info_len + 1, MYF_RW) || + my_write(file, (const byte*)&auto_partitioned, 1, MYF_RW)) goto err; } else #endif { - bzero(buff, 9); - if (my_write(file, (byte*) buff, 9, MYF_RW)) + bzero(buff, 6); + if (my_write(file, (byte*) buff, 6, MYF_RW)) goto err; } for (i= 0; i < keys; i++)