1 drop table if exists t1, t2;
3 # Bug#48229: group by performance issue of partitioned table
10 PARTITION BY HASH (a) PARTITIONS 1;
11 INSERT INTO t1 VALUES (0, 580092), (3, 894076), (4, 805483), (4, 913540), (6, 611137), (8, 171602), (9, 599495), (9, 746305), (10, 272829), (10, 847519), (12, 258869), (12, 929028), (13, 288970), (15, 20971), (15, 105839), (16, 788272), (17, 76914), (18, 827274), (19, 802258), (20, 123677), (20, 587729), (22, 701449), (25, 31565), (25, 230782), (25, 442887), (25, 733139), (25, 851020);
12 EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100, 3) GROUP BY a;
13 id select_type table type possible_keys key key_len ref rows Extra
14 1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
16 create table t1 (a int)
17 partition by range (a)
18 ( partition p0 values less than (maxvalue));
19 alter table t1 add partition (partition p1 values less than (100000));
20 ERROR HY000: MAXVALUE can only be used in last partition definition
23 t1 CREATE TABLE `t1` (
24 `a` int(11) DEFAULT NULL
25 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
26 /*!50100 PARTITION BY RANGE (a)
27 (PARTITION p0 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
29 create table t1 (a integer)
30 partition by range (a)
31 ( partition p0 values less than (4),
32 partition p1 values less than (100));
33 create trigger tr1 before insert on t1
37 alter table t1 drop partition p0;
39 create table t1 (a integer)
40 partition by range (a)
41 ( partition p0 values less than (4),
42 partition p1 values less than (100));
44 alter table t1 drop partition p0;
45 alter table t1 reorganize partition p1 into
46 ( partition p0 values less than (4),
47 partition p1 values less than (100));
48 alter table t1 add partition ( partition p2 values less than (200));
51 create table t1 (a int unsigned)
52 partition by range (a)
53 (partition pnull values less than (0),
54 partition p0 values less than (1),
55 partition p1 values less than(2));
56 insert into t1 values (null),(0),(1);
57 select * from t1 where a is null;
60 select * from t1 where a >= 0;
64 select * from t1 where a < 0;
66 select * from t1 where a <= 0;
69 select * from t1 where a > 1;
71 explain partitions select * from t1 where a is null;
72 id select_type table partitions type possible_keys key key_len ref rows Extra
73 1 SIMPLE t1 pnull system NULL NULL NULL NULL 1
74 explain partitions select * from t1 where a >= 0;
75 id select_type table partitions type possible_keys key key_len ref rows Extra
76 1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 2 Using where
77 explain partitions select * from t1 where a < 0;
78 id select_type table partitions type possible_keys key key_len ref rows Extra
79 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
80 explain partitions select * from t1 where a <= 0;
81 id select_type table partitions type possible_keys key key_len ref rows Extra
82 1 SIMPLE t1 pnull,p0 ALL NULL NULL NULL NULL 2 Using where
83 explain partitions select * from t1 where a > 1;
84 id select_type table partitions type possible_keys key key_len ref rows Extra
85 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
87 create table t1 (a int unsigned, b int unsigned)
88 partition by range (a)
89 subpartition by hash (b)
91 (partition pnull values less than (0),
92 partition p0 values less than (1),
93 partition p1 values less than(2));
94 insert into t1 values (null,0),(null,1),(0,0),(0,1),(1,0),(1,1);
95 select * from t1 where a is null;
99 select * from t1 where a >= 0;
105 select * from t1 where a < 0;
107 select * from t1 where a <= 0;
111 select * from t1 where a > 1;
113 explain partitions select * from t1 where a is null;
114 id select_type table partitions type possible_keys key key_len ref rows Extra
115 1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1 ALL NULL NULL NULL NULL 2 Using where
116 explain partitions select * from t1 where a >= 0;
117 id select_type table partitions type possible_keys key key_len ref rows Extra
118 1 SIMPLE t1 p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1 ALL NULL NULL NULL NULL 4 Using where
119 explain partitions select * from t1 where a < 0;
120 id select_type table partitions type possible_keys key key_len ref rows Extra
121 1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1 ALL NULL NULL NULL NULL 2 Using where
122 explain partitions select * from t1 where a <= 0;
123 id select_type table partitions type possible_keys key key_len ref rows Extra
124 1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1,p0_p0sp0,p0_p0sp1 ALL NULL NULL NULL NULL 4 Using where
125 explain partitions select * from t1 where a > 1;
126 id select_type table partitions type possible_keys key key_len ref rows Extra
127 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
134 partition by range (a)
136 (partition x1 values less than (5) tablespace ts1,
137 partition x2 values less than (10) tablespace ts2,
138 partition x3 values less than maxvalue tablespace ts3);
139 INSERT into t1 values (1, 1, 1);
140 INSERT into t1 values (6, 1, 1);
141 INSERT into t1 values (10, 1, 1);
142 INSERT into t1 values (15, 1, 1);
149 show create table t1;
151 t1 CREATE TABLE `t1` (
152 `a` int(11) NOT NULL,
153 `b` int(11) NOT NULL,
154 `c` int(11) NOT NULL,
155 PRIMARY KEY (`a`,`b`)
156 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
157 /*!50100 PARTITION BY RANGE (a)
158 (PARTITION x1 VALUES LESS THAN (5) TABLESPACE = ts1 ENGINE = MyISAM,
159 PARTITION x2 VALUES LESS THAN (10) TABLESPACE = ts2 ENGINE = MyISAM,
160 PARTITION x3 VALUES LESS THAN MAXVALUE TABLESPACE = ts3 ENGINE = MyISAM) */
162 partition by range (a)
164 (partition x1 values less than (5) tablespace ts1,
165 partition x2 values less than (10) tablespace ts2,
166 partition x3 values less than maxvalue tablespace ts3);
173 show create table t1;
175 t1 CREATE TABLE `t1` (
176 `a` int(11) NOT NULL,
177 `b` int(11) NOT NULL,
178 `c` int(11) NOT NULL,
179 PRIMARY KEY (`a`,`b`)
180 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
181 /*!50100 PARTITION BY RANGE (a)
182 (PARTITION x1 VALUES LESS THAN (5) TABLESPACE = ts1 ENGINE = MyISAM,
183 PARTITION x2 VALUES LESS THAN (10) TABLESPACE = ts2 ENGINE = MyISAM,
184 PARTITION x3 VALUES LESS THAN MAXVALUE TABLESPACE = ts3 ENGINE = MyISAM) */
185 drop table if exists t1;
190 partition by range (a)
192 (partition x1 values less than (5) tablespace ts1,
193 partition x2 values less than (10) tablespace ts2,
194 partition x3 values less than maxvalue tablespace ts3);
195 INSERT into t1 values (1, 1, 1);
196 INSERT into t1 values (6, 1, 1);
197 INSERT into t1 values (10, 1, 1);
198 INSERT into t1 values (15, 1, 1);
206 partition by range (a)
208 (partition x1 values less than (5) tablespace ts1,
209 partition x2 values less than (10) tablespace ts2,
210 partition x3 values less than maxvalue tablespace ts3);
217 drop table if exists t1;
223 partition by range (a)
225 (partition x1 values less than (5) tablespace ts1,
226 partition x2 values less than (10) tablespace ts2,
227 partition x3 values less than (15) tablespace ts3);
228 INSERT into t1 values (1, 1, 1);
229 INSERT into t1 values (6, 1, 1);
230 INSERT into t1 values (10, 1, 1);
231 INSERT into t1 values (15, 1, 1);
232 ERROR HY000: Table has no partition for value 15
239 partition by range (a)
241 (partition x1 values less than (5) tablespace ts1,
242 partition x2 values less than (10) tablespace ts2,
243 partition x3 values less than (15) tablespace ts3);
255 partition by range (a)
256 (partition x1 values less than (1));
263 partition by range (a)
264 subpartition by hash (a+b)
265 ( partition x1 values less than (1)
268 partition x2 values less than (5)
274 show create table t1;
276 t1 CREATE TABLE `t1` (
277 `a` int(11) NOT NULL,
278 `b` int(11) NOT NULL,
279 `c` int(11) NOT NULL,
280 PRIMARY KEY (`a`,`b`)
281 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
282 /*!50100 PARTITION BY RANGE (a)
283 SUBPARTITION BY HASH (a+b)
284 (PARTITION x1 VALUES LESS THAN (1)
285 (SUBPARTITION x11 ENGINE = MyISAM,
286 SUBPARTITION x12 ENGINE = MyISAM),
287 PARTITION x2 VALUES LESS THAN (5)
288 (SUBPARTITION x21 ENGINE = MyISAM,
289 SUBPARTITION x22 ENGINE = MyISAM)) */
290 ALTER TABLE t1 ADD COLUMN d int;
291 show create table t1;
293 t1 CREATE TABLE `t1` (
294 `a` int(11) NOT NULL,
295 `b` int(11) NOT NULL,
296 `c` int(11) NOT NULL,
297 `d` int(11) DEFAULT NULL,
298 PRIMARY KEY (`a`,`b`)
299 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
300 /*!50100 PARTITION BY RANGE (a)
301 SUBPARTITION BY HASH (a+b)
302 (PARTITION x1 VALUES LESS THAN (1)
303 (SUBPARTITION x11 ENGINE = MyISAM,
304 SUBPARTITION x12 ENGINE = MyISAM),
305 PARTITION x2 VALUES LESS THAN (5)
306 (SUBPARTITION x21 ENGINE = MyISAM,
307 SUBPARTITION x22 ENGINE = MyISAM)) */
314 partition by range (a)
315 subpartition by hash (a+b)
316 ( partition x1 values less than (1)
317 ( subpartition x11 tablespace t1 engine myisam nodegroup 0,
318 subpartition x12 tablespace t2 engine myisam nodegroup 1),
319 partition x2 values less than (5)
320 ( subpartition x21 tablespace t1 engine myisam nodegroup 0,
321 subpartition x22 tablespace t2 engine myisam nodegroup 1)
331 partition by range (a)
332 subpartition by hash (a+b)
333 ( partition x1 values less than (1)
334 ( subpartition x11 tablespace t1 nodegroup 0,
335 subpartition x12 tablespace t2 nodegroup 1),
336 partition x2 values less than (5)
337 ( subpartition x21 tablespace t1 nodegroup 0,
338 subpartition x22 tablespace t2 nodegroup 1)
348 partition by range (a)
349 subpartition by hash (a+b)
350 ( partition x1 values less than (1)
351 ( subpartition x11 engine myisam nodegroup 0,
352 subpartition x12 engine myisam nodegroup 1),
353 partition x2 values less than (5)
354 ( subpartition x21 engine myisam nodegroup 0,
355 subpartition x22 engine myisam nodegroup 1)
357 INSERT into t1 VALUES (1,1,1);
358 INSERT into t1 VALUES (4,1,1);
359 INSERT into t1 VALUES (5,1,1);
360 ERROR HY000: Table has no partition for value 5
366 partition by range (a)
367 subpartition by hash (a+b)
368 ( partition x1 values less than (1)
369 ( subpartition x11 engine myisam nodegroup 0,
370 subpartition x12 engine myisam nodegroup 1),
371 partition x2 values less than (5)
372 ( subpartition x21 engine myisam nodegroup 0,
373 subpartition x22 engine myisam nodegroup 1)
385 partition by range (a)
386 subpartition by hash (a+b)
387 ( partition x1 values less than (1)
388 ( subpartition x11 tablespace t1 engine myisam,
389 subpartition x12 tablespace t2 engine myisam),
390 partition x2 values less than (5)
391 ( subpartition x21 tablespace t1 engine myisam,
392 subpartition x22 tablespace t2 engine myisam)
394 INSERT into t1 VALUES (1,1,1);
395 INSERT into t1 VALUES (4,1,1);
396 INSERT into t1 VALUES (5,1,1);
397 ERROR HY000: Table has no partition for value 5
403 partition by range (a)
404 subpartition by hash (a+b)
405 ( partition x1 values less than (1)
406 ( subpartition x11 tablespace t1 engine myisam,
407 subpartition x12 tablespace t2 engine myisam),
408 partition x2 values less than (5)
409 ( subpartition x21 tablespace t1 engine myisam,
410 subpartition x22 tablespace t2 engine myisam)
422 partition by range (a)
423 subpartition by hash (a+b)
424 ( partition x1 values less than (1)
425 ( subpartition x11 tablespace t1,
426 subpartition x12 tablespace t2),
427 partition x2 values less than (5)
428 ( subpartition x21 tablespace t1,
429 subpartition x22 tablespace t2)
431 INSERT into t1 VALUES (1,1,1);
432 INSERT into t1 VALUES (4,1,1);
433 INSERT into t1 VALUES (5,1,1);
434 ERROR HY000: Table has no partition for value 5
440 partition by range (a)
441 subpartition by hash (a+b)
442 ( partition x1 values less than (1)
443 ( subpartition x11 tablespace t1 engine myisam,
444 subpartition x12 tablespace t2 engine myisam),
445 partition x2 values less than (5)
446 ( subpartition x21 tablespace t1 engine myisam,
447 subpartition x22 tablespace t2 engine myisam)
459 partition by range (a)
460 subpartition by hash (a+b)
461 ( partition x1 values less than (1)
462 ( subpartition x11 engine myisam,
463 subpartition x12 engine myisam),
464 partition x2 values less than (5)
465 ( subpartition x21 engine myisam,
466 subpartition x22 engine myisam)
468 INSERT into t1 VALUES (1,1,1);
469 INSERT into t1 VALUES (4,1,1);
470 INSERT into t1 VALUES (5,1,1);
471 ERROR HY000: Table has no partition for value 5
477 partition by range (a)
478 subpartition by hash (a+b)
479 ( partition x1 values less than (1)
480 ( subpartition x11 engine myisam,
481 subpartition x12 engine myisam),
482 partition x2 values less than (5)
483 ( subpartition x21 engine myisam,
484 subpartition x22 engine myisam)
491 CREATE TABLE t1 (c1 int default NULL, c2 varchar(30) default NULL,
492 c3 date default NULL) engine=myisam
493 PARTITION BY RANGE (year(c3)) (PARTITION p0 VALUES LESS THAN (1995),
494 PARTITION p1 VALUES LESS THAN (1996) , PARTITION p2 VALUES LESS THAN (1997) ,
495 PARTITION p3 VALUES LESS THAN (1998) , PARTITION p4 VALUES LESS THAN (1999) ,
496 PARTITION p5 VALUES LESS THAN (2000) , PARTITION p6 VALUES LESS THAN (2001) ,
497 PARTITION p7 VALUES LESS THAN (2002) , PARTITION p8 VALUES LESS THAN (2003) ,
498 PARTITION p9 VALUES LESS THAN (2004) , PARTITION p10 VALUES LESS THAN (2010),
499 PARTITION p11 VALUES LESS THAN MAXVALUE );
500 INSERT INTO t1 VALUES (1, 'testing partitions', '1995-07-17'),
501 (3, 'testing partitions','1995-07-31'),
502 (5, 'testing partitions','1995-08-13'),
503 (7, 'testing partitions','1995-08-26'),
504 (9, 'testing partitions','1995-09-09'),
505 (0, 'testing partitions','2000-07-10'),
506 (2, 'testing partitions','2000-07-23'),
507 (4, 'testing partitions','2000-08-05'),
508 (6, 'testing partitions','2000-08-19'),
509 (8, 'testing partitions','2000-09-01');
510 SELECT COUNT(*) FROM t1 WHERE c3 BETWEEN '1996-12-31' AND '2000-12-31';
513 SELECT COUNT(*) FROM t1 WHERE c3 < '2000-12-31';
517 create table t1 (a bigint unsigned)
518 partition by range (a)
519 (partition p0 values less than (10),
520 partition p1 values less than (0));
521 ERROR HY000: VALUES LESS THAN value must be strictly increasing for each partition
522 create table t1 (a bigint unsigned)
523 partition by range (a)
524 (partition p0 values less than (0),
525 partition p1 values less than (10));
526 show create table t1;
528 t1 CREATE TABLE `t1` (
529 `a` bigint(20) unsigned DEFAULT NULL
530 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
531 /*!50100 PARTITION BY RANGE (a)
532 (PARTITION p0 VALUES LESS THAN (0) ENGINE = MyISAM,
533 PARTITION p1 VALUES LESS THAN (10) ENGINE = MyISAM) */
535 create table t1 (a bigint unsigned)
536 partition by range (a)
537 (partition p0 values less than (2),
538 partition p1 values less than (10));
539 show create table t1;
541 t1 CREATE TABLE `t1` (
542 `a` bigint(20) unsigned DEFAULT NULL
543 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
544 /*!50100 PARTITION BY RANGE (a)
545 (PARTITION p0 VALUES LESS THAN (2) ENGINE = MyISAM,
546 PARTITION p1 VALUES LESS THAN (10) ENGINE = MyISAM) */
547 insert into t1 values (0xFFFFFFFFFFFFFFFF);
548 ERROR HY000: Table has no partition for value 18446744073709551615
550 create table t1 (a int)
551 partition by range (MOD(a,3))
552 subpartition by hash(a)
554 (partition p0 values less than (1),
555 partition p1 values less than (2),
556 partition p2 values less than (3),
557 partition p3 values less than (4));
558 ALTER TABLE t1 DROP PARTITION p3;
559 ALTER TABLE t1 DROP PARTITION p1;
560 ALTER TABLE t1 DROP PARTITION p2;
562 create table t1 (a int)
563 partition by range (MOD(a,3))
564 subpartition by hash(a)
566 (partition p0 values less than (1),
567 partition p1 values less than (2),
568 partition p2 values less than (3),
569 partition p3 values less than (4));
570 ALTER TABLE t1 DROP PARTITION p0;
571 ALTER TABLE t1 DROP PARTITION p1;
572 ALTER TABLE t1 DROP PARTITION p2;
574 create table t1 (a int DEFAULT NULL,
575 b varchar(30) DEFAULT NULL,
577 ENGINE=MYISAM DEFAULT CHARSET=latin1;
578 insert into t1 values (1, 'abc', '1995-01-01');
579 insert into t1 values (1, 'abc', '1995-01-02');
580 insert into t1 values (1, 'abc', '1995-01-03');
581 insert into t1 values (1, 'abc', '1995-01-04');
582 insert into t1 values (1, 'abc', '1995-01-05');
583 insert into t1 values (1, 'abc', '1995-01-06');
584 insert into t1 values (1, 'abc', '1995-01-07');
585 insert into t1 values (1, 'abc', '1995-01-08');
586 insert into t1 values (1, 'abc', '1995-01-09');
587 insert into t1 values (1, 'abc', '1995-01-10');
588 insert into t1 values (1, 'abc', '1995-01-11');
589 insert into t1 values (1, 'abc', '1995-01-12');
590 insert into t1 values (1, 'abc', '1995-01-13');
591 insert into t1 values (1, 'abc', '1995-01-14');
592 insert into t1 values (1, 'abc', '1995-01-15');
593 insert into t1 values (1, 'abc', '1997-01-01');
594 insert into t1 values (1, 'abc', '1997-01-02');
595 insert into t1 values (1, 'abc', '1997-01-03');
596 insert into t1 values (1, 'abc', '1997-01-04');
597 insert into t1 values (1, 'abc', '1997-01-05');
598 insert into t1 values (1, 'abc', '1997-01-06');
599 insert into t1 values (1, 'abc', '1997-01-07');
600 insert into t1 values (1, 'abc', '1997-01-08');
601 insert into t1 values (1, 'abc', '1997-01-09');
602 insert into t1 values (1, 'abc', '1997-01-10');
603 insert into t1 values (1, 'abc', '1997-01-11');
604 insert into t1 values (1, 'abc', '1997-01-12');
605 insert into t1 values (1, 'abc', '1997-01-13');
606 insert into t1 values (1, 'abc', '1997-01-14');
607 insert into t1 values (1, 'abc', '1997-01-15');
608 insert into t1 values (1, 'abc', '1998-01-01');
609 insert into t1 values (1, 'abc', '1998-01-02');
610 insert into t1 values (1, 'abc', '1998-01-03');
611 insert into t1 values (1, 'abc', '1998-01-04');
612 insert into t1 values (1, 'abc', '1998-01-05');
613 insert into t1 values (1, 'abc', '1998-01-06');
614 insert into t1 values (1, 'abc', '1998-01-07');
615 insert into t1 values (1, 'abc', '1998-01-08');
616 insert into t1 values (1, 'abc', '1998-01-09');
617 insert into t1 values (1, 'abc', '1998-01-10');
618 insert into t1 values (1, 'abc', '1998-01-11');
619 insert into t1 values (1, 'abc', '1998-01-12');
620 insert into t1 values (1, 'abc', '1998-01-13');
621 insert into t1 values (1, 'abc', '1998-01-14');
622 insert into t1 values (1, 'abc', '1998-01-15');
623 insert into t1 values (1, 'abc', '1999-01-01');
624 insert into t1 values (1, 'abc', '1999-01-02');
625 insert into t1 values (1, 'abc', '1999-01-03');
626 insert into t1 values (1, 'abc', '1999-01-04');
627 insert into t1 values (1, 'abc', '1999-01-05');
628 insert into t1 values (1, 'abc', '1999-01-06');
629 insert into t1 values (1, 'abc', '1999-01-07');
630 insert into t1 values (1, 'abc', '1999-01-08');
631 insert into t1 values (1, 'abc', '1999-01-09');
632 insert into t1 values (1, 'abc', '1999-01-10');
633 insert into t1 values (1, 'abc', '1999-01-11');
634 insert into t1 values (1, 'abc', '1999-01-12');
635 insert into t1 values (1, 'abc', '1999-01-13');
636 insert into t1 values (1, 'abc', '1999-01-14');
637 insert into t1 values (1, 'abc', '1999-01-15');
638 insert into t1 values (1, 'abc', '2000-01-01');
639 insert into t1 values (1, 'abc', '2000-01-02');
640 insert into t1 values (1, 'abc', '2000-01-03');
641 insert into t1 values (1, 'abc', '2000-01-04');
642 insert into t1 values (1, 'abc', '2000-01-05');
643 insert into t1 values (1, 'abc', '2000-01-06');
644 insert into t1 values (1, 'abc', '2000-01-07');
645 insert into t1 values (1, 'abc', '2000-01-08');
646 insert into t1 values (1, 'abc', '2000-01-09');
647 insert into t1 values (1, 'abc', '2000-01-15');
648 insert into t1 values (1, 'abc', '2000-01-11');
649 insert into t1 values (1, 'abc', '2000-01-12');
650 insert into t1 values (1, 'abc', '2000-01-13');
651 insert into t1 values (1, 'abc', '2000-01-14');
652 insert into t1 values (1, 'abc', '2000-01-15');
653 insert into t1 values (1, 'abc', '2001-01-01');
654 insert into t1 values (1, 'abc', '2001-01-02');
655 insert into t1 values (1, 'abc', '2001-01-03');
656 insert into t1 values (1, 'abc', '2001-01-04');
657 insert into t1 values (1, 'abc', '2001-01-05');
658 insert into t1 values (1, 'abc', '2001-01-06');
659 insert into t1 values (1, 'abc', '2001-01-07');
660 insert into t1 values (1, 'abc', '2001-01-08');
661 insert into t1 values (1, 'abc', '2001-01-09');
662 insert into t1 values (1, 'abc', '2001-01-15');
663 insert into t1 values (1, 'abc', '2001-01-11');
664 insert into t1 values (1, 'abc', '2001-01-12');
665 insert into t1 values (1, 'abc', '2001-01-13');
666 insert into t1 values (1, 'abc', '2001-01-14');
667 insert into t1 values (1, 'abc', '2001-01-15');
669 partition by range (year(c))
670 (partition p5 values less than (2000), partition p10 values less than (2010));
672 reorganize partition p5 into
673 (partition p1 values less than (1996),
674 partition p2 values less than (1997),
675 partition p3 values less than (1998),
676 partition p4 values less than (1999),
677 partition p5 values less than (2000));
679 CREATE TABLE t1 (a date)
680 PARTITION BY RANGE (TO_DAYS(a))
681 (PARTITION p3xx VALUES LESS THAN (TO_DAYS('2004-01-01')),
682 PARTITION p401 VALUES LESS THAN (TO_DAYS('2004-02-01')),
683 PARTITION p402 VALUES LESS THAN (TO_DAYS('2004-03-01')),
684 PARTITION p403 VALUES LESS THAN (TO_DAYS('2004-04-01')),
685 PARTITION p404 VALUES LESS THAN (TO_DAYS('2004-05-01')),
686 PARTITION p405 VALUES LESS THAN (TO_DAYS('2004-06-01')),
687 PARTITION p406 VALUES LESS THAN (TO_DAYS('2004-07-01')),
688 PARTITION p407 VALUES LESS THAN (TO_DAYS('2004-08-01')),
689 PARTITION p408 VALUES LESS THAN (TO_DAYS('2004-09-01')),
690 PARTITION p409 VALUES LESS THAN (TO_DAYS('2004-10-01')),
691 PARTITION p410 VALUES LESS THAN (TO_DAYS('2004-11-01')),
692 PARTITION p411 VALUES LESS THAN (TO_DAYS('2004-12-01')),
693 PARTITION p412 VALUES LESS THAN (TO_DAYS('2005-01-01')),
694 PARTITION p501 VALUES LESS THAN (TO_DAYS('2005-02-01')),
695 PARTITION p502 VALUES LESS THAN (TO_DAYS('2005-03-01')),
696 PARTITION p503 VALUES LESS THAN (TO_DAYS('2005-04-01')),
697 PARTITION p504 VALUES LESS THAN (TO_DAYS('2005-05-01')),
698 PARTITION p505 VALUES LESS THAN (TO_DAYS('2005-06-01')),
699 PARTITION p506 VALUES LESS THAN (TO_DAYS('2005-07-01')),
700 PARTITION p507 VALUES LESS THAN (TO_DAYS('2005-08-01')),
701 PARTITION p508 VALUES LESS THAN (TO_DAYS('2005-09-01')),
702 PARTITION p509 VALUES LESS THAN (TO_DAYS('2005-10-01')),
703 PARTITION p510 VALUES LESS THAN (TO_DAYS('2005-11-01')),
704 PARTITION p511 VALUES LESS THAN (TO_DAYS('2005-12-01')),
705 PARTITION p512 VALUES LESS THAN (TO_DAYS('2006-01-01')),
706 PARTITION p601 VALUES LESS THAN (TO_DAYS('2006-02-01')),
707 PARTITION p602 VALUES LESS THAN (TO_DAYS('2006-03-01')),
708 PARTITION p603 VALUES LESS THAN (TO_DAYS('2006-04-01')),
709 PARTITION p604 VALUES LESS THAN (TO_DAYS('2006-05-01')),
710 PARTITION p605 VALUES LESS THAN (TO_DAYS('2006-06-01')),
711 PARTITION p606 VALUES LESS THAN (TO_DAYS('2006-07-01')),
712 PARTITION p607 VALUES LESS THAN (TO_DAYS('2006-08-01')));
713 INSERT INTO t1 VALUES ('2003-01-13'),('2003-06-20'),('2003-08-30');
714 INSERT INTO t1 VALUES ('2003-04-13'),('2003-07-20'),('2003-10-30');
715 INSERT INTO t1 VALUES ('2003-05-13'),('2003-11-20'),('2003-12-30');
716 INSERT INTO t1 VALUES ('2004-01-13'),('2004-01-20'),('2004-01-30');
717 INSERT INTO t1 VALUES ('2004-02-13'),('2004-02-20'),('2004-02-28');
718 INSERT INTO t1 VALUES ('2004-03-13'),('2004-03-20'),('2004-03-30');
719 INSERT INTO t1 VALUES ('2004-04-13'),('2004-04-20'),('2004-04-30');
720 INSERT INTO t1 VALUES ('2004-05-13'),('2004-05-20'),('2004-05-30');
721 INSERT INTO t1 VALUES ('2004-06-13'),('2004-06-20'),('2004-06-30');
722 INSERT INTO t1 VALUES ('2004-07-13'),('2004-07-20'),('2004-07-30');
723 INSERT INTO t1 VALUES ('2004-08-13'),('2004-08-20'),('2004-08-30');
724 INSERT INTO t1 VALUES ('2004-09-13'),('2004-09-20'),('2004-09-30');
725 INSERT INTO t1 VALUES ('2004-10-13'),('2004-10-20'),('2004-10-30');
726 INSERT INTO t1 VALUES ('2004-11-13'),('2004-11-20'),('2004-11-30');
727 INSERT INTO t1 VALUES ('2004-12-13'),('2004-12-20'),('2004-12-30');
728 INSERT INTO t1 VALUES ('2005-01-13'),('2005-01-20'),('2005-01-30');
729 INSERT INTO t1 VALUES ('2005-02-13'),('2005-02-20'),('2005-02-28');
730 INSERT INTO t1 VALUES ('2005-03-13'),('2005-03-20'),('2005-03-30');
731 INSERT INTO t1 VALUES ('2005-04-13'),('2005-04-20'),('2005-04-30');
732 INSERT INTO t1 VALUES ('2005-05-13'),('2005-05-20'),('2005-05-30');
733 INSERT INTO t1 VALUES ('2005-06-13'),('2005-06-20'),('2005-06-30');
734 INSERT INTO t1 VALUES ('2005-07-13'),('2005-07-20'),('2005-07-30');
735 INSERT INTO t1 VALUES ('2005-08-13'),('2005-08-20'),('2005-08-30');
736 INSERT INTO t1 VALUES ('2005-09-13'),('2005-09-20'),('2005-09-30');
737 INSERT INTO t1 VALUES ('2005-10-13'),('2005-10-20'),('2005-10-30');
738 INSERT INTO t1 VALUES ('2005-11-13'),('2005-11-20'),('2005-11-30');
739 INSERT INTO t1 VALUES ('2005-12-13'),('2005-12-20'),('2005-12-30');
740 INSERT INTO t1 VALUES ('2006-01-13'),('2006-01-20'),('2006-01-30');
741 INSERT INTO t1 VALUES ('2006-02-13'),('2006-02-20'),('2006-02-28');
742 INSERT INTO t1 VALUES ('2006-03-13'),('2006-03-20'),('2006-03-30');
743 INSERT INTO t1 VALUES ('2006-04-13'),('2006-04-20'),('2006-04-30');
744 INSERT INTO t1 VALUES ('2006-05-13'),('2006-05-20'),('2006-05-30');
745 INSERT INTO t1 VALUES ('2006-06-13'),('2006-06-20'),('2006-06-30');
746 INSERT INTO t1 VALUES ('2006-07-13'),('2006-07-20'),('2006-07-30');
748 WHERE a >= '2004-07-01' AND a <= '2004-09-30';
759 EXPLAIN PARTITIONS SELECT * FROM t1
760 WHERE a >= '2004-07-01' AND a <= '2004-09-30';
761 id select_type table partitions type possible_keys key key_len ref rows Extra
762 1 SIMPLE t1 p3xx,p407,p408,p409 ALL NULL NULL NULL NULL 18 Using where
764 WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
765 (a >= '2005-07-01' AND a <= '2005-09-30');
785 EXPLAIN PARTITIONS SELECT * from t1
786 WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
787 (a >= '2005-07-01' AND a <= '2005-09-30');
788 id select_type table partitions type possible_keys key key_len ref rows Extra
789 1 SIMPLE t1 p3xx,p407,p408,p409,p507,p508,p509 ALL NULL NULL NULL NULL 27 Using where
791 create table t1 (a int);
792 insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
794 defid int(10) unsigned NOT NULL,
795 day int(10) unsigned NOT NULL,
796 count int(10) unsigned NOT NULL,
800 PARTITION BY RANGE (day) (
801 PARTITION p7 VALUES LESS THAN (20070401) ,
802 PARTITION p8 VALUES LESS THAN (20070501));
803 insert into t2 select 20, 20070311, 1, 'filler' from t1 A, t1 B;
804 insert into t2 select 20, 20070411, 1, 'filler' from t1 A, t1 B;
805 insert into t2 values(52, 20070321, 123, 'filler') ;
806 insert into t2 values(52, 20070322, 456, 'filler') ;
807 select sum(count) from t2 ch where ch.defid in (50,52) and ch.day between 20070320 and 20070401 group by defid;
812 # Bug#50939: Loose Index Scan unduly relies on engine to remember range
819 ) PARTITION BY HASH (a) PARTITIONS 1;
825 INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
826 INSERT INTO t1 SELECT a + 5, b + 5 FROM t1;
827 INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
828 INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
829 INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
830 INSERT INTO t2 SELECT * FROM t1;
831 # plans should be identical
832 EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
833 id select_type table type possible_keys key key_len ref rows Extra
834 1 SIMPLE t1 range a a 5 NULL 1 Using where; Using index for group-by
835 EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
836 id select_type table type possible_keys key key_len ref rows Extra
837 1 SIMPLE t2 range a a 5 NULL 2 Using where; Using index for group-by
839 SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
842 # Should be no more than 4 reads.
843 SHOW status LIKE 'handler_read_key';
847 SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
850 # Should be no more than 4 reads.
851 SHOW status LIKE 'handler_read_key';