/usr/lib/mysql-testsuite/t/greedy_optimizer.test is in percona-server-test-5.6 5.6.22-rel71.0-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 | #Want to skip this test from daily Valgrind execution
--source include/no_valgrind_without_big.inc
#
# A simple test of the greedy query optimization algorithm and the switches that
# control the optimizationprocess.
#
#
# Schema
#
--disable_warnings
drop table if exists t1,t2,t3,t4,t5,t6,t7;
--enable_warnings
create table t1 (
c11 integer,c12 integer,c13 integer,c14 integer,c15 integer,c16 integer,
primary key (c11)
);
create table t2 (
c21 integer,c22 integer,c23 integer,c24 integer,c25 integer,c26 integer
);
create table t3 (
c31 integer,c32 integer,c33 integer,c34 integer,c35 integer,c36 integer,
primary key (c31)
);
create table t4 (
c41 integer,c42 integer,c43 integer,c44 integer,c45 integer,c46 integer
);
create table t5 (
c51 integer,c52 integer,c53 integer,c54 integer,c55 integer,c56 integer,
primary key (c51)
);
create table t6 (
c61 integer,c62 integer,c63 integer,c64 integer,c65 integer,c66 integer
);
create table t7 (
c71 integer,c72 integer,c73 integer,c74 integer,c75 integer,c76 integer,
primary key (c71)
);
#
# Data
# cardinality(Ti) = cardinality(T(i-1)) + 3
#
insert into t1 values (1,2,3,4,5,6);
insert into t1 values (2,2,3,4,5,6);
insert into t1 values (3,2,3,4,5,6);
insert into t2 values (1,2,3,4,5,6);
insert into t2 values (2,2,3,4,5,6);
insert into t2 values (3,2,3,4,5,6);
insert into t2 values (4,2,3,4,5,6);
insert into t2 values (5,2,3,4,5,6);
insert into t2 values (6,2,3,4,5,6);
insert into t3 values (1,2,3,4,5,6);
insert into t3 values (2,2,3,4,5,6);
insert into t3 values (3,2,3,4,5,6);
insert into t3 values (4,2,3,4,5,6);
insert into t3 values (5,2,3,4,5,6);
insert into t3 values (6,2,3,4,5,6);
insert into t3 values (7,2,3,4,5,6);
insert into t3 values (8,2,3,4,5,6);
insert into t3 values (9,2,3,4,5,6);
insert into t4 values (1,2,3,4,5,6);
insert into t4 values (2,2,3,4,5,6);
insert into t4 values (3,2,3,4,5,6);
insert into t4 values (4,2,3,4,5,6);
insert into t4 values (5,2,3,4,5,6);
insert into t4 values (6,2,3,4,5,6);
insert into t4 values (7,2,3,4,5,6);
insert into t4 values (8,2,3,4,5,6);
insert into t4 values (9,2,3,4,5,6);
insert into t4 values (10,2,3,4,5,6);
insert into t4 values (11,2,3,4,5,6);
insert into t4 values (12,2,3,4,5,6);
insert into t5 values (1,2,3,4,5,6);
insert into t5 values (2,2,3,4,5,6);
insert into t5 values (3,2,3,4,5,6);
insert into t5 values (4,2,3,4,5,6);
insert into t5 values (5,2,3,4,5,6);
insert into t5 values (6,2,3,4,5,6);
insert into t5 values (7,2,3,4,5,6);
insert into t5 values (8,2,3,4,5,6);
insert into t5 values (9,2,3,4,5,6);
insert into t5 values (10,2,3,4,5,6);
insert into t5 values (11,2,3,4,5,6);
insert into t5 values (12,2,3,4,5,6);
insert into t5 values (13,2,3,4,5,6);
insert into t5 values (14,2,3,4,5,6);
insert into t5 values (15,2,3,4,5,6);
insert into t6 values (1,2,3,4,5,6);
insert into t6 values (2,2,3,4,5,6);
insert into t6 values (3,2,3,4,5,6);
insert into t6 values (4,2,3,4,5,6);
insert into t6 values (5,2,3,4,5,6);
insert into t6 values (6,2,3,4,5,6);
insert into t6 values (7,2,3,4,5,6);
insert into t6 values (8,2,3,4,5,6);
insert into t6 values (9,2,3,4,5,6);
insert into t6 values (10,2,3,4,5,6);
insert into t6 values (11,2,3,4,5,6);
insert into t6 values (12,2,3,4,5,6);
insert into t6 values (13,2,3,4,5,6);
insert into t6 values (14,2,3,4,5,6);
insert into t6 values (15,2,3,4,5,6);
insert into t6 values (16,2,3,4,5,6);
insert into t6 values (17,2,3,4,5,6);
insert into t6 values (18,2,3,4,5,6);
insert into t7 values (1,2,3,4,5,6);
insert into t7 values (2,2,3,4,5,6);
insert into t7 values (3,2,3,4,5,6);
insert into t7 values (4,2,3,4,5,6);
insert into t7 values (5,2,3,4,5,6);
insert into t7 values (6,2,3,4,5,6);
insert into t7 values (7,2,3,4,5,6);
insert into t7 values (8,2,3,4,5,6);
insert into t7 values (9,2,3,4,5,6);
insert into t7 values (10,2,3,4,5,6);
insert into t7 values (11,2,3,4,5,6);
insert into t7 values (12,2,3,4,5,6);
insert into t7 values (13,2,3,4,5,6);
insert into t7 values (14,2,3,4,5,6);
insert into t7 values (15,2,3,4,5,6);
insert into t7 values (16,2,3,4,5,6);
insert into t7 values (17,2,3,4,5,6);
insert into t7 values (18,2,3,4,5,6);
insert into t7 values (19,2,3,4,5,6);
insert into t7 values (20,2,3,4,5,6);
insert into t7 values (21,2,3,4,5,6);
#
# The actual test begins here
#
# Check the default values for the optimizer paramters
select @@optimizer_search_depth;
select @@optimizer_prune_level;
# These are the values for the parameters that control the greedy optimizer
# (total 6 combinations - 3 for optimizer_search_depth, 2 for optimizer_prune_level):
# 3:
# set optimizer_search_depth=0; - automatic
# set optimizer_search_depth=1; - min
# set optimizer_search_depth=62; - max (default)
# 2:
# set optimizer_prune_level=0 - exhaustive;
# set optimizer_prune_level=1 - heuristic; # default
#
# Compile several queries with all combinations of the query
# optimizer parameters. Each test query has two variants, where
# in the second variant the tables in the FROM clause are in
# inverse order to the tables in the first variant.
# Due to pre-sorting of tables before compilation, there should
# be no difference in the plans for each two such query variants.
#
# Test the greedy optimization procedures
set optimizer_prune_level=0;
select @@optimizer_prune_level;
set optimizer_search_depth=0;
select @@optimizer_search_depth;
# 6-table join, chain
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, star
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, clique
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
set optimizer_search_depth=1;
select @@optimizer_search_depth;
# 6-table join, chain
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, star
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, clique
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
set optimizer_search_depth=62;
select @@optimizer_search_depth;
# 6-table join, chain
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, star
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, clique
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
set optimizer_prune_level=1;
select @@optimizer_prune_level;
set optimizer_search_depth=0;
select @@optimizer_search_depth;
# 6-table join, chain
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, star
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, clique
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
set optimizer_search_depth=1;
select @@optimizer_search_depth;
# 6-table join, chain
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, star
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, clique
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
set optimizer_search_depth=62;
select @@optimizer_search_depth;
# 6-table join, chain
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, star
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
--source include/execute_with_statistics.inc
# 6-table join, clique
let $query=
select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
let $query=
select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
--source include/execute_with_statistics.inc
drop table t1,t2,t3,t4,t5,t6,t7;
#
# Bug # 38795: Automatic search depth and nested join's results in server
# crash
#
CREATE TABLE t1 (a int, b int, d int, i int); INSERT INTO t1 VALUES (1,1,1,1);
CREATE TABLE t2 (b int, c int, j int); INSERT INTO t2 VALUES (1,1,1);
CREATE TABLE t2_1 (j int); INSERT INTO t2_1 VALUES (1);
CREATE TABLE t3 (c int, f int); INSERT INTO t3 VALUES (1,1);
CREATE TABLE t3_1 (f int); INSERT INTO t3_1 VALUES (1);
CREATE TABLE t4 (d int, e int, k int); INSERT INTO t4 VALUES (1,1,1);
CREATE TABLE t4_1 (k int); INSERT INTO t4_1 VALUES (1);
CREATE TABLE t5 (g int, d int, h int, l int); INSERT INTO t5 VALUES (1,1,1,1);
CREATE TABLE t5_1 (l int); INSERT INTO t5_1 VALUES (1);
SET optimizer_search_depth = 3;
SELECT 1
FROM t1
LEFT JOIN (
t2 JOIN t3 ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
t4 JOIN t5 ON t5.d = t4.d
) ON t4.d = t1.d
;
SELECT 1
FROM t1
LEFT JOIN (
t2 LEFT JOIN (t3 JOIN t3_1 ON t3.f = t3_1.f) ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
t4 JOIN t5 ON t5.d = t4.d
) ON t4.d = t1.d
;
SELECT 1
FROM t1
LEFT JOIN (
(t2 JOIN t2_1 ON t2.j = t2_1.j) JOIN t3 ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
t4 JOIN t5 ON t5.d = t4.d
) ON t4.d = t1.d
;
SELECT 1
FROM t1
LEFT JOIN (
t2 JOIN t3 ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
(t4 JOIN t4_1 ON t4.k = t4_1.k) LEFT JOIN t5 ON t5.d = t4.d
) ON t4.d = t1.d
;
SELECT 1
FROM t1
LEFT JOIN (
t2 JOIN t3 ON t3.c = t2.c
) ON t2.b = t1.b
LEFT JOIN (
t4 LEFT JOIN (t5 JOIN t5_1 ON t5.l = t5_1.l) ON t5.d = t4.d
) ON t4.d = t1.d
;
SET optimizer_search_depth = DEFAULT;
DROP TABLE t1,t2,t2_1,t3,t3_1,t4,t4_1,t5,t5_1;
--echo End of 5.0 tests
--echo #
--echo # Bug #59326: Greedy optimizer produce stupid query execution plans.
--echo #
CREATE TABLE t10(
K INT NOT NULL AUTO_INCREMENT,
I INT,
PRIMARY KEY(K)
);
INSERT INTO t10(I) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(0);
CREATE TABLE t100 LIKE t10;
INSERT INTO t100(I)
SELECT X.I FROM t10 AS X,t10 AS Y;
CREATE TABLE t10000 LIKE t10;
INSERT INTO t10000(I)
SELECT X.I FROM t100 AS X, t100 AS Y;
let $total_handler_reads=
select sum(variable_value) from information_schema.session_status
where VARIABLE_NAME like 'Handler_read%';
## All crossproducts should be executed in order t10,t100,t10000
EXPLAIN SELECT * FROM t10,t100,t10000;
EXPLAIN SELECT * FROM t10,t10000,t100;
EXPLAIN SELECT * FROM t100,t10,t10000;
EXPLAIN SELECT * FROM t100,t10000,t10;
EXPLAIN SELECT * FROM t10000,t10,t100;
EXPLAIN SELECT * FROM t10000,t100,t10;
######
## Ordering between T100,T10000 EQ-joined T10 will
## normally be with smallest EQ-table joined first
######
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
AND t10000.K=t10.I;
--source include/expect_qep.inc
## However, swapping EQ_REF-joined tables gives the same cost
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000,t100
WHERE t100.K=t10.I
AND t10000.K=t10.I;
--source include/check_qep.inc
#####
# Expect all variants of EQ joining t100 & t10000 with T10
# to have same cost # handler_reads:
let $query=
SELECT COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
AND t10000.K=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000,t100
WHERE t100.K=t10.I
AND t10000.K=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
AND t10000.K=t10.K;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000,t100
WHERE t100.K=t10.I
AND t10000.K=t10.K;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t100,t10,t10000
WHERE t100.K=t10.I
AND t10000.K=t10.K;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t100,t10000,t10
WHERE t100.K=t10.I
AND t10000.K=t10.K;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10000,t10,t100
WHERE t100.K=t10.I
AND t10000.K=t10.K;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10000,t100,t10
WHERE t100.K=t10.I
AND t10000.K=t10.K;
--source include/check_qep.inc
#####
## EQ_REF Should be executed before table scan(ALL)
## - Independent of #records in table being EQ_REF-joined
#####
#####
# Expect: Join EQ_REF(t100) before ALL(t10000)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
AND t10000.I=t10.I;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
AND t10000.I=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000,t100
WHERE t100.K=t10.I
AND t10000.I=t10.I;
--source include/check_qep.inc
#####
# Expect: Join EQ_REF(t10000) before ALL(t100) (star-join)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000,t100
WHERE t100.I=t10.I
AND t10000.K=t10.I;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t100,t10000
WHERE t100.I=t10.I
AND t10000.K=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000,t100
WHERE t100.I=t10.I
AND t10000.K=t10.I;
--source include/check_qep.inc
#####
# Expect: Join EQ_REF(t10000) before ALL(t100)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000,t100
WHERE t100.I=t10.I
AND t10000.K=t100.I;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t100,t10000
WHERE t100.I=t10.I
AND t10000.K=t100.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000,t100
WHERE t100.I=t10.I
AND t10000.K=t100.I;
--source include/check_qep.inc
#####
## EQ_REF & ALL join two instances of t10000 with t10:
## Always EQ_REF join first before producing cross product
#####
#####
# Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before 'cross' ALL(Y)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 Y,t10000 X
WHERE X.K=t10.I;
--source include/check_qep.inc
#####
# Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before ALL(Y)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I
AND Y.I=t10.I;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I
AND Y.I=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 Y,t10000 X
WHERE X.K=t10.I
AND Y.I=t10.I;
--source include/check_qep.inc
#####
# Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before ALL(Y)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I
AND Y.I=X.K;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I
AND Y.I=X.K;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 Y,t10000 X
WHERE X.K=t10.I
AND Y.I=X.K;
--source include/check_qep.inc
## Create indexes to test REF access
CREATE INDEX IX ON t10(I);
CREATE INDEX IX ON t100(I);
CREATE INDEX IX ON t10000(I);
########
## EQ_REF Should be executed before 'REF'
## - Independent of #records in table being EQ_REF-joined
####
# Expected QEP: 'join EQ_REF(t100) on t100.K=t10.I' before REF(t10000)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
AND t10000.I=t10.I;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t100,t10000
WHERE t100.K=t10.I
AND t10000.I=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000,t100
WHERE t100.K=t10.I
AND t10000.I=t10.I;
--source include/check_qep.inc
#####
## EQ_REF & REF join two instances of t10000 with t10:
#####
#####
## Expect this QEP, cost & #handler_read
# Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before 'cross' ALL(Y)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 Y,t10000 X
WHERE X.K=t10.I;
--source include/check_qep.inc
#####
# Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before REF(Y)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I
AND Y.I=t10.I;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I
AND Y.I=t10.I;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 Y,t10000 X
WHERE X.K=t10.I
AND Y.I=t10.I;
--source include/check_qep.inc
#####
# Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before REF(Y)
let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I
AND Y.I=X.K;
--source include/expect_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 X,t10000 Y
WHERE X.K=t10.I
AND Y.I=X.K;
--source include/check_qep.inc
let $query=
SELECT COUNT(*) FROM t10,t10000 Y,t10000 X
WHERE X.K=t10.I
AND Y.I=X.K;
--source include/check_qep.inc
########
########
--echo #
--echo # Test improved capabilities of analyzing complex query
--echo # plans without restricting 'optimizer_search_depth'.
--echo # Fix problems like those reported as bug#41740 & bug#58225.
--echo #
--echo # EPLAIN of queries using T1-T62 will timeout/hang wo/ fixes
--echo #
DROP TABLE t10, t10000;
--disable_result_log
let $tabledef=
( K INT NOT NULL AUTO_INCREMENT,
I INT,
A INT,
PRIMARY KEY(K), KEY IX(A)
) engine = InnoDB;
let $analyze = ANALYZE TABLE t100;
let $i= 1;
while ($i < 62)
{
let $create= CREATE TABLE T$i $tabledef;
eval $create;
let $insert =
INSERT INTO T$i(I,A) SELECT X.K,X.K FROM t100 AS X, t100 AS Y WHERE X.K < 20 AND Y.K <= $i;
eval $insert;
let $analyze = $analyze, T$i;
inc $i;
}
eval $analyze;
set optimizer_prune_level=1;
#################
## The EXPLAIN'ed query itself can't be part of the verified
## result as the QEP is not 100% predictable due to variation
## in statistics from the engines. This is believed to be
## caused by:
## - Variations in table fill degree.
## - 'Fuzzy' statistics provided by engines.
## - Round errors caused by 'cost' calculation using
## 'only' 64-bit double precision.
## - Other bugs...?
##
###############
## Will test with optimizer_search_depth= [0,1,3,62]
let $depth= 0;
while ($depth<4)
{
if ($depth==0)
{
set optimizer_search_depth=0;
}
if ($depth==1)
{
set optimizer_search_depth=1;
}
if ($depth==2)
{
set optimizer_search_depth=3;
}
if ($depth==3)
{
set optimizer_search_depth=62;
}
inc $depth;
## Test pruning of joined table scans (ALL)
## Prepare of QEP without timeout is heavily dependent
## on maintaining correctly '#rows-sorted' plan
##
let $query= SELECT COUNT(*) FROM T1 AS X;
let $i= 1;
while ($i < 61)
{
let $query= $query JOIN T$i ON T$i.I=X.I;
inc $i;
select @@optimizer_prune_level;
select @@optimizer_search_depth;
eval EXPLAIN $query;
}
## Test pruning of joined table scans (ALL)
## with multiple instances of same table.
## (All instances being equally expensive)
let $query= SELECT COUNT(*) FROM T1 AS X;
let $i= 1;
while ($i <= 56)
{
let $t= T$i;
let $query= $query JOIN $t as T$i ON T$i.I=X.I;
inc $i;
let $query= $query JOIN $t as T$i ON T$i.I=X.I;
inc $i;
let $query= $query JOIN $t as T$i ON T$i.I=X.I;
inc $i;
let $query= $query JOIN $t as T$i ON T$i.I=X.I;
inc $i;
let $query= $query JOIN $t as T$i ON T$i.I=X.I;
inc $i;
let $query= $query JOIN $t as T$i ON T$i.I=X.I;
inc $i;
let $query= $query JOIN $t as T$i ON T$i.I=X.I;
inc $i;
let $query= $query JOIN $t as T$i ON T$i.I=X.I;
inc $i;
select @@optimizer_prune_level;
select @@optimizer_search_depth;
eval EXPLAIN $query;
}
## A mix of 25% EQ_REF / 75% ALL joins
##
let $query= SELECT COUNT(*) FROM T1 AS X;
let $i= 1;
while ($i < 60)
{
let $query= $query JOIN T$i ON T$i.I = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.K = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.I = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.I = X.I;
inc $i;
eval EXPLAIN $query;
}
## A mix of 50% EQ_REF / 50% ALL joins
##
let $query= SELECT COUNT(*) FROM T1 AS X;
let $i= 1;
while ($i < 60)
{
let $query= $query JOIN T$i ON T$i.I = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.K = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.I = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.K = X.I;
inc $i;
eval EXPLAIN $query;
}
## A mix of 75% EQ_REF / 25% ALL joins
##
let $query= SELECT COUNT(*) FROM T1 AS X;
let $i= 1;
while ($i < 60)
{
let $query= $query JOIN T$i ON T$i.I = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.K = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.K = X.I;
inc $i;
let $query= $query JOIN T$i ON T$i.K = X.I;
inc $i;
eval EXPLAIN $query;
}
## 100% EQ_REF joins
##
let $query= SELECT COUNT(*) FROM T1 AS X;
let $i= 1;
while ($i < 61)
{
let $query= $query JOIN T$i ON T$i.K=X.I;
inc $i;
eval EXPLAIN $query;
}
}
let $drop = DROP TABLE t100;
let $i= 1;
while ($i < 62)
{
let $drop = $drop, T$i;
inc $i;
}
eval $drop;
--enable_result_log
SET OPTIMIZER_SEARCH_DEPTH = DEFAULT;
--ECHO END OF 5.6 TESTS
|