From 11c503567fdcc2a0802d258f10b31ea3dc551a4c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Sep 2005 10:29:59 -0400 Subject: [PATCH] Handle default engine type better for partitioned tables mysql-test/r/partition.result: New test cases for SHOW CREATE TABLE mysql-test/r/partition_range.result: New test cases for SHOW CREATE TABLE mysql-test/t/partition.test: New test cases for SHOW CREATE TABLE mysql-test/t/partition_range.test: New test cases for SHOW CREATE TABLE sql/handler.h: Handle default engine type better sql/sql_partition.cc: Handle default engine type better sql/sql_show.cc: Handle default engine type better sql/sql_table.cc: Handle default engine type better sql/sql_yacc.yy: Handle default engine type better sql/table.cc: Handle default engine type better sql/unireg.cc: Handle default engine type better --- mysql-test/r/partition.result | 8 +++++++ mysql-test/r/partition_range.result | 34 +++++++++++++++++++++++++++++ mysql-test/t/partition.test | 5 +++++ mysql-test/t/partition_range.test | 6 +++++ sql/handler.h | 2 +- sql/sql_partition.cc | 8 ++++++- sql/sql_show.cc | 21 ++++++++++-------- sql/sql_table.cc | 18 ++++++--------- sql/sql_yacc.yy | 6 ++++- sql/table.cc | 5 ++++- sql/unireg.cc | 1 + 11 files changed, 90 insertions(+), 24 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 06097e26183..eefa45a9e0c 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -8,6 +8,14 @@ partition by key (a); select count(*) from t1; count(*) 0 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` int(11) NOT NULL, + `c` int(11) NOT NULL, + PRIMARY KEY (`a`,`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY KEY (a) drop table t1; CREATE TABLE t1 ( a int not null, diff --git a/mysql-test/r/partition_range.result b/mysql-test/r/partition_range.result index 740fec485a3..f8b4f1b054b 100644 --- a/mysql-test/r/partition_range.result +++ b/mysql-test/r/partition_range.result @@ -19,6 +19,14 @@ a b c 6 1 1 10 1 1 15 1 1 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` int(11) NOT NULL, + `c` int(11) NOT NULL, + PRIMARY KEY (`a`,`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) (PARTITION x1 VALUES LESS THAN (5) TABLESPACE = ts1 ENGINE = MyISAM, PARTITION x2 VALUES LESS THAN (10) TABLESPACE = ts2 ENGINE = MyISAM, PARTITION x3 VALUES LESS THAN MAXVALUE TABLESPACE = ts3 ENGINE = MyISAM) ALTER TABLE t1 partition by range (a) partitions 3 @@ -31,6 +39,14 @@ a b c 6 1 1 10 1 1 15 1 1 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` int(11) NOT NULL, + `c` int(11) NOT NULL, + PRIMARY KEY (`a`,`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) (PARTITION x1 VALUES LESS THAN (5) TABLESPACE = ts1 ENGINE = MyISAM, PARTITION x2 VALUES LESS THAN (10) TABLESPACE = ts2 ENGINE = MyISAM, PARTITION x3 VALUES LESS THAN MAXVALUE TABLESPACE = ts3 ENGINE = MyISAM) drop table if exists t1; CREATE TABLE t1 ( a int not null, @@ -120,6 +136,24 @@ subpartition x22) ); SELECT * from t1; a b c +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` int(11) NOT NULL, + `c` int(11) NOT NULL, + PRIMARY KEY (`a`,`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a+b) (PARTITION x1 VALUES LESS THAN (1) (SUBPARTITION x11 ENGINE = MyISAM, SUBPARTITION x12 ENGINE = MyISAM), PARTITION x2 VALUES LESS THAN (5) (SUBPARTITION x21 ENGINE = MyISAM, SUBPARTITION x22 ENGINE = MyISAM)) +ALTER TABLE t1 ADD COLUMN d int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` int(11) NOT NULL, + `c` int(11) NOT NULL, + `d` int(11) default NULL, + PRIMARY KEY (`a`,`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a+b) (PARTITION x1 VALUES LESS THAN (1) (SUBPARTITION x11 ENGINE = MyISAM, SUBPARTITION x12 ENGINE = MyISAM), PARTITION x2 VALUES LESS THAN (5) (SUBPARTITION x21 ENGINE = MyISAM, SUBPARTITION x22 ENGINE = MyISAM)) drop table t1; CREATE TABLE t1 ( a int not null, diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index a45046239bc..21b24dfe4f2 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -23,6 +23,11 @@ partition by key (a); # select count(*) from t1; +# +# Test SHOW CREATE TABLE +# +show create table t1; + drop table t1; # # Partition by key no partition, list of fields diff --git a/mysql-test/t/partition_range.test b/mysql-test/t/partition_range.test index 36c97fa4e48..08cc841b12e 100644 --- a/mysql-test/t/partition_range.test +++ b/mysql-test/t/partition_range.test @@ -30,6 +30,7 @@ INSERT into t1 values (10, 1, 1); INSERT into t1 values (15, 1, 1); select * from t1; +show create table t1; ALTER TABLE t1 partition by range (a) @@ -39,6 +40,7 @@ partitions 3 partition x3 values less than maxvalue tablespace ts3); select * from t1; +show create table t1; drop table if exists t1; @@ -143,6 +145,10 @@ subpartition by hash (a+b) ); SELECT * from t1; +show create table t1; + +ALTER TABLE t1 ADD COLUMN d int; +show create table t1; drop table t1; diff --git a/sql/handler.h b/sql/handler.h index 86d96ede4dd..bd935da2a80 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -686,7 +686,7 @@ void get_full_part_id_from_key(const TABLE *table, byte *buf, const key_range *key_spec, part_id_range *part_spec); bool mysql_unpack_partition(File file, THD *thd, uint part_info_len, - TABLE *table); + TABLE *table, enum db_type default_db_type); #endif diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 5910e43a112..906d1cd40a8 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -3081,7 +3081,7 @@ void get_partition_set(const TABLE *table, byte *buf, const uint index, */ bool mysql_unpack_partition(File file, THD *thd, uint part_info_len, - TABLE* table) + TABLE* table, enum db_type default_db_type) { Item *thd_free_list= thd->free_list; bool result= TRUE; @@ -3119,6 +3119,12 @@ bool mysql_unpack_partition(File file, THD *thd, uint part_info_len, } part_info= lex.part_info; table->s->part_info= part_info; + if (part_info->default_engine_type == DB_TYPE_UNKNOWN) + part_info->default_engine_type= default_db_type; + else + { + DBUG_ASSERT(part_info->default_engine_type == default_db_type); + } part_info->item_free_list= thd->free_list; { diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 8d0cc63a5f6..c0bb29e035b 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -961,16 +961,19 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet) packet->append("\n)", 2); if (!(thd->variables.sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode) { -#if 0 //def HAVE_PARTITION_DB - if (!table->s->part_info) -#endif - { - if (thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) - packet->append(" TYPE=", 6); - else - packet->append(" ENGINE=", 8); + if (thd->variables.sql_mode & (MODE_MYSQL323 | MODE_MYSQL40)) + packet->append(" TYPE=", 6); + else + packet->append(" ENGINE=", 8); +#ifdef HAVE_PARTITION_DB + if (table->s->part_info) + packet->append(ha_get_storage_engine( + table->s->part_info->default_engine_type)); + else packet->append(file->table_type()); - } +#else + packet->append(file->table_type()); +#endif if (share->table_charset && !(thd->variables.sql_mode & MODE_MYSQL323) && diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 07dfd77fb49..59e23f8b972 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1620,6 +1620,10 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, part_engine_type= ha_checktype(thd, part_info->default_engine_type, 0, 0); } + else + { + part_info->default_engine_type= create_info->db_type; + } if (check_partition_info(part_info, part_engine_type, file, create_info->max_rows)) DBUG_RETURN(TRUE); @@ -3467,16 +3471,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0)); DBUG_RETURN(TRUE); } - { - List_iterator t_it(tab_part_info->partitions); - partition_element *t_part_elem= t_it++; - if (is_sub_partitioned(tab_part_info)) - { - List_iterator s_it(t_part_elem->subpartitions); - t_part_elem= s_it++; - } - default_engine_type= t_part_elem->engine_type; - } + default_engine_type= tab_part_info->default_engine_type; /* 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 @@ -3860,7 +3855,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, */ if (thd->lex->part_info != table->s->part_info) partition_changed= TRUE; - thd->lex->part_info->default_engine_type= create_info->db_type; + if (create_info->db_type != DB_TYPE_PARTITION_DB) + thd->lex->part_info->default_engine_type= create_info->db_type; create_info->db_type= DB_TYPE_PARTITION_DB; } } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 2d2cae5968d..49c385dd1be 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -3038,7 +3038,11 @@ opt_part_option: TABLESPACE opt_equal ident_or_text { Lex->part_info->curr_part_elem->tablespace_name= $3.str; } | opt_storage ENGINE_SYM opt_equal storage_engines - { Lex->part_info->curr_part_elem->engine_type= $4; } + { + LEX *lex= Lex; + lex->part_info->curr_part_elem->engine_type= $4; + lex->part_info->default_engine_type= $4; + } | NODEGROUP_SYM opt_equal ulong_num { Lex->part_info->curr_part_elem->nodegroup_id= $3; } | MAX_ROWS opt_equal ulonglong_num diff --git a/sql/table.cc b/sql/table.cc index 412506ccbc8..9d91cb51ee1 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -87,6 +87,7 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat, SQL_CRYPT *crypted=0; MEM_ROOT **root_ptr, *old_root; TABLE_SHARE *share; + enum db_type default_part_db_type; DBUG_ENTER("openfrm"); DBUG_PRINT("enter",("name: '%s' form: 0x%lx",name,outparam)); @@ -164,6 +165,7 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat, if (share->frm_version == FRM_VER_TRUE_VARCHAR -1 && head[33] == 5) share->frm_version= FRM_VER_TRUE_VARCHAR; + default_part_db_type= ha_checktype(thd,(enum db_type) (uint) *(head+61),0,0); share->db_type= ha_checktype(thd,(enum db_type) (uint) *(head+3),0,0); share->db_create_options= db_create_options=uint2korr(head+30); share->db_options_in_use= share->db_create_options; @@ -452,7 +454,8 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat, if (part_info_len > 0) { #ifdef HAVE_PARTITION_DB - if (mysql_unpack_partition(file, thd, part_info_len, outparam)) + if (mysql_unpack_partition(file, thd, part_info_len, + outparam, default_part_db_type)) goto err; #else goto err; diff --git a/sql/unireg.cc b/sql/unireg.cc index f46f4cace59..0279f224940 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -149,6 +149,7 @@ bool mysql_create_frm(THD *thd, my_string file_name, if (part_info) { int4store(fileinfo+55,part_info->part_info_len); + fileinfo[61]= (uchar) part_info->default_engine_type; } #endif int2store(fileinfo+59,db_file->extra_rec_buf_length());