1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 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 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 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 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 1160 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 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 1240 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 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 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 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 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 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 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 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 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 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 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 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 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 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 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 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 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 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 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 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 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 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 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 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088
|
########################################
# Define two connections as we want DDL to use its own connection
# in order to keep DDL statistics counting out of the way
# of the SPJ testing
########################################
connect (spj,localhost,root,,test);
connect (ddl,localhost,root,,test);
select @@session.optimizer_switch;
connection spj;
# Save old mysqld counter values.
create temporary table server_counts_at_startup
select * from performance_schema.global_status
where variable_name in
('Ndb_pruned_scan_count',
'Ndb_sorted_scan_count',
'Ndb_pushed_queries_defined',
'Ndb_pushed_queries_dropped');
##############
# Test start
--error 0,1193
set @save_debug = @@global.debug;
set @save_ndb_join_pushdown = @@session.ndb_join_pushdown;
set ndb_join_pushdown = true;
connection ddl;
create table t1 (
a int not null,
b int not null,
c int not null,
d int not null,
primary key (`a`,`b`)
) engine=ndbcluster
partition by key() partitions 8;
connection spj;
insert into t1 values
(1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4),
(1,2,5,1), (1,3,1,2), (1,4,2,3),
(2,1,3,4), (2,3,4,5), (2,4,5,1),
(3,1,1,2), (3,2,2,3), (3,4,3,4),
(4,1,4,5), (4,2,5,1), (4,3,1,2);
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
# Check that new JSON explain format is also handled:
explain format=JSON
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
# Check that we do not push an operation if this prevents us from using
# 'join buffer'.
explain
select straight_join count(*)
from t1 as x1
join t1 as x2 on x1.d > x2.a + 1000
join t1 as x3 on x1.c=x3.a and x1.d=x3.b;
select straight_join count(*)
from t1 as x1
join t1 as x2 on x1.d > x2.a + 1000
join t1 as x3 on x1.c=x3.a and x1.d=x3.b;
# Check that we do not push an operation if this prevents us from using
# 'join buffer'.
explain select *
from t1 as x1
join t1 as x2 on x1.a=1 and x1.c=x2.a and x1.d=x2.b
join t1 as x3
join t1 as x4 where x4.a=x3.c and x4.b=x1.d;
--sorted_result
select *
from t1 as x1
join t1 as x2 on x1.a=1 and x1.c=x2.a and x1.d=x2.b
join t1 as x3
join t1 as x4 where x4.a=x3.c and x4.b=x1.d;
explain
select *
from t1
left join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
--sorted_result
select *
from t1
left join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
where t1.a = 1 and t1.b = 1;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
where t1.a = 1 and t1.b = 1;
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b;
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
left join t1 as t3 on t3.a = t2.a and t3.b = t2.b;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
left join t1 as t3 on t3.a = t2.a and t3.b = t2.b;
explain
select *
from t1
left join t1 as t2 on t2.a = t1.b and t2.b = t1.c
left join t1 as t3 on t3.a = t2.a and t3.b = t2.b;
--sorted_result
select *
from t1
left join t1 as t2 on t2.a = t1.b and t2.b = t1.c
left join t1 as t3 on t3.a = t2.a and t3.b = t2.b;
set ndb_join_pushdown=true;
--replace_result p0,p1,p2,p3,p4,p5,p6,p7 pXYZ p0 pX p5 pX
explain
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
################################################################
# Bug#13901890 SQL NODE CRASHES DURING INSERT SELECT
#
# Incorrect lifetime handling for NdbQuery objects where
# the root operation was a 'const' lookup operation.
#
# 'virtual handler::index_read_idx_map()' was incorectly
# implemented by ha_ndbcluster, such that it failed to
# 'close' the table when the single 'const' row has been read.
# Neither was it registered as 'open' by using the ::ha_index_init().
# (Called ha_ndbcluster::index_init() directly)
# This resulted in that NdbQuery::close() was never called
# on these 'const' SPJ queries. Instead NdbTransaction end
# forcefully whiped them away by calling NdbQuery::release().
# However, as there still was dangling pointer refs to
# them from ha_ndbcluster::m_active_query, we may later refer
# them and crash!
#
# - Same query as above.
# - Added explict table locks as cleanup of these is one
# (of several?) way to cause released NdbQuery objects to
# be refered.
################################################################
# LOCK'ed tables invokes the same code path as executing
# an 'INSERT... SELECT' inside a procedure invoked from a trigger.
# ... and is a much simpler testcase.....
LOCK TABLES t1 read, t1 as t2 read;
--replace_result p0,p1,p2,p3,p4,p5,p6,p7 pXYZ p0 pX p5 pX
explain
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
#Returns empty result set
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
#Returns a single row
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 3 and t1.b = 3;
UNLOCK TABLES;
--replace_result p0,p1,p2,p3,p4,p5,p6,p7 pXYZ p0 pX p5 pX
explain
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
--replace_result p0,p1,p2,p3,p4,p5,p6,p7 pXYZ p0 pX p5 pX
explain
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3
order by t1.c;
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3
order by t1.c;
set ndb_join_pushdown=false;
--replace_result p0,p1,p2,p3,p4,p5,p6,p7 pXYZ p0 pX p5 pX
explain
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
--replace_result p0,p1,p2,p3,p4,p5,p6,p7 pXYZ p0 pX p5 pX
explain
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 2 and t1.b = 3;
set ndb_join_pushdown=true;
explain
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 1 and t1.b = 1;
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 1 and t1.b = 1;
explain
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 1 and t1.b = 1;
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 1 and t1.b = 1;
set ndb_join_pushdown=false;
explain
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 1 and t1.b = 1;
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 1 and t1.b = 1;
explain
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 1 and t1.b = 1;
select *
from t1
left join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a = 1 and t1.b = 1;
## Join as 't1 ALL' -> 't2 RANGE' -> 't3 EQ_REF'
## Possibly joinable starting with 't2 - RANGE' as root.
## However t3's join condition 't3.a = t1.c' refers t1 which is
## outside the scope of current queryplan. The equality set
## should be consulted in order to replace 't1.c' with 't2.a'
## inside the scope
set ndb_join_pushdown=true;
explain
select *
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t1.c and t3.b = t2.b;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t1.c and t3.b = t2.b;
## Join as 'x ALL' -> 'y ALL' -> 'z EQ_REF'
## As Scan vs. scan is not pushable, only y,z is pushed
## However join cond on z refer x which is a
## (pseudo constant) paramValue wrt. the pushed join.
## As we have a dependency on previous rows these
## should not be join cached (ref. HA_PUSH_BLOCK_JOINCACHE)
explain
select straight_join *
from (t1 as x cross join t1 as y)
join t1 as z on z.a=x.a and z.b=y.b;
--sorted_result
select straight_join *
from (t1 as x cross join t1 as y)
join t1 as z on z.a=x.a and z.b=y.b;
## Some variants of the above where t3 has a join conditions in t1
## where t1 is outside scope of pushed join (as above). However, in
## these tests t3 is also linked with t2 through another join condition.
## This makes t3 join pushable by specifying the value of t1.c as a
## paramValue()
explain
select *
from t1
straight_join t1 as t2 on t2.a = t1.b+0 and t2.b = t1.c
straight_join t1 as t3 on t3.a = t1.b and t3.b = t2.b;
--sorted_result
select *
from t1
straight_join t1 as t2 on t2.a = t1.b+0 and t2.b = t1.c
straight_join t1 as t3 on t3.a = t1.b and t3.b = t2.b;
--replace_column 10 # 11 #
explain
select *
from t1
straight_join t1 as t2 on t2.a = t1.b+0 and t2.b = t1.c
straight_join t1 as t3 on t3.a = t1.b and t3.b = t2.b
where t1.a=1 and t1.d=1;
--sorted_result
select *
from t1
straight_join t1 as t2 on t2.a = t1.b+0 and t2.b = t1.c
straight_join t1 as t3 on t3.a = t1.b and t3.b = t2.b
where t1.a=1 and t1.d=1;
explain
select *
from t1
straight_join t1 as t2 on t2.a = t1.b+0
straight_join t1 as t3 on t3.a = t1.b and t3.b = t2.b;
--sorted_result
select *
from t1
straight_join t1 as t2 on t2.a = t1.b+0
straight_join t1 as t3 on t3.a = t1.b and t3.b = t2.b;
## Create a non-ndb table used as a tool to force part of
## a query to be non-pushable.
connection ddl;
create table t1_myisam (
a int not null,
b int not null,
c int not null,
d int not null,
primary key (`a`,`b`)
) engine=myisam;
connection spj;
insert into t1_myisam values
(1,1,1,1), (2,2,1,1), (3,3,1,1), (4,4,1,1);
## Optimizer will use the equality set to replace 't2.a'
## in the term 't3.a = t2.a' with 't1.c' (as 't2.a = t1.c').
## Furthermore the MyIsam table t1 is const table optimized making
## 't1.c' a const_item. This constant value has not yet been materialized
## into the key_buffer when the definition for the linked query is
## created. However, it is always available through the
## Field defining the KEY_PART of this JT_EQ_REF.
##
set ndb_join_pushdown=true;
explain
select *
from t1_myisam as t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
where t1.a=2 and t1.b=2;
--sorted_result
select *
from t1_myisam as t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
where t1.a=2 and t1.b=2;
## Bug#28898811 INCORRECTLY REJECT JOIN TO BE PUSHED DOWN
##
## .. also served to detect (also see ndb_endian.test):
## Bug#29010641 FAILS TO HANDLE DIFFERENT ENDIANNESS FORMATS IN PUSHED JOIN KEYS
##
## Tables not beings considered in the join pushdown analysis,
## e.g. a table not being a ndb table, where also incorrectly
## excluded as a table which could be referred in the join conditions
## from a pushed child table (on .. t3.b = t1.b <-, below)
##
explain
select *
from t1_myisam as t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.b and t3.b = t1.b;
--sorted_result
select *
from t1_myisam as t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.b and t3.b = t1.b;
connection ddl;
drop table t1_myisam;
#
# Test scans with filter. These should be pushed as linked operations
# where the root operation is a scan *with* a (pushed) filter and a
# primary key lookup child operation.
#
connection spj;
set ndb_join_pushdown=true;
# Table scan
--replace_column 10 # 11 #
explain select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.d = 3;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.d = 3;
# Ordered index scan
--replace_column 10 # 11 #
explain select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a > 2 and t1.d = 3;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.a > 2 and t1.d = 3;
# Sorted scan of ordered index.
--replace_column 10 # 11 #
explain select *
from t1 join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.d = 3
order by t1.a;
--sorted_result
select *
from t1 join t1 as t2 on t2.a = t1.c and t2.b = t1.d
where t1.d = 3
order by t1.a;
#
# Test index scan w/ equal-bounds (low == high)
# NOTE: There used to be temp restriction of not allowing ordered
# index scans to be pushed. (Has later been lifted)
# SQL stmt. are therefore written with pushable JT_REFs from table 2 ->
#
set ndb_join_pushdown=true;
explain
select *
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t1.a = 1 and t1.b = 1;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t1.a = 1 and t1.b = 1;
explain
select *
from t1
left join t1 as t2 on t2.a = t1.c
left join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t1.a = 1 and t1.b = 1;
--sorted_result
select *
from t1
left join t1 as t2 on t2.a = t1.c
left join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t1.a = 1 and t1.b = 1;
set ndb_join_pushdown=false;
explain
select *
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t1.a = 1 and t1.b = 1;
--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t1.a = 1 and t1.b = 1;
explain
select *
from t1
left join t1 as t2 on t2.a = t1.c
left join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t1.a = 1 and t1.b = 1;
--sorted_result
select *
from t1
left join t1 as t2 on t2.a = t1.c
left join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t1.a = 1 and t1.b = 1;
# JT_REF as root operations is now supported as pushed joins
set ndb_join_pushdown=true;
explain
select *
from t1 as t2
join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t2.a = 1;
--sorted_result
select *
from t1 as t2
join t1 as t3 on t3.a = t2.c and t3.b = t2.d
where t2.a = 1;
# Test multiparent pushed joins where it is not possible
# to find a single common parent by using the equality set
#
# NOTE: We should take care to join the multiparent linked
# table on field refs. not also being refered from other join expr.
# as this will make them candidates for equality set replacement.
#
set ndb_join_pushdown=true;
# t3 refer both t1,t2 as parrent.
# t1 should be identifed as a grandparent available
# through its child t2.
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t2.c and t3.b = t1.c;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t2.c and t3.b = t1.c;
# t4 is pushable iff we force an artificial parental dependency between t2 & t3.
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.c;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.c;
# t3 is a child of t2 and grandchild of t1
# t4 is a child of t3 and grandchild of t2
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t2.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.c;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t2.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.c;
# t3 is a child of t2 and grandchild of t1
# t4 is a child of t3 and grandgrandchild of t1
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t2.d
join t1 as t4 on t4.a = t3.c and t4.b = t1.d;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t2.d
join t1 as t4 on t4.a = t3.c and t4.b = t1.d;
# Some testcases where t4 is not directly pushable, but
# may be made pushable by equality set replacement.
#
# BEWARE: mysqld optimizer may do its own replacement
# before ha_ndbcluster_push analyze the AQP. We therefore
# provide multiple similar testcases and hope that
# some of them will trigger the replacement code in
# ha_ndbcluster_push :-o
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.a and t4.b = t2.c;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.a and t4.b = t2.c;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.b and t4.b = t2.c;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.b and t4.b = t2.c;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.a;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.a;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.b;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.b;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t1.c and t4.b = t2.c;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t1.c and t4.b = t2.c;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.c and t4.b = t1.b;
--sorted_result
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t4 on t4.a = t3.c and t4.b = t1.b;
# Added more multidependency tests;
#
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t2x on t2x.a = t2.c and t2x.b = t2.d
join t1 as t3x on t3x.a = t1.c and t3x.b = t1.d
join t1 as t4 on t4.a = t3x.c and t4.b = t2x.c;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t2x on t2x.a = t2.c and t2x.b = t2.d
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t3x on t3x.a = t3.c and t3x.b = t3.d
join t1 as t4 on t4.a = t3x.c and t4.b = t2x.c;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t2x on t2x.a = t2.c and t2x.b = t2.d
join t1 as t3x on t3x.a = t3.c and t3x.b = t3.d
join t1 as t4 on t4.a = t3x.c and t4.b = t2x.c;
# 't3' is not referred as ancestor and should not be
# included in the forced dependencies
# (Depends directly on 't1' and can be bushy wrt. to
# the other tables)
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t2x on t2x.a = t2.c and t2x.b = t2.d
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
join t1 as t3x on t3x.a = t1.c and t3x.b = t1.d
join t1 as t4 on t4.a = t3x.c and t4.b = t2x.c;
# 't3' is still independent - see comment above.
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t2x on t2x.a = t2.c and t2x.b = t2.d
join t1 as t3 on t3.a = t1.c and t3.b = t1.b
join t1 as t3x on t3x.a = t1.c and t3x.b = t1.d
join t1 as t4 on t4.a = t3x.c and t4.b = t2x.c;
## It should not be possible to force grandparent dependencies
## via a previously outer joined table:
explain
select straight_join *
from t1
left join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.c and t3.b = t1.d
left join t1 as t4 on t4.a = t3.c and t4.b = t2.c;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
left join t1 as t3 on t3.a = t1.c and t3.b = t1.d
left join t1 as t4 on t4.a = t3.c and t4.b = t2.c;
explain
select straight_join *
from t1
left join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.a
left join t1 as t4 on t4.a = t3.c and t4.b = t2.c;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
left join t1 as t3 on t3.a = t1.a
left join t1 as t4 on t4.a = t3.c and t4.b = t2.c;
explain
select straight_join *
from t1
left join t1 as t2 on t2.a = t1.a and t2.b = t1.b
join t1 as t3 on t3.a = t1.a
left join t1 as t4 on t4.a = t3.c;
explain
select straight_join *
from t1
join t1 as t2 on t2.a = t1.a and t2.b = t1.b
left join t1 as t3 on t3.a = t1.a
left join t1 as t4 on t4.a = t3.c;
# Bug#16199028:
# Tescase where a too strict 'root' was checked:
# In these cases t4 was not pushed as it was incorrectly
# concluded that its grandparent ref of 't2' through 't3'
# introduced dependencies on the outer joined t1.
#
explain
select straight_join *
from
( t1 as t0 left join t1 as t1 on t1.a = t0.a and t1.b = t0.b
)
left join
( t1 as t2 join t1 as t3 on t3.a = t2.c and t3.b = t2.d
join t1 as t4 on t4.a = t3.c and t4.b = t2.c
)
on t2.a = t1.a and t2.b = t1.b;
explain
select straight_join *
from
t1 as x1
left join
( t1 as x2 join t1 as x3 on x3.a=x2.c
join t1 as x4 on x4.a=x2.d
join t1 as x5 on x5.a=x3.d and x5.b=x4.d
)
on x2.a=x1.c and x2.b=x1.c and
x3.b=x1.d and
x4.b=x1.d;
# Bug#16198866:
# Additional tests where equality set [t1.d, t3.b, t4.d]
# propagation incorrectly allowed grandparent references
# to be allowed 'through' outer joins (t2):
#
# Test: don't allow t4 to propagate parent deps past
# outer joined 't2' into t3.
# (As that would implicit cause t3 to depend on t2.)
#
explain
select straight_join * from
(t1 left join t1 as t2 on t2.a = t1.c and t2.b = t1.d)
inner join t1 as t3 on t3.a = t1.b and t3.b = t1.c
left join t1 as t4 on t4.a = t2.c and t4.b = t1.c;
--sorted_result
select straight_join * from
(t1 left join t1 as t2 on t2.a = t1.c and t2.b = t1.d)
inner join t1 as t3 on t3.a = t1.b and t3.b = t1.c
left join t1 as t4 on t4.a = t2.c and t4.b = t1.c;
# However, if t3 already depends on t2 (t3.a = t2.b)
# it *is* allowed as it will not introduce any new
# t3 dependencies.
#
# Note: Both these two queries are fully pushable, but
# the later will likely result in a better query plan.
#
explain
select straight_join * from
(t1 left join t1 as t2 on t2.a = t1.c and t2.b = t1.d)
inner join t1 as t3 on t3.a = t2.b and t3.b = t1.c
left join t1 as t4 on t4.a = t2.c and t4.b = t1.c;
--sorted_result
select straight_join * from
(t1 left join t1 as t2 on t2.a = t1.c and t2.b = t1.d)
inner join t1 as t3 on t3.a = t2.b and t3.b = t1.c
left join t1 as t4 on t4.a = t2.c and t4.b = t1.c;
# Test a combination of pushed table scan (x, y)
# & pushed EQ-bound (indexScan) (z, t1)
# This used to give incorrect results with random result for last table (t1)
set ndb_join_pushdown=true;
explain
select * from t1 x, t1 y, t1 z, t1 where
y.a=x.d and y.b=x.b and
z.a=y.d and
t1.a = z.d and t1.b=z.b;
--sorted_result
select * from t1 x, t1 y, t1 z, t1 where
y.a=x.d and y.b=x.b and
z.a=y.d and
t1.a = z.d and t1.b=z.b;
# Pushed scanIndex() with (multi-)range:
explain
select * from t1 x, t1 y where
x.a <= 2 and
y.a=x.d and y.b=x.b;
--sorted_result
select * from t1 x, t1 y where
x.a <= 2 and
y.a=x.d and y.b=x.b;
explain
select * from t1 x, t1 y where
(x.a <= 2 or x.a > 3) and
y.a=x.d and y.b=x.b;
--sorted_result
select * from t1 x, t1 y where
(x.a <= 2 or x.a > 3) and
y.a=x.d and y.b=x.b;
# 'open' range:
--replace_column 10 # 11 #
explain
select * from t1 x, t1 y where
(x.a >= 2 or x.a < 3) and
y.a=x.d and y.b=x.b;
--sorted_result
select * from t1 x, t1 y where
(x.a >= 2 or x.a < 3) and
y.a=x.d and y.b=x.b;
# Combination of range and 'in' list
explain
select * from t1 x, t1 y where
(x.a <= 2 or x.a in (0,5,4)) and
y.a=x.d and y.b=x.b;
--sorted_result
select * from t1 x, t1 y where
(x.a <= 2 or x.a in (0,5,4)) and
y.a=x.d and y.b=x.b;
# Combination of range and 'in' list with exact match
# NOTE: Due to simplification in pushed mrr, exact matches are also
# executed as range scans
explain
select * from t1 x, t1 y where
(x.a <= 2 or (x.a,x.b) in ((0,0),(5,0),(4,3))) and
y.a=x.d and y.b=x.b;
--sorted_result
select * from t1 x, t1 y where
(x.a <= 2 or (x.a,x.b) in ((0,0),(5,0),(4,3))) and
y.a=x.d and y.b=x.b;
# Test ORDER BY expressions
# If it is a 'simple' order, i.e all order by's are plain column refs
# to the first non-const table, the optimizer will (by heuristic)
# make the first table 'ordered' beforing joining in the siblings.
# This may involve presorting of the first table into intermediate storage.
#
# This will make this (parent-) table non-pushable as
# read of rows to be filesorted will also prefetch rows from pushed child
# operands. These are not cached by the filesort buffer mechanisnm and are
# effectively lost.
#
# Non simple ordering will always writte entire resultset to temp.
# table and filesort that -> No extra push restrictions on these.
#
# Integrating pushed joins we either has to:
# 1) find a suitable ordered index which we can create an ordered indexscan on
# (-> joinType() -> JT_NEXT, or type: 'index' w/ explain)
# or:
# 2) Reject pushing of the this parent table.
#
# Comment1: As 'order by' correctness is part of what we want to test,
# '--sorted_result' is *not* specified. Instead we aim at
# specifying a deterministic sort ordering in order by list.
#
# Comment2: 't1.a, t1.b' is appended where required to the order by spec
# to get a deterministic sorting order wo/ '--sorted_result'
#
#
# Bug #30338585
# SPJ INTEGRATION: FAILS TO DETECT FILESORT OF A TABLE IN MIDDLE OF PUSHED JOIN
#
# Extracted from TPC-H Q16, which failed to detect that the first
# table in the query plan required a 'filesort', and thus should not
# have been pushed. That effectively voided the entire pushed join and
# caused poor performance. The correct query plan for Q16 would be
# to 'filesort' the first table, then push the join of the two preceeding
# tables.
#
# Below is a test case transformed to the test tables we normally use.
# Optimizer will decide to presort t1 into a temporary table before
# joining with t2. Thus the below query should not be pushed.
#
explain format=tree
select straight_join t1.b, count(distinct t2.b) as cnt
from t1
join t1 as t2 on t2.a = t1.c
group by t1.b
order by t1.b, cnt;
select straight_join t1.b, count(distinct t2.b) as cnt
from t1
join t1 as t2 on t2.a = t1.c
group by t1.b
order by t1.b, cnt;
# Remaining (Original) test cases for eliminating filesort'ed tables
# from a pushed join:
## Non-pushed join w/ 'simple order' on non_PK - Presorts parent table.
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.c,t1.d,
t1.a, t1.b;
#--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.c,t1.d,
t1.a, t1.b;
## pushed join w/ non-'simple order' on non_PK - Need temp table + filesort
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.c,t2.d,
t1.a, t1.b;
#--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.c,t2.d,
t1.a, t1.b;
## pushed join w/ 'simple order' on PK - Should use ordered index scan
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.a,t1.b;
#--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.a,t1.b;
## pushed join w/ non-'simple order' on PK - will need temp table + filesort
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.a,t2.b,
t1.a, t1.b;
#--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.a,t2.b,
t1.a, t1.b;
## Descending ordering on PK - use reversed ordered index scan
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.a desc,t1.b desc;
#--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.a desc,t1.b desc;
## Simple-PK column in incorrect order, -> Presort parent table, (no-push)
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.b,t1.a;
#--sorted_result
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.b,t1.a;
## Explore other permutations of PK columns in ORDER BY clause
## Don't care about the results here....
# Subset of first part of PK -> ordered index scan
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.a;
# PK columns not including first part -> Presort parent table, (no-push)
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
order by t1.b;
## Similar tests for GROUP BY expression
## PK grouping (or subpart) may be optimized
## by ordered index access.
##
explain
select t1.a, t1.b, count(*)
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
group by t1.a, t1.b;
--sorted_result
select t1.a, t1.b, count(*)
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
group by t1.a, t1.b;
explain
select t1.a, count(*)
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
group by t1.a;
--sorted_result
select t1.a, count(*)
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
group by t1.a;
explain
select t1.b, count(*)
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
group by t1.b;
--sorted_result
select t1.b, count(*)
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
join t1 as t3 on t3.a = t2.a and t3.b = t2.b
group by t1.b;
--replace_result p0,p1,p2,p3,p4,p5,p6,p7 pXYZ p1 pX p2 pX
explain
select t2.c, count(distinct t2.a)
from t1
join t1 as t2 on t1.a = t2.c and t1.b = t2.d
where t2.a = 4 and t2.b=4
group by t2.c;
--sorted_result
select t2.c, count(distinct t2.a)
from t1
join t1 as t2 on t1.a = t2.c and t1.b = t2.d
where t2.a = 4 and t2.b=4
group by t2.c;
explain
select t2.c, count(distinct t2.a)
from t1
join t1 as t2 on t1.a = t2.c and t1.b = t2.d
where t2.a = 4
group by t2.c;
--sorted_result
select t2.c, count(distinct t2.a)
from t1
join t1 as t2 on t1.a = t2.c and t1.b = t2.d
where t2.a = 4
group by t2.c;
--replace_result p0,p1,p2,p3,p4,p5,p6,p7 pXYZ p1 pX p2 pX
explain
select t2.c, count(distinct t2.a)
from t1
join t1 as t2 on t1.a = t2.c and t1.b = t2.d
where t2.a = 4 and t2.b=4
group by t2.c order by t2.c;
--sorted_result
select t2.c, count(distinct t2.a)
from t1
join t1 as t2 on t1.a = t2.c and t1.b = t2.d
where t2.a = 4 and t2.b=4
group by t2.c order by t2.c;
connection ddl;
create table tx like t1;
connection spj;
insert into tx
select x1.a+x2.a*16, x1.b+x2.b*16, x1.c+x2.c*16, x1.d+x2.d*16
from t1 as x1 cross join t1 as x2;
# Test of outer join with scan child.
# This query should not be pushed. Doing so would produce lots of extra
# [<x1 row>.NULL] rows, since the x1.d=x2.d predicate cannot be pushed.
explain select count(*) from tx as x1
left join tx as x2 on x1.c=x2.a and x1.d=x2.d;
select count(*) from tx as x1
left join tx as x2 on x1.c=x2.a and x1.d=x2.d;
connection ddl;
drop table tx;
# Test bushy join with pruned scan.
connection ddl;
alter table t1 partition by key(a);
connection spj;
explain select count(*) from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t1.d;
select count(*) from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t1.d;
# Test bushy join with pruned scan and larger result set.
connection ddl;
CREATE TABLE tx (
a int NOT NULL,
PRIMARY KEY (`a`)
) comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
delete from t1;
insert into tx values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9);
insert into t1 select 1, x1.a * 10+x2.a, 1, 1 from tx as x1 cross join tx as x2;
--error 0,1193
set global debug='+d,max_64rows_in_spj_batches';
--replace_column 10 # 11 #
explain select count(*) from t1 as x1
join t1 as x2 on x2.a = x1.c and x1.b < 2
join t1 as x3 on x3.a = x1.d;
select count(*) from t1 as x1
join t1 as x2 on x2.a = x1.c and x1.b < 2
join t1 as x3 on x3.a = x1.d;
--error 0,1193
set global debug=@save_debug;
connection ddl;
drop table t1;
drop table tx;
# Test user defined partition not being pushed
#
# Note: User defined partitions are handled
# by the SQL layer, and as such are unknown
# to the NDB datanodes.
#
connection spj;
create table t1 (
a int not null,
b int not null,
c int not null,
d int not null,
primary key (`a`,`b`)
) engine=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM"
partition by key(a);
connection spj;
insert into t1 values
(1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4),
(1,2,5,1), (1,3,1,2), (1,4,2,3),
(2,1,3,4), (2,3,4,5), (2,4,5,1),
(3,1,1,2), (3,2,2,3), (3,4,3,4),
(4,1,4,5), (4,2,5,1), (4,3,1,2);
# Only this query('partition by key') should be pushed
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
connection ddl;
set new=on;
alter table t1 partition by hash(a);
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
connection ddl;
alter table t1 partition by list(a) (
partition p1 values in (1),
partition p2 values in (2),
partition p3 values in (3),
partition p4 values in (4)
);
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
connection ddl;
alter table t1 partition by range(a) partitions 4 (
partition p1 values less than (0),
partition p2 values less than (2),
partition p3 values less than (4),
partition p4 values less than (99999)
);
explain
select *
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
connection ddl;
drop table t1;
set new=default;
# pushed mrr does not yet handle multiple PK operations in same transaction
# Need 6.0 result handling stuff to simplify result handling
# *** join push is currently dissabled for these ****
#
connection ddl;
create table t1 (a int, b int, primary key(a) using hash) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (1, 2);
insert into t1 values (2, 3);
insert into t1 values (3, 1);
set ndb_join_pushdown=true;
##
# In ps-protocol, server will adds calls to execute(Commit)
# (these are optimized away by ndbapi, since there is nothing to commit)
# and these generates a diff in execute-count
# To not have to investigate problem futher, I simply set autocommit=off
# (and back further down where we don't track execute-count any longer)
# It would probably be good to changes these tests to instead use frazers new
# ndbapi counters, and instead measure #round-trips
set autocommit=off;
explain
select *
from t1, t1 as t2
where t1.a in (1,3,5)
and t2.a = t1.b;
--source suite/ndb/include/ndb_init_execute_count.inc
--sorted_result
select *
from t1, t1 as t2
where t1.a in (1,3,5)
and t2.a = t1.b;
--source suite/ndb/include/ndb_execute_count.inc
--echo This should yield 3 executes (for now...buh)
set autocommit=on;
connection ddl;
drop table t1;
# Same case when there is an ordered index on PK
connection ddl;
create table t1 (a int, b int, primary key(a)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (1, 2);
insert into t1 values (2, 3);
insert into t1 values (3, 1);
set ndb_join_pushdown=true;
##
# In ps-protocol, server will adds calls to execute(Commit)
# (these are optimized away by ndbapi, since there is nothing to commit)
# and these generates a diff in execute-count
# To not have to investigate problem futher, I simply set autocommit=off
# (and back further down where we don't track execute-count any longer)
# It would probably be good to changes these tests to instead use frazers new
# ndbapi counters, and instead measure #round-trips
set autocommit=off;
explain
select *
from t1, t1 as t2
where t1.a in (1,3,5)
and t2.a = t1.b;
--source suite/ndb/include/ndb_init_execute_count.inc
--sorted_result
select *
from t1, t1 as t2
where t1.a in (1,3,5)
and t2.a = t1.b;
--source suite/ndb/include/ndb_execute_count.inc
--echo This should yield 1 execute (but inefficient since it's based on scan)
set autocommit=on;
## Adding and 'order by ... desc' trigger the usage
## of QUICK_SELECT_DESC which somehow prepares a
## pushed join as indexscan but ends up executing it as
## primary key access. This (auto-) disables the pushed
## join execution (EXPLAIN still says 'pushdown') which
## should test handling of this in ha_ndbcluster::index_read_pushed()
explain
select *
from t1, t1 as t2
where t1.a in (1,3,5)
and t2.a = t1.b
order by t1.a desc;
select *
from t1, t1 as t2
where t1.a in (1,3,5)
and t2.a = t1.b
order by t1.a desc;
connection ddl;
drop table t1;
set ndb_join_pushdown=true;
connection ddl;
create table t1 (a int, b int, primary key(a)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create table t2 (c int, d int, primary key(c)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create table t3 (a3 int, b3 int, c3 int not null, d3 int not null,
primary key(a3, b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create table t3_hash (a3 int, b3 int, c3 int not null, d3 int not null,
primary key(a3, b3) using hash) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (0x1f, 0x2f);
insert into t1 values (0x2f, 0x3f);
insert into t1 values (0x3f, 0x1f);
insert into t2 values (0x1f, 0x2f);
insert into t2 values (0x2f, 0x3f);
insert into t2 values (0x3f, 0x1f);
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
insert into t3_hash values (0x1f, 0x2f, 1, 0x1f);
insert into t3_hash values (0x2f, 0x3f, 2, 0x2f);
insert into t3_hash values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y, t1 where y.a3=x.d3 and y.b3=x.b3 and t1.a = y.d3;
--sorted_result
select * from t3 x, t3 y, t1 where y.a3=x.d3 and y.b3=x.b3 and t1.a = y.d3;
explain
select *
from t3 x, t3 y, t3 z, t3 z2, t1
where y.a3=x.d3 and y.b3=x.b3 and
z.a3=y.d3 and z.b3=y.b3 and
z2.a3=z.d3 and z2.b3=z.b3 and
t1.a = z2.d3;
--sorted_result
select *
from t3 x, t3 y, t3 z, t3 z2, t1
where y.a3=x.d3 and y.b3=x.b3 and
z.a3=y.d3 and z.b3=y.b3 and
z2.a3=z.d3 and z2.b3=z.b3 and
t1.a = z2.d3;
# Table expressions wo/ parent-child linkage should *not* be executes as a pushed join:
--replace_column 10 # 11 #
explain
select straight_join * from t1 x, t1 y where y.a=0x1f and x.b = 0x1f;
select straight_join * from t1 x, t1 y where y.a=0x1f and x.b = 0x1f;
# NOTE: Due to constValue replacement in equality sets, query below are
# effectively the same as the one above. -> Don't push either
--replace_column 10 # 11 #
explain
select straight_join * from t1 x, t1 y where y.a=x.b and x.b = 0x1f;
select straight_join * from t1 x, t1 y where y.a=x.b and x.b = 0x1f;
# Tests usage of unique index
connection ddl;
create unique index t3_d3 on t3(d3);
create unique index t3_d3 on t3_hash(d3);
commit;
connection spj;
# Use an unique key to lookup root in pushed join:
explain
select * from t3 x, t3 y where x.d3=31 and y.a3=x.d3 and y.b3=x.b3;
select * from t3 x, t3 y where x.d3=31 and y.a3=x.d3 and y.b3=x.b3;
# No data-found on unique key lookup root
explain
select * from t3 x, t3 y where x.d3=0 and y.a3=x.d3 and y.b3=x.b3;
select * from t3 x, t3 y where x.d3=0 and y.a3=x.d3 and y.b3=x.b3;
# Use an unique key to lookup joined child tables
explain
select * from t1 x, t3 y where y.d3=x.b;
--sorted_result
select * from t1 x, t3 y where y.d3=x.b;
# Unique index used both for root lookup and child linkage.
explain
select * from t3 x, t3 y where x.d3=31 and y.d3=x.b3;
select * from t3 x, t3 y where x.d3=31 and y.d3=x.b3;
# No data-found on unique key lookup child
explain
select * from t3 x, t3 y where x.d3=31 and y.d3=x.c3;
select * from t3 x, t3 y where x.d3=31 and y.d3=x.c3;
# 'index_merge' between PRIMARY and index t3.d3
# NOTE: currently unhandled
explain
select * from t3 x, t3 y
where ((x.a3=0x2f and x.b3=0x3f) or x.d3=0x1f)
and (y.a3=x.d3 and y.b3=x.b3);
# No 'sorted_result' required as index merge itself sort on PK
select * from t3 x, t3 y
where ((x.a3=0x2f and x.b3=0x3f) or x.d3=0x1f)
and (y.a3=x.d3 and y.b3=x.b3);
explain
select * from t3_hash x, t3_hash y
where ((x.a3=0x2f and x.b3=0x3f) or x.d3=0x1f)
and (y.a3=x.d3 and y.b3=x.b3);
# No 'sorted_result' required as index merge itself sort on PK
select * from t3_hash x, t3_hash y
where ((x.a3=0x2f and x.b3=0x3f) or x.d3=0x1f)
and (y.a3=x.d3 and y.b3=x.b3);
# Any ordered index may also be used to scan a 'range'
explain
select * from t3 x, t3 y where x.d3>=31 and y.d3=x.b3;
--sorted_result
select * from t3 x, t3 y where x.d3>=31 and y.d3=x.b3;
# handle "null" key
insert into t1 values (0x4f, null);
--sorted_result
select * from t1 left join t1 as t2 on t2.a = t1.b;
### Test max number of pushable operations.
insert into t3 values (8,8,8,8);
# Unique lookups only.
explain select count(*) from t3 as x0
join t3 as x1 on x0.b3=x1.d3 and x0.d3=8
join t3 as x2 on x1.b3=x2.d3
join t3 as x3 on x2.b3=x3.d3
join t3 as x4 on x3.b3=x4.d3
join t3 as x5 on x4.b3=x5.d3
join t3 as x6 on x5.b3=x6.d3
join t3 as x7 on x6.b3=x7.d3
join t3 as x8 on x7.b3=x8.d3
join t3 as x9 on x8.b3=x9.d3
join t3 as x10 on x9.b3=x10.d3
join t3 as x11 on x10.b3=x11.d3
join t3 as x12 on x11.b3=x12.d3
join t3 as x13 on x12.b3=x13.d3
join t3 as x14 on x13.b3=x14.d3
join t3 as x15 on x14.b3=x15.d3
join t3 as x16 on x15.b3=x16.d3
join t3 as x17 on x16.b3=x17.d3;
select count(*) from t3 as x0
join t3 as x1 on x0.b3=x1.d3 and x0.d3=8
join t3 as x2 on x1.b3=x2.d3
join t3 as x3 on x2.b3=x3.d3
join t3 as x4 on x3.b3=x4.d3
join t3 as x5 on x4.b3=x5.d3
join t3 as x6 on x5.b3=x6.d3
join t3 as x7 on x6.b3=x7.d3
join t3 as x8 on x7.b3=x8.d3
join t3 as x9 on x8.b3=x9.d3
join t3 as x10 on x9.b3=x10.d3
join t3 as x11 on x10.b3=x11.d3
join t3 as x12 on x11.b3=x12.d3
join t3 as x13 on x12.b3=x13.d3
join t3 as x14 on x13.b3=x14.d3
join t3 as x15 on x14.b3=x15.d3
join t3 as x16 on x15.b3=x16.d3
join t3 as x17 on x16.b3=x17.d3;
# Max scans
explain select count(*) from t3 as x0
join t3 as x1 on x0.c3=x1.a3
join t3 as x2 on x1.c3=x2.a3
join t3 as x3 on x2.c3=x3.a3
join t3 as x4 on x3.c3=x4.a3
join t3 as x5 on x4.c3=x5.a3
join t3 as x6 on x5.c3=x6.a3
join t3 as x7 on x6.c3=x7.a3
join t3 as x8 on x7.c3=x8.a3
join t3 as x9 on x8.c3=x9.a3
join t3 as x10 on x9.c3=x10.a3
join t3 as x11 on x10.c3=x11.a3
join t3 as x12 on x11.c3=x12.a3
join t3 as x13 on x12.c3=x13.a3
join t3 as x14 on x13.c3=x14.a3
join t3 as x15 on x14.c3=x15.a3
join t3 as x16 on x15.c3=x16.a3
join t3 as x17 on x16.c3=x17.a3
join t3 as x18 on x17.c3=x18.a3
join t3 as x19 on x18.c3=x19.a3
join t3 as x20 on x19.c3=x20.a3
join t3 as x21 on x20.c3=x21.a3
join t3 as x22 on x21.c3=x22.a3
join t3 as x23 on x22.c3=x23.a3
join t3 as x24 on x23.c3=x24.a3
join t3 as x25 on x24.c3=x25.a3
join t3 as x26 on x25.c3=x26.a3
join t3 as x27 on x26.c3=x27.a3
join t3 as x28 on x27.c3=x28.a3
join t3 as x29 on x28.c3=x29.a3
join t3 as x30 on x29.c3=x30.a3
join t3 as x31 on x30.c3=x31.a3
join t3 as x32 on x31.c3=x32.a3
join t3 as x33 on x32.c3=x33.a3;
select count(*) from t3 as x0
join t3 as x1 on x0.c3=x1.a3
join t3 as x2 on x1.c3=x2.a3
join t3 as x3 on x2.c3=x3.a3
join t3 as x4 on x3.c3=x4.a3
join t3 as x5 on x4.c3=x5.a3
join t3 as x6 on x5.c3=x6.a3
join t3 as x7 on x6.c3=x7.a3
join t3 as x8 on x7.c3=x8.a3
join t3 as x9 on x8.c3=x9.a3
join t3 as x10 on x9.c3=x10.a3
join t3 as x11 on x10.c3=x11.a3
join t3 as x12 on x11.c3=x12.a3
join t3 as x13 on x12.c3=x13.a3
join t3 as x14 on x13.c3=x14.a3
join t3 as x15 on x14.c3=x15.a3
join t3 as x16 on x15.c3=x16.a3
join t3 as x17 on x16.c3=x17.a3
join t3 as x18 on x17.c3=x18.a3
join t3 as x19 on x18.c3=x19.a3
join t3 as x20 on x19.c3=x20.a3
join t3 as x21 on x20.c3=x21.a3
join t3 as x22 on x21.c3=x22.a3
join t3 as x23 on x22.c3=x23.a3
join t3 as x24 on x23.c3=x24.a3
join t3 as x25 on x24.c3=x25.a3
join t3 as x26 on x25.c3=x26.a3
join t3 as x27 on x26.c3=x27.a3
join t3 as x28 on x27.c3=x28.a3
join t3 as x29 on x28.c3=x29.a3
join t3 as x30 on x29.c3=x30.a3
join t3 as x31 on x30.c3=x31.a3
join t3 as x32 on x31.c3=x32.a3
join t3 as x33 on x32.c3=x33.a3;
#Mixed join
explain select count(*) from t3 as x0
join t3 as x1 on x0.b3=x1.d3
join t3 as x2 on x1.b3=x2.d3
join t3 as x3 on x2.b3=x3.d3
join t3 as x4 on x3.b3=x4.d3
join t3 as x5 on x4.b3=x5.d3
join t3 as x6 on x5.b3=x6.d3
join t3 as x7 on x6.b3=x7.d3
join t3 as x8 on x7.b3=x8.d3
join t3 as x9 on x8.b3=x9.d3
join t3 as x10 on x9.b3=x10.d3
join t3 as x11 on x10.b3=x11.d3
join t3 as x12 on x11.b3=x12.d3
join t3 as x13 on x12.b3=x13.d3
join t3 as x14 on x13.b3=x14.d3
join t3 as x15 on x14.b3=x15.d3
join t3 as x16 on x15.b3=x16.d3
join t3 as x17 on x15.b3=x17.a3
join t3 as x18 on x16.b3=x18.d3;
select count(*) from t3 as x0
join t3 as x1 on x0.b3=x1.d3
join t3 as x2 on x1.b3=x2.d3
join t3 as x3 on x2.b3=x3.d3
join t3 as x4 on x3.b3=x4.d3
join t3 as x5 on x4.b3=x5.d3
join t3 as x6 on x5.b3=x6.d3
join t3 as x7 on x6.b3=x7.d3
join t3 as x8 on x7.b3=x8.d3
join t3 as x9 on x8.b3=x9.d3
join t3 as x10 on x9.b3=x10.d3
join t3 as x11 on x10.b3=x11.d3
join t3 as x12 on x11.b3=x12.d3
join t3 as x13 on x12.b3=x13.d3
join t3 as x14 on x13.b3=x14.d3
join t3 as x15 on x14.b3=x15.d3
join t3 as x16 on x15.b3=x16.d3
join t3 as x17 on x15.b3=x17.a3
join t3 as x18 on x16.b3=x18.d3;
connection ddl;
drop table t1,t2,t3, t3_hash;
###############################
## Test Primary key and unique key defined 'out of order'
## wrt. the order in which columns was defined in 'create table'
connection ddl;
create table t3 (a3 int, b3 int, c3 int, d3 int,
primary key(b3, a3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create table t3_hash (a3 int, b3 int, c3 int, d3 int,
primary key(b3,a3) using hash) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create table t3_unq (pk int, a3 int not null, b3 int not null, c3 int, d3 int,
primary key(pk) using hash, unique key(b3,a3) using hash) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
insert into t3_hash values (0x1f, 0x2f, 1, 0x1f);
insert into t3_hash values (0x2f, 0x3f, 2, 0x2f);
insert into t3_hash values (0x3f, 0x1f, 3, 0x3f);
insert into t3_unq values (1001, 0x1f, 0x2f, 1, 0x1f);
insert into t3_unq values (1002, 0x2f, 0x3f, 2, 0x2f);
insert into t3_unq values (1003, 0x3f, 0x1f, 3, 0x3f);
## Table scans (ALL) as pushed root
explain
select * from t3 x, t3 y where y.a3=x.d3 and y.b3=x.b3;
--sorted_result
select * from t3 x, t3 y where y.a3=x.d3 and y.b3=x.b3;
explain
select * from t3_hash x, t3_hash y where y.a3=x.d3 and y.b3=x.b3;
--sorted_result
select * from t3_hash x, t3_hash y where y.a3=x.d3 and y.b3=x.b3;
explain
select * from t3_unq x, t3_unq y where y.a3=x.d3 and y.b3=x.b3;
--sorted_result
select * from t3_unq x, t3_unq y where y.a3=x.d3 and y.b3=x.b3;
## Lookup (eq_ref/const) as pushed root
explain
select * from t3 x, t3 y where y.a3=x.d3 and y.b3=x.b3
and x.a3=0x2f and x.b3=0x3f;
select * from t3 x, t3 y where y.a3=x.d3 and y.b3=x.b3
and x.a3=0x2f and x.b3=0x3f;
explain
select * from t3_hash x, t3_hash y where y.a3=x.d3 and y.b3=x.b3
and x.a3=0x2f and x.b3=0x3f;
select * from t3_hash x, t3_hash y where y.a3=x.d3 and y.b3=x.b3
and x.a3=0x2f and x.b3=0x3f;
explain
select * from t3_unq x, t3_unq y where y.a3=x.d3 and y.b3=x.b3
and x.a3=0x2f and x.b3=0x3f;
select * from t3_unq x, t3_unq y where y.a3=x.d3 and y.b3=x.b3
and x.a3=0x2f and x.b3=0x3f;
connection ddl;
drop table t3, t3_hash, t3_unq;
###########
connection ddl;
create table t3 (a3 int, b3 int, c3 int, d3 int,
primary key(a3), unique key(d3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
insert into t3 values (0x4f, 0, null, null);
explain
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.d3
left outer join t3 as t3 on t3.a3 = t2.d3;
--sorted_result
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.d3
left outer join t3 as t3 on t3.a3 = t2.d3;
## Test usage of nullable unique key column in where clause on pushed parent node
explain
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.a3
left outer join t3 as t3 on t3.a3 = t2.d3
where t1.d3 = 47;
--sorted_result
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.a3
left outer join t3 as t3 on t3.a3 = t2.d3
where t1.d3 = 47;
explain
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.a3
left outer join t3 as t3 on t3.a3 = t2.d3
where t1.d3 >= 47;
--sorted_result
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.a3
left outer join t3 as t3 on t3.a3 = t2.d3
where t1.d3 >= 47;
explain
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.a3
left outer join t3 as t3 on t3.a3 = t2.d3
where t1.d3 is null;
--sorted_result
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.a3
left outer join t3 as t3 on t3.a3 = t2.d3
where t1.d3 is null;
explain
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.a3
left outer join t3 as t3 on t3.a3 = t2.d3
where t1.d3 is not null;
--sorted_result
select * from t3 as t1
left outer join t3 as t2 on t2.d3 = t1.a3
left outer join t3 as t3 on t3.a3 = t2.d3
where t1.d3 is not null;
################################
# Bug#33451256 AbstractQueryPlan (AQP) return incorrect
# access type to be used for a table.
#
# If the column(s) an unique index is specified over
# are nullable, _and_ the key contains a NULL value,
# multiple NULL-valued rows may still be returned from the UNIQUE index.
# (All the non-NULL columns are unique though)
#
# Note that the optimizer correctly set the access type to REF (-> non-unique)
# However, the AQP still decided it was 'unique' as all key values
# was specified.
#
# Note that none of the 4 test cases added for this bug should
# emit the Warning '1296 Prepared pushed join could not be executed'
# with the patch for this bug. (It does without the patch)
# Insert an additional NULL value, such that the unique index on column d3
# now has 2 null values - Should not fail.
insert into t3 values (0x5f, 0x5f, 4, null);
# Need a non-unique index
alter table t3 add index ix(b3);
###################################
# AQP incorrectly clasified 'where t1.d3 is null' as a
# single row lookup operation (Even if explain says 'REF').
#
# As pushdown of index scans with a lookup root is not supported,
# we could not push 't3 as t1' as a root in query below.
# (t2 join t3) was pushed though.
#
# Correctly classifying t1-access as a index access would have
# allowed all 3 tables to be pushed.
let $query1 =
select straight_join *
from t3 as t1
left join t3 as t2 on t2.b3 = t1.a3
left join t3 as t3 on t3.b3 = t2.d3
where t1.d3 is null;
eval explain $query1;
--sorted_result
eval $query1;
#################################
# The other way around, making t2 and t3 acccess an EQ_REF:
# t1 is still incorrectly believed to be a single row operation
#
# A pushed join was now prepared for the full 't1 join t2 join t3' -
# ... with t1 as single row lookup operation.
#
# At execution time it turns out that t1 had a NULL in its key,
# which required an index scan access type. Thus the prepared pushed join
# ends up being unsuitable, and is dropped from being executed
let $query2 =
select straight_join *
from t3 as t1
left join t3 as t2 on t2.d3 = t1.a3
left join t3 as t3 on t3.d3 = t2.d3
where t1.d3 is null;
eval explain $query2;
--sorted_result
eval $query2;
# The only time where the optimizer set up a REF access, and
# we still do a unique single row access against it, is when
# we are using a HASH index. Then there is no ordered index
# available for doing a range type access:
alter table t3 drop index d3;
# Note that a 'using hash' index will warn about doing full table scans
# if the key has NULL values
alter table t3 add unique key(d3) using hash;
######################################
# Use the same two queries a above, now with a redefined HASH index:
# t1 access will now either be a unique single row acces, if key
# has no NULLs, or a full table scan. Which of them we can't really
# know until execution time when the key values are known, unless
# they are a const-literal.
#
# The first one now fails to push t1 as root as it belived it was
# a lookup type operation with t2 & t3 as scan child.
#
# As the t1 key is constructed from 't1.d3 is null', we should be
# able to detect early that t1 will be accessed using a full table scan.
# Thus preparing a scan type pushed join for all 3 tables
eval explain $query1;
--sorted_result
eval $query1;
####################################
# The other query was, and still is, asuming t1 to be a single row lookup.
# Thus we may prepare a pushed lookup join for all 3 tables.
#
# However, as the t1 condition 't1.d3 is null' turns out to need a
# full table scan, the pushed join is rejected at execution time
#
# We should be able to detect at prepare time that the key contain
# a NULL value, thus needing a table scan.
eval explain $query2;
--sorted_result
eval $query2;
# Bug#33451256 ... end
###################################
connection ddl;
drop table t3;
####### Composite unique keys, 'const' is part of EQ_REF on child nodes ####
connection ddl;
create table t3 (a3 int not null, b3 int not null, c3 int, d3 int,
primary key(a3), unique key(b3,d3), unique key(c3,b3), unique key(c3,d3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
insert into t3 values (0x40, 0, null, null);
insert into t3 values (0x41, 0, null, null);
insert into t3 values (0x42, 0, 4, null);
insert into t3 values (0x43, 0, null, 0x43);
## Baseline: Not pushed as only one of the columns in unique indexes are REF'ed
explain
select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3;
## Extend query above with 'where <const cond>'
explain
select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 = 0x2f;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 = 0x2f;
--replace_column 10 # 11 #
explain
select straight_join *
from t3 as x join t3 as y on x.c3 = y.c3
where y.d3 = 0x2f;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.c3 = y.c3
where y.d3 = 0x2f;
explain
select straight_join *
from t3 as x join t3 as y on x.d3 = y.d3
where y.b3 = 0x2f;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.d3 = y.d3
where y.b3 = 0x2f;
explain
select straight_join *
from t3 as x join t3 as y on x.d3 = y.d3
where y.b3 = 0x20+0x2f;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.d3 = y.d3
where y.b3 = 0x20+0x2f;
## Not pushable as 'not null' is actually not a single const value
--replace_column 10 # 11 #
explain
select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 is not null;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 is not null;
## Neither 'is null' pushable as uniqueness is not defined for null
## ... and null's are not present in the unique index
explain
select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 is null;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 is null;
explain
select straight_join *
from t3 as x join t3 as y on x.c3 = y.c3
where y.b3 = 0;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.c3 = y.c3
where y.b3 = 0;
## As 'b3' is defined as 'not null', this query will optimized as 'Impossible WHERE' (No push)
explain
select straight_join *
from t3 as x join t3 as y on x.c3 = y.c3
where y.b3 is null;
--sorted_result
select straight_join *
from t3 as x join t3 as y on x.c3 = y.c3
where y.b3 is null;
## Will break up query in 2 pushed joins.
## Last join (join t3 as y2) refer x1.c3 which will
## be handled as a constant paramValue wrt. scope of the
## second pushed join.
explain
select straight_join * from
t3 as x1
join t3 as y1 on y1.b3 = x1.b3 and y1.d3 = x1.d3
join t3 as x2 on x2.b3 = y1.b3+0
join t3 as y2 on y2.b3 = x2.c3 and y2.d3 = x1.c3;
--sorted_result
select straight_join * from
t3 as x1
join t3 as y1 on y1.b3 = x1.b3 and y1.d3 = x1.d3
join t3 as x2 on x2.b3 = y1.b3+0
join t3 as y2 on y2.b3 = x2.c3 and y2.d3 = x1.c3;
###########################
### Prepared statments ####
###########################
prepare stmt1 from
'select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 = 0x2f';
#execute multiple times
execute stmt1;
execute stmt1;
# Execute after drop expected to fail
drop prepare stmt1;
--error 1243
execute stmt1;
# Multiple prepare of same stmt should silently discard prev prepared stmt
prepare stmt1 from
'select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 = 0x2f';
prepare stmt1 from
'select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 = 0x2f';
drop prepare stmt1;
#Prepare explain'ed statement and execute it
prepare stmt1 from
'explain select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 = 0x2f';
execute stmt1;
execute stmt1;
#survives commit;
commit;
execute stmt1;
# Drop index used by query -> Query plan should change to unpushed join
connection ddl;
drop index b3 on t3;
connection spj;
--replace_column 10 # 11 #
execute stmt1;
# Then recreate it -> original query plan
connection ddl;
create unique index b3 on t3(b3,d3);
connection spj;
execute stmt1;
drop prepare stmt1;
### Prepared stmt with dynamic parameters ('?') ###
prepare stmt1 from
'explain select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 = ?';
set @a=47;
execute stmt1 using @a;
set @a=0;
execute stmt1 using @a;
set @a=null;
execute stmt1 using @a;
prepare stmt1 from
'select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3
where y.d3 = ?';
set @a=47;
execute stmt1 using @a;
set @a=0;
execute stmt1 using @a;
set @a=null;
execute stmt1 using @a;
prepare stmt1 from
'explain select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3 and x.d3 = y.d3
where x.a3 = ?';
set @a=47;
execute stmt1 using @a;
set @a=0;
execute stmt1 using @a;
set @a=null;
execute stmt1 using @a;
prepare stmt1 from
'select straight_join *
from t3 as x join t3 as y on x.b3 = y.b3 and x.d3 = y.d3
where x.a3 = ?';
set @a=47;
execute stmt1 using @a;
set @a=0;
execute stmt1 using @a;
set @a=null;
execute stmt1 using @a;
connection ddl;
drop table t3;
connection spj;
# Execute after table dropped should fail
set @a=47;
--error 1146
execute stmt1 using @a;
####################
# test index scan disguised as JT_ALL
connection ddl;
create table t1 (a int primary key, b int, c int, index(b,c)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (1,null, 2);
insert into t1 values (2,1, null);
insert into t1 values (3,2,2);
insert into t1 values (4,null, 2);
insert into t1 values (5,1, null);
insert into t1 values (6,2,2);
set ndb_join_pushdown=false;
--sorted_result
select *
from t1
join t1 as t2 on (t2.b = t1.b or t2.b = t1.a)
join t1 as t3 on t3.a = t2.a
join t1 as t4 on t4.a = t3.b /* index scan disguised as JT_ALL, pushdown=off */;
set ndb_join_pushdown=true;
explain
select *
from t1
join t1 as t2 on (t2.b = t1.b or t2.b = t1.a)
join t1 as t3 on t3.a = t2.a
join t1 as t4 on t4.a = t3.b /* index scan disguised as JT_ALL, pushdown=on */;
--sorted_result
select *
from t1
join t1 as t2 on (t2.b = t1.b or t2.b = t1.a)
join t1 as t3 on t3.a = t2.a
join t1 as t4 on t4.a = t3.b /* index scan disguised as JT_ALL, pushdown=on */;
## Test subquery execution where 'Full scan on null key' strategy requires
## table scan execution in addition to the key lookup which was prepared
## as part of the pushed join NdbQuery
explain
select *
from t1 where b in
(select x.a from t1 as x join t1 as y on (y.a = x.b))
xor c > 5;
--sorted_result
select *
from t1 where b in
(select x.a from t1 as x join t1 as y on (y.a = x.b))
xor c > 5;
##############
## Subqueries with EQ_REFs in subquery containing an outer referrences
## to 't1.b' should not be pushed as outer referrences are outside
## the scope of our JOIN_TAB's
##############
--replace_column 10 # 11 #
explain
select t1.a, (select straight_join x.a from t1 as x join t1 as y on x.a=y.b where y.a = t1.b) from t1;
--sorted_result
select t1.a, (select straight_join x.a from t1 as x join t1 as y on x.a=y.b where y.a = t1.b) from t1;
connection ddl;
drop table t1;
# mixed engines
connection ddl;
create table t1 (a int primary key, b int) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create table t2 (a int primary key, b int) engine = myisam;
connection spj;
insert into t1 values(1,1), (2,2), (3,3), (4,4);
insert into t2 values(1,1), (2,2), (3,3), (4,4);
explain
select * from t1, t2, t1 as t3
where t2.a = t1.b
and t3.a = t2.b /* mixed engines */;
--sorted_result
select * from t1, t2, t1 as t3
where t2.a = t1.b
and t3.a = t2.b /* mixed engines */;
connection ddl;
drop table t1, t2;
# Tables with blob, but not in the selected columns:
connection ddl;
create table t1 (a int primary key, b int, c blob) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create table t2 (a int primary key, b int) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (1,1, 'kalle');
insert into t1 values (2,1, 'kalle');
insert into t1 values (3,3, 'kalle');
insert into t1 values (4,1, 'kalle');
insert into t2 values (1,1);
insert into t2 values (2,1);
insert into t2 values (3,3);
insert into t2 values (4,1);
set ndb_join_pushdown=true;
explain
select t1.a, t1.b, t2.a, t2.b
from t1, t2
where t2.a = t1.b;
--sorted_result
select t1.a, t1.b, t2.a, t2.b
from t1, t2
where t2.a = t1.b;
explain
select t1.a, t1.b, t2.a, t2.b
from t1, t2
where t2.a = t1.b
and t1.a = 2;
--sorted_result
select t1.a, t1.b, t2.a, t2.b
from t1, t2
where t2.a = t1.b
and t1.a = 2;
explain
select t1.a, t1.b, t2.a, t2.b
from t1, t2
where t1.a = t2.b;
--sorted_result
select t1.a, t1.b, t2.a, t2.b
from t1, t2
where t2.a = t1.b;
explain
select t1.a, t1.b, t2.a, t2.b
from t1, t2
where t1.a = t2.b
and t2.a = 3;
--sorted_result
select t1.a, t1.b, t2.a, t2.b
from t1, t2
where t1.a = t2.b
and t2.a = 3;
#
# result sets contain blob
# i.e no push
explain
select *
from t1, t2
where t2.a = t1.b;
--sorted_result
select *
from t1, t2
where t2.a = t1.b;
explain
select *
from t1, t2
where t2.a = t1.b
and t1.a = 2;
--sorted_result
select *
from t1, t2
where t2.a = t1.b
and t1.a = 2;
explain
select *
from t1, t2
where t1.a = t2.b;
--sorted_result
select *
from t1, t2
where t2.a = t1.b;
explain
select *
from t1, t2
where t1.a = t2.b
and t2.a = 3;
--sorted_result
select *
from t1, t2
where t1.a = t2.b
and t2.a = 3;
connection ddl;
drop table t1, t2;
## Test usage of a constValue() as part of the EQ_REF key relating a child operation
## with its previous parents.
## All datatypes are tested in the section below
##
connection ddl;
create table t3 (a3 int, b3 tinyint, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3="63";
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3="63";
connection ddl;
drop table t3;
create table t3 (a3 int, b3 tinyint unsigned, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 smallint, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 smallint unsigned, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 mediumint, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 mediumint unsigned, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 int, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 int unsigned, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 bigint, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 bigint unsigned, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=(60+3);
connection ddl;
drop table t3;
create table t3 (a3 int, b3 boolean, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0, 1, 0x1f);
insert into t3 values (0x2f, 1, 2, 0x2f);
insert into t3 values (0x3f, 0, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=1;
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=1;
connection ddl;
drop table t3;
create table t3 (a3 int, b3 float, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 2.71, 1, 0x1f);
insert into t3 values (0x2f, 3.00, 2, 0x2f);
insert into t3 values (0x3f, 0.50, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.0;
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.0;
connection ddl;
drop table t3;
create table t3 (a3 int, b3 float unsigned, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 2.71, 1, 0x1f);
insert into t3 values (0x2f, 3.00, 2, 0x2f);
insert into t3 values (0x3f, 0.50, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.0;
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.0;
connection ddl;
drop table t3;
create table t3 (a3 int, b3 double, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 2.71, 1, 0x1f);
insert into t3 values (0x2f, 3.14, 2, 0x2f);
insert into t3 values (0x3f, 0.50, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.14;
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.14;
connection ddl;
drop table t3;
create table t3 (a3 int, b3 double unsigned, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 2.71, 1, 0x1f);
insert into t3 values (0x2f, 3.14, 2, 0x2f);
insert into t3 values (0x3f, 0.50, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.14;
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.14;
connection ddl;
drop table t3;
create table t3 (a3 int, b3 decimal, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=63;
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=63;
connection ddl;
drop table t3;
create table t3 (a3 int, b3 decimal(12,4), c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 2.71, 1, 0x1f);
insert into t3 values (0x2f, 3.14, 2, 0x2f);
insert into t3 values (0x3f, 0.50, 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.14;
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3=3.14;
connection ddl;
drop table t3;
create table t3 (a3 int, b3 date, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, '1905-05-17', 1, 0x1f);
insert into t3 values (0x2f, '2000-02-28', 2, 0x2f);
insert into t3 values (0x3f, '2000-02-29', 3, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='2000-02-28';
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='2000-02-28';
## Temp removed due to lack of DATETIME2 support
#connection ddl;
# drop table t3;
# create table t3 (a3 int, b3 datetime, c3 int not null, d3 int not null,
# primary key(a3,b3)) engine = ndb;
#connection spj;
# insert into t3 values (0x1f, '1905-05-17 12:30:00', 1, 0x1f);
# insert into t3 values (0x2f, '2000-02-28 23:59:00', 2, 0x2f);
# insert into t3 values (0x3f, '2000-02-29 12:59:59', 2, 0x3f);
# explain
# select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='2000-02-28 23:59';
# select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='2000-02-28 23:59';
#
#connection ddl;
# drop table t3;
# create table t3 (a3 int, b3 time, c3 int not null, d3 int not null,
# primary key(a3,b3)) engine = ndb;
#connection spj;
# insert into t3 values (0x1f, '12:30:00', 1, 0x1f);
# insert into t3 values (0x2f, '23:59:00', 2, 0x2f);
# insert into t3 values (0x3f, '12:59:59', 2, 0x3f);
# explain
# select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='23:59';
# select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='23:59';
connection ddl;
drop table t3;
create table t3 (a3 int, b3 char(16), c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 'Ole', 1, 0x1f);
insert into t3 values (0x2f, 'Dole', 2, 0x2f);
insert into t3 values (0x3f, 'Doffen', 2, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
connection ddl;
drop table t3;
create table t3 (a3 int, b3 varchar(16), c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 'Ole', 1, 0x1f);
insert into t3 values (0x2f, 'Dole', 2, 0x2f);
insert into t3 values (0x3f, 'Doffen', 2, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
connection ddl;
drop table t3;
create table t3 (a3 int, b3 varchar(512), c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 'Ole', 1, 0x1f);
insert into t3 values (0x2f, 'Dole', 2, 0x2f);
insert into t3 values (0x3f, 'Doffen', 2, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
connection ddl;
drop table t3;
create table t3 (a3 int, b3 binary(16), c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 'Ole', 1, 0x1f);
insert into t3 values (0x2f, 'Dole', 2, 0x2f);
insert into t3 values (0x3f, 'Doffen', 2, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
connection ddl;
drop table t3;
create table t3 (a3 int, b3 varbinary(16), c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 'Ole', 1, 0x1f);
insert into t3 values (0x2f, 'Dole', 2, 0x2f);
insert into t3 values (0x3f, 'Doffen', 2, 0x3f);
explain
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
select * from t3 x, t3 y where x.a3=0x2f and y.a3=x.d3 and y.b3='Dole';
connection ddl;
drop table t3;
## Joins where the datatype of the EQ_REF columns are not identical
## should not be pushed
##
connection ddl;
create table t3 (a3 int, b3 tinyint, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values (0x1f, 0x2f, 1, 0x1f);
insert into t3 values (0x2f, 0x3f, 2, 0x2f);
insert into t3 values (0x3f, 0x1f, 3, 0x3f);
explain
select * from t3 x, t3 y where y.a3=x.b3 and y.b3="63";
select * from t3 x, t3 y where y.a3=x.b3 and y.b3="63";
connection ddl;
drop table t3;
##
## Testing of varchar datatype as part of lookup key and index bounds.
## Need special attention due to the 'ShrinkVarchar' format used by mysqld.
connection ddl;
create table t3 (a3 varchar(16), b3 int, c3 int not null, d3 int not null,
primary key(a3,b3)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t3 values ('Ole', 0x1f, 1, 0x1f);
insert into t3 values ('Dole', 0x2f, 2, 0x2f);
insert into t3 values ('Doffen', 0x3f, 2, 0x3f);
# Varchar is lookup key
explain
select * from t3 x, t3 y where x.a3='Dole' and x.b3=0x2f and y.a3=x.a3 and y.b3=x.d3;
select * from t3 x, t3 y where x.a3='Dole' and x.b3=0x2f and y.a3=x.a3 and y.b3=x.d3;
# Varchar as hi/low bound
explain
select * from t3 x, t3 y where x.a3='Dole' and y.a3=x.a3 and y.b3=x.d3;
select * from t3 x, t3 y where x.a3='Dole' and y.a3=x.a3 and y.b3=x.d3;
connection ddl;
drop table t3;
connection ddl;
create table t1 (k int primary key, b int) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (1,1), (2,1), (3,1), (4,1);
## Pushed join driven by a scan, with cached row lookups:
## (Note: We force the Scan to not be pushed as the parent op
## by making the join condition on t2 a non-FIELD_ITEM ('t1.b+0')
## As all column 'b' has the same value (1), the scan will refer
## the same t2 (parent) row in every access. This will trigger the
## row caching in join_read_key() where we eliminate redundant lookups
## where 'next row == current row'. In order to work for linked operations,
## the value and status for all linked tables should be kept unaltered.
explain
select *
from t1
straight_join t1 as t2 on t2.k = t1.b+0
straight_join t1 as t3 on t3.k = t2.b
straight_join t1 as t4 on t4.k = t1.b;
--sorted_result
select *
from t1
straight_join t1 as t2 on t2.k = t1.b+0
straight_join t1 as t3 on t3.k = t2.b
straight_join t1 as t4 on t4.k = t1.b;
## Similar example as above, except that access to 't2' is made
## a const table access
explain
select *
from t1
straight_join t1 as t2 on t2.k = t1.b+0
straight_join t1 as t3 on t3.k = t2.b
straight_join t1 as t4 on t4.k = t1.b
where t2.k = 1;
--sorted_result
select *
from t1
straight_join t1 as t2 on t2.k = t1.b+0
straight_join t1 as t3 on t3.k = t2.b
straight_join t1 as t4 on t4.k = t1.b
where t2.k = 1;
connection ddl;
drop table t1;
##
# Try with higher row-count to test batching/flow control
#
--error 0,1193
set global debug='+d,max_64rows_in_spj_batches';
connection ddl;
create table t1 (
a int not null auto_increment,
b char(255) not null,
c int not null,
d char(255) not null,
primary key (`a`,`b`)
) engine=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
let $1=1000;
disable_query_log;
while ($1)
{
eval insert into t1(a,b,c,d) values
($1, 'a', $1, 'a'),($1, 'b', $1+1, 'b'),($1, 'c', $1-1, 'c');
dec $1;
}
enable_query_log;
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
join t1 as t3 on t3.a = t2.c and t3.b = t2.d;
select count(*)
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
join t1 as t3 on t3.a = t2.c and t3.b = t2.d;
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.c and t3.b = t2.d;
select count(*)
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.c and t3.b = t2.d;
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
join t1 as t3 on t3.a = t2.c;
select count(*)
from t1
join t1 as t2 on t2.a = t1.c and t2.b = t1.d
join t1 as t3 on t3.a = t2.c;
connection ddl;
alter table t1 partition by key(a);
connection spj;
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.c and t3.b = t2.d;
select count(*)
from t1
join t1 as t2 on t2.a = t1.c
join t1 as t3 on t3.a = t2.c and t3.b = t2.d;
connection ddl;
drop table t1;
--error 0,1193
set global debug=@save_debug;
# Pushed join accessing disk data.
connection ddl;
create logfile group lg1
add undofile 'undofile.dat'
initial_size 1m
undo_buffer_size = 1m
engine=ndb;
create tablespace ts1
add datafile 'datafile.dat'
use logfile group lg1
initial_size 6m
engine ndb;
create table t1 (a int not null,
b int not null storage disk,
c int not null storage memory,
primary key(a))
tablespace ts1 storage disk engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (10, 11, 11);
insert into t1 values (11, 12, 12);
insert into t1 values (12, 13, 13);
connection ddl;
create table t2 (a int not null,
b int not null, primary key(a)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t2 values (10, 11);
insert into t2 values (11, 12);
insert into t2 values (12, 13);
# Disk data in projection of first op.
explain select * from t1, t2 where t1.c = t2.a;
--sorted_result
select * from t1, t2 where t1.c = t2.a;
explain select * from t1, t2 where t1.a=11 and t1.c = t2.a;
select * from t1, t2 where t1.a=11 and t1.c = t2.a;
# Disk data in projection of second op.
explain select * from t2, t1 where t2.b = t1.a;
--sorted_result
select * from t2, t1 where t2.b = t1.a;
explain select * from t2, t1 where t2.a=11 and t2.b = t1.a;
select * from t2, t1 where t2.a=11 and t2.b = t1.a;
# Disk data in predicate but not in projection
explain select t1.a, t1.c, t2.a, t2.b from t1, t2 where t1.b = t2.a;
--sorted_result
select t1.a, t1.c, t2.a, t2.b from t1, t2 where t1.b = t2.a;
explain select t1.a, t1.c, t2.a, t2.b from t1, t2 where t1.a=11 and t1.b = t2.a;
select t1.a, t1.c, t2.a, t2.b from t1, t2 where t1.a=11 and t1.b = t2.a;
connection ddl;
drop table t1;
drop table t2;
alter tablespace ts1
drop datafile 'datafile.dat';
drop tablespace ts1;
drop logfile group lg1
engine ndb;
connection spj;
# Store old counter values.
connection ddl;
create temporary table old_count
select counter_name, sum(val) as val
from ndbinfo.counters
where block_name='DBSPJ'
group by counter_name;
connection ddl;
# Specify number of partition to be independent of configured #LDM's
create table t1 (a int not null,
b int not null,
c int not null,
primary key(a))
engine = ndb
partition by key() partitions 8;
connection spj;
# We use key values that have the same representation in little and big endian.
# Otherwise, the numbers for local and remote reads may depend on endian-ness,
# since hashing is endian dependent.
insert into t1 values (1, 2, 2);
insert into t1 values (2, 3, 3);
insert into t1 values (3, 4, 4);
# Run some queries that should increment the counters.
select * from t1 t1, t1 t2 where t1.a = 2 and t2.a = t1.b;
select count(*) from t1 t1, t1 t2 where t2.a = t1.b;
select count(*) from t1 t1, t1 t2 where t1.a >= 2 and t2.a = t1.b;
# Get new counter values.
connection ddl;
create temporary table new_count
select counter_name, sum(val) as val
from ndbinfo.counters
where block_name='DBSPJ'
group by counter_name;
# Compute the difference.
--sorted_result
select new_count.counter_name, new_count.val - old_count.val
from new_count, old_count
where new_count.counter_name = old_count.counter_name
and new_count.counter_name <> 'LOCAL_READS_SENT'
and new_count.counter_name <> 'REMOTE_READS_SENT';
select 'READS_SENT', sum(new_count.val - old_count.val)
from new_count, old_count
where new_count.counter_name = old_count.counter_name
and (new_count.counter_name = 'LOCAL_READS_SENT'
or new_count.counter_name = 'REMOTE_READS_SENT');
connection ddl;
drop table old_count;
drop table new_count;
drop table t1;
### Test that scan filters are used for pushed operations.
connection ddl;
create table t1 (
a int primary key,
b int,
c int) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (1, 2, 3);
insert into t1 values (2, 3, 4);
insert into t1 values (3, 4, 5);
# Find the total number of lookups issued by the SPJ blocks.
let $spj_lookups = query_get_value(select sum(val) as Value from ndbinfo.counters where block_name='DBSPJ' and (counter_name='LOCAL_READS_SENT' or counter_name='REMOTE_READS_SENT'), Value, 1);
# Root scan should give only one tuple if scan filter is pushed.
# Therefore only one lookup on 'y'.
--replace_column 10 # 11 #
explain select * from t1 x, t1 y where x.b=y.a and x.c=4;
select * from t1 x, t1 y where x.b=y.a and x.c=4;
--disable_query_log
--eval select sum(val) - $spj_lookups as lookups from ndbinfo.counters where block_name='DBSPJ' and (counter_name='LOCAL_READS_SENT' or counter_name='REMOTE_READS_SENT')
--enable_query_log
# Lookup on y should only give one result tuple if filter is pushed.
# This should give 3 lookups on 'y' and 1 on 'z', 4 in all.
--replace_column 10 # 11 #
explain select * from t1 x, t1 y, t1 z where x.b=y.a and y.c=4 and y.b=z.a;
select * from t1 x, t1 y, t1 z where x.b=y.a and y.c=4 and y.b=z.a;
--disable_query_log
--eval select sum(val) - $spj_lookups as lookups from ndbinfo.counters where block_name='DBSPJ' and (counter_name='LOCAL_READS_SENT' or counter_name='REMOTE_READS_SENT')
--enable_query_log
connection ddl;
drop table t1;
# Test and server status variables (i.e. mysqld counters)
connection ddl;
create table t1(
a int not null,
b int not null,
c int not null,
primary key(a,b))
engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM"
partition by key (a);
connection spj;
insert into t1 values (10, 10, 11);
insert into t1 values (11, 11, 12);
insert into t1 values (12, 12, 13);
# First query against a new table causes an extra scan (of a dictionaty table??)
# so adding an extra scan here to make results from the following part easier
# to interpret.
select * from t1 t1, t1 t2
where t1.a = 10 and t1.b = 10 and
t2.a = t1.c and t2.b = t1.c;
# Save old counter values.
# Save old mysqld counter values.
create temporary table server_counts
select * from performance_schema.global_status
where variable_name in
('Ndb_scan_count',
'Ndb_pruned_scan_count',
'Ndb_sorted_scan_count',
'Ndb_pushed_queries_defined',
'Ndb_pushed_queries_dropped',
'Ndb_pushed_reads');
# Run some queries that should increment the counters.
# This query should push a single read.
select * from t1 t1, t1 t2
where t1.a = 11 and t1.b = 11 and
t2.a = t1.c and t2.b = t1.c;
# This query should push a sorted scan (and three reads).
select * from t1 t1, t1 t2
where t2.a = t1.c and t2.b = t1.c
order by t1.a;
# This query should push a pruned scan (but pruning must be fixed for
# pushed scans.)
select count(*) from t1 t1, t1 t2
where t1.a = 11 and
t2.a = t1.c and t2.b = t1.c;
# Calculate the change in mysqld counters.
select new.variable_name, new.variable_value - old.variable_value
from server_counts as old,
performance_schema.global_status as new
where new.variable_name = old.variable_name
order by new.variable_name;
drop table server_counts;
connection ddl;
drop table t1;
# Test scan pruning
connection ddl;
create table t1(
d int not null,
c int not null,
a int not null,
b int not null,
primary key using hash (a,b))
engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM"
partition by key (a);
connection spj;
insert into t1(a,b,c,d) values (10, 10, 11, 11);
insert into t1(a,b,c,d) values (11, 11, 12, 12);
insert into t1(a,b,c,d) values (12, 12, 13, 13);
let $old_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
# Should give pruned scan.
connection ddl;
create index i1 on t1(c,a);
connection spj;
select count(*) from t1 t1, t1 t2 where t1.c = 12 and t1.a = 11 and t2.a = t1.d and t2.b = t1.d;
connection ddl;
drop index i1 on t1;
connection spj;
--disable_query_log
let $new_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--eval select $new_pruned_scan_count - $old_pruned_scan_count as pruned_scan_count
let $old_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--enable_query_log
# Should give pruned scan. There is a one sided limit for t1.b, but this is
# after the partition key prefix.
connection ddl;
create index i2 on t1(a,b);
connection spj;
select count(*) from t1 t1, t1 t2 where t1.a = 11 and t1.b<13 and t2.a = t1.c and t2.b = t1.c;
--disable_query_log
let $new_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--eval select $new_pruned_scan_count - $old_pruned_scan_count as pruned_scan_count
let $old_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--enable_query_log
# Should give pruned scan. Upper and lower bounds for t1.a are the sane.
select count(*) from t1 t1, t1 t2 where t1.a >= 12 and t1.a<=12 and t2.a = t1.c and t2.b = t1.c;
--disable_query_log
let $new_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--eval select $new_pruned_scan_count - $old_pruned_scan_count as pruned_scan_count
let $old_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--enable_query_log
# Should not give pruned scan. Upper and lower bounds for t1.a are different.
select count(*) from t1 t1, t1 t2 where t1.a >= 11 and t1.a<=12 and t2.a = t1.c and t2.b = t1.c;
--disable_query_log
let $new_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--eval select $new_pruned_scan_count - $old_pruned_scan_count as pruned_scan_count
let $old_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--enable_query_log
# Should not give pruned scan. There will be two sets of bounds that have
# different distribution keys (t1.a=10 and t1.a=12).
select count(*) from t1 t1, t1 t2 where (t1.a = 10 or t1.a=12) and t1.b<13 and t2.a = t1.c and t2.b = t1.c;
--disable_query_log
let $new_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--eval select $new_pruned_scan_count - $old_pruned_scan_count as pruned_scan_count
let $old_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--enable_query_log
# Should give pruned scan. There will be two sets of bounds, but they have the
# same distribution key.
select count(*) from t1 t1, t1 t2 where t1.a = 10 and (t1.b<11 or t1.b>11) and t2.a = t1.c and t2.b = t1.c;
--disable_query_log
let $new_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--eval select $new_pruned_scan_count - $old_pruned_scan_count as pruned_scan_count
let $old_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--enable_query_log
connection ddl;
drop table t1;
create table t2(
d int not null,
e int not null,
f int not null,
a int not null,
b int not null,
c int not null,
primary key using hash (a,b,c))
engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM"
partition by key (b,a);
connection spj;
insert into t2(a,b,c,d,e,f) values (1, 2, 3, 1, 2, 3);
insert into t2(a,b,c,d,e,f) values (1, 2, 4, 1, 2, 3);
insert into t2(a,b,c,d,e,f) values (2, 3, 4, 1, 2, 3);
insert into t2(a,b,c,d,e,f) values (3, 4, 5, 1, 2, 3);
insert into t2(a,b,c,d,e,f) values (4, 5, 6, 1, 2, 3);
insert into t2(a,b,c,d,e,f) values (5, 6, 7, 1, 2, 3);
insert into t2(a,b,c,d,e,f) values (6, 7, 8, 1, 2, 3);
insert into t2(a,b,c,d,e,f) values (7, 8, 9, 1, 2, 3);
connection ddl;
create index i2_1 on t2(d, a, b, e);
connection spj;
# Should give pruned scan. The index prefix containing the distribution key
# has a single possible value.
select count(*) from t2 x, t2 y where x.d=1 and x.a=1 and x.b=2 and y.a=x.d and y.b=x.e and y.c=3;
--disable_query_log
let $new_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--eval select $new_pruned_scan_count - $old_pruned_scan_count as pruned_scan_count
let $old_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--enable_query_log
connection ddl;
drop index i2_1 on t2;
create index i2_3 on t2(a, d, b, e);
connection spj;
# Should give pruned scan. The index prefix containing the distribution key
# has a single possible value.
# Turn off condition_fanout_filter to keep "old" QEP
set optimizer_switch='condition_fanout_filter=off';
select count(*) from t2 x, t2 y where x.d=1 and x.a=1 and x.b=2 and y.a=x.d and y.b=x.e and y.c=3;
# Restore condition_fanout_filter to default value
set optimizer_switch='condition_fanout_filter=default';
--disable_query_log
let $new_pruned_scan_count = query_get_value(show status like 'Ndb_pruned_scan_count', Value, 1);
--eval select $new_pruned_scan_count - $old_pruned_scan_count as pruned_scan_count
--enable_query_log
connection ddl;
drop table t2;
connection ddl;
create table t1 (a binary(10) primary key, b binary(10) not null) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values ('\0123456789', '1234567890');
insert into t1 values ('1234567890', '\0123456789');
explain
select count(*)
from t1 join t1 as t2 on t2.a = t1.b
where t1.a = '\0123456789';
select count(*)
from t1 join t1 as t2 on t2.a = t1.b
where t1.a = '\0123456789';
connection ddl;
drop table t1;
# Tests for some bugfixes which have been cherry picked from 5.1 main
# Not necessarily test of SPJ functionality, but may test optimizer
# behaviour which we depend on when doing RQG testing
# We can remove these testcases when fixes - and propper MTR testcases -
# Have been merged from 5.1 main branch.
connection ddl;
create table t1 (pk int primary key, a int unique key) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (1,10), (2,20), (3,30);
set ndb_join_pushdown = false;
# Bug#53334:
# Join should be optimized as 'Impossible On condition'
# ... *not* 'Impossible WHERE'
explain
select * from t1 as x right join t1 as y
on x.pk = y.pk
and x.pk = y.a
and x.a = y.pk
where y.pk = 2;
select * from t1 as x right join t1 as y
on x.pk = y.pk
and x.pk = y.a
and x.a = y.pk
where y.pk = 2;
set ndb_join_pushdown = true;
explain
select * from t1 as x right join t1 as y
on x.pk = y.pk
and x.pk = y.a
and x.a = y.pk
where y.pk = 2;
select * from t1 as x right join t1 as y
on x.pk = y.pk
and x.pk = y.a
and x.a = y.pk
where y.pk = 2;
connection ddl;
drop table t1;
#########################################
# Test section for scan-child operations
#########################################
# Test scan-lookup-scan query (see http://lists.mysql.com/commits/115164)
connection ddl;
create table t1 (pk int primary key, u int not null, a int, b int) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create index ix1 on t1(b,a);
connection spj;
insert into t1 values (0,1,10,20);
insert into t1 values (1,2,20,30);
insert into t1 values (2,3,30,40);
--replace_column 10 # 11 #
explain select * from t1 as x join t1 as y join t1 as z on x.u=y.pk and y.a=z.b;
--sorted_result
select * from t1 as x join t1 as y join t1 as z on x.u=y.pk and y.a=z.b;
connection ddl;
drop table t1;
# Test sorted scan where inner join eliminates all rows (known regression).
connection ddl;
create table t1 (pk int primary key, u int not null) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (0,-1), (1,-1), (2,-1), (3,-1), (4,-1), (5,-1), (6,-1),
(7,-1), (8,-1), (9,-1), (10,-1), (11,-1), (12,-1), (13,-1), (14,-1), (15,-1),
(16,-1), (17,-1), (18,-1), (19,-1), (20,-1), (21,-1), (22,-1), (23,-1),
(24,-1), (25,-1), (26,-1), (27,-1), (28,-1), (29,-1), (30,-1), (31,-1),
(32,-1), (33,-1), (34,-1), (35,-1), (36,-1), (37,-1), (38,-1), (39,-1),
(40,-1), (41,-1), (42,-1), (43,-1), (44,-1), (45,-1), (46,-1), (47,-1),
(48,-1), (49,-1), (50,-1), (51,-1), (52,-1), (53,-1), (54,-1), (55,-1),
(56,-1), (57,-1), (58,-1), (59,-1), (60,-1), (61,-1), (62,-1), (63,-1),
(64,-1), (65,-1), (66,-1), (67,-1), (68,-1), (69,-1), (70,-1), (71,-1),
(72,-1), (73,-1), (74,-1), (75,-1), (76,-1), (77,-1), (78,-1), (79,-1),
(80,-1), (81,-1), (82,-1), (83,-1), (84,-1), (85,-1), (86,-1), (87,-1),
(88,-1), (89,-1), (90,-1), (91,-1), (92,-1), (93,-1), (94,-1), (95,-1),
(96,-1), (97,-1), (98,-1), (99,-1), (100,-1), (101,-1), (102,-1), (103,-1),
(104,-1), (105,-1), (106,-1), (107,-1), (108,-1), (109,-1), (110,-1),
(111,-1), (112,-1), (113,-1), (114,-1), (115,-1), (116,-1), (117,-1),
(118,-1), (119,-1), (120,-1), (121,-1), (122,-1), (123,-1), (124,-1),
(125,-1), (126,-1), (127,-1), (128,-1), (129,-1), (130,-1), (131,-1),
(132,-1), (133,-1), (134,-1), (135,-1), (136,-1), (137,-1), (138,-1), (139,-1);
--error 0,1193
set global debug='+d,max_64rows_in_spj_batches';
explain select * from t1 as x join t1 as y on x.u=y.pk order by(x.pk);
select * from t1 as x join t1 as y on x.u=y.pk order by(x.pk);
--error 0,1193
set global debug=@save_debug;
connection ddl;
drop table t1;
# Test query using "scan -> unique index lookup -> index scan".
connection ddl;
create table t1 (pk int primary key, u int not null, a int, b int) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create index ix1 on t1(b,a);
create unique index ix2 on t1(u);
connection spj;
insert into t1 values (0,0,10,10);
insert into t1 values (1,1,10,10);
insert into t1 values (2,2,10,10);
insert into t1 values (3,3,10,10);
insert into t1 values (4,4,10,10);
insert into t1 values (5,5,10,10);
insert into t1 values (6,6,10,10);
insert into t1 values (7,7,10,10);
insert into t1 values (8,8,10,10);
insert into t1 values (9,9,10,10);
insert into t1 values (10,10,10,10);
insert into t1 values (11,11,10,10);
explain select count(*) from t1 as x1 join t1 as x2 join t1 as x3
on x1.a=x2.u and x2.a = x3.b;
select count(*) from t1 as x1 join t1 as x2 join t1 as x3
on x1.a=x2.u and x2.a = x3.b;
explain select count(*) from t1 as x1, t1 as x2, t1 as x3
where x1.u=x2.pk and x1.a=x3.b;
select count(*) from t1 as x1, t1 as x2, t1 as x3
where x1.u=x2.pk and x1.a=x3.b;
# Regression test for commit http://lists.mysql.com/commits/116372
# (missing rows in left join query with multiple result batches).
insert into t1 values (12,12,20,10);
explain select count(*) from t1 as x1 left join t1 as x2 on x1.a=x2.b;
select count(*) from t1 as x1 left join t1 as x2 on x1.a=x2.b;
set ndb_join_pushdown=off;
select count(*) from t1 as x1 left join t1 as x2 on x1.a=x2.b;
set ndb_join_pushdown=on;
# Test left join with mix of scan and lookup.
explain select count(*) from t1 as x1
left join t1 as x2 on x1.u=x2.pk
left join t1 as x3 on x2.a=x3.b;
select count(*) from t1 as x1
left join t1 as x2 on x1.u=x2.pk
left join t1 as x3 on x2.a=x3.b;
set ndb_join_pushdown=off;
select count(*) from t1 as x1
left join t1 as x2 on x1.u=x2.pk
left join t1 as x3 on x2.a=x3.b;
set ndb_join_pushdown=on;
explain select count(*) from t1 as x1
left join t1 as x2 on x1.u=x2.pk
left join t1 as x3 on x2.a=x3.b
left join t1 as x4 on x3.u=x4.pk
left join t1 as x5 on x4.a=x5.b;
select count(*) from t1 as x1
left join t1 as x2 on x1.u=x2.pk
left join t1 as x3 on x2.a=x3.b
left join t1 as x4 on x3.u=x4.pk
left join t1 as x5 on x4.a=x5.b;
set ndb_join_pushdown=off;
select count(*) from t1 as x1
left join t1 as x2 on x1.u=x2.pk
left join t1 as x3 on x2.a=x3.b
left join t1 as x4 on x3.u=x4.pk
left join t1 as x5 on x4.a=x5.b;
set ndb_join_pushdown=on;
############################
# Testcase for 'Got error 20002 'Unknown error code' from NDBCLUSTER'
# Caused by failure to identify AT_MULTI_PRIMARY_KEY as a lookup operation.
# This in turn caused a pushed 'lookup-scan' query to be produced - which we don't support
# Should not be pushed (lookup-scan query)
explain select count(*) from t1 as x1
join t1 as x2 on x1.a=x2.b
where x1.pk = 1 or x1.u=1;
select count(*) from t1 as x1
join t1 as x2 on x1.a=x2.b
where x1.pk = 1 or x1.u=1;
############################
# Testcase which forced us to ditch using the 'global cursor'
# on the NdbQuery result set from mysqld.
#
# As the global cursor will fool mysqld into handling the resultset
# as a result from a scan - n*lookup query, incorrect cardinality on the
# parent operation was perceived. Which caused extra null-joined outer rows
# to be emitted in this testcase.
#
# Refactored handler interface and SPJ API use subcursor on each operation
# which correctly preserves the dependency between the parent subscans
# and its child(s).
--error 0,1193
set global debug='+d,max_4rows_in_spj_batches';
set ndb_join_pushdown=on;
explain
select straight_join * from t1 as table1
left join
(t1 as table2 join t1 as table3 on table2.pk = table3.b)
on table1.pk = table2.b;
--sorted_result
select straight_join * from t1 as table1
left join
(t1 as table2 join t1 as table3 on table2.pk = table3.b)
on table1.pk = table2.b;
--error 0,1193
set global debug=@save_debug;
#############
# Testcase for 'sledgehammer' fix for scan -> outer join scan:
# Pushing of outer joined has to be dissabled as incomplete child batches
# may cause the parent row to be returned multiple times:
# Push scan-scan when inner joined
explain select straight_join * from t1 as x1
inner join t1 as x2 on x2.b = x1.a;
# Outer joined scans are not pushed.
explain select straight_join * from t1 as x1
left join t1 as x2 on x2.b = x1.a;
explain select straight_join * from t1 as x1
right join t1 as x2 on x2.b = x1.a;
# If there is a lookup operation(s) inbetween the scans
# pushing is disabled if any of these are outer joined
# inner joined lookups, push allowed
explain select straight_join * from
t1 as x1 inner join
(t1 as x2 inner join t1 as x3 on x3.b = x2.a)
on x2.pk = x1.a;
# Even if x3 is inner joined with x2 (lookup)
# push is dissabled as x2 is outer joined with embedding scan operation
# which makes join relation between the scans on x1 & x3 an 'indirect' outer join
explain select straight_join * from
t1 as x1 left join
(t1 as x2 inner join t1 as x3 on x3.b = x2.a)
on x2.pk = x1.a;
#############
# Test bushy-scans:
# These should be allowed to be executed in 'parallel', depending on
# only the root operation
#
explain select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.b = x1.b;
set ndb_join_pushdown=off;
select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.b = x1.b;
set ndb_join_pushdown=on;
select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.b = x1.b;
# A really bushy scan - would take almost forever to execute if
# we had to force the child scan to be non-bushy (serialized by
# adding artificial parent dependencies)
#
--replace_column 10 # 11 #
explain select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.b = x1.a
join t1 as x4 on x4.b = x1.a
join t1 as x5 on x5.b = x1.a
join t1 as x6 on x6.b = x1.a
join t1 as x7 on x7.b = x1.a
where x3.a < x2.pk and x4.a < x3.pk;
# set '64rows' in order to avoid to small batches which will
# cause all subscans to be repeated... and repeated... and
--error 0,1193
set global debug='+d,max_64rows_in_spj_batches';
select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.b = x1.a
join t1 as x4 on x4.b = x1.a
join t1 as x5 on x5.b = x1.a
join t1 as x6 on x6.b = x1.a
join t1 as x7 on x7.b = x1.a
where x3.a < x2.pk and x4.a < x3.pk;
--error 0,1193
set global debug=@save_debug;
#############
# If we have an outer join, we can't create an artificial dep. 'through' the outer join.
# In this case the child scan can't be part of the pushed query.
#
explain select straight_join count(*) from t1 as x1
left join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.b = x1.b;
set ndb_join_pushdown=off;
select straight_join count(*) from t1 as x1
left join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.b = x1.b;
set ndb_join_pushdown=on;
select straight_join count(*) from t1 as x1
left join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.b = x1.b;
############
# However, When the scanchild itself is an outer join, we *can* push that scan operation
#
explain select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
left join t1 as x3 on x3.b = x1.b;
set ndb_join_pushdown=off;
select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
left join t1 as x3 on x3.b = x1.b;
set ndb_join_pushdown=on;
select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
left join t1 as x3 on x3.b = x1.b;
##############
# If we have a bushy lookup, with scandescendants depending on these lookups,
# the query is 'scan-bushy' through these lookups.
#
# Bushy execution is expected for these scans (x2 & x4) wrt. root (x1)
#
explain
select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.pk = x1.a join t1 as x4 on x4.b = x3.a;
set ndb_join_pushdown=off;
select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.pk = x1.a join t1 as x4 on x4.b = x3.a;
set ndb_join_pushdown=on;
select straight_join count(*) from t1 as x1
join t1 as x2 on x2.b = x1.a
join t1 as x3 on x3.pk = x1.a join t1 as x4 on x4.b = x3.a;
#############
# Test bushy lookups + 1scan,
# (Regression test for previous commit: http://lists.mysql.com/commits/117571)
# Repeatable child rangescan with same parent should be allowed to be in
# 'm_iterState != Iter_finished' if the child row didn't exist (outer join):
explain select straight_join count(*) from t1 as x1
left join t1 as x3 on x3.b = x1.a
join t1 as x2 on x2.pk = x1.a;
select straight_join count(*) from t1 as x1
left join t1 as x3 on x3.b = x1.a
join t1 as x2 on x2.pk = x1.a;
# Modify rows to force null rows from outer join
update t1 set b=b+10;
select straight_join count(*) from t1 as x1
left join t1 as x3 on x3.b = x1.a
join t1 as x2 on x2.pk = x1.a;
#Undo update
update t1 set b=b-10;
##############
# Testcase for: http://lists.mysql.com/commits/118917
# There used to be a bug in SPJ API resulthandling of incomplete
# child batches where we tested for incomplete fetch for any
# childs (in a bushy scan) instead if this particular child batch
# being incomplete.
#
# In this testcase (x inner join y) will have incomplete
# childbatches, while (x left join z) will be complete.
# Modify rows to force null rows from lookup(z) below
update t1 set u=u+100;
set ndb_join_pushdown=on;
--error 0,1193
set global debug='+d,max_64rows_in_spj_batches';
explain select straight_join count(*) from
(t1 as x join t1 as y on y.b = x.a)
left outer join t1 as z on z.u = x.a;
select straight_join count(*) from
(t1 as x join t1 as y on y.b = x.a)
left outer join t1 as z on z.u = x.a;
--error 0,1193
set global debug=@save_debug;
#Undo update
update t1 set u=u-100;
#############
# Additional testcase added as part of WL introducing equi-join
# non-matching row elimination optimizations into the SPJ block
# Test query topology which lacked coverage. (Found to fail
# in manual or RQG testing)
# Modify rows to force null rows from outer joined lookup below
update t1 set a=a+pk;
set ndb_join_pushdown=on;
explain
select straight_join count(*) from t1 as x
left join t1 as y on y.pk = x.a
join t1 as z on z.b = x.b;
--sorted_result
select straight_join count(*) from t1 as x
left join t1 as y on y.pk = x.a
join t1 as z on z.b = x.b;
explain
select straight_join count(*) from t1 as x
left join t1 as y1 on y1.pk = x.a
left join t1 as y2 on y2.pk = x.a
join t1 as z on z.b = x.b;
--sorted_result
select straight_join count(*) from t1 as x
left join t1 as y1 on y1.pk = x.a
left join t1 as y2 on y2.pk = x.a
join t1 as z on z.b = x.b;
explain
select straight_join count(*) from t1 as x
join t1 as y1 on y1.pk = x.a
left join t1 as y2 on y2.pk = x.a
join t1 as z on z.b = x.b;
--sorted_result
select straight_join count(*) from t1 as x
join t1 as y1 on y1.pk = x.a
left join t1 as y2 on y2.pk = x.a
join t1 as z on z.b = x.b;
explain
select straight_join count(*) from t1 as x
left join t1 as y1 on y1.pk = x.a
join t1 as y2 on y2.pk = x.a
join t1 as z on z.b = x.b;
--sorted_result
select straight_join count(*) from t1 as x
left join t1 as y1 on y1.pk = x.a
join t1 as y2 on y2.pk = x.a
join t1 as z on z.b = x.b;
explain
select straight_join count(*) from t1 as x
left join (t1 as y join t1 as yy on yy.pk=y.u) on y.pk = x.a
join t1 as z on z.b = x.b;
--sorted_result
select straight_join count(*) from t1 as x
left join (t1 as y join t1 as yy on yy.pk=y.u) on y.pk = x.a
join t1 as z on z.b = x.b;
explain
select straight_join count(*) from t1 as x
join t1 as z on z.b = x.b
left join t1 as y on y.pk = x.a;
--sorted_result
select straight_join count(*) from t1 as x
join t1 as z on z.b = x.b
left join t1 as y on y.pk = x.a;
explain
select straight_join count(*) from t1 as x
left join t1 as y1 on y1.pk = x.a
left join t1 as y2 on y2.pk = x.a
left join t1 as y3 on y3.pk = x.a;
--sorted_result
select straight_join count(*) from t1 as x
left join t1 as y1 on y1.pk = x.a
left join t1 as y2 on y2.pk = x.a
left join t1 as y3 on y3.pk = x.a;
explain
select straight_join count(*) from t1 as x
left join t1 as y on y.pk = x.a
left join t1 as z on z.pk = x.a
left join t1 as y1 on y1.pk = y.b;
--sorted_result
select straight_join count(*) from t1 as x
left join t1 as y on y.pk = x.a
left join t1 as z on z.pk = x.a
left join t1 as y1 on y1.pk = y.b;
explain
select straight_join count(*) from t1 as x
join t1 as y on y.pk = x.a
left join t1 as y1 on y1.pk = y.b
left join t1 as z on z.pk = x.b;
--sorted_result
select straight_join count(*) from t1 as x
join t1 as y on y.pk = x.a
left join t1 as y1 on y1.pk = y.b
left join t1 as z on z.pk = x.b;
explain
select straight_join count(*) from t1 as x
left join t1 as y1 on y1.pk = x.a
join t1 as y2 on y2.pk = x.b
join t1 as z on z.b = y2.b;
--sorted_result
select straight_join count(*) from t1 as x
left join t1 as y1 on y1.pk = x.a
join t1 as y2 on y2.pk = x.b
join t1 as z on z.b = y2.b;
#undo update
update t1 set a=a-pk;
##############
connection ddl;
drop index ix2 on t1;
create unique index ix2 on t1(a,u);
connection spj;
set ndb_join_pushdown=on;
explain
select straight_join * from
t1 as table1 join
(t1 as table2 join t1 as table3 on table3.a = table2.a)
on table3.u = table1.u
where table2.pk = 3;
--sorted_result
select straight_join * from
t1 as table1 join
(t1 as table2 join t1 as table3 on table3.a = table2.a)
on table3.u = table1.u
where table2.pk = 3;
##############
connection ddl;
drop table t1;
##############
# Test that branches of a bushy scan are correctly reset.
connection ddl;
CREATE TABLE t1 (
a int NOT NULL,
b int NOT NULL,
c int NOT NULL,
d int NOT NULL,
PRIMARY KEY (`a`,`b`)
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values (1,1,1,1), (1,2,1,1), (1,3,1,1), (1,4,1,2);
connection ddl;
CREATE TABLE t2 (
a int NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
CREATE TABLE t3 (
a int NOT NULL,
b int NOT NULL,
PRIMARY KEY (`a`,`b`)
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection ddl;
insert into t2 values (0), (1), (2), (3), (4), (5), (6), (7), (8), (9);
connection spj;
# Make t3 so big that it takes multiple batches to scan it.
insert into t3 select 1, x1.a * 10+x2.a from t2 as x1 cross join t2 as x2;
--error 0,1193
set global debug='+d,max_64rows_in_spj_batches';
explain select straight_join count(*) from t1 as x0
join t3 as x1 on x1.a=x0.c
join t1 as x2 on x2.a=x0.d
join t3 as x3 on x3.a=x2.c
join t1 as x4 on x4.a=x0.d and x4.b=x3.b;
select straight_join count(*) from t1 as x0
join t3 as x1 on x1.a=x0.c
join t1 as x2 on x2.a=x0.d
join t3 as x3 on x3.a=x2.c
join t1 as x4 on x4.a=x0.d and x4.b=x3.b;
# If the first batch of an index scan has low parallelism and returns few rows,
# there is a mechanism that will try to query the remaining fragments within
# the same batch. This is done in order to avoid repeating other branches of
# a bushy scan whenever possible. This is a test of that mechanism. Scan
# of x2 should return only one row. Therefore we should be able to fetch
# x2 in one batch and scan x3 only once.
let $scan_rows = query_get_value(select sum(val) as Value from ndbinfo.counters where block_name='DBSPJ' and counter_name='LOCAL_RANGE_SCANS_SENT', Value, 1);
--replace_column 10 # 11 #
explain select straight_join count(*) from t1 as x1
join t1 as x2 on x1.c=x2.a and x2.d=2
join t3 as x3 on x1.d=x3.a;
select straight_join count(*) from t1 as x1
join t1 as x2 on x1.c=x2.a and x2.d=2
join t3 as x3 on x1.d=x3.a;
#####
# Bug #18175080
# INCORRECT 'LOCAL_RANGE_SCAN' REPORTED FROM NDB_JOIN_PUSHDOWN_*.TEST
#
# Reported local_range_scan was not deterministic, so had
# to disable this subtest.
#
#--disable_query_log
#--eval select sum(val) - $scan_rows as Local_range_scans from ndbinfo.counters where block_name='DBSPJ' and counter_name='LOCAL_RANGE_SCANS_SENT';
#--enable_query_log
--error 0,1193
set global debug=@save_debug;
connection ddl;
drop table t1;
drop table t2;
drop table t3;
#############################################
# Test pruned index scan:
connection ddl;
create table t1(
d int not null,
e int null,
f int null,
a int not null,
b int not null,
c int not null,
primary key (a,b,c))
engine = ndb partition by key (b) partitions 8;
connection spj;
insert into t1(a,b,c,d,e,f) values
(1, 2, 3, 1, 2, 3),
(1, 2, 4, 1, 2, 3),
(2, 3, 4, 1, 2, 3),
(3, 4, 5, 1, 2, 3),
(4, 5, 6, 1, 2, 3),
(5, 6, 7, 1, 2, 3),
(6, 7, 8, 1, 2, 3),
(7, 8, 9, 1, 2, 3);
# Find the total number of pruned range scans so far
let $pruned_range = query_get_value(select sum(val) as Value from ndbinfo.counters where block_name='DBSPJ' and counter_name='PRUNED_RANGE_SCANS_RECEIVED', Value, 1);
let $const_pruned_range = query_get_value(select sum(val) as Value from ndbinfo.counters where block_name='DBSPJ' and counter_name='CONST_PRUNED_RANGE_SCANS_RECEIVED', Value, 1);
set ndb_join_pushdown=on;
--replace_column 10 # 11 #
explain
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=x.e;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=x.e;
connection ddl;
alter table t1 partition by key (a) partitions 8;
connection spj;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=x.e;
connection ddl;
alter table t1 partition by key (a,b) partitions 8;
connection spj;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=x.e;
connection ddl;
alter table t1 partition by key (b,a) partitions 8;
connection spj;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=x.e;
#########
# const pruned testcase
#########
connection ddl;
alter table t1 partition by key (b) partitions 8;
connection spj;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=2;
connection ddl;
alter table t1 partition by key (a) partitions 8;
connection spj;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=1 and y.b=x.e;
select straight_join * from t1 x, t1 y where y.a=0 and y.b=x.e;
# Non-const pruned as both partition keys are not const
connection ddl;
alter table t1 partition by key (a,b) partitions 8;
connection spj;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=1 and y.b=x.e;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=2;
##########
# Test pruned scan using an index:
# Declaring PK as 'using hash' will prevent that PK is used as index
# Declare PK / ix1 with mismatching column order will test correct
# usage of NdbRecord::distkey_indexes[]
##########
connection ddl;
alter table t1 drop primary key, add primary key using hash (d,b,a,c);
alter table t1 partition by key (b) partitions 8;
create index ix1 on t1(b,d,a);
connection spj;
--replace_column 10 # 11 #
explain
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=x.e;
###########
# Partition keys may evaluate to null-values:
###########
insert into t1(a,b,c,d,e,f) values
(8, 9, 0, 1, null, 3),
(9, 9, 0, 1, 2, null);
connection ddl;
alter table t1 partition by key (b) partitions 8;
connection spj;
--sorted_result
select straight_join * from t1 x, t1 y where y.a=x.d and y.b=x.e;
# Verify pruned execution by comparing the NDB$INFO counters
--disable_query_log
--eval select sum(val) - $pruned_range as pruned from ndbinfo.counters where block_name='DBSPJ' and counter_name='PRUNED_RANGE_SCANS_RECEIVED'
--eval select sum(val) - $const_pruned_range as const_pruned from ndbinfo.counters where block_name='DBSPJ' and counter_name='CONST_PRUNED_RANGE_SCANS_RECEIVED'
--enable_query_log
connection ddl;
drop table t1;
###
# Sorted scan with sub scan used to not being pushable.
# However since v7.2.6(?) we support this by enforcing
# batchRowSize=1 for the parent table in the scan-scan.
# (At the cost of more roundrtrips)
###
connection ddl;
create table t1 (pk int primary key, a int, b int) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create index ix1 on t1(b,a);
connection spj;
insert into t1 values (0,10,10);
insert into t1 values (1,10,20);
insert into t1 values (2,20,20);
insert into t1 values (3,10,10);
insert into t1 values (4,10,20);
insert into t1 values (5,10,20);
insert into t1 values (6,10,10);
insert into t1 values (7,10,10);
insert into t1 values (8,10,20);
insert into t1 values (9,10,10);
# This sorted scan-scan is pushed since V7.2.6
explain select x1.pk,x1.a,x1.b from t1 as x1
join t1 as x2 on x1.a=x2.b
join t1 as x3 on x2.a=x3.b
order by x1.pk limit 70;
select x1.pk,x1.a,x1.b from t1 as x1
join t1 as x2 on x1.a=x2.b
join t1 as x3 on x2.a=x3.b
order by x1.pk limit 70;
# This query should not be pushed, since mysqld requires sorted
# results for the root scan.
explain select * from t1 as x1, t1 as x2 where x1.a=x2.b and x1.b = 3;
select * from t1 as x1, t1 as x2 where x1.a=x2.b and x1.b = 3;
connection ddl;
drop table t1;
########
# Test correct cleanup of MRR accesses being executed multiple times.
# This used to be bug#57481, and this is a SPJ specific testcase in addition to
# the specific testcase commited together with patch for this bug.
#######
connection ddl;
create table t (pk int primary key, a int) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
insert into t values
(1,1), (2,1),
(4,3), (6,3),
(7,4), (8,4);
connection spj;
--replace_column 10 # 11 #
explain
select distinct straight_join table1.pk FROM
t as table1 join
(t as table2 join
(t as table3 join t as table4 on table3.pk = table4.a)
on table2.pk = table3.pk )
on table1.a = table4.pk
where table2.pk != 6;
--sorted_result
select distinct straight_join table1.pk FROM
t as table1 join
(t as table2 join
(t as table3 join t as table4 on table3.pk = table4.a)
on table2.pk = table3.pk )
on table1.a = table4.pk
where table2.pk != 6;
connection ddl;
drop table t;
########
# SPJ variant of bug#57396
# Test correct format of an 'open bound'
########
connection ddl;
create table t (b int, a int, primary key (a,b)) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t values(0,0);
--replace_column 10 # 11 #
explain
select * from t as t1 join t as t2 on t2.a=t1.a where t1.a < 8 or t1.a >= 8;
select * from t as t1 join t as t2 on t2.a=t1.a where t1.a < 8 or t1.a >= 8;
connection ddl;
drop table t;
#######
# Testcase for bug introduced by initial fix for
# bug#57601 'Optimizer is overly eager to request ordered access.'
# When we turned of 'sorted' for 'descending', we broke QUICK_SELECT_DESC
# which required result to be read as an ordered index access
# Note: Before V7.2.6, and as a result of WL5558, such 'turn of sorting'
# is not expected to happen any more.
#######
connection ddl;
create table t (pk1 int, pk2 int, primary key(pk1,pk2)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t values (1,3), (3,6), (6,9), (9,1);
--replace_column 10 # 11 #
explain
select * from t as t1 join t as t2
on t1.pk2 = t2.pk1
where t1.pk1 != 6
order by t1.pk1 DESC;
select * from t as t1 join t as t2
on t1.pk2 = t2.pk1
where t1.pk1 != 6
order by t1.pk1 DESC;
connection ddl;
drop table t;
#######
# Testcase using 'REF_OR_NULL'
# 'ref_or_null' contains elements of left outer join wo/ being identical.
#
connection ddl;
create table t (k int, uq int, unique key ix1 (uq)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t values (1,3), (3,NULL), (6,9), (9,1);
# Currently we do not handle 'ref_or_null' correctly.
# It is therefore disabled as pushable
explain
select straight_join * from t as a join t as b
on a.uq=b.uq or b.uq is null;
--sorted_result
select straight_join * from t as a join t as b
on a.uq=b.uq or b.uq is null;
connection ddl;
drop table t;
########
# JT_SYSTEM testcase, 'a.k is null' is known 'false' ->
# Join condition will always fail, and all 'left joins' can be NULL complemented wo/
# even requiring to access left table (b) which becomes 'system' -> No pushed joins !
########
connection ddl;
create table t (k int primary key, uq int) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t values (1,3), (3,NULL), (6,9), (9,1);
--echo #############
--echo # WL#14370: AccessPath will contain a 'zero rows'-AccessPath in place
--echo # of the known 'false' condition.
let $query =
select * from t as a left join t as b
on a.k is null and a.uq=b.uq;
eval explain $query;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
--sorted_result
eval $query;
connection ddl;
drop table t;
#######
# Test of varchar query parameteres.
#######
connection ddl;
create table tc(
a varchar(10) not null,
b varchar(10),
c varchar(10),
primary key (a),
unique key uk1 (b, c)
) engine=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into tc values ('aa','bb', 'x'), ('bb','cc', 'x'), ('cc', 'dd', 'x');
explain select * from tc as x1
right outer join tc as x2 on x1.b=x2.a
left outer join tc as x3 on x2.b = x3.b and x1.c=x3.c;
--sorted_result
select * from tc as x1
right outer join tc as x2 on x1.b=x2.a
left outer join tc as x3 on x2.b = x3.b and x1.c=x3.c;
####
# Test that 'select ... for update' is not pushed, since this requires locking.
####
explain select * from tc as x1, tc as x2 where x1.b=x2.a for update;
explain select * from tc as x1, tc as x2 where x1.b=x2.a;
connection ddl;
drop table tc;
###
# prune with xfrm set incorrect keylen
#
connection ddl;
create table t1 (
a varchar(16) not null,
b int not null,
c varchar(16) not null,
d int not null,
primary key (a,b)
) engine ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM"
partition by key (a);
connection spj;
insert into t1 values ('aaa', 1, 'aaa', 1);
select * from t1 as q1, t1 as q2 where q1.a = 'aaa' and q1.c=q2.a;
connection ddl;
drop table t1;
########################
# Bug#17845161 'CORRUPT KEY IN TC, UNABLE TO XFRM'
#
# Created an incorrect lookup key when a varchar()
# in the key was NULL
connection ddl;
CREATE TABLE t1 (
id int NOT NULL AUTO_INCREMENT,
t2_id int,
PRIMARY KEY (id)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
CREATE TABLE t2 (
id int NOT NULL AUTO_INCREMENT,
t3_id varchar(20) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
CREATE TABLE t3 (
id varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
CREATE TABLE t4 (
pk int NOT NULL,
id varchar(20) NOT NULL,
PRIMARY KEY (pk),
UNIQUE KEY (`id`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
INSERT INTO t1 VALUES (20, NULL);
INSERT INTO t1 VALUES (23, 24);
INSERT INTO t2 VALUES (24, NULL);
EXPLAIN
SELECT *
FROM t1
INNER JOIN t2 ON t2.id = t1.t2_id
LEFT OUTER JOIN t3 ON t3.id = t2.t3_id
WHERE t1.id = 20;
SELECT *
FROM t1
INNER JOIN t2 ON t2.id = t1.t2_id
LEFT OUTER JOIN t3 ON t3.id = t2.t3_id
WHERE t1.id = 20;
EXPLAIN
SELECT *
FROM t1
INNER JOIN t2 ON t2.id = t1.t2_id
LEFT OUTER JOIN t3 ON t3.id = t2.t3_id
WHERE t1.id = 23;
SELECT *
FROM t1
INNER JOIN t2 ON t2.id = t1.t2_id
LEFT OUTER JOIN t3 ON t3.id = t2.t3_id
WHERE t1.id = 23;
EXPLAIN
SELECT *
FROM t1
INNER JOIN t2 ON t2.id = t1.t2_id
LEFT OUTER JOIN t4 ON t4.id = t2.t3_id
WHERE t1.id = 23;
SELECT *
FROM t1
INNER JOIN t2 ON t2.id = t1.t2_id
LEFT OUTER JOIN t4 ON t4.id = t2.t3_id
WHERE t1.id = 23;
EXPLAIN
SELECT *
FROM t1
LEFT OUTER JOIN t2 ON t2.id = t1.t2_id
LEFT OUTER JOIN t2 as t3 ON t3.id = t1.t2_id;
--sorted_result
SELECT *
FROM t1
LEFT OUTER JOIN t2 ON t2.id = t1.t2_id
LEFT OUTER JOIN t2 as t3 ON t3.id = t1.t2_id;
connection ddl;
DROP TABLE t1,t2,t3,t4;
#######################################
# Some tests for nested left joins.
connection ddl;
CREATE TABLE t1 (
a int NOT NULL,
b int NOT NULL,
c int NOT NULL,
d int,
PRIMARY KEY (`a`,`b`),
unique key(c)
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values
(1,1,1,1),
(1,2,2,1),
(1,3,3,1),
(1,4,4,1),
(1,5,5,2),
(1,6,6,2),
(1,7,7,2),
(1,8,8,2);
explain select count(*) from t1 as x1
join (t1 as x2
left join (t1 as x3
cross join t1 as x4)
on x2.d=x3.a)
on x2.c is null or x1.a=x4.d;
select count(*) from t1 as x1
join (t1 as x2
left join (t1 as x3
cross join t1 as x4)
on x2.d=x3.a)
on x2.c is null or x1.a=x4.d;
explain select count(*) from t1 as x1
left join (t1 as x2
cross join t1 as x3)
on x1.d=x2.a;
select count(*) from t1 as x1
left join (t1 as x2
cross join t1 as x3)
on x1.d=x2.a;
--echo #################
--echo # Prior to WL#14370 we did 'pending condition' analysis inside the
--echo # join pushdown handler. That code took a too conservative approach
--echo # in identifying such pending conditions, somethimes resulting in pushdown
--echo # to be rejected due to 'table condition can not be fully evaluated...'
--echo # The AccessPath construction code does a much better job of identifying
--echo # these pending condition, and placing them at the correct branch level.
--echo # As this information is now available to us through the AccessPath
--echo # integration, we eliminated our own (incomplete) code for doing such
--echo # analysis and could avoid such false rejections at the same time.
--echo #
--echo # Note the diff in the traditional and tree format explain below:
--echo # The traditional explain says table x4 is 'using where', which was
--echo # incorrectly identified as a trigger condition on join(x2,x4).
--echo # The tree format explain shows that it has been liftet out of that
--echo # join scope as a 'filter' on the entire x1..x4 join - Thus there is
--echo # noting preventing the left-join(x2,x4)
--echo #################
let $query =
select count(*) from t1 as x0
left join (t1 as x1
join (t1 as x2
left join (t1 as x3
join t1 as x4 on x3.d=x4.a)
on x2.d=x3.a)
on x2.c is null or x1.a=x4.d)
on x0.d=x1.a;
eval explain $query;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
eval $query;
connection ddl;
drop table t1;
## Test scan sorted on string field.
connection ddl;
create table t1 (pk char(10) primary key, u int not null) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create table t2 (pk int primary key, u int not null) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values ('wh',1);
insert into t1 values ('ik',2);
insert into t1 values ('cu',3);
insert into t1 values ('pw',4);
insert into t1 values ('cq',4);
insert into t2 values (1,2), (2,3), (3,4), (4,5);
explain select * from t1 join t2 on t1.u = t2.pk order by t1.pk;
select * from t1 join t2 on t1.u = t2.pk order by t1.pk;
connection ddl;
drop table t1;
drop table t2;
########################################
# Test query with very long records.
connection ddl;
create table t1 (
a char(10) primary key,
b char(10) not null,
c char(10) not null,
l00 char(255) not null,
l01 char(255) not null,
l02 char(255) not null,
l03 char(255) not null,
l04 char(255) not null,
l05 char(255) not null,
l06 char(255) not null,
l07 char(255) not null,
l08 char(255) not null,
l09 char(255) not null,
l10 char(255) not null,
l11 char(255) not null,
l12 char(255) not null,
l13 char(255) not null,
l14 char(255) not null,
l15 char(255) not null,
l16 char(255) not null,
l17 char(255) not null,
l18 char(255) not null,
l19 char(255) not null,
l20 char(255) not null,
l21 char(255) not null,
l22 char(255) not null,
l23 char(255) not null,
l24 char(255) not null,
l25 char(255) not null,
l26 char(255) not null,
l27 char(255) not null,
l28 char(255) not null,
l29 char(255) not null,
l30 char(255) not null,
l31 char(255) not null,
index(c, b)
) engine=ndb character set latin1 partition by key(a) partitions 8;
connection spj;
insert into t1 values ('a','a','a','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x');
insert into t1 values ('b','b','b','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x');
insert into t1 values ('c','c','c','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x');
--replace_column 10 # 11 #
explain select count(*) from t1 as x1 join t1 as x2 on x1.b = x2.c;
select count(*) from t1 as x1 join t1 as x2 on x1.b = x2.c;
connection ddl;
drop table t1;
####################
# Test pruned child scans using parameter values (known regression).
####################
create table t1
(a int not null,
b int not null,
c int not null,
d int not null,
primary key(a,b,c,d)) engine=ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM"
partition by key (b,c);
connection spj;
insert into t1 values (0x4f, 0x4f, 0x4f, 0x4f);
# Prune key depends on parent row.
--replace_column 10 # 11 #
explain select * from t1 as x1
join t1 as x2 on x1.c=0x4f and x2.a=0+x1.b and x2.b=x1.b
join t1 as x3 on x3.a=x2.d and x3.b=x1.d and x3.c=x2.c;
select * from t1 as x1
join t1 as x2 on x1.c=0x4f and x2.a=0+x1.b and x2.b=x1.b
join t1 as x3 on x3.a=x2.c and x3.b=x1.d and x3.c=x2.c;
# Prune key is fixed.
--replace_column 10 # 11 #
explain select * from t1 as x1
join t1 as x2 on x1.c=0x4f and x2.a=0+x1.b and x2.b=x1.b
join t1 as x3 on x3.a=x2.d and x3.b=x1.d and x3.c=0x4f;
select * from t1 as x1
join t1 as x2 on x1.c=0x4f and x2.a=0+x1.b and x2.b=x1.b
join t1 as x3 on x3.a=x2.c and x3.b=x1.d and x3.c=0x4f;
connection ddl;
drop table t1;
############################################################
# Bug#13990924 / Bug#64865 Large WHERE IN with SPJ leads to
# cluster shutdown
#
# Caused by incorrect error handling in SPJ block when
# there was a buffer overflow (>32K)
# (Pushed condition became to large)
#
# API also failed to prevent this from happen as it checked
# for size <= 64K, while actuall buffer size was 32K
# (Has now been increased)
############################################################
create table t1 (
k1 int primary key,
i int,
name varchar(32),
key (name)
)
default charset = utf8
engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
insert into t1 values (1, 1, 'Ole');
insert into t1 values (2, 2, 'Dole');
insert into t1 values (3, 3, 'Doffen');
insert into t1 values (4, 4, 'row# 999');
###################################################
# In the IN-value tests below we use regex filtering to
# avoid having the entire IN-value list in the result-file.
# We filter out all IN-values except the first 'foo' value
# and the last 'row# <last value', leaving the result:
#
# in ('foo' .... 'row# <last value')
#
# Note, there is a regex bug:
# Bug 86164 - std::regex crashes when matching long lines
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86164
#
# The root cause is a too deep recursion when matching '+' and '*' patterns.
# in combination with a too long text to match. We hit that bug when
# regex-matching such long lines as generated in these IN-value lists.
#
# As a workaround for that bug we do the regex matching in two steps:
#
# 1) Consume all 'row# nnn' with a trailing ',' - Keeping just the last
# row# nnn which has no trailing ','
# 2) Add ' .... ' in front of the last remaining 'row#"
#
#######################################################
# These queries with large IN clauses exceeds the default memory limit of the
# range optimizer on 64 bit but not on 32 bit, thus cauing different result.
# Fix by setting a fairly low value in order to get consistent behaviour
set @save_range_opt_max = @@session.range_optimizer_max_mem_size;
set range_optimizer_max_mem_size = 64*1024;
echo ------------------------------------------------------------------;
echo;
# Build SPJ query with 2000 IN values
# This used to result in buffer overflow, but will now
# pass as buffer size is increased from 32K -> 64K
#
let $query = select * from t1 x, t1 y where y.k1=x.i and x.name in ('foo';
let $values = 0;
while ($values < 2000)
{
let $query = $query,'row# $values';
inc $values;
}
let $query = $query );
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval explain $query;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval $query;
echo ------------------------------------------------------------------;
echo;
# Same SPJ query with 4000 IN values
# This will hit the actuall limit of 64K and will be
# detected by API which will drop this pushed condition.
# 'Warning 4294 Scan filter is too large, discarded'
# (Pushed condition evaluated by ha_ndbcluster handler instead)
#
let $query = select * from t1 x, t1 y where y.k1=x.i and x.name in ('foo';
let $values = 0;
while ($values < 4000)
{
let $query = $query,'row# $values';
inc $values;
}
let $query = $query );
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval explain $query;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval $query;
echo ------------------------------------------------------------------;
echo;
# Build single table (non-SPJ) query with 4000 IN values
# Should give same 'Warning 4294' as above
let $query = select * from t1 x where x.name in ('foo';
let $values = 0;
while ($values < 4000)
{
let $query = $query,'row# $values';
inc $values;
}
let $query = $query );
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval explain $query;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval $query;
############################################################
# Bug #27397802 ENTIRE CLUSTER CRASHES WITH "MESSAGE TO BIG
# IN SENDSIGNAL" WITH BIG IN CLAUSE.
#
# Similar problem as Bug#13990924; This time with a pushed
# condition as part of an EQ_REF child node
#
############################################################
insert into t1 values (5, 4, 'row# 1');
insert into t1 values (6, 4, 'row# 2');
insert into t1 values (7, 4, 'row# 3');
insert into t1 values (8, 4, 'row# 4');
echo ------------------------------------------------------------------;
echo;
# A 'small' 1000 valued IN-list is handled OK
#
let $query = select straight_join * from t1 x, t1 y where y.k1=x.i and y.name in ('foo';
let $values = 0;
while ($values < 1000)
{
let $query = $query,'row# $values';
inc $values;
}
let $query = $query ) order by x.k1;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval explain $query;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval $query;
echo ------------------------------------------------------------------;
echo;
# Also a sufficient HUGE IN value list is ok as the pushed
# condition code is > 64K and catched by other 'Too large'
# checks.
#
let $query = select straight_join * from t1 x, t1 y where y.k1=x.i and y.name in ('foo';
let $values = 0;
while ($values < 4000)
{
let $query = $query,'row# $values';
inc $values;
}
let $query = $query ) order by x.k1;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval explain $query;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval $query;
echo ------------------------------------------------------------------;
echo;
# A pushed condition with size between 32K - 64K was not 'Too large',
# but would require fragmented sending in order to work -> Crashed.
#
let $query = select straight_join * from t1 x, t1 y where y.k1=x.i and y.name in ('foo';
let $values = 0;
while ($values < 2000)
{
let $query = $query,'row# $values';
inc $values;
}
let $query = $query ) order by x.k1;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval explain $query;
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval $query;
set range_optimizer_max_mem_size = @save_range_opt_max;
drop table t1;
echo ------------------------------------------------------------------;
echo Bug#35185670 'mysqld crashes on expensive query';
echo or we may assert, or just hang until timeout...;
echo;
#
# In a fragmenetd signal, the list of ReceiverId's were not correctly
# compiled into the REQuest. Some were duplicated, others were missing.
# In order to provoke the bug we need more than 16 receiverId's
# -> Create table with many partitions.
# -> Require the result to be ordered, which prevent multiple
# fragments to be folded into the same receiver.
#
# Test case query is based on the above large IN-list queries.
#
create table t1 (
k1 varchar(32) not null,
k2 int not null default 0,
primary key(k1,k2),
i int default 0
) engine = ndbcluster
partition by key() partitions 32;
create table t2 (
k1 int not null primary key
) engine = ndbcluster
partition by key() partitions 32;
let $query = insert into t1(k1) values ('foo');
let $values = 1;
while ($values < 2000)
{
let $query = $query,('row# $values');
inc $values;
}
###################
echo;
echo Inserting 2000 rows in table t1;
--disable_query_log
eval $query;
analyze table t1;
insert into t2(k1) values(0);
analyze table t2;
--enable_query_log
let $query = select * from t1 left join t2 on t2.k1=t1.i where t1.k1 in ('foo';
let $values = 0;
while ($values < 2000)
{
let $query = $query,'row# $values';
inc $values;
}
let $query = $query ) order by t1.k1, t1.k2;
echo;
echo Expect query and IN-condition to be pushed;
echo (If join_pushdown is enabled);
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval explain $query;
--disable_result_log
--replace_regex /'row# [0-9]+',// /'row#/ .... 'row#/
eval $query;
--enable_result_log
drop table t1;
drop table t2;
############################################################
# Bug#14010406 LARGE PUSHED JOIN HIT ASSERT IN SPJ BLOCK
#
# Buffered rows (caused by PARENT refs) was prematurely
# released when there was no TN_ACTIVE treeNodes childs.
# However, in bushy scans, a scan branch can be 'repeated'
# even if its previous execution was 'complete'.
#
# Thus we have to use a less eager release strategy where
# we don't release any buffered rows until we prepare for
# a NEXTREQ which will fetch more rows into the treeNode.
############################################################
create table t(
pk int primary key auto_increment,
i int,
j int,
k int,
index(i,j),
index(i),
index(j),
index(k)
) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
insert into t(i,j,k) values
(1,1,1), (1,1,1), (1,1,1),
(2,2,2), (2,2,2), (2,2,2);
--error 0,1193
set global debug='+d,max_4rows_in_spj_batches';
--replace_column 10 # 11 #
explain
select straight_join count(*) from
t as t1
join t as t2 on t2.i = t1.i
join (t as t3 join t as t4 on t4.k=t3.k join t as t5 on t5.i=t4.i and t5.j=t3.j) on t3.pk=t1.j
join t as t6 on t6.k = t1.k
where t1.i < 2;
select straight_join count(*) from
t as t1
join t as t2 on t2.i = t1.i
join (t as t3 join t as t4 on t4.k=t3.k join t as t5 on t5.i=t4.i and t5.j=t3.j) on t3.pk=t1.j
join t as t6 on t6.k = t1.k
where t1.i < 2;
--error 0,1193
set global debug=@save_debug;
drop table t;
####################################################
# Test LQH handling of zero-length key in LQHKEYREQ
# Bug#
create table t1 (a int primary key, b int, c int, index(b,c)) engine = ndb
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
insert into t1 values (4,null, 2);
explain
select x.a from t1 as x join t1 as y on y.a = x.b where x.a=4;
select x.a from t1 as x join t1 as y on y.a = x.b where x.a=4;
drop table t1;
####################################################
# Regression test for Bug#14644936 "INEFFICIENT AND INCORRECT EXECUTION OF
# PUSHABLE OUTER JOINS".
####################################################
connection ddl;
CREATE TABLE t1 (
a int NOT NULL,
b int DEFAULT NULL,
c int NOT NULL,
d int NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
create unique index ix1 on t1(b,c) using hash;
connection spj;
insert into t1 values (1,NULL,1,1);
explain select * from t1 as x1 left join (t1 as x2 join t1 as x3 on x2.d=x3.c) on x1.b=x3.b;
# Record value before query.
create temporary table scan_count
select * from performance_schema.global_status
where variable_name = 'Ndb_scan_count';
# Query gives wrong result on mysql-trunk-cluster, and extra scan on both
# mysql-5.5-cluster-7.2 and mysql-trunk-cluster.
select * from t1 as x1 left join (t1 as x2 join t1 as x3 on x2.d=x3.c) on x1.b=x3.b;
# Bug causes value to increase by 3 rather than 2.
select scan_count.VARIABLE_NAME,
old.VARIABLE_VALUE - scan_count.VARIABLE_VALUE
from scan_count, performance_schema.global_status as old
where old.variable_name = 'Ndb_scan_count';
drop table scan_count;
connection ddl;
drop table t1;
##############
# Bug#16925513: HIT DBUG_ASSERT IN SPJ BLOCK, ~LINE 4406
#
# Testcase extracted from failing RQG test.
connection ddl;
CREATE TABLE table1 (
col_int_unique int(11),
PRIMARY KEY (col_int_unique)
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
CREATE TABLE table3 (
col_int int(11) NOT NULL DEFAULT '0',
KEY (col_int)
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
CREATE TABLE table4 (
col_int int(11) DEFAULT NULL,
pk int(11) NOT NULL,
PRIMARY KEY (pk)
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
CREATE TABLE table6 (
col_int int(11) DEFAULT NULL,
col_int_unique int(11) DEFAULT NULL
) ENGINE=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into table6 values
(2,NULL),
(2,NULL),
(2,NULL),
(2,NULL),
(2,NULL),
(2,NULL),
(2,NULL),
(2,NULL);
--error 0,1193
set global debug='+d,max_4rows_in_spj_batches';
EXPLAIN
SELECT * FROM
table1 RIGHT JOIN
table3 LEFT JOIN table4 ON table3.col_int = table4.col_int
JOIN
table6 ON table4.pk = table6.col_int_unique
ON table1.col_int_unique = table6.col_int;
--sorted_result
SELECT * FROM
table1 RIGHT JOIN
table3 LEFT JOIN table4 ON table3.col_int = table4.col_int
JOIN
table6 ON table4.pk = table6.col_int_unique
ON table1.col_int_unique = table6.col_int;
--error 0,1193
set global debug=@save_debug;
connection ddl;
drop table table6;
drop table table4;
drop table table3;
drop table table1;
--echo 5.6 tests
#######################################
# MySQL 5.6 include improved optimizer
# handling of subqueries. Some specific
# test for handling limitations / problems
# specific to these features
#############################################
# Testing of subqueries and join pushdown
#
# Note that subqueries has limitations very similar
# to outer joins.
#############################################
##############
# Bug #16664035
# PUSHED JOIN TOGETHER WITH 'FIRSTMATCH' STRATEGY MAY RETURN TOO MANY ROWS
connection ddl;
create table t1 (
a int not null,
b int not null,
c int not null,
d int not null,
primary key (`a`,`b`),
key(c), key(d)
) engine=ndbcluster
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
insert into t1 values
(1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4),
(1,2,5,1), (1,3,1,2), (1,4,2,3),
(2,1,3,4), (2,3,4,5), (2,4,5,1),
(3,1,1,2), (3,2,2,3), (3,4,3,4),
(4,1,4,5), (4,2,5,1), (4,3,1,2);
# Use debug hook to enforce only 4 rows in each batch (Two roundtips)
--error 0,1193
set global debug='+d,max_4rows_in_spj_batches';
# Make use of FirstMatch more likely:
set @save_optimizer_switch = @@optimizer_switch;
set optimizer_switch='materialization=off';
# 'subq' should use 'ref, FirstMatch(t1)', preventing join pushdown
explain
select count(*) from t1 where
t1.c in (select c from t1 as subq);
select count(*) from t1 where
t1.c in (select c from t1 as subq);
explain
select count(*) from t1 where
t1.c in (select c from t1 as subq1) and
t1.d in (select d from t1 as subq2);
select count(*) from t1 where
t1.c in (select c from t1 as subq1) and
t1.d in (select d from t1 as subq2);
explain
select count(*) from t1 where
t1.c in (select c from t1 as subq1 where
subq1.c in (select c from t1 as subq2));
select count(*) from t1 where
t1.c in (select c from t1 as subq1 where
subq1.c in (select c from t1 as subq2));
explain
select count(*) from t1 where
t1.c in (select subq1.c from t1 as subq1 straight_join t1 as subq2 on subq1.a = subq2.c);
select count(*) from t1 where
t1.c in (select subq1.c from t1 as subq1 straight_join t1 as subq2 on subq1.a = subq2.c);
set optimizer_switch=@save_optimizer_switch;
--error 0,1193
set global debug=@save_debug;
####################################
--echo #
--echo # Bug#29860378
--echo # RESULTS NOT SORTED AS SPECIFIED WHEN QUERY IS A 'PUSHED JOIN'
--echo #
# Force a small batch size in order to reproduce bug without needing
# a large test table.
--error 0,1193
set global debug='+d,max_4rows_in_spj_batches';
explain
select straight_join t1.* from
t1 join t1 as t2 on t2.d = t1.a
where t1.a > 0
order by t1.a,t1.b;
select straight_join t1.* from
t1 join t1 as t2 on t2.d = t1.a
where t1.a > 0
order by t1.a,t1.b;
explain
select straight_join t1.a,t1.b,count(*) from
t1 join t1 as t2 on t2.d = t1.a
where t1.a > 0
group by t1.a,t1.b;
--sorted_result
select straight_join t1.a,t1.b,count(*) from
t1 join t1 as t2 on t2.d = t1.a
where t1.a > 0
group by t1.a,t1.b;
--error 0,1193
set global debug=@save_debug;
##################################################
# Bug##26926666
# 'LOOSESCAN' TABLES SHOULD NOT BE CHILD MEMBERS IN A PUSHED JOIN
#
##################################################
######
# Expect a query plan where the subquery table1s becomes
# a child candidate in a pushed join. 'LooseScan' require
# sorted results to be returned from the (child) table, which
# we do not implement.
connection spj;
set @save_optimizer_switch = @@optimizer_switch;
set @@optimizer_switch='semijoin=on';
set @@optimizer_switch='loosescan=on';
explain SELECT count(*)
FROM (t1 AS table1 JOIN t1 AS table2 USING(a,b))
WHERE table1.b IN
(SELECT /*+ SEMIJOIN(LOOSESCAN)*/ table1s.c FROM t1 as table1s);
SELECT count(*)
FROM (t1 AS table1 JOIN t1 AS table2 USING(a,b))
WHERE table1.b IN
(SELECT /*+ SEMIJOIN(LOOSESCAN)*/ table1s.c FROM t1 as table1s);
########
# Same query with 'FirstMatch', suplements FirstMatch (bug#16664035)
# testcase above
set @@optimizer_switch='firstmatch=on';
explain SELECT count(*)
FROM (t1 AS table1 JOIN t1 AS table2 USING(a,b))
WHERE table1.b IN
(SELECT /*+ SEMIJOIN(FIRSTMATCH)*/ table1s.c FROM t1 as table1s);
SELECT count(*)
FROM (t1 AS table1 JOIN t1 AS table2 USING(a,b))
WHERE table1.b IN
(SELECT /*+ SEMIJOIN(FIRSTMATCH)*/ table1s.c FROM t1 as table1s);
set optimizer_switch=@save_optimizer_switch;
##################################################
# Bug#26919289:
# mysqld crash during join_pushdown analysis
#
# The mysql optimizer introduce syntetic JOIN_TAB
# elements representing where the materialized subq
# should be accessed in the query plan. As these
# are not representing 'real tables', their 'tableno'
# was not set up in ndb_pushed_builder_ctx C'tor.
# It effectively contained uninitialized data, which was
# then later used to access a 'tableno-bitmask'.
###################################################
--echo ####################################################################
--echo # WL#14370: Change EXPLAIN to use 'format=tree'. Traditional explain
--echo # didn't correctly represent the order of tables in MATERIALIZED
--echo # sub queries. That resulted in some confusing 'EXPLAIN_NO_PUSH' diffs
--echo # where the reported root/child order didn't make sense.
--echo # As the tree-format explain will show, the changed output
--echo # make more sense related to the query plan represented by the
--echo # AccessPath tree.
--echo # WL#14370: Materialized semijoin's is not the only SJ-strategi
--echo # where we do no pushdown across main-query -> sub-query border.
--echo # (The sub-query itself may be pushed though)
--echo ###################################################################
connection spj;
set @save_optimizer_switch = @@optimizer_switch;
set @@optimizer_switch='semijoin=on';
set @@optimizer_switch='materialization=on';
let $query =
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
where t1.c IN (select /*+ SEMIJOIN(MATERIALIZATION)*/ c from t1 as t3);
--replace_regex / \(cost=.*//
eval explain format=tree $query;
eval $query;
let $query =
select count(*)
from t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
where t1.c IN (select /*+ SEMIJOIN(MATERIALIZATION)*/ c from t1 as t3);
--replace_regex / \(cost=.*//
eval explain format=tree $query;
eval $query;
let $query =
select count(*)
from (select * from t1 where t1.c IN (select /*+ SEMIJOIN(MATERIALIZATION)*/ c from t1 as t3)) as t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
eval $query;
let $query =
select count(*)
from (select * from t1 where t1.c IN (select /*+ SEMIJOIN(MATERIALIZATION)*/ c from t1 as t3)) as t1
join t1 as t2 on t2.a = t1.b and t2.b = t1.c
where t1.c IN (select /*+ SEMIJOIN(MATERIALIZATION)*/ c from t1 as t4);
--replace_regex / \(cost=.*//
eval explain format=tree $query;
eval $query;
set optimizer_switch='block_nested_loop=off';
let $query =
select count(*)
from t1 cross join t1 as t2
where t2.c IN (select /*+ SEMIJOIN(MATERIALIZATION)*/ t4s.c
from t1 as t3s join t1 as t4s on t4s.a = t3s.b);
--replace_regex / \(cost=.*//
eval explain format=tree $query;
eval $query;
set optimizer_switch=@save_optimizer_switch;
###################################################
# Bug #26984919
# SPJ: 'DUPLICATE WEEDOUT' STRATEGY MAY RETURN INCORRECT RESULTS
###################################################
# Use debug hook to enforce only 4 rows in each batch (multiple roundtips)
--error 0,1193
set global debug='+d,max_4rows_in_spj_batches';
connection spj;
set @save_optimizer_switch = @@optimizer_switch;
set @@optimizer_switch='semijoin=on';
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
where t1.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t3s.c from t1 as t3s
join t1 as t4s on t4s.a = t3s.b);
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
where t1.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t3s.c from t1 as t3s
join t1 as t4s on t4s.a = t3s.b);
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
where t2.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t3s.c from t1 as t3s
join t1 as t4s on t4s.a = t3s.b);
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
where t2.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t3s.c from t1 as t3s
join t1 as t4s on t4s.a = t3s.b);
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
join t1 as t3 on t3.a = t2.b
where t1.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t4s.c from t1 as t4s
join t1 as t5s on t5s.a = t4s.b
join t1 as t6s on t6s.a = t5s.b
);
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
join t1 as t3 on t3.a = t2.b
where t1.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t4s.c from t1 as t4s
join t1 as t5s on t5s.a = t4s.b
join t1 as t6s on t6s.a = t5s.b
);
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
join t1 as t3 on t3.a = t2.b
where t2.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t4s.c from t1 as t4s
join t1 as t5s on t5s.a = t4s.b
join t1 as t6s on t6s.a = t5s.b
);
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
join t1 as t3 on t3.a = t2.b
where t2.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t4s.c from t1 as t4s
join t1 as t5s on t5s.a = t4s.b
join t1 as t6s on t6s.a = t5s.b
);
explain
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
join t1 as t3 on t3.a = t2.b
where t3.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t4s.c from t1 as t4s
join t1 as t5s on t5s.a = t4s.b
join t1 as t6s on t6s.a = t5s.b
);
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
join t1 as t3 on t3.a = t2.b
where t3.c IN (
select /*+ SEMIJOIN(DUPSWEEDOUT)*/ t4s.c from t1 as t4s
join t1 as t5s on t5s.a = t4s.b
join t1 as t6s on t6s.a = t5s.b
);
--error 0,1193
set global debug=@save_debug;
set optimizer_switch=@save_optimizer_switch;
###################################################
# Bug#27022925
# SPJ: 'MATERIALIZED' SEMI JOINS ARE NOT CONSIDDERED FOR JOIN PUSHOWN
#
# Joins entirely inside a 'MATERIALIZED' semi join
# not considdered for join pushdown.
#
# Test cases should demonstrate that the 't3s join t4s'
# subqueries can now be pushed down, and materialized.
#
###################################################
--echo ###########
--echo # WL#14370: EXPLAIN need to use 'format=tree as table access order
--echo # in MATERIALIZED execution is not currectly represented by
--echo # the traditional explain.
--echo ###########
let $query =
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
where t1.c IN (
select /*+ SEMIJOIN(MATERIALIZATION)*/ t3s.c from t1 as t3s
join t1 as t4s on t4s.a = t3s.b);
--replace_regex / \(cost=.*//
eval explain format=tree $query;
eval $query;
let $query =
select count(*)
from t1
join t1 as t2 on t2.a = t1.b
where t1.c IN(
select /*+ SEMIJOIN(MATERIALIZATION)*/ t3s1.c from t1 as t3s1
join t1 as t4s1 on t4s1.a = t3s1.b
)
and t1.d IN (
select /*+ SEMIJOIN(MATERIALIZATION)*/ t3s2.c from t1 as t3s2
join t1 as t4s2 on t4s2.a = t3s2.b
);
--replace_regex / \(cost=.*//
eval explain format=tree $query;
eval $query;
#############################################
# Subqueries-end
#############################################
###################################################
# Bug#33416308
# Incorrect result for pushed join in combination with batched_key_access
#
# SPJ API / handler integration didn't implement retrieval of the
# RANGE_NO pseudo column. Thus, when MRR specified multiple Bound's,
# and that MRR operation was the root of a pushed join, we failed
# to related the returned SPJ rows with the correct 'Batched Key'
#
##################################################
# We use optimizer hints to ensure:
# - t2 is BKA joined (using MRR) with t1.
# - t3 is _not_ BKA joined with t2, thus enabling
# t2 join t3 to be pushed.
#
# 't1 BKA_JOIN t2' will use MRR access for the
# pushed join root t2, which will need RANGE_NO's from t2 results
# in order to relate them to the correct batched t1 row.
#
explain
select /*+ BKA(t2) NO_BKA(t3) */ t1.a, t2.a, t3.a
from t1
straight_join t1 as t2 on t2.a = t1.c
straight_join t1 as t3 on t3.a = t2.c and t3.b=t2.d;
--sorted_result
select /*+ BKA(t2) NO_BKA(t3) */ t1.a, t2.a, t3.a
from t1
straight_join t1 as t2 on t2.a = t1.c
straight_join t1 as t3 on t3.a = t2.c and t3.b=t2.d;
# Variant where t3 join condition refers t1.
# That will hit an assert(key_cmp... added as part of patch
explain
select /*+ BKA(t2) NO_BKA(t3) */ t1.a, t2.a, t3.a
from t1
straight_join t1 as t2 on t2.a = t1.c
straight_join t1 as t3 on t3.a = t1.c and t3.b=t2.d;
--sorted_result
select /*+ BKA(t2) NO_BKA(t3) */ t1.a, t2.a, t3.a
from t1
straight_join t1 as t2 on t2.a = t1.c
straight_join t1 as t3 on t3.a = t1.c and t3.b=t2.d;
connection ddl;
drop table t1;
##############
# 16999886 ORDER BY DOESN'T WORK WITH JOIN
# (Limited to pushed join + DESC order only)
connection ddl;
CREATE TABLE ndb_order_test (
node_id int(10) unsigned NOT NULL,
user_id int(10) unsigned NOT NULL,
sort_number int(10) unsigned NOT NULL,
KEY node_id (node_id,sort_number)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
CREATE TABLE ndb_user_test (
user_id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(20) NOT NULL,
PRIMARY KEY (user_id)
) ENGINE=ndbcluster DEFAULT CHARSET=utf8 AUTO_INCREMENT=2
comment="NDB_TABLE=PARTITION_BALANCE=FOR_RP_BY_LDM";
connection spj;
INSERT INTO ndb_order_test (node_id, user_id, sort_number) VALUES
(68, 1, 1398029),
(68, 1, 549053);
INSERT INTO ndb_user_test (user_id, name) VALUES
(1, 'Shawn');
EXPLAIN
SELECT *
FROM ndb_order_test JOIN ndb_user_test USING (user_id)
WHERE node_id = 68
ORDER BY sort_number DESC;
SELECT *
FROM ndb_order_test JOIN ndb_user_test USING (user_id)
WHERE node_id = 68
ORDER BY sort_number DESC;
EXPLAIN
SELECT *
FROM ndb_order_test JOIN ndb_user_test USING (user_id)
WHERE node_id = 68
ORDER BY sort_number ASC;
SELECT *
FROM ndb_order_test JOIN ndb_user_test USING (user_id)
WHERE node_id = 68
ORDER BY sort_number ASC;
connection ddl;
DROP TABLE ndb_order_test, ndb_user_test;
--echo ##################
--echo #
--echo # Bug #29501263 CRASH IN SPJ BLOCK, ILLEGAL ACCESS
--echo # TO ARRAYPOOL<T>::GETPTR
--echo #
--echo ##################
create table t1 (
pk int primary key,
i1 int
) engine = ndb;
insert into t1 values (1,1),(2,2),(3,3);
alter table t1 add column (i2 int, i3 int, i4 int, i5 int);
update t1 set i2=i1, i3=i1, i4=i1, i5=i1;
alter table t1 add index ix1(i1);
alter table t1 add index ix2(i2);
alter table t1 add index ix3(i3);
alter table t1 add index ix4(i4);
alter table t1 add index ix5(i5);
alter table t1 add unique index uix(i4,i5);
--sorted_result
select straight_join * from
t1
join t1 as t2 on t2.i1 = t1.i1
join t1 as t3 on t3.pk = t2.i2
left join t1 as t4 on t4.pk = t3.i3
left join t1 as t5 on t5.i4 = t2.i4 and t5.i5 = t1.i5;
drop table t1;
--echo ##################
--echo #
--echo # Bug#32203548 REQUIRE_FAILED WHEN COMPARE_NDBRECORD()
--echo # SORT-MERGE SPJ RESULTS FROM INDEX
--echo #
--echo ##################
create table t1 (
a int not null,
b int not null,
c varchar(1) not null,
d varchar(1) not null,
primary key (a,b),
index ix2 (d,c)
) engine=ndbcluster;
# Note that we insert all "1" into column d, such that
# the merge sort on index 'ix2 (d,c)' will always find
# column 'd' equal, and continue comparing column 'c'
# if we do not break out of compare loop for columns not
# selected.
#
insert into t1 values
(1,1,"1","1"), (2,2,"2","1"), (3,3,"3","1"), (4,4,"4","1"),
(1,2,"5","1"), (1,3,"1","1"), (1,4,"2","1"),
(2,1,"3","1"), (2,3,"4","1"), (2,4,"5","1");
# We force index 'ix2' to be used for 'order by'
explain
select t1.d from t1 FORCE INDEX FOR ORDER BY (ix2)
straight_join t1 as t2 on t2.a = t1.a
order by t1.d;
select t1.d from t1 FORCE INDEX FOR ORDER BY (ix2)
straight_join t1 as t2 on t2.a = t1.a
order by t1.d;
drop table t1;
--echo ##################
--echo #
--echo # Specific WL-14370, 'AccessPath' tests
--echo # (Unknown if/how this worked pre-wl-14370)
--echo #
--echo ##################
--echo Testcase for AccessPath::NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL
--echo Expect explain: 'Nested loop semijoin with duplicate removal on...'
--echo (Hardly ever used unless forced to...)
--echo Testcase for AccessPath::WINDOWING
# (Picked from main.subquery_scalar_to_derived_correlation.test)
create table t2(a int) engine=ndbcluster;
insert into t2 values(1), (2);
create table t3(a int, b int) engine=ndbcluster;
insert into t3 values(1, 3), (2, 3);
let $query =
select a,
(select sum(a) over w from t2 window w as(order by t3.a) limit 1)
from t3;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
--sorted_result
eval $query;
drop table t2,t3;
#WL#14370: Query_expression with multiple Query_blocks:
# (Testing Accesspath::APPEND of multiple STREAMs.)
# The constructed AQP::Join_plan is limited to handling single
# Query_blocks, which is implemented by just iterating over the
# 'block' in the Query_expression. Thus we dont have to handle
# Accesspath::APPEND and multiple 'blocks' in the 'plan'.
#
create table t1 (
a int not null,
b int not null,
c int not null,
d int not null,
primary key (`a`,`b`)
) engine=ndbcluster
partition by key() partitions 8;
insert into t1 values
(1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4),
(1,2,5,1), (1,3,1,2), (1,4,2,3),
(2,1,3,4), (2,3,4,5), (2,4,5,1),
(3,1,1,2), (3,2,2,3), (3,4,3,4),
(4,1,4,5), (4,2,5,1), (4,3,1,2);
let $query =
select *
from t1
straight_join t1 as t2 on t2.a = t1.b+0 and t2.b = t1.c
straight_join t1 as t3 on t3.a = t1.b and t3.b = t2.b
where t1.a=1 and t1.d=1;
--replace_regex / \(cost=.*//
eval explain format=tree $query union all $query;
--sorted_result
eval $query union all $query;
--replace_regex / \(cost=.*//
eval explain format=tree $query union $query;
--sorted_result
eval $query union $query;
drop table t1;
--echo ##################
--echo #
--echo # Bug#33669039 Stale rows returned from SPJ API,
--echo # hit assert(key_cmp_if_same(...)) in debug build
--echo #
--echo ##################
create table t (
pk int primary key,
a int,
b int,
c int,
d int
) engine = ndbcluster;
##############################
# The inserted rows, in combination with query,
# will do a self-join between all rows, except
# the row where pk=7, containing a=-1
insert into t values (0,0,0,0,0);
insert into t values (1,1,1,1,1);
insert into t values (2,2,2,2,2);
insert into t values (3,3,3,3,3);
insert into t values (4,4,4,4,4);
insert into t values (5,5,5,5,5);
insert into t values (6,6,6,6,6);
insert into t values (7,-1,7,7,7);
insert into t values (8,8,8,8,8);
insert into t values (9,9,9,9,9);
insert into t values (10,10,10,10,10);
insert into t values (11,11,11,11,11);
insert into t values (12,12,12,12,12);
insert into t values (13,13,13,13,13);
insert into t values (14,14,14,14,14);
insert into t values (15,15,15,15,15);
##############################
# The query below has the join nests t1 oj (t2,t3) oj (t4,t5). In addition
# There are join condition dependencies between the (t4,t5) nests, and t3
# in the other outer-nest.
# When the iterator executor evaluate the join for the row with pk=7 it
# will not find any t2 rows where t2.pk = t1.a. This will also conclude
# with a 'non match' for the nest (t2,t3)... *without* a new t3 row needed
# to be read.
# The iterator executor will then continue with trying to find matches
# for the (t4,t5) nest. This nest will have join dependencies on t3, which
# now has an old (invalid) 'current row' as read from t3 was skipped in the
# previous step.
#
let $query=
select t1.pk, t2.pk, t3.pk, t4.pk, t5.pk
from t as t1
left join (
t as t2
straight_join t as t3 on t3.pk = t2.b
) on t2.pk = t1.a
left join (
t as t4
straight_join t as t5
) on t4.pk = t1.c and t5.pk = t3.d;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
--sorted_result
eval $query;
drop table t;
--echo ##################
--echo #
--echo # Bug#34482783 NDB: mysqld crash in ::is_pushable_within_nest()
--echo #
--echo ##################
create table t (
pk int primary key,
col_int_key int not null,
col_int int not null,
key(col_int_key)
) engine = ndbcluster;
# No rows needed in table to provoke bug
let $query=
SELECT *
FROM t AS table1
LEFT JOIN t AS table2
JOIN t AS table3 ON table2.col_int IS NULL # <- 'zero rows'
ON table1.col_int = table2.col_int AND
table1.col_int_key = table2.col_int_key AND
table1.pk = table3.pk;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
--sorted_result
eval $query;
drop table t;
--echo ##################
--echo #
--echo # Bug#34723413 A 'pushed join' should not start with a scan-table
--echo # returning very few rows .
--echo #
--echo ##################
create table t10 (
k int not null auto_increment,
i int,
primary key(k),
key(i)
) engine = ndbcluster;
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 t1000 like t10;
insert into t1000(i)
select x.i from t10 as x, t10 as y, t10 as z;
# Make t10 even smaller, increase join-fanout on 'i' for t100 and t1000
delete from t10 where i > 2;
update t100 set i = i/3;
update t1000 set i = i/3;
analyze table t10,t100,t1000;
############################
# We could have pushed 't10 join t1000 join t100'
# However the small table t10 might not deliver rows to all SPJ workers,
# leaving some of them idle. Thus it will usually be better to :
# - Fetch t10 rows
# - For every t10 row: Push 't1000 join t100'
#
# Expect the explain-warning:
#
# Didn't push table 't10' as root, too few rows to enable full parallelism
#
--replace_regex / \(cost=.*//
explain format=tree
select *
from t10
straight_join t1000 on t1000.i = t10.i
straight_join t100 on t100.k = t1000.k;
############################
# However:
# Table 't100' is an ancestor of t10, and can't be made
# and t1000 ancestor. Not pushing t10 will yield t1000 and t100
# unpushed as well -> Push all 3 tables as first planned.
#
--replace_regex / \(cost=.*//
explain format=tree select *
from t10
straight_join t1000 on t1000.i = t10.i
straight_join t100 on t100.k = t10.k;
drop table t10,t100,t1000;
--echo ##################
--echo #
--echo # Bug#34782276:
--echo # Improve SPJ-internal execution plan, evaluate inner-joins first
--echo #
--echo ##################
#
# The SPJ block will build its own query plan where it will evaluate
# inner-joins first. Even in a star-join plan the joins will be evaluated
# in sequence and found matches noted in the common ancestor. Later joins
# will be skipped if some of the previously evaluated joins didn't find
# a match. (It is a property of the inner-join that matches are required
# for all tables in the same inner join 'nest').
# This will reduce the work needed to be performed by the data nodes
# in later table REQuests.
#
# Test case is the query tree: t1
# / \
# t2 t3
#
# There are matches for all rows in the join(t1,t3). However only 3 of the 9
# rows will match in join(t1,t2). The SPJ block will create its own execution
# Plan where:
# 1) join(t1,t2), Annotate t1 rows where matches are found.
# 2) Generate t3 requests from buffered t1 rows having matches.
# -> There should only be 3 keys in the REQuest sent to t3
create table t (
k int,
a int,
key ix1(k),
key ix2(a)
) engine = ndb;
insert into t values
(0,0), (1,1), (2,2),
(3,0), (4,1), (5,2),
(6,0), (7,1), (8,2);
let $old_val = query_get_value(select sum(val) as Value from ndbinfo.counters where block_name='DBSPJ' and counter_name = 'SCAN_ROWS_RETURNED', Value, 1);
# This test case is just for reference - Worked as expected even before bug fix.
let $query=
select straight_join *
from t as t1
inner join t as t2 on t2.a = t1.k
inner join t as t3 on t3.k = t1.k;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
let $old_val = query_get_value(select sum(val) as Value from ndbinfo.counters where block_name='DBSPJ' and counter_name = 'SCAN_ROWS_RETURNED', Value, 1);
--disable_result_log
eval $query;
--enable_result_log
--echo ############
--echo # Verify the expect 21 rows were returned from SPJ:
--echo # - 2 x 9 rows from t1 inner join t2
--echo # - 3 rows from t1 join t3
--echo # -> 21 rows (0 *SPJ* rows when not join-pushed (BKA))
--echo #
--disable_query_log
--eval select sum(val) - $old_val as SPJ_rows_returned from ndbinfo.counters where block_name="DBSPJ" and counter_name = "SCAN_ROWS_RETURNED"
--enable_query_log
##### Same test case with outer join:
#
# Should stil evaluate t1 join t2 first.
# A non-match on t2 will eliminate the inner joined t1 rows.
# Thus, t1 left join t3 may be skipped for t1 rows not having t2 matches
#
let $query=
select straight_join *
from t as t1
inner join t as t2 on t2.a = t1.k
left join t as t3 on t3.k = t1.k;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
let $old_val = query_get_value(select sum(val) as Value from ndbinfo.counters where block_name='DBSPJ' and counter_name = 'SCAN_ROWS_RETURNED', Value, 1);
--disable_result_log
eval $query;
--enable_result_log
--echo ############
--echo # As above, t1 inner join t2 is evaluated first
--echo # - 2 x 9 rows from join(t1,t2)
--echo # - Only the 3 matching t1 rows are requested from t3!
--echo # -> still 21 rows (and still 0 *SPJ* rows when not join-pushed (BKA))
--echo #
--disable_query_log
--eval select sum(val) - $old_val as SPJ_rows_returned from ndbinfo.counters where block_name="DBSPJ" and counter_name = "SCAN_ROWS_RETURNED";
--enable_query_log
##### Same test case with outer join evaluated before inner join:
#
# There is a legacy limitation in the SPJ API protocol, where scans need
# to be evaluated in the same order as specified in the optimizer table order.
# Test case verify that we do *not* skip t3 rows in these cases.
# (As t1 left join t2 will not eliminate non matching t1 rows and we cant evaluate
# t1 inner join t3 first due to legacy limitation.)
#
let $query=
select straight_join *
from t as t1
left join t as t2 on t2.a = t1.k
inner join t as t3 on t3.k = t1.k;
--replace_regex / \(cost=.*//
eval explain format=tree $query;
let $old_val = query_get_value(select sum(val) as Value from ndbinfo.counters where block_name='DBSPJ' and counter_name = 'SCAN_ROWS_RETURNED', Value, 1);
--disable_result_log
eval $query;
--enable_result_log
--echo ############
--echo # Verify that all 3 x 9 rows were returned from SPJ:
--echo # - 2 x 9 rows from t1 outer join t2
--echo # (No t1-match elimination in an outer-join)
--echo # - 9 rows from t1 inner join t3
--echo # -> 27 rows
--echo #
--disable_query_log
--eval select sum(val) - $old_val as SPJ_rows_returned from ndbinfo.counters where block_name="DBSPJ" and counter_name = "SCAN_ROWS_RETURNED"
--enable_query_log
drop table t;
########################################
# Verify counters for entire test:
# Note: These tables are 'temporary' withing 'connection spj'
connection spj;
# Calculate the change in mysqld counters.
select new.variable_name, new.variable_value - old.variable_value
from server_counts_at_startup as old,
performance_schema.global_status as new
where new.variable_name = old.variable_name
order by new.variable_name;
drop table server_counts_at_startup;
set ndb_join_pushdown = @save_ndb_join_pushdown;
|