Skip to content

Commit 29c60cd

Browse files
author
Mikael Ronstrom
committed
BUG#49591, Fixed version string in SHOW CREATE TABLE to accomodate for column list partitioning and new function to_seconds
1 parent d456e44 commit 29c60cd

File tree

9 files changed

+117
-12
lines changed

9 files changed

+117
-12
lines changed

mysql-test/r/partition_column.result

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Table Create Table
6969
t1 CREATE TABLE `t1` (
7070
`a` varchar(5) DEFAULT NULL
7171
) ENGINE=MyISAM DEFAULT CHARSET=latin1
72-
/*!50100 PARTITION BY LIST COLUMNS(a)
72+
/*!50500 PARTITION BY LIST COLUMNS(a)
7373
(PARTITION p0 VALUES IN ('''') ENGINE = MyISAM,
7474
PARTITION p1 VALUES IN ('\\') ENGINE = MyISAM,
7575
PARTITION p2 VALUES IN ('\0') ENGINE = MyISAM) */
@@ -128,7 +128,7 @@ t1 CREATE TABLE `t1` (
128128
`c` varchar(25) DEFAULT NULL,
129129
`d` datetime DEFAULT NULL
130130
) ENGINE=MyISAM DEFAULT CHARSET=latin1
131-
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c,d)
131+
/*!50500 PARTITION BY RANGE COLUMNS(a,b,c,d)
132132
SUBPARTITION BY HASH (to_seconds(d))
133133
SUBPARTITIONS 4
134134
(PARTITION p0 VALUES LESS THAN (1,'0',MAXVALUE,'1900-01-01') ENGINE = MyISAM,
@@ -211,7 +211,7 @@ t1 CREATE TABLE `t1` (
211211
`a` int(11) DEFAULT NULL,
212212
`b` int(11) DEFAULT NULL
213213
) ENGINE=MyISAM DEFAULT CHARSET=latin1
214-
/*!50100 PARTITION BY LIST COLUMNS(a,b)
214+
/*!50500 PARTITION BY LIST COLUMNS(a,b)
215215
(PARTITION p0 VALUES IN ((1,NULL),(2,NULL),(NULL,NULL)) ENGINE = MyISAM,
216216
PARTITION p1 VALUES IN ((1,1),(2,2)) ENGINE = MyISAM,
217217
PARTITION p2 VALUES IN ((3,NULL),(NULL,1)) ENGINE = MyISAM) */
@@ -245,7 +245,7 @@ t1 CREATE TABLE `t1` (
245245
`a` int(11) DEFAULT NULL,
246246
`b` int(11) DEFAULT NULL
247247
) ENGINE=MyISAM DEFAULT CHARSET=latin1
248-
/*!50100 PARTITION BY LIST COLUMNS(a,b)
248+
/*!50500 PARTITION BY LIST COLUMNS(a,b)
249249
(PARTITION p0 VALUES IN ((1,NULL),(2,NULL),(NULL,NULL)) ENGINE = MyISAM,
250250
PARTITION p1 VALUES IN ((1,1),(2,2)) ENGINE = MyISAM,
251251
PARTITION p2 VALUES IN ((3,NULL),(NULL,1)) ENGINE = MyISAM) */
@@ -299,7 +299,7 @@ Table Create Table
299299
t1 CREATE TABLE `t1` (
300300
`a` int(11) DEFAULT NULL
301301
) ENGINE=MyISAM DEFAULT CHARSET=latin1
302-
/*!50100 PARTITION BY LIST COLUMNS(a)
302+
/*!50500 PARTITION BY LIST COLUMNS(a)
303303
(PARTITION p0 VALUES IN (2,1) ENGINE = MyISAM,
304304
PARTITION p1 VALUES IN (4,NULL,3) ENGINE = MyISAM) */
305305
insert into t1 values (1);
@@ -314,7 +314,7 @@ Table Create Table
314314
t1 CREATE TABLE `t1` (
315315
`a` int(11) DEFAULT NULL
316316
) ENGINE=MyISAM DEFAULT CHARSET=latin1
317-
/*!50100 PARTITION BY LIST COLUMNS(a)
317+
/*!50500 PARTITION BY LIST COLUMNS(a)
318318
(PARTITION p0 VALUES IN (2,1) ENGINE = MyISAM,
319319
PARTITION p1 VALUES IN (4,NULL,3) ENGINE = MyISAM) */
320320
drop table t1;
@@ -349,7 +349,7 @@ t1 CREATE TABLE `t1` (
349349
`c` varchar(5) DEFAULT NULL,
350350
`d` int(11) DEFAULT NULL
351351
) ENGINE=MyISAM DEFAULT CHARSET=latin1
352-
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c)
352+
/*!50500 PARTITION BY RANGE COLUMNS(a,b,c)
353353
SUBPARTITION BY KEY (c,d)
354354
SUBPARTITIONS 3
355355
(PARTITION p0 VALUES LESS THAN (1,'abc','abc') ENGINE = MyISAM,
@@ -382,7 +382,7 @@ t1 CREATE TABLE `t1` (
382382
`b` varchar(2) DEFAULT NULL,
383383
`c` int(11) DEFAULT NULL
384384
) ENGINE=MyISAM DEFAULT CHARSET=latin1
385-
/*!50100 PARTITION BY RANGE COLUMNS(a,b,c)
385+
/*!50500 PARTITION BY RANGE COLUMNS(a,b,c)
386386
(PARTITION p0 VALUES LESS THAN (1,'A',1) ENGINE = MyISAM,
387387
PARTITION p1 VALUES LESS THAN (1,'B',1) ENGINE = MyISAM) */
388388
insert into t1 values (1, 'A', 1);

mysql-test/r/partition_range.result

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
drop table if exists t1, t2;
22
create table t1 (a int)
33
partition by range (a)
4+
subpartition by hash(to_seconds(a))
5+
(partition p0 values less than (1));
6+
show create table t1;
7+
Table Create Table
8+
t1 CREATE TABLE `t1` (
9+
`a` int(11) DEFAULT NULL
10+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
11+
/*!50500 PARTITION BY RANGE (a)
12+
SUBPARTITION BY HASH (to_seconds(a))
13+
(PARTITION p0 VALUES LESS THAN (1) ENGINE = MyISAM) */
14+
drop table t1;
15+
create table t1 (a int)
16+
partition by range (a)
417
( partition p0 values less than (NULL),
518
partition p1 values less than (MAXVALUE));
619
ERROR HY000: Not allowed to use NULL value in VALUES LESS THAN
@@ -30,6 +43,14 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
3043
explain partitions select * from t1 where a < '2007-03-07 23:59:59';
3144
id select_type table partitions type possible_keys key key_len ref rows Extra
3245
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 4 Using where
46+
show create table t1;
47+
Table Create Table
48+
t1 CREATE TABLE `t1` (
49+
`a` datetime NOT NULL
50+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
51+
/*!50500 PARTITION BY RANGE (TO_SECONDS(a))
52+
(PARTITION p0 VALUES LESS THAN (63340531200) ENGINE = MyISAM,
53+
PARTITION p1 VALUES LESS THAN (63342604800) ENGINE = MyISAM) */
3354
drop table t1;
3455
create table t1 (a date)
3556
partition by range(to_seconds(a))
@@ -53,6 +74,14 @@ select * from t1 where a <= '2005-01-01';
5374
a
5475
2003-12-30
5576
2004-12-31
77+
show create table t1;
78+
Table Create Table
79+
t1 CREATE TABLE `t1` (
80+
`a` date DEFAULT NULL
81+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
82+
/*!50500 PARTITION BY RANGE (to_seconds(a))
83+
(PARTITION p0 VALUES LESS THAN (63240134400) ENGINE = MyISAM,
84+
PARTITION p1 VALUES LESS THAN (63271756800) ENGINE = MyISAM) */
5685
drop table t1;
5786
create table t1 (a datetime)
5887
partition by range(to_seconds(a))
@@ -75,6 +104,14 @@ id select_type table partitions type possible_keys key key_len ref rows Extra
75104
select * from t1 where a <= '2005-01-01';
76105
a
77106
2004-01-01 11:59:29
107+
show create table t1;
108+
Table Create Table
109+
t1 CREATE TABLE `t1` (
110+
`a` datetime DEFAULT NULL
111+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
112+
/*!50500 PARTITION BY RANGE (to_seconds(a))
113+
(PARTITION p0 VALUES LESS THAN (63240177600) ENGINE = MyISAM,
114+
PARTITION p1 VALUES LESS THAN (63271800000) ENGINE = MyISAM) */
78115
drop table t1;
79116
create table t1 (a int, b char(20))
80117
partition by range columns(a,b)

mysql-test/r/partition_utf8.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Table Create Table
77
t1 CREATE TABLE `t1` (
88
`a` varchar(2) CHARACTER SET cp1250 DEFAULT NULL
99
) ENGINE=MyISAM DEFAULT CHARSET=latin1
10-
/*!50100 PARTITION BY LIST COLUMNS(a)
10+
/*!50500 PARTITION BY LIST COLUMNS(a)
1111
(PARTITION p0 VALUES IN (_cp1250 0x81) ENGINE = MyISAM) */
1212
drop table t1;
1313
create table t1 (a varchar(2) character set cp1250)
@@ -18,7 +18,7 @@ Table Create Table
1818
t1 CREATE TABLE `t1` (
1919
`a` varchar(2) CHARACTER SET cp1250 DEFAULT NULL
2020
) ENGINE=MyISAM DEFAULT CHARSET=latin1
21-
/*!50100 PARTITION BY LIST COLUMNS(a)
21+
/*!50500 PARTITION BY LIST COLUMNS(a)
2222
(PARTITION p0 VALUES IN ('€') ENGINE = MyISAM) */
2323
drop table t1;
2424
create table t1 (a varchar(1500), b varchar(1570))
@@ -45,7 +45,7 @@ Table Create Table
4545
t1 CREATE TABLE `t1` (
4646
`a` varchar(2) CHARACTER SET ucs2 DEFAULT NULL
4747
) ENGINE=MyISAM DEFAULT CHARSET=latin1
48-
/*!50100 PARTITION BY LIST COLUMNS(a)
48+
/*!50500 PARTITION BY LIST COLUMNS(a)
4949
(PARTITION p0 VALUES IN ('†') ENGINE = MyISAM,
5050
PARTITION p1 VALUES IN ('') ENGINE = MyISAM) */
5151
insert into t1 values ('');

mysql-test/t/partition_range.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
drop table if exists t1, t2;
1010
--enable_warnings
1111

12+
#
13+
#BUG#49591, Add proper version number to SHOW CREATE TABLE
14+
#
15+
create table t1 (a int)
16+
partition by range (a)
17+
subpartition by hash(to_seconds(a))
18+
(partition p0 values less than (1));
19+
show create table t1;
20+
drop table t1;
21+
1222
--error ER_NULL_IN_VALUES_LESS_THAN
1323
create table t1 (a int)
1424
partition by range (a)
@@ -30,6 +40,7 @@ explain partitions select * from t1 where a < '2007-03-08 00:00:01';
3040
explain partitions select * from t1 where a <= '2007-03-08 00:00:00';
3141
explain partitions select * from t1 where a <= '2007-03-07 23:59:59';
3242
explain partitions select * from t1 where a < '2007-03-07 23:59:59';
43+
show create table t1;
3344
drop table t1;
3445
#
3546
# New test cases for new function to_seconds
@@ -44,6 +55,7 @@ explain partitions select * from t1 where a <= '2003-12-31';
4455
select * from t1 where a <= '2003-12-31';
4556
explain partitions select * from t1 where a <= '2005-01-01';
4657
select * from t1 where a <= '2005-01-01';
58+
show create table t1;
4759
drop table t1;
4860

4961
create table t1 (a datetime)
@@ -56,6 +68,7 @@ explain partitions select * from t1 where a <= '2004-01-01 11:59.59';
5668
select * from t1 where a <= '2004-01-01 11:59:59';
5769
explain partitions select * from t1 where a <= '2005-01-01';
5870
select * from t1 where a <= '2005-01-01';
71+
show create table t1;
5972
drop table t1;
6073

6174
#

sql/item.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,15 @@ class Item {
894894
(*traverser)(this, arg);
895895
}
896896

897+
/*
898+
This is used to get the most recent version of any function in
899+
an item tree. The version is the version where a MySQL function
900+
was introduced in. So any function which is added should use
901+
this function and set the int_arg to maximum of the input data
902+
and their own version info.
903+
*/
904+
virtual bool intro_version(uchar *int_arg) { return 0; }
905+
897906
virtual bool remove_dependence_processor(uchar * arg) { return 0; }
898907
virtual bool remove_fixed(uchar * arg) { fixed= 0; return 0; }
899908
virtual bool cleanup_processor(uchar *arg);

sql/item_timefunc.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ class Item_func_to_seconds :public Item_int_func
9191
enum_monotonicity_info get_monotonicity_info() const;
9292
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
9393
bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
94+
95+
bool intro_version(uchar *int_arg)
96+
{
97+
int *input_version= (int*)int_arg;
98+
/* This function was introduced in 5.5 */
99+
int output_version= (*input_version, 50500);
100+
*input_version= output_version;
101+
return 0;
102+
}
94103
};
95104

96105

sql/partition_info.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,42 @@ char *partition_info::create_default_partition_names(uint part_no,
115115
}
116116

117117

118+
/*
119+
Generate a version string for partition expression
120+
This function must be updated every time there is a possibility for
121+
a new function of a higher version number than 5.5.0.
122+
123+
SYNOPSIS
124+
set_show_version_string()
125+
RETURN VALUES
126+
None
127+
*/
128+
void partition_info::set_show_version_string(String *packet)
129+
{
130+
int version= 0;
131+
if (column_list)
132+
packet->append(STRING_WITH_LEN("\n/*!50500"));
133+
else
134+
{
135+
if (part_expr)
136+
part_expr->walk(&Item::intro_version, 0, (uchar*)&version);
137+
if (subpart_expr)
138+
subpart_expr->walk(&Item::intro_version, 0, (uchar*)&version);
139+
if (version == 0)
140+
{
141+
/* No new functions in partition function */
142+
packet->append(STRING_WITH_LEN("\n/*!50100"));
143+
}
144+
else
145+
{
146+
char buf[65];
147+
char *buf_ptr= longlong10_to_str((longlong)version, buf, 10);
148+
packet->append(STRING_WITH_LEN("\n/*!"));
149+
packet->append(buf, (size_t)(buf_ptr - buf));
150+
}
151+
}
152+
}
153+
118154
/*
119155
Create a unique name for the subpartition as part_name'sp''subpart_no'
120156
SYNOPSIS

sql/partition_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ class partition_info : public Sql_alloc
302302
bool check_partition_field_length();
303303
bool init_column_part();
304304
bool add_column_list_value(THD *thd, Item *item);
305+
void set_show_version_string(String *packet);
305306
private:
306307
static int list_part_cmp(const void* a, const void* b);
307308
bool set_up_default_partitions(handler *file, HA_CREATE_INFO *info,

sql/sql_show.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
14971497
show_table_options,
14981498
NULL, NULL))))
14991499
{
1500-
packet->append(STRING_WITH_LEN("\n/*!50100"));
1500+
table->part_info->set_show_version_string(packet);
15011501
packet->append(part_syntax, part_syntax_len);
15021502
packet->append(STRING_WITH_LEN(" */"));
15031503
my_free(part_syntax, MYF(0));

0 commit comments

Comments
 (0)