/usr/lib/mysql-testsuite/r/partition_range.result is in mysql-testsuite-5.6 5.6.16-1~exp1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | drop table if exists t1, t2;
#
# Bug#48229: group by performance issue of partitioned table
#
CREATE TABLE t1 (
a INT,
b INT,
KEY a (a,b)
)
PARTITION BY HASH (a) PARTITIONS 1;
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);
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100, 3) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
DROP TABLE t1;
create table t1 (a DATETIME)
partition by range (TO_DAYS(a))
subpartition by hash(to_seconds(a))
(partition p0 values less than (1));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50500 PARTITION BY RANGE (TO_DAYS(a))
SUBPARTITION BY HASH (to_seconds(a))
(PARTITION p0 VALUES LESS THAN (1) ENGINE = MyISAM) */
drop table t1;
create table t1 (a int)
partition by range (a)
( partition p0 values less than (NULL),
partition p1 values less than (MAXVALUE));
ERROR HY000: Not allowed to use NULL value in VALUES LESS THAN
create table t1 (a datetime not null)
partition by range (TO_SECONDS(a))
( partition p0 VALUES LESS THAN (TO_SECONDS('2007-03-08 00:00:00')),
partition p1 VALUES LESS THAN (TO_SECONDS('2007-04-01 00:00:00')));
select partition_method, partition_expression, partition_description
from information_schema.partitions where table_name = "t1";
partition_method partition_expression partition_description
RANGE TO_SECONDS(a) 63340531200
RANGE TO_SECONDS(a) 63342604800
INSERT INTO t1 VALUES ('2007-03-01 12:00:00'), ('2007-03-07 12:00:00');
INSERT INTO t1 VALUES ('2007-03-08 12:00:00'), ('2007-03-15 12:00:00');
explain partitions select * from t1 where a < '2007-03-08 00:00:00';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 where a < '2007-03-08 00:00:01';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 4 Using where
explain partitions select * from t1 where a <= '2007-03-08 00:00:00';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 4 Using where
explain partitions select * from t1 where a <= '2007-03-07 23:59:59';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 where a < '2007-03-07 23:59:59';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0 ALL NULL NULL NULL NULL 2 Using where
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50500 PARTITION BY RANGE (TO_SECONDS(a))
(PARTITION p0 VALUES LESS THAN (63340531200) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (63342604800) ENGINE = MyISAM) */
drop table t1;
create table t1 (a date)
partition by range(to_seconds(a))
(partition p0 values less than (to_seconds('2004-01-01')),
partition p1 values less than (to_seconds('2005-01-01')));
insert into t1 values ('2003-12-30'),('2004-12-31');
select * from t1;
a
2003-12-30
2004-12-31
explain partitions select * from t1 where a <= '2003-12-31';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0 system NULL NULL NULL NULL 1 NULL
select * from t1 where a <= '2003-12-31';
a
2003-12-30
explain partitions select * from t1 where a <= '2005-01-01';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 2 Using where
select * from t1 where a <= '2005-01-01';
a
2003-12-30
2004-12-31
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50500 PARTITION BY RANGE (to_seconds(a))
(PARTITION p0 VALUES LESS THAN (63240134400) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (63271756800) ENGINE = MyISAM) */
drop table t1;
create table t1 (a datetime)
partition by range(to_seconds(a))
(partition p0 values less than (to_seconds('2004-01-01 12:00:00')),
partition p1 values less than (to_seconds('2005-01-01 12:00:00')));
insert into t1 values ('2004-01-01 11:59:29'),('2005-01-01 11:59:59');
select * from t1;
a
2004-01-01 11:59:29
2005-01-01 11:59:59
explain partitions select * from t1 where a <= '2004-01-01 11:59.59';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0 system NULL NULL NULL NULL 1 NULL
select * from t1 where a <= '2004-01-01 11:59:59';
a
2004-01-01 11:59:29
explain partitions select * from t1 where a <= '2005-01-01';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 2 Using where
select * from t1 where a <= '2005-01-01';
a
2004-01-01 11:59:29
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50500 PARTITION BY RANGE (to_seconds(a))
(PARTITION p0 VALUES LESS THAN (63240177600) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (63271800000) ENGINE = MyISAM) */
drop table t1;
create table t1 (a int, b char(20))
partition by range columns(a,b)
(partition p0 values less than (1));
ERROR 42000: Inconsistency in usage of column lists for partitioning near '))' at line 3
create table t1 (a int, b char(20))
partition by range(a)
(partition p0 values less than (1,"b"));
ERROR HY000: Cannot have more than one value for this type of RANGE partitioning
create table t1 (a int, b char(20))
partition by range(a)
(partition p0 values less than (1,"b"));
ERROR HY000: Cannot have more than one value for this type of RANGE partitioning
create table t1 (a int, b char(20))
partition by range columns(b)
(partition p0 values less than ("b"));
drop table t1;
create table t1 (a int)
partition by range (a)
( partition p0 values less than (maxvalue));
alter table t1 add partition (partition p1 values less than (100000));
ERROR HY000: MAXVALUE can only be used in last partition definition
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
drop table t1;
create table t1 (a integer)
partition by range (a)
( partition p0 values less than (4),
partition p1 values less than (100));
create trigger tr1 before insert on t1
for each row begin
set @a = 1;
end|
alter table t1 drop partition p0;
drop table t1;
create table t1 (a integer)
partition by range (a)
( partition p0 values less than (4),
partition p1 values less than (100));
LOCK TABLES t1 WRITE;
alter table t1 drop partition p0;
alter table t1 reorganize partition p1 into
( partition p0 values less than (4),
partition p1 values less than (100));
alter table t1 add partition ( partition p2 values less than (200));
UNLOCK TABLES;
drop table t1;
create table t1 (a int unsigned)
partition by range (a)
(partition pnull values less than (0),
partition p0 values less than (1),
partition p1 values less than(2));
insert into t1 values (null),(0),(1);
select * from t1 where a is null;
a
NULL
select * from t1 where a >= 0;
a
0
1
select * from t1 where a < 0;
a
select * from t1 where a <= 0;
a
0
select * from t1 where a > 1;
a
explain partitions select * from t1 where a is null;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pnull system NULL NULL NULL NULL 1 NULL
explain partitions select * from t1 where a >= 0;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 where a < 0;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
explain partitions select * from t1 where a <= 0;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pnull,p0 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 where a > 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
drop table t1;
create table t1 (a int unsigned, b int unsigned)
partition by range (a)
subpartition by hash (b)
subpartitions 2
(partition pnull values less than (0),
partition p0 values less than (1),
partition p1 values less than(2));
insert into t1 values (null,0),(null,1),(0,0),(0,1),(1,0),(1,1);
select * from t1 where a is null;
a b
NULL 0
NULL 1
select * from t1 where a >= 0;
a b
0 0
0 1
1 0
1 1
select * from t1 where a < 0;
a b
select * from t1 where a <= 0;
a b
0 0
0 1
select * from t1 where a > 1;
a b
explain partitions select * from t1 where a is null;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 where a >= 0;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1 ALL NULL NULL NULL NULL 4 Using where
explain partitions select * from t1 where a < 0;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1 ALL NULL NULL NULL NULL 2 Using where
explain partitions select * from t1 where a <= 0;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pnull_pnullsp0,pnull_pnullsp1,p0_p0sp0,p0_p0sp1 ALL NULL NULL NULL NULL 4 Using where
explain partitions select * from t1 where a > 1;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by range (a)
partitions 3
(partition x1 values less than (5) tablespace ts1,
partition x2 values less than (10) tablespace ts2,
partition x3 values less than maxvalue tablespace ts3);
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (6, 1, 1);
INSERT into t1 values (10, 1, 1);
INSERT into t1 values (15, 1, 1);
select * from t1;
a b c
1 1 1
6 1 1
10 1 1
15 1 1
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` int(11) NOT NULL,
`c` int(11) NOT NULL,
PRIMARY KEY (`a`,`b`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION x1 VALUES LESS THAN (5) TABLESPACE = ts1 ENGINE = MyISAM,
PARTITION x2 VALUES LESS THAN (10) TABLESPACE = ts2 ENGINE = MyISAM,
PARTITION x3 VALUES LESS THAN MAXVALUE TABLESPACE = ts3 ENGINE = MyISAM) */
ALTER TABLE t1
partition by range (a)
partitions 3
(partition x1 values less than (5) tablespace ts1,
partition x2 values less than (10) tablespace ts2,
partition x3 values less than maxvalue tablespace ts3);
select * from t1;
a b c
1 1 1
6 1 1
10 1 1
15 1 1
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` int(11) NOT NULL,
`c` int(11) NOT NULL,
PRIMARY KEY (`a`,`b`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION x1 VALUES LESS THAN (5) TABLESPACE = ts1 ENGINE = MyISAM,
PARTITION x2 VALUES LESS THAN (10) TABLESPACE = ts2 ENGINE = MyISAM,
PARTITION x3 VALUES LESS THAN MAXVALUE TABLESPACE = ts3 ENGINE = MyISAM) */
drop table if exists t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null)
partition by range (a)
partitions 3
(partition x1 values less than (5) tablespace ts1,
partition x2 values less than (10) tablespace ts2,
partition x3 values less than maxvalue tablespace ts3);
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (6, 1, 1);
INSERT into t1 values (10, 1, 1);
INSERT into t1 values (15, 1, 1);
select * from t1;
a b c
1 1 1
6 1 1
10 1 1
15 1 1
ALTER TABLE t1
partition by range (a)
partitions 3
(partition x1 values less than (5) tablespace ts1,
partition x2 values less than (10) tablespace ts2,
partition x3 values less than maxvalue tablespace ts3);
select * from t1;
a b c
1 1 1
6 1 1
10 1 1
15 1 1
drop table if exists t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by range (a)
partitions 3
(partition x1 values less than (5) tablespace ts1,
partition x2 values less than (10) tablespace ts2,
partition x3 values less than (15) tablespace ts3);
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (6, 1, 1);
INSERT into t1 values (10, 1, 1);
INSERT into t1 values (15, 1, 1);
ERROR HY000: Table has no partition for value 15
select * from t1;
a b c
1 1 1
6 1 1
10 1 1
ALTER TABLE t1
partition by range (a)
partitions 3
(partition x1 values less than (5) tablespace ts1,
partition x2 values less than (10) tablespace ts2,
partition x3 values less than (15) tablespace ts3);
select * from t1;
a b c
1 1 1
6 1 1
10 1 1
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by range (a)
(partition x1 values less than (1));
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11,
subpartition x12),
partition x2 values less than (5)
( subpartition x21,
subpartition x22)
);
SELECT * from t1;
a b c
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` int(11) NOT NULL,
`c` int(11) NOT NULL,
PRIMARY KEY (`a`,`b`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
SUBPARTITION BY HASH (a+b)
(PARTITION x1 VALUES LESS THAN (1)
(SUBPARTITION x11 ENGINE = MyISAM,
SUBPARTITION x12 ENGINE = MyISAM),
PARTITION x2 VALUES LESS THAN (5)
(SUBPARTITION x21 ENGINE = MyISAM,
SUBPARTITION x22 ENGINE = MyISAM)) */
ALTER TABLE t1 ADD COLUMN d int;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` int(11) NOT NULL,
`c` int(11) NOT NULL,
`d` int(11) DEFAULT NULL,
PRIMARY KEY (`a`,`b`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
SUBPARTITION BY HASH (a+b)
(PARTITION x1 VALUES LESS THAN (1)
(SUBPARTITION x11 ENGINE = MyISAM,
SUBPARTITION x12 ENGINE = MyISAM),
PARTITION x2 VALUES LESS THAN (5)
(SUBPARTITION x21 ENGINE = MyISAM,
SUBPARTITION x22 ENGINE = MyISAM)) */
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 tablespace t1 engine myisam nodegroup 0,
subpartition x12 tablespace t2 engine myisam nodegroup 1),
partition x2 values less than (5)
( subpartition x21 tablespace t1 engine myisam nodegroup 0,
subpartition x22 tablespace t2 engine myisam nodegroup 1)
);
SELECT * from t1;
a b c
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 tablespace t1 nodegroup 0,
subpartition x12 tablespace t2 nodegroup 1),
partition x2 values less than (5)
( subpartition x21 tablespace t1 nodegroup 0,
subpartition x22 tablespace t2 nodegroup 1)
);
SELECT * from t1;
a b c
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 engine myisam nodegroup 0,
subpartition x12 engine myisam nodegroup 1),
partition x2 values less than (5)
( subpartition x21 engine myisam nodegroup 0,
subpartition x22 engine myisam nodegroup 1)
);
INSERT into t1 VALUES (1,1,1);
INSERT into t1 VALUES (4,1,1);
INSERT into t1 VALUES (5,1,1);
ERROR HY000: Table has no partition for value 5
SELECT * from t1;
a b c
1 1 1
4 1 1
ALTER TABLE t1
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 engine myisam nodegroup 0,
subpartition x12 engine myisam nodegroup 1),
partition x2 values less than (5)
( subpartition x21 engine myisam nodegroup 0,
subpartition x22 engine myisam nodegroup 1)
);
SELECT * from t1;
a b c
1 1 1
4 1 1
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 tablespace t1 engine myisam,
subpartition x12 tablespace t2 engine myisam),
partition x2 values less than (5)
( subpartition x21 tablespace t1 engine myisam,
subpartition x22 tablespace t2 engine myisam)
);
INSERT into t1 VALUES (1,1,1);
INSERT into t1 VALUES (4,1,1);
INSERT into t1 VALUES (5,1,1);
ERROR HY000: Table has no partition for value 5
SELECT * from t1;
a b c
1 1 1
4 1 1
ALTER TABLE t1
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 tablespace t1 engine myisam,
subpartition x12 tablespace t2 engine myisam),
partition x2 values less than (5)
( subpartition x21 tablespace t1 engine myisam,
subpartition x22 tablespace t2 engine myisam)
);
SELECT * from t1;
a b c
1 1 1
4 1 1
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 tablespace t1,
subpartition x12 tablespace t2),
partition x2 values less than (5)
( subpartition x21 tablespace t1,
subpartition x22 tablespace t2)
);
INSERT into t1 VALUES (1,1,1);
INSERT into t1 VALUES (4,1,1);
INSERT into t1 VALUES (5,1,1);
ERROR HY000: Table has no partition for value 5
SELECT * from t1;
a b c
1 1 1
4 1 1
ALTER TABLE t1
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 tablespace t1 engine myisam,
subpartition x12 tablespace t2 engine myisam),
partition x2 values less than (5)
( subpartition x21 tablespace t1 engine myisam,
subpartition x22 tablespace t2 engine myisam)
);
SELECT * from t1;
a b c
1 1 1
4 1 1
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 engine myisam,
subpartition x12 engine myisam),
partition x2 values less than (5)
( subpartition x21 engine myisam,
subpartition x22 engine myisam)
);
INSERT into t1 VALUES (1,1,1);
INSERT into t1 VALUES (4,1,1);
INSERT into t1 VALUES (5,1,1);
ERROR HY000: Table has no partition for value 5
SELECT * from t1;
a b c
1 1 1
4 1 1
ALTER TABLE t1
partition by range (a)
subpartition by hash (a+b)
( partition x1 values less than (1)
( subpartition x11 engine myisam,
subpartition x12 engine myisam),
partition x2 values less than (5)
( subpartition x21 engine myisam,
subpartition x22 engine myisam)
);
SELECT * from t1;
a b c
1 1 1
4 1 1
drop table t1;
CREATE TABLE t1 (c1 int default NULL, c2 varchar(30) default NULL,
c3 date default NULL) engine=myisam
PARTITION BY RANGE (year(c3)) (PARTITION p0 VALUES LESS THAN (1995),
PARTITION p1 VALUES LESS THAN (1996) , PARTITION p2 VALUES LESS THAN (1997) ,
PARTITION p3 VALUES LESS THAN (1998) , PARTITION p4 VALUES LESS THAN (1999) ,
PARTITION p5 VALUES LESS THAN (2000) , PARTITION p6 VALUES LESS THAN (2001) ,
PARTITION p7 VALUES LESS THAN (2002) , PARTITION p8 VALUES LESS THAN (2003) ,
PARTITION p9 VALUES LESS THAN (2004) , PARTITION p10 VALUES LESS THAN (2010),
PARTITION p11 VALUES LESS THAN MAXVALUE );
INSERT INTO t1 VALUES (1, 'testing partitions', '1995-07-17'),
(3, 'testing partitions','1995-07-31'),
(5, 'testing partitions','1995-08-13'),
(7, 'testing partitions','1995-08-26'),
(9, 'testing partitions','1995-09-09'),
(0, 'testing partitions','2000-07-10'),
(2, 'testing partitions','2000-07-23'),
(4, 'testing partitions','2000-08-05'),
(6, 'testing partitions','2000-08-19'),
(8, 'testing partitions','2000-09-01');
SELECT COUNT(*) FROM t1 WHERE c3 BETWEEN '1996-12-31' AND '2000-12-31';
COUNT(*)
5
SELECT COUNT(*) FROM t1 WHERE c3 < '2000-12-31';
COUNT(*)
10
DROP TABLE t1;
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (10),
partition p1 values less than (0));
ERROR HY000: VALUES LESS THAN value must be strictly increasing for each partition
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (0),
partition p1 values less than (10));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) unsigned DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (0) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (10) ENGINE = MyISAM) */
drop table t1;
create table t1 (a bigint unsigned)
partition by range (a)
(partition p0 values less than (2),
partition p1 values less than (10));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) unsigned DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (a)
(PARTITION p0 VALUES LESS THAN (2) ENGINE = MyISAM,
PARTITION p1 VALUES LESS THAN (10) ENGINE = MyISAM) */
insert into t1 values (0xFFFFFFFFFFFFFFFF);
ERROR HY000: Table has no partition for value 18446744073709551615
drop table t1;
create table t1 (a int)
partition by range (MOD(a,3))
subpartition by hash(a)
subpartitions 2
(partition p0 values less than (1),
partition p1 values less than (2),
partition p2 values less than (3),
partition p3 values less than (4));
ALTER TABLE t1 DROP PARTITION p3;
ALTER TABLE t1 DROP PARTITION p1;
ALTER TABLE t1 DROP PARTITION p2;
drop table t1;
create table t1 (a int)
partition by range (MOD(a,3))
subpartition by hash(a)
subpartitions 2
(partition p0 values less than (1),
partition p1 values less than (2),
partition p2 values less than (3),
partition p3 values less than (4));
ALTER TABLE t1 DROP PARTITION p0;
ALTER TABLE t1 DROP PARTITION p1;
ALTER TABLE t1 DROP PARTITION p2;
drop table t1;
create table t1 (a int DEFAULT NULL,
b varchar(30) DEFAULT NULL,
c date DEFAULT NULL)
ENGINE=MYISAM DEFAULT CHARSET=latin1;
insert into t1 values (1, 'abc', '1995-01-01');
insert into t1 values (1, 'abc', '1995-01-02');
insert into t1 values (1, 'abc', '1995-01-03');
insert into t1 values (1, 'abc', '1995-01-04');
insert into t1 values (1, 'abc', '1995-01-05');
insert into t1 values (1, 'abc', '1995-01-06');
insert into t1 values (1, 'abc', '1995-01-07');
insert into t1 values (1, 'abc', '1995-01-08');
insert into t1 values (1, 'abc', '1995-01-09');
insert into t1 values (1, 'abc', '1995-01-10');
insert into t1 values (1, 'abc', '1995-01-11');
insert into t1 values (1, 'abc', '1995-01-12');
insert into t1 values (1, 'abc', '1995-01-13');
insert into t1 values (1, 'abc', '1995-01-14');
insert into t1 values (1, 'abc', '1995-01-15');
insert into t1 values (1, 'abc', '1997-01-01');
insert into t1 values (1, 'abc', '1997-01-02');
insert into t1 values (1, 'abc', '1997-01-03');
insert into t1 values (1, 'abc', '1997-01-04');
insert into t1 values (1, 'abc', '1997-01-05');
insert into t1 values (1, 'abc', '1997-01-06');
insert into t1 values (1, 'abc', '1997-01-07');
insert into t1 values (1, 'abc', '1997-01-08');
insert into t1 values (1, 'abc', '1997-01-09');
insert into t1 values (1, 'abc', '1997-01-10');
insert into t1 values (1, 'abc', '1997-01-11');
insert into t1 values (1, 'abc', '1997-01-12');
insert into t1 values (1, 'abc', '1997-01-13');
insert into t1 values (1, 'abc', '1997-01-14');
insert into t1 values (1, 'abc', '1997-01-15');
insert into t1 values (1, 'abc', '1998-01-01');
insert into t1 values (1, 'abc', '1998-01-02');
insert into t1 values (1, 'abc', '1998-01-03');
insert into t1 values (1, 'abc', '1998-01-04');
insert into t1 values (1, 'abc', '1998-01-05');
insert into t1 values (1, 'abc', '1998-01-06');
insert into t1 values (1, 'abc', '1998-01-07');
insert into t1 values (1, 'abc', '1998-01-08');
insert into t1 values (1, 'abc', '1998-01-09');
insert into t1 values (1, 'abc', '1998-01-10');
insert into t1 values (1, 'abc', '1998-01-11');
insert into t1 values (1, 'abc', '1998-01-12');
insert into t1 values (1, 'abc', '1998-01-13');
insert into t1 values (1, 'abc', '1998-01-14');
insert into t1 values (1, 'abc', '1998-01-15');
insert into t1 values (1, 'abc', '1999-01-01');
insert into t1 values (1, 'abc', '1999-01-02');
insert into t1 values (1, 'abc', '1999-01-03');
insert into t1 values (1, 'abc', '1999-01-04');
insert into t1 values (1, 'abc', '1999-01-05');
insert into t1 values (1, 'abc', '1999-01-06');
insert into t1 values (1, 'abc', '1999-01-07');
insert into t1 values (1, 'abc', '1999-01-08');
insert into t1 values (1, 'abc', '1999-01-09');
insert into t1 values (1, 'abc', '1999-01-10');
insert into t1 values (1, 'abc', '1999-01-11');
insert into t1 values (1, 'abc', '1999-01-12');
insert into t1 values (1, 'abc', '1999-01-13');
insert into t1 values (1, 'abc', '1999-01-14');
insert into t1 values (1, 'abc', '1999-01-15');
insert into t1 values (1, 'abc', '2000-01-01');
insert into t1 values (1, 'abc', '2000-01-02');
insert into t1 values (1, 'abc', '2000-01-03');
insert into t1 values (1, 'abc', '2000-01-04');
insert into t1 values (1, 'abc', '2000-01-05');
insert into t1 values (1, 'abc', '2000-01-06');
insert into t1 values (1, 'abc', '2000-01-07');
insert into t1 values (1, 'abc', '2000-01-08');
insert into t1 values (1, 'abc', '2000-01-09');
insert into t1 values (1, 'abc', '2000-01-15');
insert into t1 values (1, 'abc', '2000-01-11');
insert into t1 values (1, 'abc', '2000-01-12');
insert into t1 values (1, 'abc', '2000-01-13');
insert into t1 values (1, 'abc', '2000-01-14');
insert into t1 values (1, 'abc', '2000-01-15');
insert into t1 values (1, 'abc', '2001-01-01');
insert into t1 values (1, 'abc', '2001-01-02');
insert into t1 values (1, 'abc', '2001-01-03');
insert into t1 values (1, 'abc', '2001-01-04');
insert into t1 values (1, 'abc', '2001-01-05');
insert into t1 values (1, 'abc', '2001-01-06');
insert into t1 values (1, 'abc', '2001-01-07');
insert into t1 values (1, 'abc', '2001-01-08');
insert into t1 values (1, 'abc', '2001-01-09');
insert into t1 values (1, 'abc', '2001-01-15');
insert into t1 values (1, 'abc', '2001-01-11');
insert into t1 values (1, 'abc', '2001-01-12');
insert into t1 values (1, 'abc', '2001-01-13');
insert into t1 values (1, 'abc', '2001-01-14');
insert into t1 values (1, 'abc', '2001-01-15');
alter table t1
partition by range (year(c))
(partition p5 values less than (2000), partition p10 values less than (2010));
alter table t1
reorganize partition p5 into
(partition p1 values less than (1996),
partition p2 values less than (1997),
partition p3 values less than (1998),
partition p4 values less than (1999),
partition p5 values less than (2000));
drop table t1;
CREATE TABLE t1 (a date)
PARTITION BY RANGE (TO_DAYS(a))
(PARTITION p3xx VALUES LESS THAN (TO_DAYS('2004-01-01')),
PARTITION p401 VALUES LESS THAN (TO_DAYS('2004-02-01')),
PARTITION p402 VALUES LESS THAN (TO_DAYS('2004-03-01')),
PARTITION p403 VALUES LESS THAN (TO_DAYS('2004-04-01')),
PARTITION p404 VALUES LESS THAN (TO_DAYS('2004-05-01')),
PARTITION p405 VALUES LESS THAN (TO_DAYS('2004-06-01')),
PARTITION p406 VALUES LESS THAN (TO_DAYS('2004-07-01')),
PARTITION p407 VALUES LESS THAN (TO_DAYS('2004-08-01')),
PARTITION p408 VALUES LESS THAN (TO_DAYS('2004-09-01')),
PARTITION p409 VALUES LESS THAN (TO_DAYS('2004-10-01')),
PARTITION p410 VALUES LESS THAN (TO_DAYS('2004-11-01')),
PARTITION p411 VALUES LESS THAN (TO_DAYS('2004-12-01')),
PARTITION p412 VALUES LESS THAN (TO_DAYS('2005-01-01')),
PARTITION p501 VALUES LESS THAN (TO_DAYS('2005-02-01')),
PARTITION p502 VALUES LESS THAN (TO_DAYS('2005-03-01')),
PARTITION p503 VALUES LESS THAN (TO_DAYS('2005-04-01')),
PARTITION p504 VALUES LESS THAN (TO_DAYS('2005-05-01')),
PARTITION p505 VALUES LESS THAN (TO_DAYS('2005-06-01')),
PARTITION p506 VALUES LESS THAN (TO_DAYS('2005-07-01')),
PARTITION p507 VALUES LESS THAN (TO_DAYS('2005-08-01')),
PARTITION p508 VALUES LESS THAN (TO_DAYS('2005-09-01')),
PARTITION p509 VALUES LESS THAN (TO_DAYS('2005-10-01')),
PARTITION p510 VALUES LESS THAN (TO_DAYS('2005-11-01')),
PARTITION p511 VALUES LESS THAN (TO_DAYS('2005-12-01')),
PARTITION p512 VALUES LESS THAN (TO_DAYS('2006-01-01')),
PARTITION p601 VALUES LESS THAN (TO_DAYS('2006-02-01')),
PARTITION p602 VALUES LESS THAN (TO_DAYS('2006-03-01')),
PARTITION p603 VALUES LESS THAN (TO_DAYS('2006-04-01')),
PARTITION p604 VALUES LESS THAN (TO_DAYS('2006-05-01')),
PARTITION p605 VALUES LESS THAN (TO_DAYS('2006-06-01')),
PARTITION p606 VALUES LESS THAN (TO_DAYS('2006-07-01')),
PARTITION p607 VALUES LESS THAN (TO_DAYS('2006-08-01')));
INSERT INTO t1 VALUES ('2003-01-13'),('2003-06-20'),('2003-08-30');
INSERT INTO t1 VALUES ('2003-04-13'),('2003-07-20'),('2003-10-30');
INSERT INTO t1 VALUES ('2003-05-13'),('2003-11-20'),('2003-12-30');
INSERT INTO t1 VALUES ('2004-01-13'),('2004-01-20'),('2004-01-30');
INSERT INTO t1 VALUES ('2004-02-13'),('2004-02-20'),('2004-02-28');
INSERT INTO t1 VALUES ('2004-03-13'),('2004-03-20'),('2004-03-30');
INSERT INTO t1 VALUES ('2004-04-13'),('2004-04-20'),('2004-04-30');
INSERT INTO t1 VALUES ('2004-05-13'),('2004-05-20'),('2004-05-30');
INSERT INTO t1 VALUES ('2004-06-13'),('2004-06-20'),('2004-06-30');
INSERT INTO t1 VALUES ('2004-07-13'),('2004-07-20'),('2004-07-30');
INSERT INTO t1 VALUES ('2004-08-13'),('2004-08-20'),('2004-08-30');
INSERT INTO t1 VALUES ('2004-09-13'),('2004-09-20'),('2004-09-30');
INSERT INTO t1 VALUES ('2004-10-13'),('2004-10-20'),('2004-10-30');
INSERT INTO t1 VALUES ('2004-11-13'),('2004-11-20'),('2004-11-30');
INSERT INTO t1 VALUES ('2004-12-13'),('2004-12-20'),('2004-12-30');
INSERT INTO t1 VALUES ('2005-01-13'),('2005-01-20'),('2005-01-30');
INSERT INTO t1 VALUES ('2005-02-13'),('2005-02-20'),('2005-02-28');
INSERT INTO t1 VALUES ('2005-03-13'),('2005-03-20'),('2005-03-30');
INSERT INTO t1 VALUES ('2005-04-13'),('2005-04-20'),('2005-04-30');
INSERT INTO t1 VALUES ('2005-05-13'),('2005-05-20'),('2005-05-30');
INSERT INTO t1 VALUES ('2005-06-13'),('2005-06-20'),('2005-06-30');
INSERT INTO t1 VALUES ('2005-07-13'),('2005-07-20'),('2005-07-30');
INSERT INTO t1 VALUES ('2005-08-13'),('2005-08-20'),('2005-08-30');
INSERT INTO t1 VALUES ('2005-09-13'),('2005-09-20'),('2005-09-30');
INSERT INTO t1 VALUES ('2005-10-13'),('2005-10-20'),('2005-10-30');
INSERT INTO t1 VALUES ('2005-11-13'),('2005-11-20'),('2005-11-30');
INSERT INTO t1 VALUES ('2005-12-13'),('2005-12-20'),('2005-12-30');
INSERT INTO t1 VALUES ('2006-01-13'),('2006-01-20'),('2006-01-30');
INSERT INTO t1 VALUES ('2006-02-13'),('2006-02-20'),('2006-02-28');
INSERT INTO t1 VALUES ('2006-03-13'),('2006-03-20'),('2006-03-30');
INSERT INTO t1 VALUES ('2006-04-13'),('2006-04-20'),('2006-04-30');
INSERT INTO t1 VALUES ('2006-05-13'),('2006-05-20'),('2006-05-30');
INSERT INTO t1 VALUES ('2006-06-13'),('2006-06-20'),('2006-06-30');
INSERT INTO t1 VALUES ('2006-07-13'),('2006-07-20'),('2006-07-30');
SELECT * FROM t1
WHERE a >= '2004-07-01' AND a <= '2004-09-30';
a
2004-07-13
2004-07-20
2004-07-30
2004-08-13
2004-08-20
2004-08-30
2004-09-13
2004-09-20
2004-09-30
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE a >= '2004-07-01' AND a <= '2004-09-30';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p3xx,p407,p408,p409 ALL NULL NULL NULL NULL 18 Using where
SELECT * from t1
WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
(a >= '2005-07-01' AND a <= '2005-09-30');
a
2004-07-13
2004-07-20
2004-07-30
2004-08-13
2004-08-20
2004-08-30
2004-09-13
2004-09-20
2004-09-30
2005-07-13
2005-07-20
2005-07-30
2005-08-13
2005-08-20
2005-08-30
2005-09-13
2005-09-20
2005-09-30
EXPLAIN PARTITIONS SELECT * from t1
WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
(a >= '2005-07-01' AND a <= '2005-09-30');
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p3xx,p407,p408,p409,p507,p508,p509 ALL NULL NULL NULL NULL 27 Using where
DROP TABLE t1;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t2 (
defid int(10) unsigned NOT NULL,
day int(10) unsigned NOT NULL,
count int(10) unsigned NOT NULL,
filler char(200),
KEY (defid,day)
)
PARTITION BY RANGE (day) (
PARTITION p7 VALUES LESS THAN (20070401) ,
PARTITION p8 VALUES LESS THAN (20070501));
insert into t2 select 20, 20070311, 1, 'filler' from t1 A, t1 B;
insert into t2 select 20, 20070411, 1, 'filler' from t1 A, t1 B;
insert into t2 values(52, 20070321, 123, 'filler') ;
insert into t2 values(52, 20070322, 456, 'filler') ;
select sum(count) from t2 ch where ch.defid in (50,52) and ch.day between 20070320 and 20070401 group by defid;
sum(count)
579
drop table t1, t2;
#
# Bug#50939: Loose Index Scan unduly relies on engine to remember range
# endpoints
#
CREATE TABLE t1 (
a INT,
b INT,
KEY ( a, b )
) PARTITION BY HASH (a) PARTITIONS 1;
CREATE TABLE t2 (
a INT,
b INT,
KEY ( a, b )
);
INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
INSERT INTO t1 SELECT a + 5, b + 5 FROM t1;
INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
INSERT INTO t2 SELECT * FROM t1;
# plans should be identical
EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 1 Using where; Using index for group-by
EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range a a 5 NULL 2 Using where; Using index for group-by
FLUSH status;
SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
a MAX(b)
10 10
# Should be no more than 4 reads.
SHOW status LIKE 'handler_read_key';
Variable_name Value
Handler_read_key 4
FLUSH status;
SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
a MAX(b)
10 10
# Should be no more than 4 reads.
SHOW status LIKE 'handler_read_key';
Variable_name Value
Handler_read_key 4
DROP TABLE t1, t2;
|