partition_pruning.result 131 KB
Newer Older
unknown's avatar
unknown committed
1
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
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
#
# Bug#49742: Partition Pruning not working correctly for RANGE
#
CREATE TABLE t1 (a INT PRIMARY KEY)
PARTITION BY RANGE (a) (
PARTITION p0 VALUES LESS THAN (1),
PARTITION p1 VALUES LESS THAN (2),
PARTITION p2 VALUES LESS THAN (3),
PARTITION p3 VALUES LESS THAN (4),
PARTITION p4 VALUES LESS THAN (5),
PARTITION p5 VALUES LESS THAN (6),
PARTITION max VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8);
SELECT * FROM t1 WHERE a < 1;
a
-1
0
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0	index	PRIMARY	PRIMARY	4	NULL	2	Using where; Using index
SELECT * FROM t1 WHERE a < 2;
a
-1
0
1
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
SELECT * FROM t1 WHERE a < 3;
a
-1
0
1
2
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2	index	PRIMARY	PRIMARY	4	NULL	4	Using where; Using index
SELECT * FROM t1 WHERE a < 4;
a
-1
0
1
2
3
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3	index	PRIMARY	PRIMARY	4	NULL	5	Using where; Using index
SELECT * FROM t1 WHERE a < 5;
a
-1
0
1
2
3
4
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4	index	PRIMARY	PRIMARY	4	NULL	6	Using where; Using index
SELECT * FROM t1 WHERE a < 6;
a
-1
0
1
2
3
4
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,p5	index	PRIMARY	PRIMARY	4	NULL	7	Using where; Using index
SELECT * FROM t1 WHERE a < 7;
a
-1
0
1
2
3
4
5
6
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,p5,max	range	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a <= 1;
a
-1
0
1
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a <= 2;
a
-1
0
1
2
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a <= 3;
a
-1
0
1
2
3
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a <= 4;
a
-1
0
1
2
3
4
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a <= 5;
a
-1
0
1
2
3
4
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,p5	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a <= 6;
a
-1
0
1
2
3
4
5
6
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,p5,max	range	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a <= 7;
a
-1
0
1
2
3
4
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 7;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,p5,max	range	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a = 1;
a
1
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 2;
a
2
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 3;
a
3
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 4;
a
4
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p4	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 5;
a
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p5	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 6;
a
6
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	max	const	PRIMARY	PRIMARY	4	const	1	Using index
SELECT * FROM t1 WHERE a = 7;
a
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 7;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	max	const	PRIMARY	PRIMARY	4	const	1	Using index
SELECT * FROM t1 WHERE a >= 1;
a
1
2
3
4
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1,p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a >= 2;
a
2
3
4
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a >= 3;
a
3
4
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a >= 4;
a
4
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a >= 5;
a
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a >= 6;
a
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a >= 7;
a
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 7;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
273
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
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
SELECT * FROM t1 WHERE a > 1;
a
2
3
4
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2,p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a > 2;
a
3
4
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3,p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a > 3;
a
4
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p4,p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a > 4;
a
5
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p5,max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a > 5;
a
6
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
SELECT * FROM t1 WHERE a > 6;
a
7
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
330
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
331 332 333 334 335
SELECT * FROM t1 WHERE a > 7;
a
8
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 7;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
336
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	10	Using where; Using index
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
DROP TABLE t1;
CREATE TABLE t1 (a INT PRIMARY KEY)
PARTITION BY RANGE (a) (
PARTITION p0 VALUES LESS THAN (1),
PARTITION p1 VALUES LESS THAN (2),
PARTITION p2 VALUES LESS THAN (3),
PARTITION p3 VALUES LESS THAN (4),
PARTITION p4 VALUES LESS THAN (5),
PARTITION max VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7);
SELECT * FROM t1 WHERE a < 1;
a
-1
0
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0	index	PRIMARY	PRIMARY	4	NULL	2	Using where; Using index
SELECT * FROM t1 WHERE a < 2;
a
-1
0
1
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1	index	PRIMARY	PRIMARY	4	NULL	3	Using where; Using index
SELECT * FROM t1 WHERE a < 3;
a
-1
0
1
2
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2	index	PRIMARY	PRIMARY	4	NULL	4	Using where; Using index
SELECT * FROM t1 WHERE a < 4;
a
-1
0
1
2
3
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3	index	PRIMARY	PRIMARY	4	NULL	5	Using where; Using index
SELECT * FROM t1 WHERE a < 5;
a
-1
0
1
2
3
4
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4	index	PRIMARY	PRIMARY	4	NULL	6	Using where; Using index
SELECT * FROM t1 WHERE a < 6;
a
-1
0
1
2
3
4
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,max	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using index
SELECT * FROM t1 WHERE a <= 1;
a
-1
0
1
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a <= 2;
a
-1
0
1
2
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a <= 3;
a
-1
0
1
2
3
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a <= 4;
a
-1
0
1
2
3
4
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a <= 5;
a
-1
0
1
2
3
4
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,max	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using index
SELECT * FROM t1 WHERE a <= 6;
a
-1
0
1
2
3
4
5
6
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,max	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using index
SELECT * FROM t1 WHERE a = 1;
a
1
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 2;
a
2
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 3;
a
3
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 4;
a
4
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p4	system	PRIMARY	NULL	NULL	NULL	1	
SELECT * FROM t1 WHERE a = 5;
a
5
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	max	const	PRIMARY	PRIMARY	4	const	1	Using index
SELECT * FROM t1 WHERE a = 6;
a
6
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	max	const	PRIMARY	PRIMARY	4	const	1	Using index
SELECT * FROM t1 WHERE a >= 1;
a
1
2
3
4
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1,p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a >= 2;
a
2
3
4
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a >= 3;
a
3
4
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a >= 4;
a
4
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a >= 5;
a
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a >= 6;
a
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
559
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
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
SELECT * FROM t1 WHERE a > 1;
a
2
3
4
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2,p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a > 2;
a
3
4
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3,p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a > 3;
a
4
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p4,max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a > 4;
a
5
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
SELECT * FROM t1 WHERE a > 5;
a
6
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
604
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
605 606 607 608 609
SELECT * FROM t1 WHERE a > 6;
a
7
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
610
1	SIMPLE	t1	max	index	PRIMARY	PRIMARY	4	NULL	9	Using where; Using index
611
DROP TABLE t1;
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
# test of RANGE and index
CREATE TABLE t1 (a DATE, KEY(a))
PARTITION BY RANGE (TO_DAYS(a))
(PARTITION `pNULL` VALUES LESS THAN (0),
PARTITION `p0001-01-01` VALUES LESS THAN (366 + 1),
PARTITION `p1001-01-01` VALUES LESS THAN (TO_DAYS('1001-01-01') + 1),
PARTITION `p2001-01-01` VALUES LESS THAN (TO_DAYS('2001-01-01') + 1));
INSERT INTO t1 VALUES ('0000-00-00'), ('0000-01-02'), ('0001-01-01'),
('1001-00-00'), ('1001-01-01'), ('1002-00-00'), ('2001-01-01');
SELECT * FROM t1 WHERE a < '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
SELECT * FROM t1 WHERE a <= '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
SELECT * FROM t1 WHERE a >= '1001-01-01';
a
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a > '1001-01-01';
a
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a = '1001-01-01';
a
1001-01-01
SELECT * FROM t1 WHERE a < '1001-00-00';
a
0000-00-00
0000-01-02
0001-01-01
SELECT * FROM t1 WHERE a <= '1001-00-00';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
SELECT * FROM t1 WHERE a >= '1001-00-00';
a
1001-00-00
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a > '1001-00-00';
a
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a = '1001-00-00';
a
1001-00-00
671
# Disabling warnings for the invalid date
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
SELECT * FROM t1 WHERE a < '1999-02-31';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a <= '1999-02-31';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a >= '1999-02-31';
a
2001-01-01
SELECT * FROM t1 WHERE a > '1999-02-31';
a
2001-01-01
SELECT * FROM t1 WHERE a = '1999-02-31';
a
SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
a
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
a
0001-01-01
1001-00-00
1001-01-01
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
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	range	a	a	4	NULL	4	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p2001-01-01	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1001-01-01	system	a	NULL	NULL	NULL	1	
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	range	a	a	4	NULL	4	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	range	a	a	4	NULL	4	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL	ref	a	a	4	const	1	Using where; Using index
751
# Disabling warnings for the invalid date
752 753 754 755 756 757 758 759
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	range	a	a	4	NULL	5	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	range	a	a	4	NULL	5	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
760
1	SIMPLE	t1	pNULL,p2001-01-01	index	a	a	4	NULL	7	Using where; Using index
761 762
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
763
1	SIMPLE	t1	pNULL,p2001-01-01	index	a	a	4	NULL	7	Using where; Using index
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL	ref	a	a	4	const	1	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	range	a	a	4	NULL	5	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
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
# test without index
ALTER TABLE t1 DROP KEY a;
SELECT * FROM t1 WHERE a < '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
SELECT * FROM t1 WHERE a <= '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
SELECT * FROM t1 WHERE a >= '1001-01-01';
a
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a > '1001-01-01';
a
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a = '1001-01-01';
a
1001-01-01
SELECT * FROM t1 WHERE a < '1001-00-00';
a
0000-00-00
0000-01-02
0001-01-01
SELECT * FROM t1 WHERE a <= '1001-00-00';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
SELECT * FROM t1 WHERE a >= '1001-00-00';
a
1001-00-00
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a > '1001-00-00';
a
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a = '1001-00-00';
a
1001-00-00
831
# Disabling warnings for the invalid date
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
SELECT * FROM t1 WHERE a < '1999-02-31';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a <= '1999-02-31';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a >= '1999-02-31';
a
2001-01-01
SELECT * FROM t1 WHERE a > '1999-02-31';
a
2001-01-01
SELECT * FROM t1 WHERE a = '1999-02-31';
a
SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
a
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
a
0001-01-01
1001-00-00
1001-01-01
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
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1001-01-01	system	NULL	NULL	NULL	NULL	1	
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
911
# Disabling warnings for the invalid date
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
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01,p2001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p0001-01-01,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
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 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
DROP TABLE t1;
# test of LIST and index
CREATE TABLE t1 (a DATE, KEY(a))
PARTITION BY LIST (TO_DAYS(a))
(PARTITION `p0001-01-01` VALUES IN (TO_DAYS('0001-01-01')),
PARTITION `p2001-01-01` VALUES IN (TO_DAYS('2001-01-01')),
PARTITION `pNULL` VALUES IN (NULL),
PARTITION `p0000-01-02` VALUES IN (TO_DAYS('0000-01-02')),
PARTITION `p1001-01-01` VALUES IN (TO_DAYS('1001-01-01')));
INSERT INTO t1 VALUES ('0000-00-00'), ('0000-01-02'), ('0001-01-01'),
('1001-00-00'), ('1001-01-01'), ('1002-00-00'), ('2001-01-01');
SELECT * FROM t1 WHERE a < '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
SELECT * FROM t1 WHERE a <= '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
SELECT * FROM t1 WHERE a >= '1001-01-01';
a
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a > '1001-01-01';
a
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a = '1001-01-01';
a
1001-01-01
SELECT * FROM t1 WHERE a < '1001-00-00';
a
0000-00-00
0000-01-02
0001-01-01
SELECT * FROM t1 WHERE a <= '1001-00-00';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
SELECT * FROM t1 WHERE a >= '1001-00-00';
a
1001-00-00
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a > '1001-00-00';
a
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a = '1001-00-00';
a
1001-00-00
1000
# Disabling warnings for the invalid date
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
SELECT * FROM t1 WHERE a < '1999-02-31';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a <= '1999-02-31';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a >= '1999-02-31';
a
2001-01-01
SELECT * FROM t1 WHERE a > '1999-02-31';
a
2001-01-01
SELECT * FROM t1 WHERE a = '1999-02-31';
a
SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
a
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
a
0001-01-01
1001-00-00
1001-01-01
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	4	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	range	a	a	4	NULL	4	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1001-01-01	system	a	NULL	NULL	NULL	1	
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	range	a	a	4	NULL	3	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	range	a	a	4	NULL	4	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	range	a	a	4	NULL	4	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL	ref	a	a	4	const	1	Using where; Using index
1080
# Disabling warnings for the invalid date
1081 1082 1083 1084 1085 1086 1087 1088
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	5	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	5	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1089
1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	7	Using where; Using index
1090 1091
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1092
1	SIMPLE	t1	p2001-01-01,pNULL	index	a	a	4	NULL	7	Using where; Using index
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL	ref	a	a	4	const	1	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	5	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	range	a	a	4	NULL	4	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1104
1	SIMPLE	t1	pNULL,p1001-01-01	index	a	a	4	NULL	7	Using where; Using index
1105 1106 1107
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p1001-01-01	range	a	a	4	NULL	3	Using where; Using index
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
# test without index
ALTER TABLE t1 DROP KEY a;
SELECT * FROM t1 WHERE a < '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
SELECT * FROM t1 WHERE a <= '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
SELECT * FROM t1 WHERE a >= '1001-01-01';
a
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a > '1001-01-01';
a
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a = '1001-01-01';
a
1001-01-01
SELECT * FROM t1 WHERE a < '1001-00-00';
a
0000-00-00
0000-01-02
0001-01-01
SELECT * FROM t1 WHERE a <= '1001-00-00';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
SELECT * FROM t1 WHERE a >= '1001-00-00';
a
1001-00-00
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a > '1001-00-00';
a
1001-01-01
1002-00-00
2001-01-01
SELECT * FROM t1 WHERE a = '1001-00-00';
a
1001-00-00
1160
# Disabling warnings for the invalid date
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
SELECT * FROM t1 WHERE a < '1999-02-31';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a <= '1999-02-31';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a >= '1999-02-31';
a
2001-01-01
SELECT * FROM t1 WHERE a > '1999-02-31';
a
2001-01-01
SELECT * FROM t1 WHERE a = '1999-02-31';
a
SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
a
0000-00-00
0000-01-02
0001-01-01
1001-00-00
1001-01-01
SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
a
1001-00-00
1001-01-01
1002-00-00
SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
a
0001-01-01
1001-00-00
1001-01-01
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1001-01-01	system	NULL	NULL	NULL	NULL	1	
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1001-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
1240
# Disabling warnings for the invalid date
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a >= '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a > '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p2001-01-01,pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a = '1999-02-31';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1002-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p0000-01-02,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-02' AND '1002-00-00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0001-01-01' AND '1001-01-01';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0001-01-01,pNULL,p1001-01-01	ALL	NULL	NULL	NULL	NULL	7	Using where
DROP TABLE t1;
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
# Test with DATETIME column NOT NULL
CREATE TABLE t1 (
a int(10) unsigned NOT NULL,
b DATETIME NOT NULL,
PRIMARY KEY (a, b)
) PARTITION BY RANGE (TO_DAYS(b))
(PARTITION p20090401 VALUES LESS THAN (TO_DAYS('2009-04-02')),
PARTITION p20090402 VALUES LESS THAN (TO_DAYS('2009-04-03')),
PARTITION p20090403 VALUES LESS THAN (TO_DAYS('2009-04-04')),
PARTITION p20090404 VALUES LESS THAN (TO_DAYS('2009-04-05')),
PARTITION p20090405 VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (1, '2009-01-01'), (1, '2009-04-01'), (2, '2009-04-01'),
(1, '2009-04-02'), (2, '2009-04-02'), (1, '2009-04-02 23:59:59'),
(1, '2009-04-03'), (2, '2009-04-03'), (1, '2009-04-04'), (2, '2009-04-04'),
(1, '2009-04-05'), (1, '2009-04-06'), (1, '2009-04-07');
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	6	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	8	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1295
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1296 1297
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1298
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1314
1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1315 1316 1317
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1318
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1330
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1331 1332
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1333
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1345
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1346 1347
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1348
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1360
1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1361 1362
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1363
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1375
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1376 1377
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1378
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1394
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1395 1396 1397
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1398
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090402	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1414
1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1415 1416 1417
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1418
1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	index	NULL	PRIMARY	12	NULL	13	Using where; Using index
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
DROP TABLE t1;
# Test with DATE column NOT NULL
CREATE TABLE t1 (
a int(10) unsigned NOT NULL,
b DATE NOT NULL,
PRIMARY KEY (a, b)
) PARTITION BY RANGE (TO_DAYS(b))
(PARTITION p20090401 VALUES LESS THAN (TO_DAYS('2009-04-02')),
PARTITION p20090402 VALUES LESS THAN (TO_DAYS('2009-04-03')),
PARTITION p20090403 VALUES LESS THAN (TO_DAYS('2009-04-04')),
PARTITION p20090404 VALUES LESS THAN (TO_DAYS('2009-04-05')),
PARTITION p20090405 VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (1, '2009-01-01'), (1, '2009-04-01'), (2, '2009-04-01'),
(1, '2009-04-02'), (2, '2009-04-02'), (1, '2009-04-03'), (2, '2009-04-03'),
(1, '2009-04-04'), (2, '2009-04-04'), (1, '2009-04-05'), (1, '2009-04-06'),
(1, '2009-04-07');
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	5	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	7	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1446
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1447 1448
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1449
1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME);
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 b >= CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1465
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1466 1467 1468
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1469
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1481
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1482 1483
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1484
1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1496
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1497 1498
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1499
1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59';
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 b >= '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1511
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1512 1513
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1514
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1526
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1527 1528
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1529
1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME);
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 b >= CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1545
1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1546 1547 1548
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1549
1	SIMPLE	t1	p20090401,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME);
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 b >= CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1565
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1566 1567 1568
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1569
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	index	NULL	PRIMARY	7	NULL	12	Using where; Using index
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595
DROP TABLE t1;
# Test with DATETIME column NULL
CREATE TABLE t1 (
a int(10) unsigned NOT NULL,
b DATETIME NULL
) PARTITION BY RANGE (TO_DAYS(b))
(PARTITION p20090401 VALUES LESS THAN (TO_DAYS('2009-04-02')),
PARTITION p20090402 VALUES LESS THAN (TO_DAYS('2009-04-03')),
PARTITION p20090403 VALUES LESS THAN (TO_DAYS('2009-04-04')),
PARTITION p20090404 VALUES LESS THAN (TO_DAYS('2009-04-05')),
PARTITION p20090405 VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (1, '2009-01-01'), (1, '2009-04-01'), (2, '2009-04-01'),
(1, '2009-04-02'), (2, '2009-04-02'), (1, '2009-04-02 23:59:59'),
(1, '2009-04-03'), (2, '2009-04-03'), (1, '2009-04-04'), (2, '2009-04-04'),
(1, '2009-04-05'), (1, '2009-04-06'), (1, '2009-04-07');
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	6	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	8	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1596
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1597 1598
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1599
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b >= CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1615
1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1616 1617 1618
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1619
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1631
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1632 1633
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1634
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1646
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1647 1648
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1649
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1661
1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1662 1663
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1664
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1676
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1677 1678
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1679
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b >= CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1695
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1696 1697 1698
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1699
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090402	ALL	NULL	NULL	NULL	NULL	13	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b >= CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1715
1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1716 1717 1718
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1719
1	SIMPLE	t1	p20090401,p20090402,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	13	Using where
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745
DROP TABLE t1;
# Test with DATE column NULL
CREATE TABLE t1 (
a int(10) unsigned NOT NULL,
b DATE NULL
) PARTITION BY RANGE (TO_DAYS(b))
(PARTITION p20090401 VALUES LESS THAN (TO_DAYS('2009-04-02')),
PARTITION p20090402 VALUES LESS THAN (TO_DAYS('2009-04-03')),
PARTITION p20090403 VALUES LESS THAN (TO_DAYS('2009-04-04')),
PARTITION p20090404 VALUES LESS THAN (TO_DAYS('2009-04-05')),
PARTITION p20090405 VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (1, '2009-01-01'), (1, '2009-04-01'), (2, '2009-04-01'),
(1, '2009-04-02'), (2, '2009-04-02'), (1, '2009-04-03'), (2, '2009-04-03'),
(1, '2009-04-04'), (2, '2009-04-04'), (1, '2009-04-05'), (1, '2009-04-06'),
(1, '2009-04-07');
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	5	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	7	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1746
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1747 1748
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1749
1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-02 23:59:59' AS DATETIME);
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 b >= CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1765
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1766 1767 1768
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-02 23:59:59' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1769
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1781
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1782 1783
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > CAST('2009-04-03' AS DATE);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1784
1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1796
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1797 1798
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03 00:00:00';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1799
1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-02 23:59:59';
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 b >= '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1811
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1812 1813
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-02 23:59:59';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1814
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b <= '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b = '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b >= '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1826
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1827 1828
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b > '2009-04-03';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1829
1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402,p20090403	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-03 00:00:01' AS DATETIME);
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 b >= CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1845
1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1846 1847 1848
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-03 00:00:01' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1849
1	SIMPLE	t1	p20090401,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b < CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b <= CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p20090401,p20090402	ALL	NULL	NULL	NULL	NULL	12	Using where
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b = CAST('2009-04-02 23:59:58' AS DATETIME);
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 b >= CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1865
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1866 1867 1868
EXPLAIN PARTITIONS SELECT * FROM t1
WHERE b > CAST('2009-04-02 23:59:58' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1869
1	SIMPLE	t1	p20090401,p20090403,p20090404,p20090405	ALL	NULL	NULL	NULL	NULL	12	Using where
1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884
DROP TABLE t1;
# For better code coverage of the patch
CREATE TABLE t1 (
a int(10) unsigned NOT NULL,
b DATE
) PARTITION BY RANGE ( TO_DAYS(b) )
(PARTITION p20090401 VALUES LESS THAN (TO_DAYS('2009-04-02')),
PARTITION p20090402 VALUES LESS THAN (TO_DAYS('2009-04-03')),
PARTITION p20090403 VALUES LESS THAN (TO_DAYS('2009-04-04')),
PARTITION p20090404 VALUES LESS THAN (TO_DAYS('2009-04-05')),
PARTITION p20090405 VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (1, '2009-01-01'), (2, NULL);
# test with an invalid date, which lead to item->null_value is set.
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-99' AS DATETIME);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1885
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
1886 1887
Warnings:
Warning	1292	Incorrect datetime value: '2009-04-99'
1888
DROP TABLE t1;
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900
CREATE TABLE t1
(a INT NOT NULL AUTO_INCREMENT,
b DATETIME,
PRIMARY KEY (a,b),
KEY (b))
PARTITION BY RANGE (to_days(b))
(PARTITION p0 VALUES LESS THAN (733681) COMMENT = 'LESS THAN 2008-10-01',
PARTITION p1 VALUES LESS THAN (733712) COMMENT = 'LESS THAN 2008-11-01',
PARTITION pX VALUES LESS THAN MAXVALUE);
SELECT a,b FROM t1 WHERE b >= '2008-12-01' AND b < '2009-12-00';
a	b
DROP TABLE t1;
unknown's avatar
unknown committed
1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912
create table t1 ( a int not null) partition by hash(a) partitions 2;
insert into t1 values (1),(2),(3);
explain select * from t1 where a=5 and a=6;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
drop table t1;
create table t1 (
a int(11) not null
) partition by hash (a) partitions 2;
insert into t1 values (1),(2),(3);
explain partitions select * from t1 where a=1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1913
1	SIMPLE	t1	p1	ALL	NULL	NULL	NULL	NULL	2	Using where
unknown's avatar
unknown committed
1914 1915
explain partitions select * from t1 where a=2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1916
1	SIMPLE	t1	p0	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932
explain partitions select * from t1 where a=1 or a=2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	3	Using where
create table t2 (
a int not null,
b int not null
) partition by key(a,b) partitions 2;
insert into t2 values (1,1),(2,2),(3,3);
explain partitions select * from t2 where a=1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1	ALL	NULL	NULL	NULL	NULL	3	Using where
explain partitions select * from t2 where b=1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1	ALL	NULL	NULL	NULL	NULL	3	Using where
explain partitions select * from t2 where a=1 and b=1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1933
1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	3	Using where
unknown's avatar
unknown committed
1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
create table t3 (
a int
)
partition by range (a*1) ( 
partition p0 values less than (10),
partition p1 values less than (20)
);
insert into t3 values (5),(15);
explain partitions select * from t3 where a=11;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1944
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
unknown's avatar
unknown committed
1945 1946
explain partitions select * from t3 where a=10;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1947
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
unknown's avatar
unknown committed
1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
explain partitions select * from t3 where a=20;
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 t3 where a=30;
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
create table t4 (a int not null, b int not null) partition by LIST (a+b) (
partition p0 values in (12),
partition p1 values in (14)
);
insert into t4 values (10,2), (10,4);
explain partitions select * from t4 where (a=10 and b=1) or (a=10 and b=2);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1961
1	SIMPLE	t4	p0	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
1962 1963 1964
explain partitions select * from t4 
where (a=10 and b=1) or (a=10 and b=2) or (a=10 and b = 3);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1965
1	SIMPLE	t4	p0	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986
explain partitions select * from t4 where (a=10 and b=2) or (a=10 and b=3)
or (a=10 and b = 4);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	p0,p1	ALL	NULL	NULL	NULL	NULL	2	Using where
explain partitions select * from t4 where (a=10 and b=1) or a=11;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	p0,p1	ALL	NULL	NULL	NULL	NULL	2	Using where
explain partitions select * from t4 where (a=10 and b=2) or a=11;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	p0,p1	ALL	NULL	NULL	NULL	NULL	2	Using where
drop table t1, t2, t3, t4;
create table t5 (a int not null, b int not null, 
c int not null, d int not null) 
partition by LIST(a+b) subpartition by HASH (c+d) subpartitions 2
(
partition p0 values in (12),
partition p1 values in (14)
);
insert into t5 values (10,2,0,0), (10,4,0,0), (10,2,0,1), (10,4,0,1);
explain partitions select * from t5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1987
1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	
unknown's avatar
unknown committed
1988 1989 1990
explain partitions select * from t5
where (a=10 and b=1) or (a=10 and b=2) or (a=10 and b = 3);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1991
1	SIMPLE	t5	p0_p0sp0,p0_p0sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
1992 1993 1994
explain partitions select * from t5 where (a=10 and b=2) or (a=10 and b=3)
or (a=10 and b = 4);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1995
1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp0,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
1996 1997
explain partitions select * from t5 where (c=1 and d=1);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1998
1	SIMPLE	t5	p0_p0sp0,p1_p1sp0	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
1999 2000
explain partitions select * from t5 where (c=2 and d=1);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2001
1	SIMPLE	t5	p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2002 2003 2004
explain partitions select * from t5 where (a=10 and b=2 and c=1 and d=1) or 
(c=2 and d=1);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2005
1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2006 2007 2008
explain partitions select * from t5 where (a=10 and b=2 and c=1 and d=1) or 
(b=2 and c=2 and d=1);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2009
1	SIMPLE	t5	p0_p0sp0,p0_p0sp1,p1_p1sp1	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
create table t6 (a int not null) partition by LIST(a) (
partition p1 values in (1),
partition p3 values in (3),
partition p5 values in (5),
partition p7 values in (7),
partition p9 values in (9)
);
insert into t6 values (1),(3),(5);
explain partitions select * from t6 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
explain partitions select * from t6 where a <= 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2023
1	SIMPLE	t6	p1	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
2024 2025 2026 2027 2028
explain partitions select * from t6 where a >  9;
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 t6 where a >= 9;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2029
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
unknown's avatar
unknown committed
2030 2031
explain partitions select * from t6 where a > 0 and a < 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2032
1	SIMPLE	t6	p1,p3	ALL	NULL	NULL	NULL	NULL	2	Using where
unknown's avatar
unknown committed
2033 2034
explain partitions select * from t6 where a > 5 and a < 12;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2035
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
unknown's avatar
unknown committed
2036 2037
explain partitions select * from t6 where a > 3 and a < 8 ;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2038
1	SIMPLE	t6	p5,p7	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
2039 2040 2041 2042 2043
explain partitions select * from t6 where a >= 0 and a <= 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t6	p1,p3,p5	ALL	NULL	NULL	NULL	NULL	3	Using where
explain partitions select * from t6 where a >= 5 and a <= 12;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2044
1	SIMPLE	t6	p5,p7,p9	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
2045 2046
explain partitions select * from t6 where a >= 3 and a <= 8;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2047
1	SIMPLE	t6	p3,p5,p7	ALL	NULL	NULL	NULL	NULL	3	Using where
unknown's avatar
unknown committed
2048 2049 2050
explain partitions select * from t6 where a > 3 and a < 5;
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
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
drop table t6;
create table t6 (a int unsigned not null) partition by LIST(a) (
partition p1 values in (1),
partition p3 values in (3),
partition p5 values in (5),
partition p7 values in (7),
partition p9 values in (9)
);
insert into t6 values (1),(3),(5);
explain partitions select * from t6 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
explain partitions select * from t6 where a <= 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t6	p1	system	NULL	NULL	NULL	NULL	1	
explain partitions select * from t6 where a >  9;
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 t6 where a >= 9;
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 t6 where a > 0 and a < 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t6	p1,p3	ALL	NULL	NULL	NULL	NULL	2	Using where
explain partitions select * from t6 where a > 5 and a < 12;
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 t6 where a > 3 and a < 8 ;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t6	p5,p7	system	NULL	NULL	NULL	NULL	1	
explain partitions select * from t6 where a >= 0 and a <= 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t6	p1,p3,p5	ALL	NULL	NULL	NULL	NULL	3	Using where
explain partitions select * from t6 where a >= 5 and a <= 12;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t6	p5,p7,p9	system	NULL	NULL	NULL	NULL	1	
explain partitions select * from t6 where a >= 3 and a <= 8;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2089
1	SIMPLE	t6	p3,p5,p7	ALL	NULL	NULL	NULL	NULL	3	Using where
2090 2091 2092
explain partitions select * from t6 where a > 3 and a < 5;
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
unknown's avatar
unknown committed
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102
create table t7 (a int not null) partition by RANGE(a) (
partition p10 values less than (10),
partition p30 values less than (30),
partition p50 values less than (50),
partition p70 values less than (70),
partition p90 values less than (90)
);
insert into t7 values (10),(30),(50);
explain partitions select * from t7 where a < 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2103
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
unknown's avatar
unknown committed
2104 2105
explain partitions select * from t7 where a < 10;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2106
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
explain partitions select * from t7 where a <= 10;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t7	p10,p30	system	NULL	NULL	NULL	NULL	1	
explain partitions select * from t7 where a = 10;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t7	p30	system	NULL	NULL	NULL	NULL	1	
explain partitions select * from t7 where a < 90;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t7	p10,p30,p50,p70,p90	ALL	NULL	NULL	NULL	NULL	3	Using where
explain partitions select * from t7 where a = 90;
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 t7 where a > 90;
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 t7 where a >= 90;
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 t7 where a > 11 and a < 29;
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 t7;
create table t7 (a int unsigned not null) partition by RANGE(a) (
partition p10 values less than (10),
partition p30 values less than (30),
partition p50 values less than (50),
partition p70 values less than (70),
partition p90 values less than (90)
);
insert into t7 values (10),(30),(50);
explain partitions select * from t7 where a < 5;
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 t7 where a < 10;
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
unknown's avatar
unknown committed
2143 2144
explain partitions select * from t7 where a <= 10;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2145
1	SIMPLE	t7	p10,p30	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
2146 2147
explain partitions select * from t7 where a = 10;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2148
1	SIMPLE	t7	p30	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162
explain partitions select * from t7 where a < 90;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t7	p10,p30,p50,p70,p90	ALL	NULL	NULL	NULL	NULL	3	Using where
explain partitions select * from t7 where a = 90;
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 t7 where a > 90;
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 t7 where a >= 90;
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 t7 where a > 11 and a < 29;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2163
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
unknown's avatar
unknown committed
2164 2165 2166 2167 2168 2169 2170 2171
create table t8 (a date not null) partition by RANGE(YEAR(a)) (
partition p0 values less than (1980),
partition p1 values less than (1990),
partition p2 values less than (2000)
);
insert into t8 values ('1985-05-05'),('1995-05-05');
explain partitions select * from t8 where a < '1980-02-02';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2172
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
unknown's avatar
unknown committed
2173 2174 2175 2176 2177 2178 2179 2180
create table t9 (a date not null) partition by RANGE(TO_DAYS(a)) (
partition p0 values less than (732299), -- 2004-12-19
partition p1 values less than (732468), -- 2005-06-06
partition p2 values less than (732664)  -- 2005-12-19
);
insert into t9 values ('2005-05-05'), ('2005-04-04');
explain partitions select * from t9 where a <  '2004-12-19';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2181
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
unknown's avatar
unknown committed
2182 2183 2184 2185
explain partitions select * from t9 where a <= '2004-12-19';
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t9	p0,p1	ALL	NULL	NULL	NULL	NULL	2	Using where
drop table t5,t6,t7,t8,t9;
2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196
create table t1 (
a1 int not null
)
partition by range (a1) (
partition p0 values less than (3),
partition p1 values less than (6),
partition p2 values less than (9)
);
insert into t1 values (1),(2),(3);
explain partitions select * from t1 where a1 > 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2197
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2198 2199
explain partitions select * from t1 where a1 >= 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2200
1	SIMPLE	t1	p1,p2	system	NULL	NULL	NULL	NULL	1	
2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214
explain partitions select * from t1 where a1 < 3 and a1 > 3;
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 t3 (a int, b int) 
partition by list(a) subpartition by hash(b) subpartitions 4 (
partition p0 values in (1),
partition p1 values in (2),
partition p2 values in (3),
partition p3 values in (4)
);
insert into t3 values (1,1),(2,2),(3,3);
explain partitions select * from t3 where a=2 or b=1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2215
1	SIMPLE	t3	p0_p0sp1,p1_p1sp0,p1_p1sp1,p1_p1sp2,p1_p1sp3,p2_p2sp1,p3_p3sp1	ALL	NULL	NULL	NULL	NULL	2	Using where
2216 2217
explain partitions select * from t3 where a=4 or b=2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2218
1	SIMPLE	t3	p0_p0sp2,p1_p1sp2,p2_p2sp2,p3_p3sp0,p3_p3sp1,p3_p3sp2,p3_p3sp3	system	NULL	NULL	NULL	NULL	1	
2219 2220
explain partitions select * from t3 where (a=2 or b=1) and (a=4 or b=2) ;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2221
1	SIMPLE	t3	p1_p1sp2,p3_p3sp1	system	NULL	NULL	NULL	NULL	1	
2222
drop table t3;
2223 2224 2225 2226
create table t1 (a int) partition by hash(a) partitions 2;
insert into t1 values (1),(2);
explain partitions select * from t1 where a is null;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2227
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
2228 2229 2230 2231
explain partitions select * from t1 where a is not null;
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
drop table t1;
2232 2233 2234 2235 2236 2237 2238
create table t1 (a int not null, b int not null, key(a), key(b))
partition by hash(a) partitions 4;
insert into t1 values (1,1),(2,2),(3,3),(4,4);
explain partitions 
select * from t1 X, t1 Y 
where X.b = Y.b and (X.a=1 or X.a=2) and (Y.a=2 or Y.a=3);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2239
1	SIMPLE	X	p1,p2	ALL	a,b	NULL	NULL	NULL	2	Using where
2240 2241 2242 2243
1	SIMPLE	Y	p2,p3	ref	a,b	b	4	test.X.b	2	Using where
explain partitions
select * from t1 X, t1 Y where X.a = Y.a and (X.a=1 or X.a=2);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2244
1	SIMPLE	X	p1,p2	ALL	a	NULL	NULL	NULL	4	Using where
2245 2246
1	SIMPLE	Y	p1,p2	ref	a	a	4	test.X.a	2	
drop table t1;
unknown's avatar
unknown committed
2247 2248 2249 2250
create table t1 (a int) partition by hash(a) partitions 20;
insert into t1 values (1),(2),(3);
explain partitions select * from t1 where a >  1 and a < 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2251
1	SIMPLE	t1	p2	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
2252 2253
explain partitions select * from t1 where a >= 1 and a < 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
2254
1	SIMPLE	t1	p1,p2	ALL	NULL	NULL	NULL	NULL	2	Using where
unknown's avatar
unknown committed
2255 2256
explain partitions select * from t1 where a >  1 and a <= 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2257
1	SIMPLE	t1	p2,p3	ALL	NULL	NULL	NULL	NULL	3	Using where
unknown's avatar
unknown committed
2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272
explain partitions select * from t1 where a >= 1 and a <= 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1,p2,p3	ALL	NULL	NULL	NULL	NULL	3	Using where
drop table t1;
create table t1 (a int, b int) 
partition by list(a) subpartition by hash(b) subpartitions 20 
(
partition p0 values in (0),
partition p1 values in (1),
partition p2 values in (2),
partition p3 values in (3)
);
insert into t1 values (1,1),(2,2),(3,3);
explain partitions select * from t1 where b >  1 and b < 3;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2273
1	SIMPLE	t1	p0_p0sp2,p1_p1sp2,p2_p2sp2,p3_p3sp2	system	NULL	NULL	NULL	NULL	1	
unknown's avatar
unknown committed
2274 2275
explain partitions select * from t1 where b >  1 and b < 3 and (a =1 or a =2);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2276
1	SIMPLE	t1	p1_p1sp2,p2_p2sp2	system	NULL	NULL	NULL	NULL	1	
2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315
drop table t1;
create table t1 (a int) partition by list(a) (
partition p0 values in (1,2),
partition p1 values in (3,4)
);
insert into t1 values (1),(1),(2),(2),(3),(4),(3),(4);
flush status;
update t1 set a=100 where a=5;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	0
flush status;
update t1 set a=100 where a+1=5+1;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	10
flush status;
delete from t1 where a=5;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	0
flush status;
delete from t1 where a+1=5+1;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	10
create table t2 like t1;
insert into t2 select * from t2;
flush status;
update t1,t2 set t1.a=1000, t2.a=1000 where t1.a=5 and t2.a=5;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	0
flush status;
delete t1,t2 from t1, t2 where t1.a=5 and t2.a=5;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	0
drop table t1,t2;
unknown's avatar
unknown committed
2316 2317 2318 2319 2320 2321 2322 2323 2324 2325
CREATE TABLE `t1` (
`a` int(11) default NULL
);
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE `t2` (
`a` int(11) default NULL,
KEY `a` (`a`)
) ;
insert into t2 select A.a + 10*(B.a + 10* C.a) from t1 A, t1 B, t1 C ;
insert into t1 select a from t2;
2326
drop table t2;
unknown's avatar
unknown committed
2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346
CREATE TABLE `t2` (
`a` int(11) default NULL,
`b` int(11) default NULL
) 
PARTITION BY RANGE (a) (
PARTITION p0 VALUES LESS THAN (200),
PARTITION p1 VALUES LESS THAN (400),
PARTITION p2 VALUES LESS THAN (600),
PARTITION p3 VALUES LESS THAN (800),
PARTITION p4 VALUES LESS THAN (1001));
insert into t2 select a,1 from t1 where a < 200;
insert into t2 select a,2 from t1 where a >= 200 and a < 400;
insert into t2 select a,3 from t1 where a >= 400 and a < 600;
insert into t2 select a,4 from t1 where a >= 600 and a < 800;
insert into t2 select a,5 from t1 where a >= 800 and a < 1001;
explain partitions select * from t2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	
explain partitions select * from t2 where a < 801 and a > 200;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2347
1	SIMPLE	t2	p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
unknown's avatar
unknown committed
2348 2349
explain partitions select * from t2 where a < 801 and a > 800;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2350
1	SIMPLE	t2	p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
unknown's avatar
unknown committed
2351 2352
explain partitions select * from t2 where a > 600;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2353
1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
unknown's avatar
unknown committed
2354 2355
explain partitions select * from t2 where a > 600 and b = 1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2356
1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
unknown's avatar
unknown committed
2357 2358
explain partitions select * from t2 where a > 600 and b = 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2359
1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
unknown's avatar
unknown committed
2360 2361
explain partitions select * from t2 where a > 600 and b = 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2362
1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
unknown's avatar
unknown committed
2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374
explain partitions select * from t2 where b = 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
flush status;
update t2 set b = 100 where b = 6;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	1015
flush status;
update t2 set a = 1002 where a = 1001;
show status like 'Handler_read_rnd_next';
Variable_name	Value
2375
Handler_read_rnd_next	0
unknown's avatar
unknown committed
2376 2377 2378 2379
flush status;
update t2 set b = 6 where a = 600;
show status like 'Handler_read_rnd_next';
Variable_name	Value
2380
Handler_read_rnd_next	201
unknown's avatar
unknown committed
2381 2382 2383 2384
flush status;
update t2 set b = 6 where a > 600 and a < 800;
show status like 'Handler_read_rnd_next';
Variable_name	Value
2385
Handler_read_rnd_next	201
unknown's avatar
unknown committed
2386 2387 2388 2389
flush status;
delete from t2 where a > 600;
show status like 'Handler_read_rnd_next';
Variable_name	Value
2390 2391
Handler_read_rnd_next	402
drop table t2;
unknown's avatar
unknown committed
2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416
CREATE TABLE `t2` (
`a` int(11) default NULL,
`b` int(11) default NULL,
index (b)
) 
PARTITION BY RANGE (a) (
PARTITION p0 VALUES LESS THAN (200),
PARTITION p1 VALUES LESS THAN (400),
PARTITION p2 VALUES LESS THAN (600),
PARTITION p3 VALUES LESS THAN (800),
PARTITION p4 VALUES LESS THAN (1001));
insert into t2 select a,1 from t1 where a < 100;
insert into t2 select a,2 from t1 where a >= 200 and a < 300;
insert into t2 select a,3 from t1 where a >= 300 and a < 400;
insert into t2 select a,4 from t1 where a >= 400 and a < 500;
insert into t2 select a,5 from t1 where a >= 500 and a < 600;
insert into t2 select a,6 from t1 where a >= 600 and a < 700;
insert into t2 select a,7 from t1 where a >= 700 and a < 800;
insert into t2 select a,8 from t1 where a >= 800 and a < 900;
insert into t2 select a,9 from t1 where a >= 900 and a < 1001;
explain partitions select * from t2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	910	
explain partitions select * from t2 where a = 101;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2417
1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	910	Using where
unknown's avatar
unknown committed
2418 2419
explain partitions select * from t2 where a = 550;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2420
1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	910	Using where
unknown's avatar
unknown committed
2421 2422
explain partitions select * from t2 where a = 833;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2423
1	SIMPLE	t2	p4	ALL	NULL	NULL	NULL	NULL	910	Using where
unknown's avatar
unknown committed
2424 2425
explain partitions select * from t2 where (a = 100 OR a = 900);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2426
1	SIMPLE	t2	p0,p4	ALL	NULL	NULL	NULL	NULL	910	Using where
unknown's avatar
unknown committed
2427 2428
explain partitions select * from t2 where (a > 100 AND a < 600);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2429
1	SIMPLE	t2	p0,p1,p2	ALL	NULL	NULL	NULL	NULL	910	Using where
unknown's avatar
unknown committed
2430 2431 2432
explain partitions select * from t2 where b = 4;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ref	b	b	5	const	76	Using where
2433 2434 2435 2436 2437
explain extended select * from t2 where b = 6;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ref	b	b	5	const	76	100.00	Using where
Warnings:
Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = 6)
unknown's avatar
unknown committed
2438 2439 2440
explain partitions select * from t2 where b = 6;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ref	b	b	5	const	76	Using where
2441 2442 2443 2444 2445
explain extended select * from t2 where b in (1,3,5);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	b	NULL	NULL	NULL	910	40.66	Using where
Warnings:
Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` in (1,3,5))
unknown's avatar
unknown committed
2446 2447 2448
explain partitions select * from t2 where b in (1,3,5);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	910	Using where
2449 2450 2451 2452 2453
explain extended select * from t2 where b in (2,4,6);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	b	NULL	NULL	NULL	910	25.05	Using where
Warnings:
Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` in (2,4,6))
unknown's avatar
unknown committed
2454 2455 2456
explain partitions select * from t2 where b in (2,4,6);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	910	Using where
2457 2458 2459 2460 2461
explain extended select * from t2 where b in (7,8,9);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	b	NULL	NULL	NULL	910	36.70	Using where
Warnings:
Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` in (7,8,9))
unknown's avatar
unknown committed
2462 2463 2464
explain partitions select * from t2 where b in (7,8,9);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	910	Using where
2465 2466 2467 2468 2469
explain extended select * from t2 where b > 5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	b	NULL	NULL	NULL	910	44.84	Using where
Warnings:
Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` > 5)
unknown's avatar
unknown committed
2470 2471 2472
explain partitions select * from t2 where b > 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	910	Using where
2473 2474 2475 2476 2477
explain extended select * from t2 where b > 5 and b < 8;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	b	NULL	NULL	NULL	910	22.09	Using where
Warnings:
Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where ((`test`.`t2`.`b` > 5) and (`test`.`t2`.`b` < 8))
unknown's avatar
unknown committed
2478 2479 2480
explain partitions select * from t2 where b > 5 and b < 8;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	910	Using where
2481 2482 2483 2484 2485
explain extended select * from t2 where b > 5 and b < 7;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	range	b	b	5	NULL	76	100.00	Using where
Warnings:
Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where ((`test`.`t2`.`b` > 5) and (`test`.`t2`.`b` < 7))
unknown's avatar
unknown committed
2486 2487 2488
explain partitions select * from t2 where b > 5 and b < 7;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	range	b	b	5	NULL	76	Using where
2489 2490 2491 2492 2493
explain extended select * from t2 where b > 0 and b < 5;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	t2	ALL	b	NULL	NULL	NULL	910	41.65	Using where
Warnings:
Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where ((`test`.`t2`.`b` > 0) and (`test`.`t2`.`b` < 5))
unknown's avatar
unknown committed
2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532
explain partitions select * from t2 where b > 0 and b < 5;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	910	Using where
flush status;
update t2 set a = 111 where b = 10;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	0
show status like 'Handler_read_key';
Variable_name	Value
Handler_read_key	5
flush status;
update t2 set a = 111 where b in (5,6);
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	915
show status like 'Handler_read_key';
Variable_name	Value
Handler_read_key	0
flush status;
update t2 set a = 222 where b = 7;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	0
show status like 'Handler_read_key';
Variable_name	Value
Handler_read_key	5
flush status;
delete from t2 where b = 7;
show status like 'Handler_read_rnd_next';
Variable_name	Value
Handler_read_rnd_next	0
show status like 'Handler_read_key';
Variable_name	Value
Handler_read_key	5
flush status;
delete from t2 where b > 5;
show status like 'Handler_read_rnd_next';
Variable_name	Value
unknown's avatar
unknown committed
2533
Handler_read_rnd_next	1215
unknown's avatar
unknown committed
2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546
show status like 'Handler_read_key';
Variable_name	Value
Handler_read_key	0
show status like 'Handler_read_prev';
Variable_name	Value
Handler_read_prev	0
show status like 'Handler_read_next';
Variable_name	Value
Handler_read_next	0
flush status;
delete from t2 where b < 5 or b > 3;
show status like 'Handler_read_rnd_next';
Variable_name	Value
unknown's avatar
unknown committed
2547
Handler_read_rnd_next	1215
unknown's avatar
unknown committed
2548 2549 2550 2551 2552 2553 2554 2555 2556 2557
show status like 'Handler_read_key';
Variable_name	Value
Handler_read_key	0
show status like 'Handler_read_prev';
Variable_name	Value
Handler_read_prev	0
show status like 'Handler_read_next';
Variable_name	Value
Handler_read_next	0
drop table t1, t2;
2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577
create table t1 ( f_int1 mediumint, f_int2 integer) 
partition by list(mod(f_int1,4)) (
partition p_3 values in (-3),
partition p_2 values in (-2),
partition p_1 values in (-1),
partition p0 values in (0),
partition p1 values in (1),
partition p2 values in (2),
partition p3 values in (3)
);
insert into t1 values (9, 9), (8, 8), (7, 7), (6, 6), (5, 5), 
(4, 4), (3, 3), (2, 2), (1, 1);
select * from t1 where f_int1 between 5 and 15 order by f_int1;
f_int1	f_int2
5	5
6	6
7	7
8	8
9	9
drop table t1;
2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590
create table t1 (f_int1 integer) partition by list(abs(mod(f_int1,2)))
subpartition by hash(f_int1) subpartitions 2
(
partition part1 values in (0),
partition part2 values in (1),
partition part4 values in (null)
);
insert into t1 set f_int1 = null;
select * from t1 where f_int1 is null;
f_int1
NULL
explain partitions select * from t1 where f_int1 is null;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2591
1	SIMPLE	t1	part4_part4sp0	system	NULL	NULL	NULL	NULL	1	
2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619
drop table t1;
create table t1 (a int not null, b int not null)
partition by list(a) 
subpartition by hash(b) subpartitions 4 
(
partition p0 values in (1),
partition p1 values in (2),
partition p2 values in (3)
);
insert into t1 values (1,1),(1,2),(1,3),(1,4),
(2,1),(2,2),(2,3),(2,4);
explain partitions select * from t1 where a=1 AND (b=1 OR b=2);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0_p0sp1,p0_p0sp2	ALL	NULL	NULL	NULL	NULL	2	Using where
drop table t1;
create table t1 (a int, b int not null)
partition by list(a) 
subpartition by hash(b) subpartitions 2
(
partition p0 values in (1),
partition p1 values in (2),
partition p2 values in (3),
partition pn values in (NULL)
);
insert into t1 values (1,1),(1,2),(1,3),(1,4),
(2,1),(2,2),(2,3),(2,4), (NULL,1);
explain partitions select * from t1 where a IS NULL AND (b=1 OR b=2);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2620
1	SIMPLE	t1	pn_pnsp0,pn_pnsp1	system	NULL	NULL	NULL	NULL	1	
2621 2622
explain partitions select * from t1 where (a IS NULL or a < 1) AND (b=1 OR b=2);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2623
1	SIMPLE	t1	pn_pnsp0,pn_pnsp1	system	NULL	NULL	NULL	NULL	1	
2624 2625
explain partitions select * from t1 where (a IS NULL or a < 2) AND (b=1 OR b=2);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2626
1	SIMPLE	t1	p0_p0sp0,p0_p0sp1,pn_pnsp0,pn_pnsp1	ALL	NULL	NULL	NULL	NULL	5	Using where
2627 2628
explain partitions select * from t1 where (a IS NULL or a <= 1) AND (b=1 OR b=2);
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2629
1	SIMPLE	t1	p0_p0sp0,p0_p0sp1,pn_pnsp0,pn_pnsp1	ALL	NULL	NULL	NULL	NULL	5	Using where
2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653
drop table t1;
create table t1 ( a int)  partition by list (MOD(a, 10))
( partition p0  values in (0), partition p1 values in (1),
partition p2 values in (2), partition p3 values in (3),
partition p4 values in (4), partition p5 values in (5),
partition p6 values in (6), partition pn values in (NULL)
);
insert into t1 values (NULL), (0),(1),(2),(3),(4),(5),(6);
explain partitions select * from t1 where a is null or a < 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0,p1,p2,p3,p4,p5,p6,pn	ALL	NULL	NULL	NULL	NULL	8	Using where
drop table t1;
create table t1 (s1 int) partition by list (s1) 
(partition p1 values in (0), 
partition p2 values in (1), 
partition p3 values in (null));
insert into t1 values (0),(1),(null);
select count(*) from t1 where s1 < 0 or s1 is null;
count(*)
1
explain partitions select count(*) from t1 where s1 < 0 or s1 is null;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3	system	NULL	NULL	NULL	NULL	1	
drop table t1;
2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664
create table t1 (a char(32) primary key)
partition by key()
partitions 100;
insert into t1 values ('na');
select * from t1;
a
na
select * from t1 where a like 'n%';
a
na
drop table t1;
2665 2666 2667 2668 2669 2670 2671 2672
create table t1 (s1 varchar(15)) partition by key (s1);
select * from t1 where s1 = 0 or s1 is null;
s1
insert into t1 values ('aa'),('bb'),('0');
explain partitions select * from t1 where s1 = 0 or s1 is null;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	3	Using where
drop table t1;
2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691
create table t2 (a int, b int)
partition by LIST(a)
subpartition by HASH(b) subpartitions 40
( partition p_0_long_partition_name values in(1),
partition p_1_long_partition_name values in(2));
insert into t2 values (1,1),(2,2);
explain partitions select * from t2;
id	1
select_type	SIMPLE
table	t2
partitions	p_0_long_partition_name_p_0_long_partition_namesp0,p_0_long_partition_name_p_0_long_partition_namesp1,p_0_long_partition_name_p_0_long_partition_namesp2,p_0_long_partition_name_p_0_long_partition_namesp3,p_0_long_partition_name_p_0_long_partition_namesp4,p_0_long_partition_name_p_0_long_partition_namesp5,p_0_long_partition_name_p_0_long_partition_namesp6,p_0_long_partition_name_p_0_long_partition_namesp7,p_0_long_partition_name_p_0_long_partition_namesp8,p_0_long_partition_name_p_0_long_partition_namesp9,p_0_long_partition_name_p_0_long_partition_namesp10,p_0_long_partition_name_p_0_long_partition_namesp11,p_0_long_partition_name_p_0_long_partition_namesp12,p_0_long_partition_name_p_0_long_partition_namesp13,p_0_long_partition_name_p_0_long_partition_namesp14,p_0_long_partition_name_p_0_long_partition_namesp15,p_0_long_partition_name_p_0_long_partition_namesp16,p_0_long_partition_name_p_0_long_partition_namesp17,p_0_long_partition_name_p_0_long_partition_namesp18,p_0_long_partition_name_p_0_long_partition_namesp19,p_0_long_partition_name_p_0_long_partition_namesp20,p_0_long_partition_name_p_0_long_partition_namesp21,p_0_long_partition_name_p_0_long_partition_namesp22,p_0_long_partition_name_p_0_long_partition_namesp23,p_0_long_partition_name_p_0_long_partition_namesp24,p_0_long_partition_name_p_0_long_partition_namesp25,p_0_long_partition_name_p_0_long_partition_namesp26,p_0_long_partition_name_p_0_long_partition_namesp27,p_0_long_partition_name_p_0_long_partition_namesp28,p_0_long_partition_name_p_0_long_partition_namesp29,p_0_long_partition_name_p_0_long_partition_namesp30,p_0_long_partition_name_p_0_long_partition_namesp31,p_0_long_partition_name_p_0_long_partition_namesp32,p_0_long_partition_name_p_0_long_partition_namesp33,p_0_long_partition_name_p_0_long_partition_namesp34,p_0_long_partition_name_p_0_long_partition_namesp35,p_0_long_partition_name_p_0_long_partition_namesp36,p_0_long_partition_name_p_0_long_partition_namesp37,p_0_long_partition_name_p_0_long_partition_namesp38,p_0_long_partition_name_p_0_long_partition_namesp39,p_1_long_partition_name_p_1_long_partition_namesp0,p_1_long_partition_name_p_1_long_partition_namesp1,p_1_long_partition_name_p_1_long_partition_namesp2,p_1_long_partition_name_p_1_long_partition_namesp3,p_1_long_partition_name_p_1_long_partition_namesp4,p_1_long_partition_name_p_1_long_partition_namesp5,p_1_long_partition_name_p_1_long_partition_namesp6,p_1_long_partition_name_p_1_long_partition_namesp7,p_1_long_partition_name_p_1_long_partition_namesp8,p_1_long_partition_name_p_1_long_partition_namesp9,p_1_long_partition_name_p_1_long_partition_namesp10,p_1_long_partition_name_p_1_long_partition_namesp11,p_1_long_partition_name_p_1_long_partition_namesp12,p_1_long_partition_name_p_1_long_partition_namesp13,p_1_long_partition_name_p_1_long_partition_namesp14,p_1_long_partition_name_p_1_long_partition_namesp15,p_1_long_partition_name_p_1_long_partition_namesp16,p_1_long_partition_name_p_1_long_partition_namesp17,p_1_long_partition_name_p_1_long_partition_namesp18,p_1_long_partition_name_p_1_long_partition_namesp19,p_1_long_partition_name_p_1_long_partition_namesp20,p_1_long_partition_name_p_1_long_partition_namesp21,p_1_long_partition_name_p_1_long_partition_namesp22,p_1_long_partition_name_p_1_long_partition_namesp23,p_1_long_partition_name_p_1_long_partition_namesp24,p_1_long_partition_name_p_1_long_partition_namesp25,p_1_long_partition_name_p_1_long_partition_namesp26,p_1_long_partition_name_p_1_long_partition_namesp27,p_1_long_partition_name_p_1_long_partition_namesp28,p_1_long_partition_name_p_1_long_partition_namesp29,p_1_long_partition_name_p_1_long_partition_namesp30,p_1_long_partition_name_p_1_long_partition_namesp31,p_1_long_partition_name_p_1_long_partition_namesp32,p_1_long_partition_name_p_1_long_partition_namesp33,p_1_long_partition_name_p_1_long_partition_namesp34,p_1_long_partition_name_p_1_long_partition_namesp35,p_1_long_partition_name_p_1_long_partition_namesp36,p_1_long_partition_name_p_1_long_partition_namesp37,p_1_long_partition_name_p_1_long_partition_namesp38,p_1_long_partition_name_p_1_long_partition_namesp39
type	ALL
possible_keys	NULL
key	NULL
key_len	NULL
ref	NULL
rows	2
Extra	
drop table t2;
2692 2693 2694 2695 2696 2697 2698
create table t1 (s1 int);
explain partitions select 1 from t1 union all select 2;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	PRIMARY	t1	NULL	system	NULL	NULL	NULL	NULL	0	const row not found
2	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
NULL	UNION RESULT	<union1,2>	NULL	ALL	NULL	NULL	NULL	NULL	NULL	
drop table t1;
2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
create table t1 (a bigint unsigned not null) partition by range(a) (
partition p0 values less than (10),
partition p1 values less than (100),
partition p2 values less than (1000),
partition p3 values less than (18446744073709551000),
partition p4 values less than (18446744073709551614)
);
insert into t1 values (5),(15),(105),(1005);
insert into t1 values (18446744073709551000+1);
insert into t1 values (18446744073709551614-1);
explain partitions select * from t1 where a < 10;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p0	system	NULL	NULL	NULL	NULL	1	
explain partitions select * from t1 
where a >= 18446744073709551000-1 and a <= 18446744073709551000+1;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2715
1	SIMPLE	t1	p3,p4	ALL	NULL	NULL	NULL	NULL	4	Using where
2716 2717 2718
explain partitions select * from t1 
where a between 18446744073709551001 and 18446744073709551002;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2719
1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	4	Using where
2720 2721
explain partitions select * from t1 where a = 18446744073709551000;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2722
1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	4	Using where
2723 2724
explain partitions select * from t1 where a = 18446744073709551613;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2725
1	SIMPLE	t1	p4	ALL	NULL	NULL	NULL	NULL	4	Using where
2726 2727 2728 2729
explain partitions select * from t1 where a = 18446744073709551614;
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;
unknown's avatar
unknown committed
2730
create table t1 (a int)
unknown's avatar
unknown committed
2731 2732 2733 2734 2735 2736 2737 2738 2739 2740
partition by range(a) (
partition p0 values less than (64),
partition p1 values less than (128),
partition p2 values less than (255)
);
create table t2 (a int)
partition by range(a+0) (
partition p0 values less than (64),
partition p1 values less than (128),
partition p2 values less than (255)
2741 2742
);
insert into t1 values (0x20), (0x20), (0x41), (0x41), (0xFE), (0xFE);
unknown's avatar
unknown committed
2743
insert into t2 values (0x20), (0x20), (0x41), (0x41), (0xFE), (0xFE);
2744 2745 2746
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	ALL	NULL	NULL	NULL	NULL	2	Using where
unknown's avatar
unknown committed
2747 2748 2749
explain partitions select * from t2 where a=0;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	2	Using where
2750 2751
explain partitions select * from t1 where a=0xFE;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2752
1	SIMPLE	t1	p2	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2753 2754
explain partitions select * from t2 where a=0xFE;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2755
1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2756
explain partitions select * from t1 where a > 0xFE AND a <= 0xFF;
2757 2758
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
unknown's avatar
unknown committed
2759 2760 2761 2762 2763
explain partitions select * from t2 where a > 0xFE AND a <= 0xFF;
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 >= 0xFE AND a <= 0xFF;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2764
1	SIMPLE	t1	p2	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2765 2766
explain partitions select * from t2 where a >= 0xFE AND a <= 0xFF;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2767
1	SIMPLE	t2	p2	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2768 2769
explain partitions select * from t1 where a < 64 AND a >= 63;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2770
1	SIMPLE	t1	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2771 2772
explain partitions select * from t2 where a < 64 AND a >= 63;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2773
1	SIMPLE	t2	p0	ALL	NULL	NULL	NULL	NULL	4	Using where
unknown's avatar
unknown committed
2774 2775
explain partitions select * from t1 where a <= 64 AND a >= 63;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2776
1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	6	Using where
unknown's avatar
unknown committed
2777 2778
explain partitions select * from t2 where a <= 64 AND a >= 63;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
2779
1	SIMPLE	t2	p0,p1	ALL	NULL	NULL	NULL	NULL	6	Using where
2780
drop table t1;
unknown's avatar
unknown committed
2781
drop table t2;
2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812
create table t1(a bigint unsigned not null) partition by range(a+0) (
partition p1 values less than (10),
partition p2 values less than (20),
partition p3 values less than (2305561538531885056),
partition p4 values less than (2305561538531950591)
);
insert into t1 values (9),(19),(0xFFFF0000FFFF000-1), (0xFFFF0000FFFFFFF-1);
insert into t1 values (9),(19),(0xFFFF0000FFFF000-1), (0xFFFF0000FFFFFFF-1);
explain partitions select * from t1 where 
a >= 2305561538531885056-10 and a <= 2305561538531885056-8;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3	ALL	NULL	NULL	NULL	NULL	4	Using where
explain partitions select * from t1 where 
a > 0xFFFFFFFFFFFFFFEC and a < 0xFFFFFFFFFFFFFFEE;
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 and a <= 0xFFFFFFFFFFFFFFFF;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	8	Using where
drop table t1;
create table t1 (a bigint) partition by range(a+0) (
partition p1 values less than (-1000),
partition p2 values less than (-10),
partition p3 values less than (10),
partition p4 values less than (1000)
);
insert into t1 values (-15),(-5),(5),(15),(-15),(-5),(5),(15);
explain partitions select * from t1 where a>-2 and a <=0;
id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	p3	ALL	NULL	NULL	NULL	NULL	4	Using where
drop table t1;
2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840
CREATE TABLE t1 ( recdate  DATETIME NOT NULL )
PARTITION BY RANGE( TO_DAYS(recdate) ) (
PARTITION p0 VALUES LESS THAN ( TO_DAYS('2007-03-08') ),
PARTITION p1 VALUES LESS THAN ( TO_DAYS('2007-04-01') )
);
INSERT INTO t1 VALUES ('2007-03-01 12:00:00');
INSERT INTO t1 VALUES ('2007-03-07 12:00:00');
INSERT INTO t1 VALUES ('2007-03-08 12:00:00');
INSERT INTO t1 VALUES ('2007-03-15 12:00:00');
must use p0 only:
explain partitions select * from t1 where recdate < '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
drop table t1;
CREATE TABLE t1 ( recdate  DATETIME NOT NULL )
PARTITION BY RANGE( YEAR(recdate) ) (
PARTITION p0 VALUES LESS THAN (2006),
PARTITION p1 VALUES LESS THAN (2007)
);
INSERT INTO t1 VALUES ('2005-03-01 12:00:00');
INSERT INTO t1 VALUES ('2005-03-01 12:00:00');
INSERT INTO t1 VALUES ('2006-03-01 12:00:00');
INSERT INTO t1 VALUES ('2006-03-01 12:00:00');
must use p0 only:
explain partitions select * from t1 where recdate < '2006-01-01 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
drop table t1;