Skip to content

Commit e2cb1cb

Browse files
jhauglidDmitry Lenev
authored andcommitted
Bug#18513130: STRANGE INTERACTION OF SQL_MODE=ANSI AND PARTITION BY TIMESTAMP
The problem was that the presence of the ANSI_QUOTES SQL mode influenced how partitioning expressions were stored and how they were parsed on table definition load. This made it possible to successfully create a partitioned table that would result in a parsing error on later retrieval if the SQL mode changed in the meantime. This patch fixes the problem by temporarily turning off ANSI_QUOTES when storing partitioning expressions in the data dictionary and when they are printed using SHOW CREATE TABLE. This means that partitioning expressions are no longer stored exactly as given by the user, but rather using Item::print() after the expression has been parsed. This is similar to how view expressions are handled. This patch also enforces that (sub-)partition expressions can be maximum 2048 characters long. Before this fix, the server would assert if a longer expression was used.
1 parent 01d51f5 commit e2cb1cb

File tree

94 files changed

+1890
-1648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1890
-1648
lines changed

include/mysql_com.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#define SYSTEM_CHARSET_MBMAXLEN 3
4444
#define FILENAME_CHARSET_MBMAXLEN 5
4545
#define NAME_CHAR_LEN 64 /**< Field/table name length */
46+
#define PARTITION_EXPR_CHAR_LEN 2048 /**< Maximum expression length in chars */
4647
#define USERNAME_CHAR_LENGTH 32
4748
#define USERNAME_CHAR_LENGTH_STR "32"
4849
#ifndef NAME_LEN

mysql-test/r/alter_table_partition.result

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ t1 CREATE TABLE `t1` (
3636
`purchased` date DEFAULT NULL,
3737
KEY `id` (`id`)
3838
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
39-
/*!50100 PARTITION BY RANGE (YEAR(purchased))
39+
/*!50100 PARTITION BY RANGE (year(`purchased`))
4040
(PARTITION p0 VALUES LESS THAN (1990) ENGINE = InnoDB,
4141
PARTITION p1 VALUES LESS THAN (1995) ENGINE = InnoDB,
4242
PARTITION p2 VALUES LESS THAN (2000) ENGINE = InnoDB,
@@ -63,7 +63,7 @@ t1 CREATE TABLE `t1` (
6363
`purchased` date DEFAULT NULL,
6464
KEY `id` (`id`)
6565
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
66-
/*!50100 PARTITION BY RANGE (YEAR(purchased))
66+
/*!50100 PARTITION BY RANGE (year(`purchased`))
6767
(PARTITION p0 VALUES LESS THAN (1990) ENGINE = InnoDB,
6868
PARTITION p1 VALUES LESS THAN (1995) ENGINE = InnoDB,
6969
PARTITION p2 VALUES LESS THAN (2000) ENGINE = InnoDB,
@@ -88,7 +88,7 @@ t1 CREATE TABLE `t1` (
8888
`purchased` date DEFAULT NULL,
8989
KEY `id` (`id`)
9090
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
91-
/*!50100 PARTITION BY RANGE (YEAR(purchased))
91+
/*!50100 PARTITION BY RANGE (year(`purchased`))
9292
(PARTITION p0 VALUES LESS THAN (1990) ENGINE = InnoDB,
9393
PARTITION p1 VALUES LESS THAN (1995) ENGINE = InnoDB,
9494
PARTITION p2 VALUES LESS THAN (2000) ENGINE = InnoDB,
@@ -112,7 +112,7 @@ t1 CREATE TABLE `t1` (
112112
`purchased` date DEFAULT NULL,
113113
KEY `id` (`id`)
114114
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
115-
/*!50100 PARTITION BY RANGE (YEAR(purchased))
115+
/*!50100 PARTITION BY RANGE (year(`purchased`))
116116
(PARTITION p0 VALUES LESS THAN (1990) ENGINE = InnoDB,
117117
PARTITION p1 VALUES LESS THAN (1995) ENGINE = InnoDB,
118118
PARTITION p2 VALUES LESS THAN (2000) ENGINE = InnoDB,
@@ -139,7 +139,7 @@ t1 CREATE TABLE `t1` (
139139
`purchased` date DEFAULT NULL,
140140
KEY `id` (`id`)
141141
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
142-
/*!50100 PARTITION BY RANGE (YEAR(purchased))
142+
/*!50100 PARTITION BY RANGE (year(`purchased`))
143143
(PARTITION p0 VALUES LESS THAN (1990) ENGINE = InnoDB,
144144
PARTITION p1 VALUES LESS THAN (1995) ENGINE = InnoDB,
145145
PARTITION p2 VALUES LESS THAN (2000) ENGINE = InnoDB,
@@ -164,7 +164,7 @@ t1 CREATE TABLE `t1` (
164164
`purchased` date DEFAULT NULL,
165165
KEY `id` (`id`)
166166
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
167-
/*!50100 PARTITION BY RANGE (YEAR(purchased))
167+
/*!50100 PARTITION BY RANGE (year(`purchased`))
168168
(PARTITION p0 VALUES LESS THAN (1990) ENGINE = InnoDB,
169169
PARTITION p1 VALUES LESS THAN (1995) ENGINE = InnoDB,
170170
PARTITION p2 VALUES LESS THAN (2000) ENGINE = InnoDB,
@@ -187,7 +187,7 @@ t1 CREATE TABLE `t1` (
187187
`purchased` date DEFAULT NULL,
188188
KEY `id` (`id`)
189189
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
190-
/*!50100 PARTITION BY RANGE (YEAR(purchased))
190+
/*!50100 PARTITION BY RANGE (year(`purchased`))
191191
(PARTITION p0 VALUES LESS THAN (1990) ENGINE = InnoDB,
192192
PARTITION p1 VALUES LESS THAN (1995) ENGINE = InnoDB,
193193
PARTITION p2 VALUES LESS THAN (2000) ENGINE = InnoDB,

mysql-test/r/information_schema_part.result

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
1010
select * from information_schema.partitions where table_schema="test"
1111
and table_name="t1";
1212
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME
13-
def test t1 x1 NULL 1 NULL LIST NULL b*a NULL 1 0 0 16384 # 0 0 # # NULL NULL default ts1
14-
def test t1 x2 NULL 2 NULL LIST NULL b*a NULL 3,11,5,7 0 0 16384 # 0 0 # # NULL NULL default ts2
15-
def test t1 x3 NULL 3 NULL LIST NULL b*a NULL 16,8,24,27 0 0 16384 # 0 0 # # NULL NULL default ts3
13+
def test t1 x1 NULL 1 NULL LIST NULL (`b` * `a`) NULL 1 0 0 16384 # 0 0 # # NULL NULL default ts1
14+
def test t1 x2 NULL 2 NULL LIST NULL (`b` * `a`) NULL 3,11,5,7 0 0 16384 # 0 0 # # NULL NULL default ts2
15+
def test t1 x3 NULL 3 NULL LIST NULL (`b` * `a`) NULL 16,8,24,27 0 0 16384 # 0 0 # # NULL NULL default ts3
1616
create table t2 (a int not null,b int not null,c int not null, primary key(a,b))
1717
partition by range (a)
1818
partitions 3
@@ -22,18 +22,18 @@ partition x3 values less than maxvalue tablespace ts3);
2222
select * from information_schema.partitions where table_schema="test"
2323
and table_name="t2";
2424
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME
25-
def test t2 x1 NULL 1 NULL RANGE NULL a NULL 5 0 0 16384 # 0 0 # # NULL NULL default ts1
26-
def test t2 x2 NULL 2 NULL RANGE NULL a NULL 10 0 0 16384 # 0 0 # # NULL NULL default ts2
27-
def test t2 x3 NULL 3 NULL RANGE NULL a NULL MAXVALUE 0 0 16384 # 0 0 # # NULL NULL default ts3
25+
def test t2 x1 NULL 1 NULL RANGE NULL `a` NULL 5 0 0 16384 # 0 0 # # NULL NULL default ts1
26+
def test t2 x2 NULL 2 NULL RANGE NULL `a` NULL 10 0 0 16384 # 0 0 # # NULL NULL default ts2
27+
def test t2 x3 NULL 3 NULL RANGE NULL `a` NULL MAXVALUE 0 0 16384 # 0 0 # # NULL NULL default ts3
2828
create table t3 (f1 date)
2929
partition by hash(month(f1))
3030
partitions 3;
3131
select * from information_schema.partitions where table_schema="test"
3232
and table_name="t3";
3333
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME
34-
def test t3 p0 NULL 1 NULL HASH NULL month(f1) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
35-
def test t3 p1 NULL 2 NULL HASH NULL month(f1) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
36-
def test t3 p2 NULL 3 NULL HASH NULL month(f1) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
34+
def test t3 p0 NULL 1 NULL HASH NULL month(`f1`) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
35+
def test t3 p1 NULL 2 NULL HASH NULL month(`f1`) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
36+
def test t3 p2 NULL 3 NULL HASH NULL month(`f1`) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
3737
create table t4 (f1 date, f2 int)
3838
partition by key(f1,f2)
3939
partitions 3;
@@ -68,14 +68,14 @@ subpartition x22 tablespace tbsp2)
6868
);
6969
select * from information_schema.partitions where table_schema="test";
7070
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME
71-
def test t1 x1 x11 1 1 RANGE HASH a a+b 1 0 0 16384 # 0 0 # # NULL NULL default tbsp1
72-
def test t1 x1 x12 1 2 RANGE HASH a a+b 1 0 0 16384 # 0 0 # # NULL NULL default tbsp2
73-
def test t1 x2 x21 2 1 RANGE HASH a a+b 5 0 0 16384 # 0 0 # # NULL NULL default tbsp1
74-
def test t1 x2 x22 2 2 RANGE HASH a a+b 5 0 0 16384 # 0 0 # # NULL NULL default tbsp2
75-
def test t2 x1 x11 1 1 RANGE KEY a `a` 1 0 0 16384 # 0 0 # # NULL NULL default tbsp1
76-
def test t2 x1 x12 1 2 RANGE KEY a `a` 1 0 0 16384 # 0 0 # # NULL NULL default tbsp2
77-
def test t2 x2 x21 2 1 RANGE KEY a `a` 5 0 0 16384 # 0 0 # # NULL NULL default tbsp1
78-
def test t2 x2 x22 2 2 RANGE KEY a `a` 5 0 0 16384 # 0 0 # # NULL NULL default tbsp2
71+
def test t1 x1 x11 1 1 RANGE HASH `a` (`a` + `b`) 1 0 0 16384 # 0 0 # # NULL NULL default tbsp1
72+
def test t1 x1 x12 1 2 RANGE HASH `a` (`a` + `b`) 1 0 0 16384 # 0 0 # # NULL NULL default tbsp2
73+
def test t1 x2 x21 2 1 RANGE HASH `a` (`a` + `b`) 5 0 0 16384 # 0 0 # # NULL NULL default tbsp1
74+
def test t1 x2 x22 2 2 RANGE HASH `a` (`a` + `b`) 5 0 0 16384 # 0 0 # # NULL NULL default tbsp2
75+
def test t2 x1 x11 1 1 RANGE KEY `a` `a` 1 0 0 16384 # 0 0 # # NULL NULL default tbsp1
76+
def test t2 x1 x12 1 2 RANGE KEY `a` `a` 1 0 0 16384 # 0 0 # # NULL NULL default tbsp2
77+
def test t2 x2 x21 2 1 RANGE KEY `a` `a` 5 0 0 16384 # 0 0 # # NULL NULL default tbsp1
78+
def test t2 x2 x22 2 2 RANGE KEY `a` `a` 5 0 0 16384 # 0 0 # # NULL NULL default tbsp2
7979
drop table t1,t2;
8080
create table t1 (
8181
a int not null,
@@ -93,10 +93,10 @@ subpartition x22 tablespace tbsp2 nodegroup 1)
9393
);
9494
select * from information_schema.partitions where table_schema="test";
9595
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME
96-
def test t1 x1 x11 1 1 RANGE HASH a a+b 1 0 0 16384 # 0 0 # # NULL NULL 0 tbsp1
97-
def test t1 x1 x12 1 2 RANGE HASH a a+b 1 0 0 16384 # 0 0 # # NULL NULL 1 tbsp2
98-
def test t1 x2 x21 2 1 RANGE HASH a a+b 5 0 0 16384 # 0 0 # # NULL NULL 0 tbsp1
99-
def test t1 x2 x22 2 2 RANGE HASH a a+b 5 0 0 16384 # 0 0 # # NULL NULL 1 tbsp2
96+
def test t1 x1 x11 1 1 RANGE HASH `a` (`a` + `b`) 1 0 0 16384 # 0 0 # # NULL NULL 0 tbsp1
97+
def test t1 x1 x12 1 2 RANGE HASH `a` (`a` + `b`) 1 0 0 16384 # 0 0 # # NULL NULL 1 tbsp2
98+
def test t1 x2 x21 2 1 RANGE HASH `a` (`a` + `b`) 5 0 0 16384 # 0 0 # # NULL NULL 0 tbsp1
99+
def test t1 x2 x22 2 2 RANGE HASH `a` (`a` + `b`) 5 0 0 16384 # 0 0 # # NULL NULL 1 tbsp2
100100
show tables;
101101
Tables_in_test
102102
t1
@@ -112,9 +112,9 @@ partitions 3;
112112
select * from information_schema.partitions where table_schema="test"
113113
and table_name="t1";
114114
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PARTITION_NAME SUBPARTITION_NAME PARTITION_ORDINAL_POSITION SUBPARTITION_ORDINAL_POSITION PARTITION_METHOD SUBPARTITION_METHOD PARTITION_EXPRESSION SUBPARTITION_EXPRESSION PARTITION_DESCRIPTION TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE CREATE_TIME UPDATE_TIME CHECK_TIME CHECKSUM PARTITION_COMMENT NODEGROUP TABLESPACE_NAME
115-
def test t1 p0 NULL 1 NULL LINEAR HASH NULL month(f1) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
116-
def test t1 p1 NULL 2 NULL LINEAR HASH NULL month(f1) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
117-
def test t1 p2 NULL 3 NULL LINEAR HASH NULL month(f1) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
115+
def test t1 p0 NULL 1 NULL LINEAR HASH NULL month(`f1`) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
116+
def test t1 p1 NULL 2 NULL LINEAR HASH NULL month(`f1`) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
117+
def test t1 p2 NULL 3 NULL LINEAR HASH NULL month(`f1`) NULL NULL 0 0 16384 # 0 0 # # NULL NULL default NULL
118118
drop table t1;
119119
create table t1 (a int)
120120
PARTITION BY RANGE (a)
@@ -125,8 +125,8 @@ Table Create Table
125125
t1 CREATE TABLE `t1` (
126126
`a` int(11) DEFAULT NULL
127127
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
128-
/*!50100 PARTITION BY RANGE (a)
129-
SUBPARTITION BY LINEAR HASH (a)
128+
/*!50100 PARTITION BY RANGE (`a`)
129+
SUBPARTITION BY LINEAR HASH (`a`)
130130
(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB) */
131131
select SUBPARTITION_METHOD FROM information_schema.partitions WHERE
132132
table_schema="test" AND table_name="t1";
@@ -143,7 +143,7 @@ Table Create Table
143143
t1 CREATE TABLE `t1` (
144144
`a` int(11) DEFAULT NULL
145145
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
146-
/*!50100 PARTITION BY LIST (a)
146+
/*!50100 PARTITION BY LIST (`a`)
147147
(PARTITION p0 VALUES IN (10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53) ENGINE = InnoDB) */
148148
SELECT PARTITION_DESCRIPTION FROM information_schema.partitions WHERE
149149
table_schema = "test" AND table_name = "t1";

0 commit comments

Comments
 (0)