BUG#19695: Showed partition options when table options were not shown

parent e9056d85
...@@ -570,7 +570,7 @@ show create table t1; ...@@ -570,7 +570,7 @@ show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL `a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p0 VALUES LESS THAN (100) ) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (a) SUBPARTITION BY HASH (a) (PARTITION p0 VALUES LESS THAN (100))
alter table t1 add partition (partition p1 values less than (200) alter table t1 add partition (partition p1 values less than (200)
(subpartition subpart21)); (subpartition subpart21));
show create table t1; show create table t1;
...@@ -886,4 +886,15 @@ s1 ...@@ -886,4 +886,15 @@ s1
2 2
3 3
drop table t1; drop table t1;
create table t1 (a int)
PARTITION BY KEY (a)
(PARTITION p0);
set session sql_mode='no_table_options';
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) PARTITION BY KEY (a) (PARTITION p0)
set session sql_mode='';
drop table t1;
End of 5.1 tests End of 5.1 tests
...@@ -996,7 +996,7 @@ Table Create Table ...@@ -996,7 +996,7 @@ Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`f1` int(11) DEFAULT NULL, `f1` int(11) DEFAULT NULL,
`f2` char(20) DEFAULT NULL `f2` char(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (f1) SUBPARTITION BY HASH (f1) SUBPARTITIONS 2 (PARTITION part1 VALUES LESS THAN (100) , PARTITION part2 VALUES LESS THAN (2147483647) ) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (f1) SUBPARTITION BY HASH (f1) SUBPARTITIONS 2 (PARTITION part1 VALUES LESS THAN (100), PARTITION part2 VALUES LESS THAN (2147483647))
SELECT COUNT(*) = 0 AS my_value FROM t1; SELECT COUNT(*) = 0 AS my_value FROM t1;
my_value my_value
1 1
...@@ -1098,7 +1098,7 @@ Table Create Table ...@@ -1098,7 +1098,7 @@ Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`f1` int(11) DEFAULT NULL, `f1` int(11) DEFAULT NULL,
`f2` char(20) DEFAULT NULL `f2` char(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (f1) SUBPARTITION BY HASH (f1) SUBPARTITIONS 1 (PARTITION part1 VALUES LESS THAN (100) , PARTITION part2 VALUES LESS THAN (2147483647) ) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY RANGE (f1) SUBPARTITION BY HASH (f1) SUBPARTITIONS 1 (PARTITION part1 VALUES LESS THAN (100), PARTITION part2 VALUES LESS THAN (2147483647))
SELECT COUNT(*) = 0 AS my_value FROM t1; SELECT COUNT(*) = 0 AS my_value FROM t1;
my_value my_value
1 1
......
...@@ -1009,4 +1009,16 @@ select auto_increment from information_schema.tables where table_name='t1'; ...@@ -1009,4 +1009,16 @@ select auto_increment from information_schema.tables where table_name='t1';
select * from t1; select * from t1;
drop table t1; drop table t1;
#
# Bug 19695 Partitions: SHOW CREATE TABLE shows table options even when it
# shouldn't
#
create table t1 (a int)
PARTITION BY KEY (a)
(PARTITION p0);
set session sql_mode='no_table_options';
show create table t1;
set session sql_mode='';
drop table t1;
--echo End of 5.1 tests --echo End of 5.1 tests
...@@ -1675,6 +1675,7 @@ static int add_partition_options(File fptr, partition_element *p_elem) ...@@ -1675,6 +1675,7 @@ static int add_partition_options(File fptr, partition_element *p_elem)
{ {
int err= 0; int err= 0;
err+= add_space(fptr);
if (p_elem->tablespace_name) if (p_elem->tablespace_name)
err+= add_keyword_string(fptr,"TABLESPACE", FALSE, err+= add_keyword_string(fptr,"TABLESPACE", FALSE,
p_elem->tablespace_name); p_elem->tablespace_name);
...@@ -1702,7 +1703,7 @@ static int add_partition_values(File fptr, partition_info *part_info, ...@@ -1702,7 +1703,7 @@ static int add_partition_values(File fptr, partition_info *part_info,
if (part_info->part_type == RANGE_PARTITION) if (part_info->part_type == RANGE_PARTITION)
{ {
err+= add_string(fptr, "VALUES LESS THAN "); err+= add_string(fptr, " VALUES LESS THAN ");
if (p_elem->range_value != LONGLONG_MAX) if (p_elem->range_value != LONGLONG_MAX)
{ {
err+= add_begin_parenthesis(fptr); err+= add_begin_parenthesis(fptr);
...@@ -1716,7 +1717,7 @@ static int add_partition_values(File fptr, partition_info *part_info, ...@@ -1716,7 +1717,7 @@ static int add_partition_values(File fptr, partition_info *part_info,
{ {
uint i; uint i;
List_iterator<longlong> list_val_it(p_elem->list_val_list); List_iterator<longlong> list_val_it(p_elem->list_val_list);
err+= add_string(fptr, "VALUES IN "); err+= add_string(fptr, " VALUES IN ");
uint no_items= p_elem->list_val_list.elements; uint no_items= p_elem->list_val_list.elements;
err+= add_begin_parenthesis(fptr); err+= add_begin_parenthesis(fptr);
if (p_elem->has_null_value) if (p_elem->has_null_value)
...@@ -1740,7 +1741,7 @@ static int add_partition_values(File fptr, partition_info *part_info, ...@@ -1740,7 +1741,7 @@ static int add_partition_values(File fptr, partition_info *part_info,
err+= add_end_parenthesis(fptr); err+= add_end_parenthesis(fptr);
} }
end: end:
return err + add_space(fptr); return err;
} }
/* /*
...@@ -1755,6 +1756,7 @@ end: ...@@ -1755,6 +1756,7 @@ end:
use_sql_alloc Allocate buffer from sql_alloc if true use_sql_alloc Allocate buffer from sql_alloc if true
otherwise use my_malloc otherwise use my_malloc
write_all Write everything, also default values write_all Write everything, also default values
show_partition_options Should we display partition options
RETURN VALUES RETURN VALUES
NULL error NULL error
...@@ -1783,7 +1785,8 @@ end: ...@@ -1783,7 +1785,8 @@ end:
char *generate_partition_syntax(partition_info *part_info, char *generate_partition_syntax(partition_info *part_info,
uint *buf_length, uint *buf_length,
bool use_sql_alloc, bool use_sql_alloc,
bool write_all) bool write_all,
bool show_partition_options)
{ {
uint i,j, tot_no_parts, no_subparts, no_parts; uint i,j, tot_no_parts, no_subparts, no_parts;
partition_element *part_elem; partition_element *part_elem;
...@@ -1882,9 +1885,8 @@ char *generate_partition_syntax(partition_info *part_info, ...@@ -1882,9 +1885,8 @@ char *generate_partition_syntax(partition_info *part_info,
first= FALSE; first= FALSE;
err+= add_partition(fptr); err+= add_partition(fptr);
err+= add_name_string(fptr, part_elem->partition_name); err+= add_name_string(fptr, part_elem->partition_name);
err+= add_space(fptr);
err+= add_partition_values(fptr, part_info, part_elem); err+= add_partition_values(fptr, part_info, part_elem);
if (!part_info->is_sub_partitioned()) if (!part_info->is_sub_partitioned() && show_partition_options)
err+= add_partition_options(fptr, part_elem); err+= add_partition_options(fptr, part_elem);
if (part_info->is_sub_partitioned() && if (part_info->is_sub_partitioned() &&
(write_all || (!part_info->use_default_subpartitions))) (write_all || (!part_info->use_default_subpartitions)))
...@@ -1898,7 +1900,7 @@ char *generate_partition_syntax(partition_info *part_info, ...@@ -1898,7 +1900,7 @@ char *generate_partition_syntax(partition_info *part_info,
part_elem= sub_it++; part_elem= sub_it++;
err+= add_subpartition(fptr); err+= add_subpartition(fptr);
err+= add_name_string(fptr, part_elem->partition_name); err+= add_name_string(fptr, part_elem->partition_name);
err+= add_space(fptr); if (show_partition_options)
err+= add_partition_options(fptr, part_elem); err+= add_partition_options(fptr, part_elem);
if (j != (no_subparts-1)) if (j != (no_subparts-1))
{ {
......
...@@ -70,7 +70,7 @@ bool fix_partition_func(THD *thd, const char *name, TABLE *table, ...@@ -70,7 +70,7 @@ bool fix_partition_func(THD *thd, const char *name, TABLE *table,
bool create_table_ind); bool create_table_ind);
char *generate_partition_syntax(partition_info *part_info, char *generate_partition_syntax(partition_info *part_info,
uint *buf_length, bool use_sql_alloc, uint *buf_length, bool use_sql_alloc,
bool write_all); bool write_all, bool show_partition_options);
bool partition_key_modified(TABLE *table, List<Item> &fields); bool partition_key_modified(TABLE *table, List<Item> &fields);
void get_partition_set(const TABLE *table, byte *buf, const uint index, void get_partition_set(const TABLE *table, byte *buf, const uint index,
const key_range *key_spec, const key_range *key_spec,
......
...@@ -932,6 +932,7 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, ...@@ -932,6 +932,7 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
handler *file= table->file; handler *file= table->file;
TABLE_SHARE *share= table->s; TABLE_SHARE *share= table->s;
HA_CREATE_INFO create_info; HA_CREATE_INFO create_info;
bool show_table_options= FALSE;
bool foreign_db_mode= (thd->variables.sql_mode & (MODE_POSTGRESQL | bool foreign_db_mode= (thd->variables.sql_mode & (MODE_POSTGRESQL |
MODE_ORACLE | MODE_ORACLE |
MODE_MSSQL | MODE_MSSQL |
...@@ -1149,6 +1150,7 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, ...@@ -1149,6 +1150,7 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
packet->append(STRING_WITH_LEN("\n)")); packet->append(STRING_WITH_LEN("\n)"));
if (!(thd->variables.sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode) if (!(thd->variables.sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode)
{ {
show_table_options= TRUE;
/* /*
Get possible table space definitions and append them Get possible table space definitions and append them
to the CREATE TABLE statement to the CREATE TABLE statement
...@@ -1288,7 +1290,8 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, ...@@ -1288,7 +1290,8 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
if (table->part_info && if (table->part_info &&
((part_syntax= generate_partition_syntax(table->part_info, ((part_syntax= generate_partition_syntax(table->part_info,
&part_syntax_len, &part_syntax_len,
FALSE,FALSE)))) FALSE,FALSE,
show_table_options))))
{ {
packet->append(part_syntax, part_syntax_len); packet->append(part_syntax, part_syntax_len);
my_free(part_syntax, MYF(0)); my_free(part_syntax, MYF(0));
......
...@@ -1231,7 +1231,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) ...@@ -1231,7 +1231,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
{ {
if (!(part_syntax_buf= generate_partition_syntax(part_info, if (!(part_syntax_buf= generate_partition_syntax(part_info,
&syntax_len, &syntax_len,
TRUE, FALSE))) TRUE, FALSE, TRUE)))
{ {
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
...@@ -3149,7 +3149,7 @@ bool mysql_create_table_internal(THD *thd, ...@@ -3149,7 +3149,7 @@ bool mysql_create_table_internal(THD *thd,
*/ */
if (!(part_syntax_buf= generate_partition_syntax(part_info, if (!(part_syntax_buf= generate_partition_syntax(part_info,
&syntax_len, &syntax_len,
TRUE, FALSE))) TRUE, FALSE, TRUE)))
goto err; goto err;
part_info->part_info_string= part_syntax_buf; part_info->part_info_string= part_syntax_buf;
part_info->part_info_len= syntax_len; part_info->part_info_len= syntax_len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment