1#
2# Tests for the new column list partitioning introduced in second
3# version for partitioning.
4#
5--source include/have_partition.inc
6
7--disable_warnings
8drop table if exists t1;
9--enable_warnings
10
11--echo #
12--echo # Bug#52815: LIST COLUMNS doesn't insert rows in correct partition
13--echo #            if muliple columns used
14CREATE TABLE t1 (
15id INT NOT NULL,
16name VARCHAR(255),
17department VARCHAR(10),
18country VARCHAR(255)
19) PARTITION BY LIST COLUMNS (department, country) (
20PARTITION first_office VALUES IN (('dep1', 'Russia'), ('dep1', 'Croatia')),
21PARTITION second_office VALUES IN (('dep2', 'Russia'))
22);
23
24INSERT INTO t1 VALUES(1, 'Ann', 'dep1', 'Russia');
25INSERT INTO t1 VALUES(2, 'Bob', 'dep1', 'Croatia');
26INSERT INTO t1 VALUES(3, 'Cecil', 'dep2', 'Russia');
27--error ER_NO_PARTITION_FOR_GIVEN_VALUE
28INSERT INTO t1 VALUES(3, 'Dan', 'dep2', 'Croatia');
29SELECT PARTITION_NAME,TABLE_ROWS
30FROM INFORMATION_SCHEMA.PARTITIONS
31WHERE TABLE_NAME = 't1';
32SHOW CREATE TABLE t1;
33SELECT * FROM t1 WHERE department = 'dep2' and country = 'Croatia';
34SELECT * FROM t1 WHERE department = 'dep1' and country = 'Croatia';
35DROP TABLE t1;
36
37#
38# Bug#51347: assertion with show create table + partition by columns
39# on decimal column
40#
41--error ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD
42CREATE TABLE t1 (a DECIMAL)
43PARTITION BY RANGE COLUMNS (a)
44(PARTITION p0 VALUES LESS THAN (0));
45
46--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR
47CREATE TABLE t1 (a BLOB)
48PARTITION BY RANGE COLUMNS (a)
49(PARTITION p0 VALUES LESS THAN ("X"));
50
51--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR
52CREATE TABLE t1 (a TEXT)
53PARTITION BY RANGE COLUMNS (a)
54(PARTITION p0 VALUES LESS THAN ("X"));
55
56--error ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD
57CREATE TABLE t1 (a FLOAT)
58PARTITION BY RANGE COLUMNS (a)
59(PARTITION p0 VALUES LESS THAN (0.0));
60
61--error ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD
62CREATE TABLE t1 (a DOUBLE)
63PARTITION BY RANGE COLUMNS (a)
64(PARTITION p0 VALUES LESS THAN (0.0));
65
66--error ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD
67CREATE TABLE t1 (d TIMESTAMP)
68PARTITION BY RANGE COLUMNS(d)
69(PARTITION p0 VALUES LESS THAN ('2000-01-01'),
70 PARTITION p1 VALUES LESS THAN ('2040-01-01'));
71
72--error ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD
73CREATE TABLE t1 (d BIT(1))
74PARTITION BY RANGE COLUMNS(d)
75(PARTITION p0 VALUES LESS THAN (0),
76 PARTITION p1 VALUES LESS THAN (1));
77
78--error ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD
79CREATE TABLE t1 (d ENUM("YES","NO"))
80PARTITION BY RANGE COLUMNS(d)
81(PARTITION p0 VALUES LESS THAN ("NO"),
82 PARTITION p1 VALUES LESS THAN (MAXVALUE));
83
84--error ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD
85CREATE TABLE t1 (d SET("Car","MC"))
86PARTITION BY RANGE COLUMNS(d)
87(PARTITION p0 VALUES LESS THAN ("MC"),
88 PARTITION p1 VALUES LESS THAN (MAXVALUE));
89
90#
91# BUG#49180, Possible to define empty intervals for column list partitioning
92#
93--error ER_RANGE_NOT_INCREASING_ERROR
94create table t1 (a int, b int)
95partition by range columns (a,b)
96( partition p0 values less than (maxvalue, 10),
97  partition p1 values less than (maxvalue, maxvalue));
98
99--error ER_RANGE_NOT_INCREASING_ERROR
100create table t1 (a int, b int, c int)
101partition by range columns (a,b,c)
102( partition p0 values less than (1, maxvalue, 10),
103  partition p1 values less than (1, maxvalue, maxvalue));
104
105#
106# BUG#48737, Search fails with ucs2
107#
108create table t1 (a varchar(5) character set ucs2 collate ucs2_bin)
109partition by range columns (a)
110(partition p0 values less than (0x0041));
111insert into t1 values (0x00410000);
112select hex(a) from t1 where a like 'A_';
113explain partitions select hex(a) from t1 where a like 'A_';
114alter table t1 remove partitioning;
115select hex(a) from t1 where a like 'A_';
116create index a on t1 (a);
117select hex(a) from t1 where a like 'A_';
118insert into t1 values ('A_');
119select hex(a) from t1;
120drop table t1;
121
122#
123# BUG#48161, Delivering too few records using collate syntax with partitions
124#
125# Test case from BUG#48447 with some extension
126create table t1 (a varchar(1) character set latin1 collate latin1_general_ci)
127partition by range columns(a)
128( partition p0 values less than ('a'),
129  partition p1 values less than ('b'),
130  partition p2 values less than ('c'),
131  partition p3 values less than ('d'));
132insert into t1 values ('A'),('a'),('B'),('b'),('C'),('c');
133select * from t1 where a > 'B' collate latin1_bin;
134select * from t1 where a <> 'B' collate latin1_bin;
135alter table t1 remove partitioning;
136select * from t1 where a > 'B' collate latin1_bin;
137select * from t1 where a <> 'B' collate latin1_bin;
138drop table t1;
139
140# Test case from BUG#48161
141create table t1 (a varchar(2) character set latin1,
142                 b varchar(2) character set latin1)
143partition by list columns(a,b)
144(partition p0 values in (('a','a')));
145insert into t1 values ('A','A');
146select * from t1 where b <> 'a' collate latin1_bin AND
147                       a = 'A' collate latin1_bin;
148alter table t1 remove partitioning;
149select * from t1 where b <> 'a' collate latin1_bin AND
150                       a = 'A' collate latin1_bin;
151drop table t1;
152
153create table t1 (a varchar(5))
154partition by list columns(a)
155( partition p0 values in ('\''),
156  partition p1 values in ('\\'),
157  partition p2 values in ('\0'));
158show create table t1;
159drop table t1;
160
161#
162# BUG#48165, sql_mode gives error
163#
164set @@sql_mode=allow_invalid_dates;
165--error ER_WRONG_TYPE_COLUMN_VALUE_ERROR
166create table t1 (a char, b char, c date)
167partition by range columns (a,b,c)
168( partition p0 values less than (0,0,to_days('3000-11-31')));
169
170--error ER_WRONG_TYPE_COLUMN_VALUE_ERROR
171create table t1 (a char, b char, c date)
172partition by range columns (a,b,c)
173( partition p0 values less than (0,0,'3000-11-31'));
174set @@sql_mode='';
175
176--error ER_WRONG_TYPE_COLUMN_VALUE_ERROR
177create table t1 (a int, b char(10), c varchar(25), d datetime)
178partition by range columns(a,b,c,d)
179subpartition by hash (to_seconds(d))
180subpartitions 4
181( partition p0 values less than (1, 0, MAXVALUE, '1900-01-01'),
182  partition p1 values less than (1, 'a', MAXVALUE, '1999-01-01'),
183  partition p2 values less than (1, 'a', MAXVALUE, MAXVALUE),
184  partition p3 values less than (1, MAXVALUE, MAXVALUE, MAXVALUE));
185
186create table t1 (a int, b char(10), c varchar(25), d datetime)
187partition by range columns(a,b,c,d)
188subpartition by hash (to_seconds(d))
189subpartitions 4
190( partition p0 values less than (1, '0', MAXVALUE, '1900-01-01'),
191  partition p1 values less than (1, 'a', MAXVALUE, '1999-01-01'),
192  partition p2 values less than (1, 'b', MAXVALUE, MAXVALUE),
193  partition p3 values less than (1, MAXVALUE, MAXVALUE, MAXVALUE));
194select partition_method, partition_expression, partition_description
195  from information_schema.partitions where table_name = "t1";
196show create table t1;
197drop table t1;
198
199--error ER_NULL_IN_VALUES_LESS_THAN
200create table t1 (a int, b int)
201partition by range columns (a,b)
202(partition p0 values less than (NULL, maxvalue));
203
204--error ER_MAXVALUE_IN_VALUES_IN, ER_PARSE_ERROR
205create table t1 (a int, b int)
206partition by list columns(a,b)
207( partition p0 values in ((maxvalue, 0)));
208
209create table t1 (a int, b int)
210partition by list columns (a,b)
211( partition p0 values in ((0,0)));
212--error ER_MAXVALUE_IN_VALUES_IN, ER_PARSE_ERROR
213alter table t1 add partition
214(partition p1 values in (maxvalue, maxvalue));
215drop table t1;
216#
217# BUG#47837, Crash when two same fields in column list processing
218#
219--error ER_SAME_NAME_PARTITION_FIELD
220create table t1 (a int, b int)
221partition by key (a,a);
222--error ER_SAME_NAME_PARTITION_FIELD
223create table t1 (a int, b int)
224partition by list columns(a,a)
225( partition p values in ((1,1)));
226
227#
228# BUG#47838, List partitioning have problems with <= and >=
229#
230create table t1 (a int signed)
231partition by list (a)
232( partition p0 values in (1, 3, 5, 7, 9, NULL),
233  partition p1 values in (2, 4, 6, 8, 0));
234insert into t1 values (NULL),(0),(1),(2),(2),(4),(4),(4),(8),(8);
235select * from t1 where NULL <= a;
236select * from t1 where a is null;
237explain partitions select * from t1 where a is null;
238select * from t1 where a <= 1;
239drop table t1;
240
241create table t1 (a int signed)
242partition by list columns(a)
243( partition p0 values in (1, 3, 5, 7, 9, NULL),
244  partition p1 values in (2, 4, 6, 8, 0));
245insert into t1 values (NULL),(0),(1),(2),(2),(4),(4),(4),(8),(8);
246select * from t1 where a <= NULL;
247select * from t1 where a is null;
248explain partitions select * from t1 where a is null;
249select * from t1 where a <= 1;
250drop table t1;
251
252create table t1 (a int, b int)
253partition by list columns(a,b)
254( partition p0 values in ((1, NULL), (2, NULL), (NULL, NULL)),
255  partition p1 values in ((1,1), (2,2)),
256  partition p2 values in ((3, NULL), (NULL, 1)));
257select partition_method, partition_expression, partition_description
258  from information_schema.partitions where table_name = "t1";
259show create table t1;
260#
261# BUG#47754 Crash when selecting using NOT BETWEEN for column list partitioning
262#
263insert into t1 values (3, NULL);
264insert into t1 values (NULL, 1);
265insert into t1 values (NULL, NULL);
266insert into t1 values (1, NULL);
267insert into t1 values (2, NULL);
268insert into t1 values (1,1);
269insert into t1 values (2,2);
270select * from t1 where a = 1;
271select * from t1 where a = 2;
272select * from t1 where a > 8;
273select * from t1 where a not between 8 and 8;
274show create table t1;
275drop table t1;
276
277--error ER_MULTIPLE_DEF_CONST_IN_LIST_PART_ERROR
278create table t1 (a int)
279partition by list (a)
280( partition p0 values in (1),
281  partition p1 values in (1));
282
283create table t1 (a int)
284partition by list (a)
285( partition p0 values in (2, 1),
286  partition p1 values in (4, NULL, 3));
287select partition_method, partition_expression, partition_description
288  from information_schema.partitions where table_name = "t1";
289show create table t1;
290insert into t1 values (1);
291insert into t1 values (2);
292insert into t1 values (3);
293insert into t1 values (4);
294insert into t1 values (NULL);
295--error ER_NO_PARTITION_FOR_GIVEN_VALUE
296insert into t1 values (5);
297drop table t1;
298
299--error ER_PARSE_ERROR
300create table t1 (a int)
301partition by list columns(a)
302( partition p0 values in (2, 1),
303  partition p1 values in ((4), (NULL), (3)));
304
305create table t1 (a int)
306partition by list columns(a)
307( partition p0 values in (2, 1),
308  partition p1 values in (4, NULL, 3));
309select partition_method, partition_expression, partition_description
310 from information_schema.partitions where table_name = "t1";
311show create table t1;
312insert into t1 values (1);
313insert into t1 values (2);
314insert into t1 values (3);
315insert into t1 values (4);
316insert into t1 values (NULL);
317--error ER_NO_PARTITION_FOR_GIVEN_VALUE
318insert into t1 values (5);
319show create table t1;
320drop table t1;
321
322create table t1 (a int, b char(10), c varchar(5), d int)
323partition by range columns(a,b,c)
324subpartition by key (c,d)
325subpartitions 3
326( partition p0 values less than (1,'abc','abc'),
327  partition p1 values less than (2,'abc','abc'),
328  partition p2 values less than (3,'abc','abc'),
329  partition p3 values less than (4,'abc','abc'));
330select partition_method, partition_expression, partition_description
331  from information_schema.partitions where table_name = "t1";
332show create table t1;
333
334insert into t1 values (1,'a','b',1),(2,'a','b',2),(3,'a','b',3);
335insert into t1 values (1,'b','c',1),(2,'b','c',2),(3,'b','c',3);
336insert into t1 values (1,'c','d',1),(2,'c','d',2),(3,'c','d',3);
337insert into t1 values (1,'d','e',1),(2,'d','e',2),(3,'d','e',3);
338select * from t1 where (a = 1 AND b < 'd' AND (c = 'b' OR (c = 'c' AND d = 1)) OR
339                       (a = 1 AND b >= 'a' AND (c = 'c' OR (c = 'd' AND d = 2))));
340drop table t1;
341
342create table t1 (a int, b varchar(2), c int)
343partition by range columns (a, b, c)
344(partition p0 values less than (1, 'A', 1),
345 partition p1 values less than (1, 'B', 1));
346select partition_method, partition_expression, partition_description
347  from information_schema.partitions where table_name = "t1";
348show create table t1;
349insert into t1 values (1, 'A', 1);
350explain partitions select * from t1 where a = 1 AND b <= 'A' and c = 1;
351select * from t1 where a = 1 AND b <= 'A' and c = 1;
352drop table t1;
353
354create table t1 (a char, b char, c char)
355partition by list columns(a)
356( partition p0 values in ('a'));
357insert into t1 (a) values ('a');
358select * from t1 where a = 'a';
359drop table t1;
360
361--error ER_WRONG_TYPE_COLUMN_VALUE_ERROR
362create table t1 (d time)
363partition by range columns(d)
364( partition p0 values less than ('2000-01-01'),
365  partition p1 values less than ('2040-01-01'));
366
367create table t1 (a int, b int)
368partition by range columns(a,b)
369(partition p0 values less than (maxvalue, 10));
370drop table t1;
371
372create table t1 (d date)
373partition by range columns(d)
374( partition p0 values less than ('2000-01-01'),
375  partition p1 values less than ('2009-01-01'));
376drop table t1;
377
378create table t1 (d date)
379partition by range columns(d)
380( partition p0 values less than ('1999-01-01'),
381  partition p1 values less than ('2000-01-01'));
382drop table t1;
383
384create table t1 (d date)
385partition by range columns(d)
386( partition p0 values less than ('2000-01-01'),
387  partition p1 values less than ('3000-01-01'));
388drop table t1;
389
390create table t1 (a int, b int)
391partition by range columns(a,b)
392(partition p2 values less than (99,99),
393 partition p1 values less than (99,999));
394
395insert into t1 values (99,998);
396select * from t1 where b = 998;
397drop table t1;
398
399create table t1 as select to_seconds(null) as to_seconds;
400select data_type from information_schema.columns
401where table_schema='test' and column_name='to_seconds';
402drop table t1;
403
404--error ER_PARSE_ERROR
405create table t1 (a int, b int)
406partition by list columns(a,b)
407(partition p0 values in ((maxvalue,maxvalue)));
408create table t1 (a int, b int)
409partition by range columns(a,b)
410(partition p0 values less than (maxvalue,maxvalue));
411drop table t1;
412
413create table t1 (a int)
414partition by list columns(a)
415(partition p0 values in (0));
416select partition_method from information_schema.partitions where table_name='t1';
417drop table t1;
418
419create table t1 (a char(6))
420partition by range columns(a)
421(partition p0 values less than ('H23456'),
422 partition p1 values less than ('M23456'));
423insert into t1 values ('F23456');
424select * from t1;
425drop table t1;
426
427-- error 1054
428create table t1 (a char(6))
429partition by range columns(a)
430(partition p0 values less than (H23456),
431 partition p1 values less than (M23456));
432
433-- error ER_WRONG_TYPE_COLUMN_VALUE_ERROR
434create table t1 (a char(6))
435partition by range columns(a)
436(partition p0 values less than (23456),
437 partition p1 values less than (23456));
438
439-- error 1064
440create table t1 (a int, b int)
441partition by range columns(a,b)
442(partition p0 values less than (10));
443
444-- error ER_PARTITION_COLUMN_LIST_ERROR
445create table t1 (a int, b int)
446partition by range columns(a,b)
447(partition p0 values less than (1,1,1);
448
449create table t1 (a int, b int)
450partition by range columns(a,b)
451(partition p0 values less than (1, 0),
452 partition p1 values less than (2, maxvalue),
453 partition p2 values less than (3, 3),
454 partition p3 values less than (10, maxvalue));
455
456-- error ER_NO_PARTITION_FOR_GIVEN_VALUE
457insert into t1 values (11,0);
458insert into t1 values (0,1),(1,1),(2,1),(3,1),(3,4),(4,9),(9,1);
459select * from t1;
460
461alter table t1
462partition by range columns(b,a)
463(partition p0 values less than (1,2),
464 partition p1 values less than (3,3),
465 partition p2 values less than (9,5));
466explain partitions select * from t1 where b < 2;
467select * from t1 where b < 2;
468explain partitions select * from t1 where b < 4;
469select * from t1 where b < 4;
470
471alter table t1 reorganize partition p1 into
472(partition p11 values less than (2,2),
473 partition p12 values less than (3,3));
474
475-- error ER_REORG_OUTSIDE_RANGE
476alter table t1 reorganize partition p0 into
477(partition p01 values less than (0,3),
478 partition p02 values less than (1,1));
479
480-- error ER_PARTITION_COLUMN_LIST_ERROR
481alter table t1 reorganize partition p2 into
482(partition p2 values less than(9,6,1));
483
484-- error ER_PARTITION_COLUMN_LIST_ERROR
485alter table t1 reorganize partition p2 into
486(partition p2 values less than (10));
487
488alter table t1 reorganize partition p2 into
489(partition p21 values less than (4,7),
490 partition p22 values less than (9,5));
491explain partitions select * from t1 where b < 4;
492select * from t1 where b < 4;
493drop table t1;
494
495create table t1 (a int, b int)
496partition by list columns(a,b)
497subpartition by hash (b)
498subpartitions 2
499(partition p0 values in ((0,0), (1,1)),
500 partition p1 values in ((1000,1000)));
501insert into t1 values (1000,1000);
502#select * from t1 where a = 0 and b = 0;
503drop table t1;
504
505create table t1 (a char, b char, c char)
506partition by range columns(a,b,c)
507( partition p0 values less than ('a','b','c'));
508alter table t1 add partition
509(partition p1 values less than ('b','c','d'));
510drop table t1;
511