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
|
set optimizer_switch='index_condition_pushdown=on';
SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
CREATE TABLE t1 (
event_date date DEFAULT '0000-00-00' NOT NULL,
type int(11) DEFAULT '0' NOT NULL,
event_id int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (event_date,type,event_id)
);
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES ('1999-07-10',100100,24), ('1999-07-11',100100,25),
('1999-07-13',100600,0), ('1999-07-13',100600,4), ('1999-07-13',100600,26),
('1999-07-14',100600,10), ('1999-07-15',100600,16), ('1999-07-15',100800,45),
('1999-07-15',101000,47), ('1999-07-16',100800,46), ('1999-07-20',100600,5),
('1999-07-20',100600,27), ('1999-07-21',100600,11), ('1999-07-22',100600,17),
('1999-07-23',100100,39), ('1999-07-24',100100,39), ('1999-07-24',100500,40),
('1999-07-25',100100,39), ('1999-07-27',100600,1), ('1999-07-27',100600,6),
('1999-07-27',100600,28), ('1999-07-28',100600,12), ('1999-07-29',100500,41),
('1999-07-29',100600,18), ('1999-07-30',100500,41), ('1999-07-31',100500,41),
('1999-08-01',100700,34), ('1999-08-03',100600,7), ('1999-08-03',100600,29),
('1999-08-04',100600,13), ('1999-08-05',100500,42), ('1999-08-05',100600,19),
('1999-08-06',100500,42), ('1999-08-07',100500,42), ('1999-08-08',100500,42),
('1999-08-10',100600,2), ('1999-08-10',100600,9), ('1999-08-10',100600,30),
('1999-08-11',100600,14), ('1999-08-12',100600,20), ('1999-08-17',100500,8),
('1999-08-17',100600,31), ('1999-08-18',100600,15), ('1999-08-19',100600,22),
('1999-08-24',100600,3), ('1999-08-24',100600,32), ('1999-08-27',100500,43),
('1999-08-31',100600,33), ('1999-09-17',100100,37), ('1999-09-18',100100,37),
('1999-09-19',100100,37), ('2000-12-18',100700,38);
explain select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 7 NULL 6 19.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`event_date` AS `event_date`,`test`.`t1`.`type` AS `type`,`test`.`t1`.`event_id` AS `event_id` from `test`.`t1` where ((`test`.`t1`.`event_date` >= DATE'1999-07-01') and (`test`.`t1`.`event_date` < DATE'1999-07-15') and ((`test`.`t1`.`type` = 100600) or (`test`.`t1`.`type` = 100100))) order by `test`.`t1`.`event_date`
explain format=tree select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
EXPLAIN
-> Filter: ((t1.event_date >= DATE'1999-07-01') and (t1.event_date < DATE'1999-07-15') and ((t1.`type` = 100600) or (t1.`type` = 100100))) (cost=1.46 rows=1.14)
-> Covering index range scan on t1 using PRIMARY over ('1999-07-01' <= event_date <= '1999-07-15' AND 100100 <= type) (cost=1.46 rows=6)
select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
event_date type event_id
1999-07-10 100100 24
1999-07-11 100100 25
1999-07-13 100600 0
1999-07-13 100600 4
1999-07-13 100600 26
1999-07-14 100600 10
explain select event_date,type,event_id from t1 WHERE type = 100601 and event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`event_date` AS `event_date`,`test`.`t1`.`type` AS `type`,`test`.`t1`.`event_id` AS `event_id` from `test`.`t1` where false order by `test`.`t1`.`event_date`
select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND (type=100600 OR type=100100) or event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND type=100099;
event_date type event_id
1999-07-10 100100 24
1999-07-11 100100 25
1999-07-13 100600 0
1999-07-13 100600 4
1999-07-13 100600 26
1999-07-14 100600 10
1999-07-15 100600 16
drop table t1;
CREATE TABLE t1 (
PAPER_ID smallint(6) DEFAULT '0' NOT NULL,
YEAR smallint(6) DEFAULT '0' NOT NULL,
ISSUE smallint(6) DEFAULT '0' NOT NULL,
CLOSED tinyint(4) DEFAULT '0' NOT NULL,
ISS_DATE date DEFAULT '0000-00-00' NOT NULL,
PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
);
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES (3,1999,34,0,'1999-07-12'), (1,1999,111,0,'1999-03-23'),
(1,1999,222,0,'1999-03-23'), (3,1999,33,0,'1999-07-12'),
(3,1999,32,0,'1999-07-12'), (3,1999,31,0,'1999-07-12'),
(3,1999,30,0,'1999-07-12'), (3,1999,29,0,'1999-07-12'),
(3,1999,28,0,'1999-07-12'), (1,1999,40,1,'1999-05-01'),
(1,1999,41,1,'1999-05-01'), (1,1999,42,1,'1999-05-01'),
(1,1999,46,1,'1999-05-01'), (1,1999,47,1,'1999-05-01'),
(1,1999,48,1,'1999-05-01'), (1,1999,49,1,'1999-05-01'),
(1,1999,50,0,'1999-05-01'), (1,1999,51,0,'1999-05-01'),
(1,1999,200,0,'1999-06-28'), (1,1999,52,0,'1999-06-28'),
(1,1999,53,0,'1999-06-28'), (1,1999,54,0,'1999-06-28'),
(1,1999,55,0,'1999-06-28'), (1,1999,56,0,'1999-07-01'),
(1,1999,57,0,'1999-07-01'), (1,1999,58,0,'1999-07-01'),
(1,1999,59,0,'1999-07-01'), (1,1999,60,0,'1999-07-01'),
(3,1999,35,0,'1999-07-12');
select YEAR,ISSUE from t1 where PAPER_ID=3 and (YEAR>1999 or (YEAR=1999 and ISSUE>28)) order by YEAR,ISSUE;
YEAR ISSUE
1999 29
1999 30
1999 31
1999 32
1999 33
1999 34
1999 35
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
repair table t1;
Table Op Msg_type Msg_text
test.t1 repair note The storage engine for the table doesn't support repair
drop table t1;
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
parent_id int(11) DEFAULT '0' NOT NULL,
level tinyint(4) DEFAULT '0' NOT NULL,
PRIMARY KEY (id),
KEY parent_id (parent_id),
KEY level (level)
);
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES (1,0,0), (3,1,1), (4,1,1), (8,2,2), (9,2,2), (17,3,2),
(22,4,2), (24,4,2), (28,5,2), (29,5,2), (30,5,2), (31,6,2), (32,6,2), (33,6,2),
(203,7,2), (202,7,2), (20,3,2), (157,0,0), (193,5,2), (40,7,2), (2,1,1),
(15,2,2), (6,1,1), (34,6,2), (35,6,2), (16,3,2), (7,1,1), (36,7,2), (18,3,2),
(26,5,2), (27,5,2), (183,4,2), (38,7,2), (25,5,2), (37,7,2), (21,4,2),
(19,3,2), (5,1,1), (179,5,2);
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1 order by id;
id parent_id level
2 1 1
3 1 1
4 1 1
5 1 1
6 1 1
7 1 1
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1 order by id;
id parent_id level
2 1 1
3 1 1
4 1 1
5 1 1
6 1 1
7 1 1
drop table t1;
create table t1(
Satellite varchar(25) not null,
SensorMode varchar(25) not null,
FullImageCornersUpperLeftLongitude double not null,
FullImageCornersUpperRightLongitude double not null,
FullImageCornersUpperRightLatitude double not null,
FullImageCornersLowerRightLatitude double not null,
index two (Satellite, SensorMode, FullImageCornersUpperLeftLongitude, FullImageCornersUpperRightLongitude, FullImageCornersUpperRightLatitude, FullImageCornersLowerRightLatitude));
insert into t1 values("OV-3","PAN1",91,-92,40,50);
insert into t1 values("OV-4","PAN1",91,-92,40,50);
select * from t1 where t1.Satellite = "OV-3" and t1.SensorMode = "PAN1" and t1.FullImageCornersUpperLeftLongitude > -90.000000 and t1.FullImageCornersUpperRightLongitude < -82.000000;
Satellite SensorMode FullImageCornersUpperLeftLongitude FullImageCornersUpperRightLongitude FullImageCornersUpperRightLatitude FullImageCornersLowerRightLatitude
OV-3 PAN1 91 -92 40 50
drop table t1;
create table t1 ( aString char(100) not null default "", key aString (aString(10)) );
insert t1 (aString) values ( "believe in myself" ), ( "believe" ), ("baaa" ), ( "believe in love");
select * from t1 where aString < "believe in myself" order by aString;
aString
baaa
believe
believe in love
select * from t1 where aString > "believe in love" order by aString;
aString
believe in myself
alter table t1 drop key aString;
select * from t1 where aString < "believe in myself" order by aString;
aString
baaa
believe
believe in love
select * from t1 where aString > "believe in love" order by aString;
aString
believe in myself
drop table t1;
CREATE TABLE t1 (
t1ID int(10) unsigned NOT NULL auto_increment,
art binary(1) NOT NULL default '',
KNR char(5) NOT NULL default '',
RECHNR char(6) NOT NULL default '',
POSNR char(2) NOT NULL default '',
ARTNR char(10) NOT NULL default '',
TEX char(70) NOT NULL default '',
PRIMARY KEY (t1ID),
KEY IdxArt (art),
KEY IdxKnr (KNR),
KEY IdxArtnr (ARTNR)
) ENGINE=MyISAM;
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 (art) VALUES ('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j');
select count(*) from t1 where upper(art) = 'J';
count(*)
213
select count(*) from t1 where art = 'J' or art = 'j';
count(*)
602
select count(*) from t1 where art = 'j' or art = 'J';
count(*)
602
select count(*) from t1 where art = 'j';
count(*)
389
select count(*) from t1 where art = 'J';
count(*)
213
drop table t1;
create table t1 (x int, y int, index(x), index(y));
insert into t1 (x) values (1),(2),(3),(4),(5),(6),(7),(8),(9);
update t1 set y=x;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref y y 5 const 1 100.00 NULL
1 SIMPLE t2 NULL range x x 5 NULL 2 100.00 Using index condition; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y`,`test`.`t2`.`x` AS `x`,`test`.`t2`.`y` AS `y` from `test`.`t1` join `test`.`t1` `t2` where ((`test`.`t1`.`y` = 8) and (`test`.`t2`.`x` between 7 and <cache>((8 + 0))))
explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref y y 5 const 1 100.00 NULL
1 SIMPLE t2 NULL range x x 5 NULL 2 100.00 Using index condition; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y`,`test`.`t2`.`x` AS `x`,`test`.`t2`.`y` AS `y` from `test`.`t1` join `test`.`t1` `t2` where ((`test`.`t1`.`y` = 8) and (`test`.`t2`.`x` >= 7) and (`test`.`t2`.`x` <= <cache>((8 + 0))))
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref y y 5 const 1 100.00 NULL
1 SIMPLE t2 NULL range x x 5 NULL 3 100.00 Using index condition; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y`,`test`.`t2`.`x` AS `x`,`test`.`t2`.`y` AS `y` from `test`.`t1` join `test`.`t1` `t2` where ((`test`.`t1`.`y` = 2) and (`test`.`t2`.`x` between <cache>((2 - 1)) and <cache>((2 + 1))))
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref y y 5 const 1 100.00 NULL
1 SIMPLE t2 NULL range x x 5 NULL 3 100.00 Using index condition; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y`,`test`.`t2`.`x` AS `x`,`test`.`t2`.`y` AS `y` from `test`.`t1` join `test`.`t1` `t2` where ((`test`.`t1`.`y` = 2) and (`test`.`t2`.`x` >= <cache>((2 - 1))) and (`test`.`t2`.`x` <= <cache>((2 + 1))))
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref y y 5 const 1 100.00 NULL
1 SIMPLE t2 NULL range x x 5 NULL 2 100.00 Using index condition; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y`,`test`.`t2`.`x` AS `x`,`test`.`t2`.`y` AS `y` from `test`.`t1` join `test`.`t1` `t2` where ((`test`.`t1`.`y` = 2) and (`test`.`t2`.`x` between 0 and 2))
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref y y 5 const 1 100.00 NULL
1 SIMPLE t2 NULL range x x 5 NULL 2 100.00 Using index condition; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y`,`test`.`t2`.`x` AS `x`,`test`.`t2`.`y` AS `y` from `test`.`t1` join `test`.`t1` `t2` where ((`test`.`t1`.`y` = 2) and (`test`.`t2`.`x` >= 0) and (`test`.`t2`.`x` <= 2))
explain select count(*) from t1 where x in (1);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref x x 5 const 1 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select count(0) AS `count(*)` from `test`.`t1` where (`test`.`t1`.`x` = 1)
explain select count(*) from t1 where x in (1,2);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 5 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select count(0) AS `count(*)` from `test`.`t1` where (`test`.`t1`.`x` in (1,2))
drop table t1;
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL ref j1 j1 4 const 1 100.00 Using index
1 SIMPLE t1 NULL index i1 i1 4 NULL 7 100.00 Using where; Using index; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`key1` AS `key1`,`test`.`t2`.`keya` AS `keya` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`keya` = 3) and (`test`.`t1`.`key1` < <cache>((3 + 1))))
explain select * from t1 force index(i1), t2 force index(j1) where
(t1.key1 <t2.keya + 1) and t2.keya=3;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL ref j1 j1 4 const 1 100.00 Using index
1 SIMPLE t1 NULL index i1 i1 4 NULL 7 100.00 Using where; Using index; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`key1` AS `key1`,`test`.`t2`.`keya` AS `keya` from `test`.`t1` FORCE INDEX (`i1`) join `test`.`t2` FORCE INDEX (`j1`) where ((`test`.`t2`.`keya` = 3) and (`test`.`t1`.`key1` < <cache>((3 + 1))))
DROP TABLE t1,t2;
CREATE TABLE t1 (
a int(11) default NULL,
b int(11) default NULL,
KEY a (a),
KEY b (b)
) ENGINE=MyISAM;
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES
(1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1),(10,2),(10,2),
(13,2),(14,2),(15,2),(16,2),(17,3),(17,3),(16,3),(17,3),(19,3),(20,3),
(21,4),(22,5),(23,5),(24,5),(25,5),(26,5),(30,5),(31,5),(32,5),(33,5),
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a,b a 5 NULL 2 40.54 Using index condition; Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 5) and (`test`.`t1`.`a` in (1,2)))
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
a b
DROP TABLE t1;
CREATE TABLE t1 (a int, b int, c int, INDEX (c,a,b));
INSERT INTO t1 VALUES (1,0,0),(1,0,0),(1,0,0);
INSERT INTO t1 VALUES (0,1,0),(0,1,0),(0,1,0);
SELECT COUNT(*) FROM t1 WHERE (c=0 and a=1) or (c=0 and b=1);
COUNT(*)
6
SELECT COUNT(*) FROM t1 WHERE (c=0 and b=1) or (c=0 and a=1);
COUNT(*)
6
DROP TABLE t1;
CREATE TABLE t1 ( a int not null, b int not null, INDEX ab(a,b) );
INSERT INTO t1 VALUES (47,1), (70,1), (15,1), (15, 4);
SELECT * FROM t1
WHERE
(
( b =1 AND a BETWEEN 14 AND 21 ) OR
( b =2 AND a BETWEEN 16 AND 18 ) OR
( b =3 AND a BETWEEN 15 AND 19 ) OR
(a BETWEEN 19 AND 47)
);
a b
15 1
47 1
DROP TABLE t1;
CREATE TABLE t1 (
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
line int( 5 ) unsigned NOT NULL default '0',
columnid int( 3 ) unsigned NOT NULL default '0',
owner int( 3 ) unsigned NOT NULL default '0',
ordinal int( 3 ) unsigned NOT NULL default '0',
showid smallint( 6 ) unsigned NOT NULL default '1',
tableid int( 1 ) unsigned NOT NULL default '1',
content int( 5 ) unsigned NOT NULL default '188',
PRIMARY KEY ( owner, id ) ,
KEY menu( owner, showid, columnid ) ,
KEY `COLUMN` ( owner, columnid, line ) ,
KEY `LINES` ( owner, tableid, content, id ) ,
KEY recount( owner, line )
) ENGINE = MYISAM;
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT into t1 (owner,id,columnid,line) values (11,15,15,1),(11,13,13,5);
SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
id columnid tableid content showid line ordinal
13 13 1 188 1 5 0
15 15 1 188 1 1 0
drop table t1;
create table t1 (id int(10) primary key);
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
select id from t1 where id in (2,5,9) ;
id
2
5
9
select id from t1 where id=2 or id=5 or id=9 ;
id
2
5
9
drop table t1;
create table t1 ( id1 int not null, id2 int not null, idnull int null, c char(20), primary key (id1,id2));
insert into t1 values (0,1,NULL,"aaa"), (1,1,NULL,"aaa"), (2,1,NULL,"aaa"),
(3,1,NULL,"aaa"), (4,1,NULL,"aaa"), (5,1,NULL,"aaa"),
(6,1,NULL,"aaa"), (7,1,NULL,"aaa"), (8,1,NULL,"aaa"),
(9,1,NULL,"aaa"), (10,1,NULL,"aaa"), (11,1,NULL,"aaa"),
(12,1,NULL,"aaa"), (13,1,NULL,"aaa"), (14,1,NULL,"aaa"),
(15,1,NULL,"aaa"), (16,1,NULL,"aaa"), (17,1,NULL,"aaa"),
(18,1,NULL,"aaa"), (19,1,NULL,"aaa"), (20,1,NULL,"aaa");
select a.id1, b.idnull from t1 as a, t1 as b where a.id2=1 and a.id1=1 and b.id1=a.idnull order by b.id2 desc limit 1;
id1 idnull
drop table t1;
create table t1 (
id int not null auto_increment,
name char(1) not null,
uid int not null,
primary key (id),
index uid_index (uid));
create table t2 (
id int not null auto_increment,
name char(1) not null,
uid int not null,
primary key (id),
index uid_index (uid));
insert into t1(id, uid, name) values(1, 0, ' ');
insert into t1(uid, name) values(0, ' ');
insert into t2(uid, name) select uid, name from t1;
insert into t1(uid, name) select uid, name from t2;
insert into t2(uid, name) select uid, name from t1;
insert into t1(uid, name) select uid, name from t2;
insert into t2(uid, name) select uid, name from t1;
insert into t1(uid, name) select uid, name from t2;
insert into t2(uid, name) select uid, name from t1;
insert into t1(uid, name) select uid, name from t2;
insert into t2(uid, name) select uid, name from t1;
insert into t1(uid, name) select uid, name from t2;
insert into t2(uid, name) select uid, name from t1;
insert into t2(uid, name) select uid, name from t1;
insert into t2(uid, name) select uid, name from t1;
insert into t2(uid, name) select uid, name from t1;
insert into t1(uid, name) select uid, name from t2;
delete from t2;
insert into t2(uid, name) values
(1, CHAR(64+1)),
(2, CHAR(64+2)),
(3, CHAR(64+3)),
(4, CHAR(64+4)),
(5, CHAR(64+5)),
(6, CHAR(64+6)),
(7, CHAR(64+7)),
(8, CHAR(64+8)),
(9, CHAR(64+9)),
(10, CHAR(64+10)),
(11, CHAR(64+11)),
(12, CHAR(64+12)),
(13, CHAR(64+13)),
(14, CHAR(64+14)),
(15, CHAR(64+15)),
(16, CHAR(64+16)),
(17, CHAR(64+17)),
(18, CHAR(64+18)),
(19, CHAR(64+19)),
(20, CHAR(64+20)),
(21, CHAR(64+21)),
(22, CHAR(64+22)),
(23, CHAR(64+23)),
(24, CHAR(64+24)),
(25, CHAR(64+25)),
(26, CHAR(64+26));
insert into t1(uid, name) select uid, name from t2 order by uid;
delete from t2;
insert into t2(id, uid, name) select id, uid, name from t1;
select count(*) from t1;
count(*)
1026
select count(*) from t2;
count(*)
1026
analyze table t1,t2;
Table Op Msg_type Msg_text
test.t1 analyze status OK
test.t2 analyze status OK
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE # NULL range uid_index uid_index 4 # 28 100.00 Using index condition
1 SIMPLE # NULL ref uid_index uid_index 4 # 28 100.00 NULL
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid > 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE # NULL range uid_index uid_index 4 # 28 100.00 Using index condition
1 SIMPLE # NULL ref uid_index uid_index 4 # 28 100.00 NULL
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE # NULL range uid_index uid_index 4 # 28 100.00 Using index condition
1 SIMPLE # NULL ref uid_index uid_index 4 # 28 100.00 NULL
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid != 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE # NULL range uid_index uid_index 4 # 28 100.00 Using index condition
1 SIMPLE # NULL ref uid_index uid_index 4 # 28 100.00 NULL
select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
id name uid id name uid
1257 A 1 1257 A 1
1258 B 2 1258 B 2
1259 C 3 1259 C 3
1260 D 4 1260 D 4
1261 E 5 1261 E 5
1262 F 6 1262 F 6
1263 G 7 1263 G 7
1264 H 8 1264 H 8
1265 I 9 1265 I 9
1266 J 10 1266 J 10
1267 K 11 1267 K 11
1268 L 12 1268 L 12
1269 M 13 1269 M 13
1270 N 14 1270 N 14
1271 O 15 1271 O 15
1272 P 16 1272 P 16
1273 Q 17 1273 Q 17
1274 R 18 1274 R 18
1275 S 19 1275 S 19
1276 T 20 1276 T 20
1277 U 21 1277 U 21
1278 V 22 1278 V 22
1279 W 23 1279 W 23
1280 X 24 1280 X 24
1281 Y 25 1281 Y 25
1282 Z 26 1282 Z 26
select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
id name uid id name uid
1257 A 1 1257 A 1
1258 B 2 1258 B 2
1259 C 3 1259 C 3
1260 D 4 1260 D 4
1261 E 5 1261 E 5
1262 F 6 1262 F 6
1263 G 7 1263 G 7
1264 H 8 1264 H 8
1265 I 9 1265 I 9
1266 J 10 1266 J 10
1267 K 11 1267 K 11
1268 L 12 1268 L 12
1269 M 13 1269 M 13
1270 N 14 1270 N 14
1271 O 15 1271 O 15
1272 P 16 1272 P 16
1273 Q 17 1273 Q 17
1274 R 18 1274 R 18
1275 S 19 1275 S 19
1276 T 20 1276 T 20
1277 U 21 1277 U 21
1278 V 22 1278 V 22
1279 W 23 1279 W 23
1280 X 24 1280 X 24
1281 Y 25 1281 Y 25
1282 Z 26 1282 Z 26
drop table t1,t2;
create table t1 (x bigint unsigned not null);
insert into t1(x) values (0xfffffffffffffff0);
insert into t1(x) values (0xfffffffffffffff1);
select * from t1;
x
18446744073709551600
18446744073709551601
select count(*) from t1 where x>0;
count(*)
2
select count(*) from t1 where x=0;
count(*)
0
select count(*) from t1 where x<0;
count(*)
0
select count(*) from t1 where x < -16;
count(*)
0
select count(*) from t1 where x = -16;
count(*)
0
select count(*) from t1 where x > -16;
count(*)
2
select count(*) from t1 where x = 18446744073709551601;
count(*)
1
create table t2 (x bigint not null);
insert into t2(x) values (-16);
insert into t2(x) values (-15);
select * from t2;
x
-16
-15
select count(*) from t2 where x>0;
count(*)
0
select count(*) from t2 where x=0;
count(*)
0
select count(*) from t2 where x<0;
count(*)
2
select count(*) from t2 where x < -16;
count(*)
0
select count(*) from t2 where x = -16;
count(*)
1
select count(*) from t2 where x > -16;
count(*)
1
select count(*) from t2 where x = 18446744073709551601;
count(*)
0
drop table t1,t2;
create table t1 (x bigint unsigned not null primary key) engine=innodb;
insert into t1(x) values (0xfffffffffffffff0);
insert into t1(x) values (0xfffffffffffffff1);
select * from t1;
x
18446744073709551600
18446744073709551601
select count(*) from t1 where x>0;
count(*)
2
select count(*) from t1 where x=0;
count(*)
0
select count(*) from t1 where x<0;
count(*)
0
select count(*) from t1 where x < -16;
count(*)
0
select count(*) from t1 where x = -16;
count(*)
0
select count(*) from t1 where x > -16;
count(*)
2
select count(*) from t1 where x = 18446744073709551601;
count(*)
1
drop table t1;
create table t1 (a bigint unsigned);
create index t1i on t1(a);
insert into t1 select 18446744073709551615;
insert into t1 select 18446744073709551614;
explain select * from t1 where a <> -1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index t1i t1i 9 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null)
select * from t1 where a <> -1;
a
18446744073709551614
18446744073709551615
explain select * from t1 where a > -1 or a < -1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index t1i t1i 9 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null)
select * from t1 where a > -1 or a < -1;
a
18446744073709551614
18446744073709551615
explain select * from t1 where a > -1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index t1i t1i 9 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null)
select * from t1 where a > -1;
a
18446744073709551614
18446744073709551615
explain select * from t1 where a < -1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where false
select * from t1 where a < -1;
a
drop table t1;
set names latin1;
create table t1 (a char(10), b text, key (a)) character set latin1;
INSERT INTO t1 (a) VALUES
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
explain select * from t1 where a='aaa';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref a a 11 const 2 100.00 NULL
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` = 'aaa')
explain select * from t1 where a=binary 'aaa';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 11 NULL 2 100.00 Using index condition
Warnings:
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 1739 Cannot use ref access on index 'a' due to type or collation conversion on field 'a'
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` = <cache>(cast('aaa' as char charset binary)))
explain select * from t1 where a='aaa' collate latin1_bin;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 11 NULL 2 100.00 Using index condition
Warnings:
Warning 1739 Cannot use ref access on index 'a' due to type or collation conversion on field 'a'
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` = <cache>(('aaa' collate latin1_bin)))
explain select * from t1 where a='aaa' collate latin1_german1_ci;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL a NULL NULL NULL 9 11.11 Using where
Warnings:
Warning 1739 Cannot use ref access on index 'a' due to type or collation conversion on field 'a'
Warning 1739 Cannot use range access on index 'a' due to type or collation conversion on field 'a'
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` = <cache>(('aaa' collate latin1_german1_ci)))
drop table t1;
CREATE TABLE t1 (
`CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000',
`ARG1` char(3) character set latin1 collate latin1_bin NOT NULL default '',
`ARG2` char(3) character set latin1 collate latin1_bin NOT NULL default '',
`FUNCTION` varchar(10) character set latin1 collate latin1_bin NOT NULL default '',
`FUNCTINT` int(11) NOT NULL default '0',
KEY `VERI_CLNT~2` (`ARG1`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
('001',' 3',' 0','Text 017',0);
SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 1' OR ARG1 != ' 2');
count(*)
4
SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 2' OR ARG1 != ' 1');
count(*)
4
drop table t1;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t2 (
pk1 int(11) NOT NULL,
pk2 int(11) NOT NULL,
pk3 int(11) NOT NULL,
pk4 int(11) NOT NULL,
filler char(82),
PRIMARY KEY (pk1,pk2,pk3,pk4)
) DEFAULT CHARSET=latin1;
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
(2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
(2621, 2635, 14, 0,'filler'), (2621, 2635, 1000015, 0,'filler');
SELECT * FROM t2
WHERE ((((pk4 =0) AND (pk1 =2621) AND (pk2 =2635)))
OR ((pk4 =1) AND (((pk1 IN ( 7, 2, 1 ))) OR (pk1 =522)) AND ((pk2 IN ( 0, 2635))))
) AND (pk3 >=1000000);
pk1 pk2 pk3 pk4 filler
2621 2635 1000015 0 filler
drop table t1, t2;
create table t1(a char(2), key(a(1))) charset utf8mb4;
insert into t1 values ('x'), ('xx');
explain select a from t1 where a > 'x';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 5 NULL 2 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 'x')
select a from t1 where a > 'x';
a
xx
drop table t1;
CREATE TABLE t1 (
OXID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
OXPARENTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT 'oxrootid',
OXLEFT int NOT NULL DEFAULT '0',
OXRIGHT int NOT NULL DEFAULT '0',
OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
PRIMARY KEY (OXID),
KEY OXNID (OXID),
KEY OXLEFT (OXLEFT),
KEY OXRIGHT (OXRIGHT),
KEY OXROOTID (OXROOTID)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
INSERT INTO t1 VALUES
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
'd8c4177d09f8b11f5.52725521'),
('d8c4177d206a333d2.74422679','d8c4177d09f8b11f5.52725521',4,5,
'd8c4177d09f8b11f5.52725521'),
('d8c4177d225791924.30714720','d8c4177d09f8b11f5.52725521',6,7,
'd8c4177d09f8b11f5.52725521'),
('d8c4177d2380fc201.39666693','d8c4177d09f8b11f5.52725521',8,9,
'd8c4177d09f8b11f5.52725521'),
('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11,
'd8c4177d09f8b11f5.52725521');
EXPLAIN
SELECT s.oxid FROM t1 v, t1 s
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE v NULL ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 5 100.00 NULL
1 SIMPLE s NULL ref OXLEFT,OXROOTID OXROOTID 34 const 5 16.67 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`s`.`OXID` AS `oxid` from `test`.`t1` `v` join `test`.`t1` `s` where ((`test`.`s`.`OXROOTID` = 'd8c4177d09f8b11f5.52725521') and (`test`.`v`.`OXROOTID` = 'd8c4177d09f8b11f5.52725521') and (`test`.`s`.`OXLEFT` > `test`.`v`.`OXLEFT`) and (`test`.`s`.`OXLEFT` < `test`.`v`.`OXRIGHT`))
SELECT s.oxid FROM t1 v, t1 s
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
oxid
d8c4177d151affab2.81582770
d8c4177d206a333d2.74422679
d8c4177d225791924.30714720
d8c4177d2380fc201.39666693
d8c4177d24ccef970.14957924
DROP TABLE t1;
create table t1 (
c1 char(10), c2 char(10), c3 char(10), c4 char(10),
c5 char(10), c6 char(10), c7 char(10), c8 char(10),
c9 char(10), c10 char(10), c11 char(10), c12 char(10),
c13 char(10), c14 char(10), c15 char(10), c16 char(10),
index(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,c13,c14,c15,c16)
);
insert into t1 (c1) values ('1'),('1'),('1'),('1');
select * from t1 where
c1 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c2 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c3 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c4 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c5 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c6 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c7 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c8 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c9 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
and c10 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC");
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16
Warnings:
Warning 3170 Memory capacity of 8388608 bytes for 'range_optimizer_max_mem_size' exceeded. Range optimization was not done for this query.
drop table t1;
End of 4.1 tests
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
status varchar(20),
PRIMARY KEY (id),
KEY (status)
) CHARSET utf8mb4;
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES
(1,'B'), (2,'B'), (3,'B'), (4,'B'), (5,'B'), (6,'B'),
(7,'B'), (8,'B'), (9,'B'), (10,'B'), (11,'B'), (12,'B'),
(13,'B'), (14,'B'), (15,'B'), (16,'B'), (17,'B'), (18,'B'),
(19,'B'), (20,'B'), (21,'B'), (22,'B'), (23,'B'), (24,'B'),
(25,'A'), (26,'A'), (27,'A'), (28,'A'), (29,'A'), (30,'A'),
(31,'A'), (32,'A'), (33,'A'), (34,'A'), (35,'A'), (36,'A'),
(37,'A'), (38,'A'), (39,'A'), (40,'A'), (41,'A'), (42,'A'),
(43,'A'), (44,'A'), (45,'A'), (46,'A'), (47,'A'), (48,'A'),
(49,'A'), (50,'A'), (51,'A'), (52,'A'), (53,'C'), (54,'C'),
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range status status 83 NULL 10 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`status` AS `status` from `test`.`t1` where ((`test`.`t1`.`status` <> 'A') and (`test`.`t1`.`status` <> 'B'))
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range status status 83 NULL 10 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`status` AS `status` from `test`.`t1` where (`test`.`t1`.`status` not in ('A','B'))
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
id status
53 C
54 C
55 C
56 C
57 C
58 C
59 C
60 C
SELECT * FROM t1 WHERE status NOT IN ('A','B');
id status
53 C
54 C
55 C
56 C
57 C
58 C
59 C
60 C
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range status status 83 NULL 10 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`status` AS `status` from `test`.`t1` where ((`test`.`t1`.`status` <> 'A') and (`test`.`t1`.`status` <> 'B'))
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range status status 83 NULL 10 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`status` AS `status` from `test`.`t1` where (`test`.`t1`.`status` not in ('A','B'))
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range status status 83 NULL 9 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`status` AS `status` from `test`.`t1` where (`test`.`t1`.`status` not between 'A' and 'B')
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range status status 83 NULL 9 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`status` AS `status` from `test`.`t1` where ((`test`.`t1`.`status` < 'A') or (`test`.`t1`.`status` > 'B'))
SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
id status
53 C
54 C
55 C
56 C
57 C
58 C
59 C
60 C
SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
id status
53 C
54 C
55 C
56 C
57 C
58 C
59 C
60 C
DROP TABLE t1;
CREATE TABLE t1 (a int, b int, primary key(a,b));
INSERT INTO t1 VALUES
(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3);
CREATE VIEW v1 as SELECT a,b FROM t1 WHERE b=3;
EXPLAIN SELECT a,b FROM t1 WHERE a < 2 and b=3;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 4 NULL 3 10.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 3) and (`test`.`t1`.`a` < 2))
EXPLAIN SELECT a,b FROM v1 WHERE a < 2 and b=3;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 4 NULL 3 10.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 3) and (`test`.`t1`.`a` < 2))
EXPLAIN SELECT a,b FROM t1 WHERE a < 2;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` < 2)
EXPLAIN SELECT a,b FROM v1 WHERE a < 2;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 4 NULL 3 10.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 3) and (`test`.`t1`.`a` < 2))
SELECT a,b FROM t1 WHERE a < 2 and b=3;
a b
1 3
SELECT a,b FROM v1 WHERE a < 2 and b=3;
a b
1 3
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
INSERT INTO t1 VALUES ('Betty'), ('Anna');
SELECT * FROM t1;
name
Anna
Betty
DELETE FROM t1 WHERE name NOT LIKE 'A%a';
SELECT * FROM t1;
name
Anna
DROP TABLE t1;
CREATE TABLE t1 (a int, KEY idx(a));
INSERT INTO t1 VALUES (NULL), (1), (2), (3);
SELECT * FROM t1;
a
NULL
1
2
3
DELETE FROM t1 WHERE NOT(a <=> 2);
SELECT * FROM t1;
a
2
DROP TABLE t1;
create table t1 (a int, b int, primary key(a,b));
create view v1 as select a, b from t1;
INSERT INTO `t1` VALUES
(0,0),(1,0),(2,0),(3,0),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,2),(11,2),(12,2)
,(13,2),(14,2),(15,3),(16,3),(17,3),(18,3),(19,3);
explain select * from t1 where a in (3,4) and b in (1,2,3);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 8 NULL # 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a` in (3,4)) and (`test`.`t1`.`b` in (1,2,3)))
explain select * from v1 where a in (3,4) and b in (1,2,3);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 8 NULL # 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a` in (3,4)) and (`test`.`t1`.`b` in (1,2,3)))
explain select * from t1 where a between 3 and 4 and b between 1 and 2;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 8 NULL # 11.11 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a` between 3 and 4) and (`test`.`t1`.`b` between 1 and 2))
explain select * from v1 where a between 3 and 4 and b between 1 and 2;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 8 NULL # 11.11 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a` between 3 and 4) and (`test`.`t1`.`b` between 1 and 2))
drop view v1;
drop table t1;
create table t3 (a int);
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;
insert into t1 values ('a','');
insert into t1 values ('a ','');
insert into t1 values ('a ', '');
insert into t1 select concat('a', 1000 + A.a + 10 * (B.a + 10 * C.a)), ''
from t3 A, t3 B, t3 C;
create table t2 (a varchar(10), filler char(200), key(a)) charset utf8mb4;
insert into t2 select * from t1;
explain select * from t1 where a between 'a' and 'a ';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 13 NULL # 100.00 Using index condition
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`filler` AS `filler` from `test`.`t1` where (`test`.`t1`.`a` between 'a' and 'a ')
explain select * from t1 where a = 'a' or a='a ';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 13 NULL # 100.00 Using index condition
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`filler` AS `filler` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') or (`test`.`t1`.`a` = 'a '))
explain select * from t2 where a between 'a' and 'A';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL ref a a 43 const # 100.00 Using index condition
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`filler` AS `filler` from `test`.`t2` where (`test`.`t2`.`a` between 'a' and 'A')
explain select * from t2 where a = 'a' or a='A';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL ref a a 43 const # 100.00 NULL
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`filler` AS `filler` from `test`.`t2` where ((`test`.`t2`.`a` = 'a') or (`test`.`t2`.`a` = 'A'))
update t1 set a='b' where a<>'a';
explain select * from t1 where a not between 'b' and 'b';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL a NULL NULL NULL # 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`filler` AS `filler` from `test`.`t1` where (`test`.`t1`.`a` not between 'b' and 'b')
select a, hex(filler) from t1 where a not between 'b' and 'b';
a hex(filler)
a 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
drop table t1,t2,t3;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, key(a));
insert into t2 select 2*(A.a + 10*(B.a + 10*C.a)) from t1 A, t1 B, t1 C;
set @a="select * from t2 force index (a) where a NOT IN(0";
select count(*) from (select @a:=concat(@a, ',', a) from t2 ) Z;
count(*)
1000
Warnings:
Warning 1287 Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'.
set @a=concat(@a, ')');
insert into t2 values (11),(13),(15);
set @b= concat("explain ", @a);
prepare stmt1 from @b;
execute stmt1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL index a a 5 NULL 1003 50.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` FORCE INDEX (`a`) where (`test`.`t2`.`a` not in (0,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,256,258,260,262,264,266,268,270,272,274,276,278,280,282,284,286,288,290,292,294,296,298,300,302,304,306,308,310,312,314,316,318,320,322,324,326,328,330,332,334,336,338,340,342,344,346,348,350,352,354,356,358,360,362,364,366,368,370,372,374,376,378,380,382,384,386,388,390,392,394,396,398,400,402,404,406,408,410,412,414,416,418,420,422,424,426,428,430,432,434,436,438,440,442,444,446,448,450,452,454,456,458,460,462,464,466,468,470,472,474,476,478,480,482,484,486,488,490,492,494,496,498,500,502,504,506,508,510,512,514,516,518,520,522,524,526,528,530,532,534,536,538,540,542,544,546,548,550,552,554,556,558,560,562,564,566,568,570,572,574,576,578,580,582,584,586,588,590,592,594,596,598,600,602,604,606,608,610,612,614,616,618,620,622,624,626,628,630,632,634,636,638,640,642,644,646,648,650,652,654,656,658,660,662,664,666,668,670,672,674,676,678,680,682,684,686,688,690,692,694,696,698,700,702,704,706,708,710,712,714,716,718,720,722,724,726,728,730,732,734,736,738,740,742,744,746,748,750,752,754,756,758,760,762,764,766,768,770,772,774,776,778,780,782,784,786,788,790,792,794,796,798,800,802,804,806,808,810,812,814,816,818,820,822,824,826,828,830,832,834,836,838,840,842,844,846,848,850,852,854,856,858,860,862,864,866,868,870,872,874,876,878,880,882,884,886,888,890,892,894,896,898,900,902,904,906,908,910,912,914,916,918,920,922,924,926,928,930,932,934,936,938,940,942,944,946,948,950,952,954,956,958,960,962,964,966,968,970,972,974,976,978,980,982,984,986,988,990,992,994,996,998,1000,1002,1004,1006,1008,1010,1012,1014,1016,1018,1020,1022,1024,1026,1028,1030,1032,1034,1036,1038,1040,1042,1044,1046,1048,1050,1052,1054,1056,1058,1060,1062,1064,1066,1068,1070,1072,1074,1076,1078,1080,1082,1084,1086,1088,1090,1092,1094,1096,1098,1100,1102,1104,1106,1108,1110,1112,1114,1116,1118,1120,1122,1124,1126,1128,1130,1132,1134,1136,1138,1140,1142,1144,1146,1148,1150,1152,1154,1156,1158,1160,1162,1164,1166,1168,1170,1172,1174,1176,1178,1180,1182,1184,1186,1188,1190,1192,1194,1196,1198,1200,1202,1204,1206,1208,1210,1212,1214,1216,1218,1220,1222,1224,1226,1228,1230,1232,1234,1236,1238,1240,1242,1244,1246,1248,1250,1252,1254,1256,1258,1260,1262,1264,1266,1268,1270,1272,1274,1276,1278,1280,1282,1284,1286,1288,1290,1292,1294,1296,1298,1300,1302,1304,1306,1308,1310,1312,1314,1316,1318,1320,1322,1324,1326,1328,1330,1332,1334,1336,1338,1340,1342,1344,1346,1348,1350,1352,1354,1356,1358,1360,1362,1364,1366,1368,1370,1372,1374,1376,1378,1380,1382,1384,1386,1388,1390,1392,1394,1396,1398,1400,1402,1404,1406,1408,1410,1412,1414,1416,1418,1420,1422,1424,1426,1428,1430,1432,1434,1436,1438,1440,1442,1444,1446,1448,1450,1452,1454,1456,1458,1460,1462,1464,1466,1468,1470,1472,1474,1476,1478,1480,1482,1484,1486,1488,1490,1492,1494,1496,1498,1500,1502,1504,1506,1508,1510,1512,1514,1516,1518,1520,1522,1524,1526,1528,1530,1532,1534,1536,1538,1540,1542,1544,1546,1548,1550,1552,1554,1556,1558,1560,1562,1564,1566,1568,1570,1572,1574,1576,1578,1580,1582,1584,1586,1588,1590,1592,1594,1596,1598,1600,1602,1604,1606,1608,1610,1612,1614,1616,1618,1620,1622,1624,1626,1628,1630,1632,1634,1636,1638,1640,1642,1644,1646,1648,1650,1652,1654,1656,1658,1660,1662,1664,1666,1668,1670,1672,1674,1676,1678,1680,1682,1684,1686,1688,1690,1692,1694,1696,1698,1700,1702,1704,1706,1708,1710,1712,1714,1716,1718,1720,1722,1724,1726,1728,1730,1732,1734,1736,1738,1740,1742,1744,1746,1748,1750,1752,1754,1756,1758,1760,1762,1764,1766,1768,1770,1772,1774,1776,1778,1780,1782,1784,1786,1788,1790,1792,1794,1796,1798,1800,1802,1804,1806,1808,1810,1812,1814,1816,1818,1820,1822,1824,1826,1828,1830,1832,1834,1836,1838,1840,1842,1844,1846,1848,1850,1852,1854,1856,1858,1860,1862,1864,1866,1868,1870,1872,1874,1876,1878,1880,1882,1884,1886,1888,1890,1892,1894,1896,1898,1900,1902,1904,1906,1908,1910,1912,1914,1916,1918,1920,1922,1924,1926,1928,1930,1932,1934,1936,1938,1940,1942,1944,1946,1948,1950,1952,1954,1956,1958,1960,1962,1964,1966,1968,1970,1972,1974,1976,1978,1980,1982,1984,1986,1988,1990,1992,1994,1996,1998))
prepare stmt1 from @a;
execute stmt1;
a
11
13
15
drop table t1, t2;
CREATE TABLE t1 (
id int NOT NULL DEFAULT '0',
b int NOT NULL DEFAULT '0',
c int NOT NULL DEFAULT '0',
INDEX idx1(b,c), INDEX idx2(c));
INSERT INTO t1(id) VALUES (1), (2), (3), (4), (5), (6), (7), (8);
INSERT INTO t1(b,c) VALUES (3,4), (3,4);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SELECT * FROM t1 WHERE b<=3 AND 3<=c;
id b c
0 3 4
0 3 4
SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
id b c
0 3 4
0 3 4
EXPLAIN SELECT * FROM t1 WHERE b<=3 AND 3<=c;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((`test`.`t1`.`b` <= 3) and (3 <= `test`.`t1`.`c`))
EXPLAIN SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (3 between `test`.`t1`.`b` and `test`.`t1`.`c`)
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
id b c
0 3 4
0 3 4
SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
id b c
0 3 4
0 3 4
EXPLAIN SELECT * FROM t1 WHERE 0 < b OR 0 > c;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index_merge idx1,idx2 idx1,idx2 4,4 NULL 3 100.00 Using sort_union(idx1,idx2); Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((0 < `test`.`t1`.`b`) or (0 > `test`.`t1`.`c`))
EXPLAIN SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index_merge idx1,idx2 idx1,idx2 4,4 NULL 3 100.00 Using sort_union(idx1,idx2); Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (0 not between `test`.`t1`.`b` and `test`.`t1`.`c`)
EXPLAIN FORMAT=tree SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
EXPLAIN
-> Filter: (0 not between t1.b and t1.c) (cost=2.15 rows=3)
-> Sort-deduplicate by row ID (cost=2.15 rows=3)
-> Index range scan on t1 using idx1 over (0 < b) (cost=0.46 rows=2)
-> Index range scan on t1 using idx2 over (c < 0) (cost=0.36 rows=1)
DROP TABLE t1;
CREATE TABLE t1 (
item char(20) NOT NULL default '',
started datetime NOT NULL default '0000-00-00 00:00:00',
price decimal(16,3) NOT NULL default '0.000',
PRIMARY KEY (item,started)
) ENGINE=MyISAM, CHARSET utf8mb4;
INSERT INTO t1 VALUES
('A1','2005-11-01 08:00:00',1000),
('A1','2005-11-15 00:00:00',2000),
('A1','2005-12-12 08:00:00',3000),
('A2','2005-12-01 08:00:00',1000);
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
ERROR HY000: Incorrect DATETIME value: '2005-12-01 24:00:00'
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
ERROR HY000: Incorrect DATETIME value: '2005-12-01 24:00:00'
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
item started price
A1 2005-11-01 08:00:00 1000.000
A1 2005-11-15 00:00:00 2000.000
DROP INDEX `PRIMARY` ON t1;
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
ERROR HY000: Incorrect DATETIME value: '2005-12-01 24:00:00'
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
ERROR HY000: Incorrect DATETIME value: '2005-12-01 24:00:00'
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
item started price
A1 2005-11-01 08:00:00 1000.000
A1 2005-11-15 00:00:00 2000.000
DROP TABLE t1;
BUG#32198 "Comparison of DATE with DATETIME still not using indexes correctly"
CREATE TABLE t1 (
id int(11) NOT NULL auto_increment,
dateval date default NULL,
PRIMARY KEY (id),
KEY dateval (dateval)
) AUTO_INCREMENT=173;
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES
(1,'2007-01-01'),(2,'2007-01-02'),(3,'2007-01-03'),(4,'2007-01-04'),
(5,'2007-01-05'),(6,'2007-01-06'),(7,'2007-01-07'),(8,'2007-01-08'),
(9,'2007-01-09'),(10,'2007-01-10'),(11,'2007-01-11');
This must use range access:
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range dateval dateval 4 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`dateval` AS `dateval` from `test`.`t1` where ((`test`.`t1`.`dateval` >= DATE'2007-01-01') and (`test`.`t1`.`dateval` <= DATE'2007-01-02'))
drop table t1;
CREATE TABLE t1 (
a varchar(32), index (a)
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
INSERT INTO t1 VALUES
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
SELECT a FROM t1 WHERE a='b' OR a='B';
a
B
B
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 35 NULL 3 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 'b') or (`test`.`t1`.`a` = 'B'))
DROP TABLE t1;
CREATE TABLE t1 (f1 TINYINT(11) UNSIGNED NOT NULL, PRIMARY KEY (f1));
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
COUNT(*)
5
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
COUNT(*)
5
SELECT COUNT(*) FROM t1 WHERE f1 < 255;
COUNT(*)
4
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
COUNT(*)
0
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
COUNT(*)
5
DROP TABLE t1;
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
COUNT(*)
5
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
COUNT(*)
5
SELECT COUNT(*) FROM t1 WHERE f1 < 127;
COUNT(*)
4
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
COUNT(*)
5
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
COUNT(*)
5
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
COUNT(*)
4
DROP TABLE t1;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, filler char(100));
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
t1 B, t1 C where A.a < 5;
insert into t2 select 1000, b, 'filler' from t2;
alter table t2 add index (a,b);
Access method can be range/ALL with #rows >= 500.
Or it can be ref with #rows = 2, only when there is memory limit.
explain select * from t2 where a=1000 and b<11;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL ALL a NULL NULL NULL 1000 50.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`filler` AS `filler` from `test`.`t2` where ((`test`.`t2`.`a` = 1000) and (`test`.`t2`.`b` < 11))
drop table t1, t2;
CREATE TABLE t1( a INT, b INT, KEY( a, b ) );
CREATE TABLE t2( a INT, b INT, KEY( a, b ) );
CREATE TABLE t3( a INT, b INT, KEY( a, b ) );
INSERT INTO t1( a, b )
VALUES (0, 1), (1, 2), (1, 4), (2, 3), (5, 0), (9, 7);
INSERT INTO t2( a, b )
VALUES ( 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);
INSERT INTO t2 SELECT a, 2 FROM t2 WHERE b = 1;
INSERT INTO t2 SELECT a, 3 FROM t2 WHERE b = 1;
INSERT INTO t2 SELECT -1, -1 FROM t2;
INSERT INTO t2 SELECT -1, -1 FROM t2;
INSERT INTO t2 SELECT -1, -1 FROM t2;
INSERT INTO t3
VALUES (1, 0), (2, 0), (3, 0), (4, 0), (5, 0),
(6, 0), (7, 0), (8, 0), (9, 0), (10, 0);
INSERT INTO t3 SELECT * FROM t3 WHERE a = 10;
INSERT INTO t3 SELECT * FROM t3 WHERE a = 10;
SELECT * FROM t1 WHERE
3 <= a AND a < 5 OR
5 < a AND b = 3 OR
3 <= a;
a b
5 0
9 7
EXPLAIN
SELECT * FROM t1 WHERE
3 <= a AND a < 5 OR
5 < a AND b = 3 OR
3 <= a;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 5 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((3 <= `test`.`t1`.`a`) and (`test`.`t1`.`a` < 5)) or ((`test`.`t1`.`b` = 3) and (5 < `test`.`t1`.`a`)) or (3 <= `test`.`t1`.`a`))
SELECT * FROM t1 WHERE
3 <= a AND a < 5 OR
5 <= a AND b = 3 OR
3 <= a;
a b
5 0
9 7
EXPLAIN
SELECT * FROM t1 WHERE
3 <= a AND a < 5 OR
5 <= a AND b = 3 OR
3 <= a;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 5 NULL 3 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((3 <= `test`.`t1`.`a`) and (`test`.`t1`.`a` < 5)) or ((`test`.`t1`.`b` = 3) and (5 <= `test`.`t1`.`a`)) or (3 <= `test`.`t1`.`a`))
SELECT * FROM t1 WHERE
3 <= a AND a <= 5 OR
5 <= a AND b = 3 OR
3 <= a;
a b
5 0
9 7
EXPLAIN
SELECT * FROM t1 WHERE
3 <= a AND a <= 5 OR
5 <= a AND b = 3 OR
3 <= a;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 5 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((3 <= `test`.`t1`.`a`) and (`test`.`t1`.`a` <= 5)) or ((`test`.`t1`.`b` = 3) and (5 <= `test`.`t1`.`a`)) or (3 <= `test`.`t1`.`a`))
SELECT * FROM t1 WHERE
3 <= a AND a <= 5 OR
3 <= a;
a b
5 0
9 7
EXPLAIN
SELECT * FROM t1 WHERE
3 <= a AND a <= 5 OR
3 <= a;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 5 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((3 <= `test`.`t1`.`a`) and (`test`.`t1`.`a` <= 5)) or (3 <= `test`.`t1`.`a`))
SELECT * FROM t2 WHERE
5 <= a AND a < 10 AND b = 1 OR
15 <= a AND a < 20 AND b = 3
OR
1 <= a AND b = 1;
a b
1 1
10 1
11 1
12 1
13 1
14 1
15 1
15 3
16 1
16 3
17 1
17 3
18 1
18 3
19 1
19 3
2 1
20 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
EXPLAIN
SELECT * FROM t2 WHERE
5 <= a AND a < 10 AND b = 1 OR
15 <= a AND a < 20 AND b = 3
OR
1 <= a AND b = 1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL range a a 10 NULL 60 27.10 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (((`test`.`t2`.`b` = 1) and (5 <= `test`.`t2`.`a`) and (`test`.`t2`.`a` < 10)) or ((`test`.`t2`.`b` = 3) and (15 <= `test`.`t2`.`a`) and (`test`.`t2`.`a` < 20)) or ((`test`.`t2`.`b` = 1) and (1 <= `test`.`t2`.`a`)))
SELECT * FROM t2 WHERE
5 <= a AND a < 10 AND b = 2 OR
15 <= a AND a < 20 AND b = 3
OR
1 <= a AND b = 1;
a b
1 1
10 1
11 1
12 1
13 1
14 1
15 1
15 3
16 1
16 3
17 1
17 3
18 1
18 3
19 1
19 3
2 1
20 1
3 1
4 1
5 1
5 2
6 1
6 2
7 1
7 2
8 1
8 2
9 1
9 2
EXPLAIN
SELECT * FROM t2 WHERE
5 <= a AND a < 10 AND b = 2 OR
15 <= a AND a < 20 AND b = 3
OR
1 <= a AND b = 1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL range a a 10 NULL 60 27.10 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (((`test`.`t2`.`b` = 2) and (5 <= `test`.`t2`.`a`) and (`test`.`t2`.`a` < 10)) or ((`test`.`t2`.`b` = 3) and (15 <= `test`.`t2`.`a`) and (`test`.`t2`.`a` < 20)) or ((`test`.`t2`.`b` = 1) and (1 <= `test`.`t2`.`a`)))
SELECT * FROM t3 WHERE
5 <= a AND a < 10 AND b = 3 OR
a < 5 OR
a < 10;
a b
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
EXPLAIN
SELECT * FROM t3 WHERE
5 <= a AND a < 10 AND b = 3 OR
a < 5 OR
a < 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 NULL range a a 5 NULL 9 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t3` where (((`test`.`t3`.`b` = 3) and (5 <= `test`.`t3`.`a`) and (`test`.`t3`.`a` < 10)) or (`test`.`t3`.`a` < 5) or (`test`.`t3`.`a` < 10))
DROP TABLE t1, t2, t3;
#
# Bug #47123: Endless 100% CPU loop with STRAIGHT_JOIN
#
CREATE TABLE t1(a INT, KEY(a));
INSERT INTO t1 VALUES (1), (NULL);
SELECT * FROM t1 WHERE a <> NULL and (a <> NULL or a <= NULL);
a
DROP TABLE t1;
#
# Bug#47925: regression of range optimizer and date comparison in 5.1.39!
#
CREATE TABLE t1 ( a DATE, KEY ( a ) );
CREATE TABLE t2 ( a DATETIME, KEY ( a ) );
# Make optimizer choose range scan
INSERT INTO t1 VALUES ('2009-09-22'), ('2009-09-22'), ('2009-09-22');
INSERT INTO t1 VALUES ('2009-09-23'), ('2009-09-23'), ('2009-09-23');
INSERT INTO t2 VALUES ('2009-09-22 12:00:00'), ('2009-09-22 12:00:00'),
('2009-09-22 12:00:00');
INSERT INTO t2 VALUES ('2009-09-23 12:00:00'), ('2009-09-23 12:00:00'),
('2009-09-23 12:00:00');
# DATE vs DATE
EXPLAIN
SELECT * FROM t1 WHERE a >= '2009/09/23';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
X X X NULL range a a X X X 100.00 X
Warnings:
X X X
X X X
SELECT * FROM t1 WHERE a >= '2009/09/23';
a
2009-09-23
2009-09-23
2009-09-23
Warnings:
Warning 4095 Delimiter '/' in position 4 in datetime value '2009/09/23' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t1 WHERE a >= '20090923';
a
2009-09-23
2009-09-23
2009-09-23
SELECT * FROM t1 WHERE a >= 20090923;
a
2009-09-23
2009-09-23
2009-09-23
SELECT * FROM t1 WHERE a >= '2009-9-23';
a
2009-09-23
2009-09-23
2009-09-23
SELECT * FROM t1 WHERE a >= '2009.09.23';
a
2009-09-23
2009-09-23
2009-09-23
Warnings:
Warning 4095 Delimiter '.' in position 4 in datetime value '2009.09.23' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t1 WHERE a >= '2009:09:23';
a
2009-09-23
2009-09-23
2009-09-23
Warnings:
Warning 4095 Delimiter ':' in position 4 in datetime value '2009:09:23' at row 1 is deprecated. Prefer the standard '-'.
# DATE vs DATETIME
EXPLAIN
SELECT * FROM t2 WHERE a >= '2009/09/23';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
X X X NULL range a a X X X 100.00 X
Warnings:
X X X
X X X
SELECT * FROM t2 WHERE a >= '2009/09/23';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
Warnings:
Warning 4095 Delimiter '/' in position 4 in datetime value '2009/09/23' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t2 WHERE a >= '2009/09/23';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
Warnings:
Warning 4095 Delimiter '/' in position 4 in datetime value '2009/09/23' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t2 WHERE a >= '20090923';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
SELECT * FROM t2 WHERE a >= 20090923;
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
SELECT * FROM t2 WHERE a >= '2009-9-23';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
SELECT * FROM t2 WHERE a >= '2009.09.23';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
Warnings:
Warning 4095 Delimiter '.' in position 4 in datetime value '2009.09.23' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t2 WHERE a >= '2009:09:23';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
Warnings:
Warning 4095 Delimiter ':' in position 4 in datetime value '2009:09:23' at row 1 is deprecated. Prefer the standard '-'.
# DATETIME vs DATETIME
EXPLAIN
SELECT * FROM t2 WHERE a >= '2009/09/23 12:00:00';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
X X X NULL range a a X X X 100.00 X
Warnings:
X X X
X X X
SELECT * FROM t2 WHERE a >= '2009/09/23 12:00:00';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
Warnings:
Warning 4095 Delimiter '/' in position 4 in datetime value '2009/09/23 12:00:00' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t2 WHERE a >= '20090923120000';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
SELECT * FROM t2 WHERE a >= 20090923120000;
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
SELECT * FROM t2 WHERE a >= '2009-9-23 12:00:00';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
SELECT * FROM t2 WHERE a >= '2009.09.23 12:00:00';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
Warnings:
Warning 4095 Delimiter '.' in position 4 in datetime value '2009.09.23 12:00:00' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t2 WHERE a >= '2009:09:23 12:00:00';
a
2009-09-23 12:00:00
2009-09-23 12:00:00
2009-09-23 12:00:00
Warnings:
Warning 4095 Delimiter ':' in position 4 in datetime value '2009:09:23 12:00:00' at row 1 is deprecated. Prefer the standard '-'.
# DATETIME vs DATE
EXPLAIN
SELECT * FROM t1 WHERE a >= '2009/09/23 00:00:00';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
X X X NULL range a a X X X 100.00 X
Warnings:
X X X
X X X
SELECT * FROM t1 WHERE a >= '2009/09/23 00:00:00';
a
2009-09-23
2009-09-23
2009-09-23
Warnings:
Warning 4095 Delimiter '/' in position 4 in datetime value '2009/09/23 00:00:00' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t1 WHERE a >= '2009/09/23 00:00:00';
a
2009-09-23
2009-09-23
2009-09-23
Warnings:
Warning 4095 Delimiter '/' in position 4 in datetime value '2009/09/23 00:00:00' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t1 WHERE a >= '20090923000000';
a
2009-09-23
2009-09-23
2009-09-23
SELECT * FROM t1 WHERE a >= 20090923000000;
a
2009-09-23
2009-09-23
2009-09-23
SELECT * FROM t1 WHERE a >= '2009-9-23 00:00:00';
a
2009-09-23
2009-09-23
2009-09-23
SELECT * FROM t1 WHERE a >= '2009.09.23 00:00:00';
a
2009-09-23
2009-09-23
2009-09-23
Warnings:
Warning 4095 Delimiter '.' in position 4 in datetime value '2009.09.23 00:00:00' at row 1 is deprecated. Prefer the standard '-'.
SELECT * FROM t1 WHERE a >= '2009:09:23 00:00:00';
a
2009-09-23
2009-09-23
2009-09-23
Warnings:
Warning 4095 Delimiter ':' in position 4 in datetime value '2009:09:23 00:00:00' at row 1 is deprecated. Prefer the standard '-'.
# Test of the new get_date_from_str implementation
# Behavior differs slightly between the trunk and mysql-pe.
# The former may give errors for the truncated values, while the latter
# gives warnings. The purpose of this test is not to interfere, and only
# preserve existing behavior.
# This case was made obsolete after the changes applied by
# Bug#28940878 WRONG RESULT WHEN COMPARING DATE[TIME] WITH STRING
# as we don't fallback anymore to string comparison if the date is invalid.
SELECT str_to_date('2007-10-00', '%Y-%m-%d') >= '' AND
str_to_date('2007-10-00', '%Y-%m-%d') <= '2007/10/20';
ERROR HY000: Incorrect DATE value: ''
SELECT str_to_date('2007-20-00', '%Y-%m-%d') >= '2007/10/20' AND
str_to_date('2007-20-00', '%Y-%m-%d') <= '';
ERROR HY000: Incorrect DATE value: ''
SELECT str_to_date('2007-10-00', '%Y-%m-%d') BETWEEN '' AND '2007/10/20';
str_to_date('2007-10-00', '%Y-%m-%d') BETWEEN '' AND '2007/10/20'
1
Warnings:
Warning 1292 Truncated incorrect date value: ''
Warning 4095 Delimiter '/' in position 4 in datetime value '2007/10/20' at row 1 is deprecated. Prefer the standard '-'.
SELECT str_to_date('2007-20-00', '%Y-%m-%d') BETWEEN '2007/10/20' AND '';
str_to_date('2007-20-00', '%Y-%m-%d') BETWEEN '2007/10/20' AND ''
NULL
Warnings:
Warning 1411 Incorrect datetime value: '2007-20-00' for function str_to_date
SELECT str_to_date('', '%Y-%m-%d');
str_to_date('', '%Y-%m-%d')
0000-00-00
DROP TABLE t1, t2;
#
# Bug#48459: valgrind errors with query using 'Range checked for each
# record'
#
CREATE TABLE t1 (
a INT,
b CHAR(2),
c INT,
d INT,
KEY ( c ),
KEY ( d, a, b ( 2 ) ),
KEY ( b ( 1 ) )
);
INSERT INTO t1 VALUES ( NULL, 'a', 1, 2 ), ( NULL, 'a', 1, 2 ),
( 1, 'a', 1, 2 ), ( 1, 'a', 1, 2 );
CREATE TABLE t2 (
a INT,
c INT,
e INT,
KEY ( e )
);
INSERT INTO t2 VALUES ( 1, 1, NULL ), ( 1, 1, NULL );
# Should not give Valgrind warnings
SELECT 1
FROM t1, t2
WHERE t1.d <> '1' AND t1.b > '1'
AND t1.a = t2.a AND t1.c = t2.c;
1
1
1
1
1
DROP TABLE t1, t2;
#
# Bug #48665: sql-bench's insert test fails due to wrong result
#
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a));
INSERT INTO t1 VALUES (0,0), (1,1);
EXPLAIN
SELECT * FROM t1 FORCE INDEX (PRIMARY)
WHERE (a>=1 AND a<=2) OR (a>=4 AND a<=5) OR (a>=0 AND a <=10);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
@ @ @ NULL range @ @ @ @ @ 100.00 @
Warnings:
@ @ @
# Should return 2 rows
SELECT * FROM t1 FORCE INDEX (PRIMARY)
WHERE (a>=1 AND a<=2) OR (a>=4 AND a<=5) OR (a>=0 AND a <=10);
a b
0 0
1 1
DROP TABLE t1;
#
# Bug #54802: 'NOT BETWEEN' evaluation is incorrect
#
CREATE TABLE t1 (c_key INT, c_notkey INT, KEY(c_key));
INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3);
EXPLAIN SELECT * FROM t1 WHERE 2 NOT BETWEEN c_notkey AND c_key;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL c_key NULL NULL NULL 3 66.67 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`c_key` AS `c_key`,`test`.`t1`.`c_notkey` AS `c_notkey` from `test`.`t1` where (2 not between `test`.`t1`.`c_notkey` and `test`.`t1`.`c_key`)
SELECT * FROM t1 WHERE 2 NOT BETWEEN c_notkey AND c_key;
c_key c_notkey
1 1
3 3
DROP TABLE t1;
#
# Bug #57030: 'BETWEEN' evaluation is incorrect
#
CREATE TABLE t1(pk INT PRIMARY KEY, i4 INT);
CREATE UNIQUE INDEX i4_uq ON t1(i4);
INSERT INTO t1 VALUES (1,10), (2,20), (3,30);
EXPLAIN
SELECT * FROM t1 WHERE i4 BETWEEN 10 AND 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL const i4_uq i4_uq 5 const 1 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select '1' AS `pk`,'10' AS `i4` from `test`.`t1` where true
SELECT * FROM t1 WHERE i4 BETWEEN 10 AND 10;
pk i4
1 10
EXPLAIN
SELECT * FROM t1 WHERE 10 BETWEEN i4 AND i4;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL const i4_uq i4_uq 5 const 1 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select '1' AS `pk`,'10' AS `i4` from `test`.`t1` where true
SELECT * FROM t1 WHERE 10 BETWEEN i4 AND i4;
pk i4
1 10
EXPLAIN
SELECT * FROM t1 WHERE 10 BETWEEN 10 AND i4;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index i4_uq i4_uq 5 NULL 3 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1` where (10 between 10 and `test`.`t1`.`i4`)
SELECT * FROM t1 WHERE 10 BETWEEN 10 AND i4;
pk i4
1 10
2 20
3 30
EXPLAIN
SELECT * FROM t1 WHERE 10 BETWEEN i4 AND 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range i4_uq i4_uq 5 NULL 1 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1` where (10 between `test`.`t1`.`i4` and 10)
SELECT * FROM t1 WHERE 10 BETWEEN i4 AND 10;
pk i4
1 10
EXPLAIN
SELECT * FROM t1 WHERE 10 BETWEEN 10 AND 10;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index NULL i4_uq 5 NULL 3 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1`
SELECT * FROM t1 WHERE 10 BETWEEN 10 AND 10;
pk i4
1 10
2 20
3 30
EXPLAIN
SELECT * FROM t1 WHERE 10 BETWEEN 11 AND 11;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1` where false
SELECT * FROM t1 WHERE 10 BETWEEN 11 AND 11;
pk i4
EXPLAIN
SELECT * FROM t1 WHERE 10 BETWEEN 100 AND 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1` where false
SELECT * FROM t1 WHERE 10 BETWEEN 100 AND 0;
pk i4
EXPLAIN
SELECT * FROM t1 WHERE i4 BETWEEN 100 AND 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1` where (`test`.`t1`.`i4` between 100 and 0)
SELECT * FROM t1 WHERE i4 BETWEEN 100 AND 0;
pk i4
EXPLAIN
SELECT * FROM t1 WHERE i4 BETWEEN 10 AND 99999999999999999;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index i4_uq i4_uq 5 NULL 3 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1` where (`test`.`t1`.`i4` between 10 and 99999999999999999)
SELECT * FROM t1 WHERE i4 BETWEEN 10 AND 99999999999999999;
pk i4
1 10
2 20
3 30
EXPLAIN
SELECT * FROM t1 WHERE i4 BETWEEN 999999999999999 AND 30;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1` where (`test`.`t1`.`i4` between 999999999999999 and 30)
SELECT * FROM t1 WHERE i4 BETWEEN 999999999999999 AND 30;
pk i4
EXPLAIN
SELECT * FROM t1 WHERE i4 BETWEEN 10 AND '20';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range i4_uq i4_uq 5 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4` from `test`.`t1` where (`test`.`t1`.`i4` between 10 and '20')
SELECT * FROM t1 WHERE i4 BETWEEN 10 AND '20';
pk i4
1 10
2 20
EXPLAIN
SELECT * FROM t1, t1 as t2 WHERE t2.pk BETWEEN t1.i4 AND t1.i4;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index i4_uq i4_uq 5 NULL 3 100.00 Using where; Using index
1 SIMPLE t2 NULL eq_ref PRIMARY PRIMARY 4 test.t1.i4 1 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`i4` AS `i4` from `test`.`t1` join `test`.`t1` `t2` where (`test`.`t2`.`pk` between `test`.`t1`.`i4` and `test`.`t1`.`i4`)
EXPLAIN FORMAT=tree
SELECT * FROM t1, t1 as t2 WHERE t2.pk BETWEEN t1.i4 AND t1.i4;
EXPLAIN
-> Nested loop inner join (cost=1.6 rows=3)
-> Filter: (t1.i4 is not null) (cost=0.55 rows=3)
-> Index scan on t1 using i4_uq (cost=0.55 rows=3)
-> Filter: (t2.pk between t1.i4 and t1.i4) (cost=0.283 rows=1)
-> Single-row index lookup on t2 using PRIMARY (pk=t1.i4) (cost=0.283 rows=1)
SELECT * FROM t1, t1 as t2 WHERE t2.pk BETWEEN t1.i4 AND t1.i4;
pk i4 pk i4
EXPLAIN
SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index i4_uq i4_uq 5 NULL 3 100.00 Using where; Using index
1 SIMPLE t2 NULL eq_ref PRIMARY PRIMARY 4 test.t1.i4 1 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`i4` AS `i4`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`i4` AS `i4` from `test`.`t1` join `test`.`t1` `t2` where (`test`.`t1`.`i4` between `test`.`t2`.`pk` and `test`.`t2`.`pk`)
SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk;
pk i4 pk i4
DROP TABLE t1;
#
# BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND
# WITH/WITHOUT INDEX RANGE SCAN
#
create table t1 (id int unsigned not null auto_increment primary key);
insert into t1 values (null);
insert into t1 select null from t1;
insert into t1 select null from t1;
insert into t1 select null from t1;
insert into t1 select null from t1;
insert into t1 select null from t1;
insert into t1 select null from t1;
insert into t1 select null from t1;
insert into t1 select null from t1;
create table t2 (
id int unsigned not null auto_increment,
val decimal(5,3) not null,
primary key (id,val),
unique key (val,id),
unique key (id));
insert into t2 select null,id*0.0009 from t1;
select count(val) from t2 ignore index (val) where val > 0.1155;
count(val)
185
select count(val) from t2 force index (val) where val > 0.1155;
count(val)
185
drop table t2, t1;
#
# BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG
# RESULTS WITH DECIMAL CONVERSION
#
create table t1 (a int,b int,c int,primary key (a,c));
insert into t1 values (1,1,2),(1,1,3),(1,1,4);
select convert(3, signed integer) > 2.9;
convert(3, signed integer) > 2.9
1
select * from t1 force index (primary) where a=1 and c>= 2.9;
a b c
1 1 3
1 1 4
select * from t1 ignore index (primary) where a=1 and c>= 2.9;
a b c
1 1 3
1 1 4
select * from t1 force index (primary) where a=1 and c> 2.9;
a b c
1 1 3
1 1 4
select * from t1 ignore index (primary) where a=1 and c> 2.9;
a b c
1 1 3
1 1 4
drop table t1;
#
# BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG
# RESULT AFTER MYSQL 5.1.
#
CREATE TABLE t1(
F1 CHAR(5) NOT NULL,
F2 CHAR(5) NOT NULL,
F3 CHAR(5) NOT NULL,
PRIMARY KEY(F1),
INDEX IDX_F2(F2)
) COLLATE latin1_swedish_ci;
INSERT INTO t1 VALUES
('A','A','A'),('AA','AA','AA'),('AAA','AAA','AAA'),
('AAAA','AAAA','AAAA'),('AAAAA','AAAAA','AAAAA');
SELECT * FROM t1 WHERE F1 = 'A ';
F1 F2 F3
A A A
SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 = 'A ';
F1 F2 F3
A A A
SELECT * FROM t1 WHERE F1 >= 'A ';
F1 F2 F3
A A A
AA AA AA
AAA AAA AAA
AAAA AAAA AAAA
AAAAA AAAAA AAAAA
SELECT * FROM t1 WHERE F1 > 'A ';
F1 F2 F3
AA AA AA
AAA AAA AAA
AAAA AAAA AAAA
AAAAA AAAAA AAAAA
SELECT * FROM t1 WHERE F1 BETWEEN 'A ' AND 'AAAAA';
F1 F2 F3
A A A
AA AA AA
AAA AAA AAA
AAAA AAAA AAAA
AAAAA AAAAA AAAAA
SELECT * FROM t1 WHERE F2 BETWEEN 'A ' AND 'AAAAA';
F1 F2 F3
A A A
AA AA AA
AAA AAA AAA
AAAA AAAA AAAA
AAAAA AAAAA AAAAA
SELECT * FROM t1 WHERE F3 BETWEEN 'A ' AND 'AAAAA';
F1 F2 F3
A A A
AA AA AA
AAA AAA AAA
AAAA AAAA AAAA
AAAAA AAAAA AAAAA
SELECT * FROM t1 IGNORE INDEX(PRIMARY) WHERE F1 BETWEEN 'A ' AND
'AAAAA';
F1 F2 F3
A A A
AA AA AA
AAA AAA AAA
AAAA AAAA AAAA
AAAAA AAAAA AAAAA
DROP TABLE t1;
End of 5.1 tests
CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
INSERT INTO t1 VALUES (1),(2),(3);
SELECT c1 FROM t1 WHERE c1 >= 'A' GROUP BY 1;
c1
1
2
3
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: 'A'
DROP TABLE t1;
create table t1 (a int,b int,key (b),key (a),key (b,a));
insert into t1(a,b) values (1,2),(3,4),(5,6),(7,8);
create table t2 (c int);
insert into t2(c) values (1),(5),(6),(7),(8);
select 1 from (select c from t1,t2 where b >= 1 and a <=> c group by 1 limit 1) as d1;
1
1
drop table t1, t2;
#
# Bug #26106: Wrong plan may be chosen when there are several possible
# range and ref accesses
#
# Note: The fix for this bug has been reverted. The code will no longer
# select the optimal plan for the two following test queries. This is
# not due to a bug but due to minor differences in range estimates
# produced by the storage engine.
CREATE TABLE t1(
a INT,
b INT,
KEY k ( a ),
KEY l ( a, b )
);
INSERT INTO t1(a) VALUES (1);
INSERT INTO t1
VALUES (2,3),(2,3),(2,3),(2,3),(2,3),(2,3),(2,3),(2,3),(2,3),(2,3);
INSERT INTO t1 SELECT 3, 4 FROM t1 WHERE a = 2 AND b = 3;
INSERT INTO t1 SELECT 4, 1 FROM t1 WHERE a = 2 AND b = 3;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
INSERT INTO t1 VALUES (1, 2);
INSERT INTO t1 SELECT a, b FROM t1 WHERE a=1 AND b=2;
INSERT INTO t1 SELECT a, b FROM t1 WHERE a=1 AND b=2;
INSERT INTO t1 SELECT a, b FROM t1 WHERE a=1 AND b=2;
INSERT INTO t1 SELECT a, b FROM t1 WHERE a=1 AND b=2;
INSERT INTO t1 SELECT a, b FROM t1 WHERE a=1 AND b=2;
INSERT INTO t1 SELECT a, b FROM t1 WHERE a=1 AND b=2;
INSERT INTO t1 SELECT a, b FROM t1 WHERE a=1 AND b=2;
# This must use range over index l, not k.
# Update: Due to patch being reverted and minor differences in
# range estimates k is selected.
EXPLAIN SELECT * FROM t1 WHERE a = 1 AND b >= 2;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref k,l k 5 const 129 33.33 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a` = 1) and (`test`.`t1`.`b` >= 2))
CREATE TABLE t2(
a INT,
b INT,
c INT,
KEY k ( a ),
KEY l ( a, b ),
KEY m ( b ),
KEY n ( a, c )
);
INSERT INTO t2(a) VALUES (1);
INSERT INTO t2
VALUES (2,3,3),(2,3,3),(2,3,3),(2,3,3),(2,3,3),
(2,3,3),(2,3,3),(2,3,3),(2,3,3),(2,3,3);
INSERT INTO t2 SELECT 3, 4, 4 FROM t2 WHERE a = 2 AND b = 3;
INSERT INTO t2 SELECT 4, 1, 1 FROM t2 WHERE a = 2 AND b = 3;
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
INSERT INTO t2 VALUES (1, 2, 2);
INSERT INTO t2 SELECT a, b, c FROM t2 WHERE a=1 AND b=2;
INSERT INTO t2 SELECT a, b, c FROM t2 WHERE a=1 AND b=2;
INSERT INTO t2 SELECT a, b, c FROM t2 WHERE a=1 AND b=2;
INSERT INTO t2 SELECT a, b, c FROM t2 WHERE a=1 AND b=2;
INSERT INTO t2 SELECT a, b, c FROM t2 WHERE a=1 AND b=2;
INSERT INTO t2 SELECT a, b, c FROM t2 WHERE a=1 AND b=2;
INSERT INTO t2 VALUES (1, 1, 2);
# This must use range over index l, not n.
# Update: Due to patch being reverted and minor differences in
# range estimates k is selected.
EXPLAIN SELECT * FROM t2 WHERE a = 1 AND b >= 2 AND c >= 2;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL ref k,l,m,n k 5 const 66 29.16 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`a` = 1) and (`test`.`t2`.`b` >= 2) and (`test`.`t2`.`c` >= 2))
DROP TABLE t1, t2;
#
# BUG#11765831: 'RANGE ACCESS' MAY INCORRECTLY FILTER
# AWAY QUALIFYING ROWS
#
CREATE TABLE t10(
K INT NOT NULL AUTO_INCREMENT,
I INT, J INT,
PRIMARY KEY(K),
KEY(I,J)
);
INSERT INTO t10(I,J) VALUES (6,1),(6,2),(6,3),(6,4),(6,5),
(6,6),(6,7),(6,8),(6,9),(6,0);
CREATE TABLE t100 LIKE t10;
INSERT INTO t100(I,J) SELECT X.I, X.K+(10*Y.K) FROM t10 AS X,t10 AS Y;
INSERT INTO t100(I,J) VALUES(8,26);
EXPLAIN SELECT * FROM t100 WHERE I <> 6 OR (I <> 8 AND J = 5);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t100 NULL range I I 10 NULL 3 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t100`.`K` AS `K`,`test`.`t100`.`I` AS `I`,`test`.`t100`.`J` AS `J` from `test`.`t100` where ((`test`.`t100`.`I` <> 6) or ((`test`.`t100`.`J` = 5) and (`test`.`t100`.`I` <> 8)))
SELECT * FROM t100 WHERE I <> 6 OR (I <> 8 AND J = 5);
K I J
128 8 26
DROP TABLE t10,t100;
#
# BUG#12698916 - JOIN QUERY GIVES WRONG RESULT AT 2ND EXEC. OR
# AFTER FLUSH TABLES [-INT VS NULL]
#
CREATE TABLE t1 (col_int INT, pk INT) ENGINE=InnoDB STATS_PERSISTENT=0;
INSERT INTO t1 VALUES (-100,1),(1,6);
CREATE TABLE t2 (
col_int_key INT,
col_varchar VARCHAR(100) NOT NULL DEFAULT "DEFAULT",
pk INT NOT NULL,
PRIMARY KEY (pk),
KEY (col_int_key)
) ENGINE=InnoDB STATS_PERSISTENT=0;
INSERT INTO t2 VALUES
(1,"GOOD",1),(100,"",2),(200,"",3),(300,"",4),(400,"",5),(500,"",8);
EXPLAIN SELECT t1.*,t2.* FROM t1 straight_join t2
ON t2.col_int_key = t1.col_int WHERE t2.pk < t1.pk;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL # # Using where
1 SIMPLE t2 NULL ref PRIMARY,col_int_key col_int_key 5 test.t1.col_int # # Using index condition
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`col_int` AS `col_int`,`test`.`t1`.`pk` AS `pk`,`test`.`t2`.`col_int_key` AS `col_int_key`,`test`.`t2`.`col_varchar` AS `col_varchar`,`test`.`t2`.`pk` AS `pk` from `test`.`t1` straight_join `test`.`t2` where ((`test`.`t2`.`col_int_key` = `test`.`t1`.`col_int`) and (`test`.`t2`.`pk` < `test`.`t1`.`pk`))
EXPLAIN FORMAT=tree SELECT t1.*,t2.* FROM t1 straight_join t2
ON t2.col_int_key = t1.col_int WHERE t2.pk < t1.pk;
EXPLAIN
-> Nested loop inner join (cost=1.55 rows=2)
-> Filter: (t1.col_int is not null) (cost=0.45 rows=2)
-> Table scan on t1 (cost=0.45 rows=2)
-> Index lookup on t2 using col_int_key (col_int_key=t1.col_int), with index condition: (t2.pk < t1.pk) (cost=0.267 rows=1)
SELECT t1.*,t2.* FROM t1 straight_join t2
ON t2.col_int_key = t1.col_int WHERE t2.pk < t1.pk;
col_int pk col_int_key col_varchar pk
1 6 1 GOOD 1
# need FLUSH so that InnoDB statistics change and thus plan changes
FLUSH TABLES;
EXPLAIN SELECT t1.*,t2.* FROM t1 straight_join t2
ON t2.col_int_key = t1.col_int WHERE t2.pk < t1.pk;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL # # NULL
1 SIMPLE t2 NULL ALL PRIMARY,col_int_key NULL NULL NULL # # Range checked for each record (index map: 0x3)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`col_int` AS `col_int`,`test`.`t1`.`pk` AS `pk`,`test`.`t2`.`col_int_key` AS `col_int_key`,`test`.`t2`.`col_varchar` AS `col_varchar`,`test`.`t2`.`pk` AS `pk` from `test`.`t1` straight_join `test`.`t2` where ((`test`.`t2`.`col_int_key` = `test`.`t1`.`col_int`) and (`test`.`t2`.`pk` < `test`.`t1`.`pk`))
EXPLAIN FORMAT=tree SELECT t1.*,t2.* FROM t1 straight_join t2
ON t2.col_int_key = t1.col_int WHERE t2.pk < t1.pk;
EXPLAIN
-> Nested loop inner join (cost=1.9 rows=4)
-> Table scan on t1 (cost=0.45 rows=2)
-> Filter: ((t2.col_int_key = t1.col_int) and (t2.pk < t1.pk)) (cost=0.225 rows=2)
-> Index range scan on t2 (re-planned for each iteration) (cost=0.225 rows=6)
SELECT t1.*,t2.* FROM t1 straight_join t2
ON t2.col_int_key = t1.col_int WHERE t2.pk < t1.pk;
col_int pk col_int_key col_varchar pk
1 6 1 GOOD 1
DROP TABLE t1,t2;
#
# Bug#12694872 -
# VALGRIND: 18,816 BYTES IN 196 BLOCKS ARE DEFINITELY LOST IN UNIQUE::GET
#
CREATE TABLE t1 (
pk INTEGER AUTO_INCREMENT,
col_int_nokey INTEGER NOT NULL,
col_int_key INTEGER NOT NULL,
col_date_key DATE NOT NULL,
col_varchar_key VARCHAR(1) NOT NULL,
col_varchar_nokey VARCHAR(1) NOT NULL,
PRIMARY KEY (pk),
KEY (col_int_key),
KEY (col_date_key),
KEY (col_varchar_key, col_int_key)
);
INSERT INTO t1 (
col_int_key,
col_int_nokey,
col_date_key,
col_varchar_key,
col_varchar_nokey
) VALUES
(0, 4, '2011-08-25', 'j', 'j'),
(8, 6, '2004-09-18', 'v', 'v'),
(1, 3, '2009-12-01', 'c', 'c'),
(8, 5, '2004-12-17', 'm', 'm'),
(9, 3, '2000-03-14', 'd', 'd'),
(6, 2, '2006-05-25', 'y', 'y'),
(1, 9, '2008-01-23', 't', 't'),
(6, 3, '2007-06-18', 'd', 'd'),
(2, 8, '2002-10-13', 's', 's'),
(4, 1, '1900-01-01', 'r', 'r'),
(8, 8, '1959-04-25', 'm', 'm'),
(4, 8, '2006-03-09', 'b', 'b'),
(4, 5, '2001-06-05', 'x', 'x'),
(7, 7, '2006-05-28', 'g', 'g'),
(4, 5, '2001-04-19', 'p', 'p'),
(1, 1, '1900-01-01', 'q', 'q'),
(9, 6, '2004-08-20', 'w', 'w'),
(4, 2, '2004-10-10', 'd', 'd'),
(8, 9, '2000-04-02', 'e', 'e')
;
SET UNIQUE_CHECKS = 0;
SET FOREIGN_KEY_CHECKS = 0;
SELECT table2.col_date_key AS field1,
CONCAT ( table2.col_varchar_nokey, table1.col_varchar_nokey ) AS field2
FROM ( t1 AS table1 INNER JOIN t1 AS table2
ON (( table2.pk <> table1.pk ) AND
( table2.pk >= table1.col_int_nokey ) ) )
WHERE ( table1.pk > 226 AND
table1.pk < ( 226 + 102 ) OR
( table1.col_int_key > 226 AND
table1.col_int_key < ( 226 + 36 ) OR
( table1.col_varchar_key <= 'h' OR
table1.col_int_key > 226 AND
table1.col_int_key < ( 226 + 227 ) )
)
)
;
field1 field2
1900-01-01 qb
1900-01-01 qc
1900-01-01 qd
1900-01-01 qd
1900-01-01 qd
1900-01-01 qe
1900-01-01 qg
1900-01-01 rb
1900-01-01 rc
1900-01-01 rd
1900-01-01 rd
1900-01-01 rd
1900-01-01 re
1900-01-01 rg
1959-04-25 mb
1959-04-25 mc
1959-04-25 md
1959-04-25 md
1959-04-25 md
1959-04-25 me
1959-04-25 mg
2000-03-14 dc
2000-03-14 dd
2000-03-14 dd
2000-04-02 eb
2000-04-02 ec
2000-04-02 ed
2000-04-02 ed
2000-04-02 ed
2000-04-02 eg
2001-04-19 pb
2001-04-19 pc
2001-04-19 pd
2001-04-19 pd
2001-04-19 pd
2001-04-19 pe
2001-04-19 pg
2001-06-05 xb
2001-06-05 xc
2001-06-05 xd
2001-06-05 xd
2001-06-05 xd
2001-06-05 xe
2001-06-05 xg
2002-10-13 sb
2002-10-13 sc
2002-10-13 sd
2002-10-13 sd
2002-10-13 sd
2002-10-13 se
2002-10-13 sg
2004-08-20 wb
2004-08-20 wc
2004-08-20 wd
2004-08-20 wd
2004-08-20 wd
2004-08-20 we
2004-08-20 wg
2004-09-18 vd
2004-10-10 db
2004-10-10 dc
2004-10-10 dd
2004-10-10 dd
2004-10-10 de
2004-10-10 dg
2004-12-17 mc
2004-12-17 md
2004-12-17 md
2004-12-17 md
2006-03-09 bc
2006-03-09 bd
2006-03-09 bd
2006-03-09 bd
2006-03-09 be
2006-03-09 bg
2006-05-25 yc
2006-05-25 yd
2006-05-25 yd
2006-05-25 yd
2006-05-28 gb
2006-05-28 gc
2006-05-28 gd
2006-05-28 gd
2006-05-28 gd
2006-05-28 ge
2007-06-18 db
2007-06-18 dc
2007-06-18 dd
2007-06-18 dd
2007-06-18 dg
2008-01-23 tc
2008-01-23 td
2008-01-23 td
2008-01-23 td
2008-01-23 tg
2009-12-01 cd
2009-12-01 cd
2009-12-01 cd
SET FOREIGN_KEY_CHECKS = 1;
SET UNIQUE_CHECKS = 1;
CREATE TABLE t2 SELECT table2.col_date_key AS field1,
CONCAT ( table2.col_varchar_nokey, table1.col_varchar_nokey ) AS field2
FROM ( t1 AS table1 INNER JOIN t1 AS table2
ON (( table2.pk <> table1.pk ) AND
( table2.pk >= table1.col_int_nokey ) ) )
WHERE ( table1.pk > 226 AND
table1.pk < ( 226 + 102 ) OR
( table1.col_int_key > 226 AND
table1.col_int_key < ( 226 + 36 ) OR
( table1.col_varchar_key <= 'h' OR
table1.col_int_key > 226 AND
table1.col_int_key < ( 226 + 227 ) )
)
)
;
SELECT * FROM t2
WHERE (field1, field2) IN (SELECT table2.col_date_key AS field1,
CONCAT ( table2.col_varchar_nokey, table1.col_varchar_nokey ) AS field2
FROM ( t1 AS table1 INNER JOIN t1 AS table2
ON (( table2.pk <> table1.pk ) AND
( table2.pk >= table1.col_int_nokey ) ) )
WHERE ( table1.pk > 226 AND
table1.pk < ( 226 + 102 ) OR
( table1.col_int_key > 226 AND
table1.col_int_key < ( 226 + 36 ) OR
( table1.col_varchar_key <= 'h' OR
table1.col_int_key > 226 AND
table1.col_int_key < ( 226 + 227 ) )
)
)
);
field1 field2
1900-01-01 qb
1900-01-01 qc
1900-01-01 qd
1900-01-01 qd
1900-01-01 qd
1900-01-01 qe
1900-01-01 qg
1900-01-01 rb
1900-01-01 rc
1900-01-01 rd
1900-01-01 rd
1900-01-01 rd
1900-01-01 re
1900-01-01 rg
1959-04-25 mb
1959-04-25 mc
1959-04-25 md
1959-04-25 md
1959-04-25 md
1959-04-25 me
1959-04-25 mg
2000-03-14 dc
2000-03-14 dd
2000-03-14 dd
2000-04-02 eb
2000-04-02 ec
2000-04-02 ed
2000-04-02 ed
2000-04-02 ed
2000-04-02 eg
2001-04-19 pb
2001-04-19 pc
2001-04-19 pd
2001-04-19 pd
2001-04-19 pd
2001-04-19 pe
2001-04-19 pg
2001-06-05 xb
2001-06-05 xc
2001-06-05 xd
2001-06-05 xd
2001-06-05 xd
2001-06-05 xe
2001-06-05 xg
2002-10-13 sb
2002-10-13 sc
2002-10-13 sd
2002-10-13 sd
2002-10-13 sd
2002-10-13 se
2002-10-13 sg
2004-08-20 wb
2004-08-20 wc
2004-08-20 wd
2004-08-20 wd
2004-08-20 wd
2004-08-20 we
2004-08-20 wg
2004-09-18 vd
2004-10-10 db
2004-10-10 dc
2004-10-10 dd
2004-10-10 dd
2004-10-10 de
2004-10-10 dg
2004-12-17 mc
2004-12-17 md
2004-12-17 md
2004-12-17 md
2006-03-09 bc
2006-03-09 bd
2006-03-09 bd
2006-03-09 bd
2006-03-09 be
2006-03-09 bg
2006-05-25 yc
2006-05-25 yd
2006-05-25 yd
2006-05-25 yd
2006-05-28 gb
2006-05-28 gc
2006-05-28 gd
2006-05-28 gd
2006-05-28 gd
2006-05-28 ge
2007-06-18 db
2007-06-18 dc
2007-06-18 dd
2007-06-18 dd
2007-06-18 dg
2008-01-23 tc
2008-01-23 td
2008-01-23 td
2008-01-23 td
2008-01-23 tg
2009-12-01 cd
2009-12-01 cd
2009-12-01 cd
DROP TABLE t1, t2;
#
# BUG#12912171 - ASSERTION FAILED: QUICK->HEAD->READ_SET ==
# SAVE_READ_SET
#
CREATE TABLE t1 (
a INT,
b INT,
c INT,
PRIMARY KEY (c,a), KEY (a),KEY (a)
) ENGINE=INNODB PARTITION BY KEY () PARTITIONS 2;
Warnings:
Warning 1831 Duplicate index 'a_2' defined on the table 'test.t1'. This is deprecated and will be disallowed in a future release.
INSERT INTO t1 VALUES (1,5,1),(2,4,1),(3,3,1),(4,2,1),(5,1,1);
UPDATE t1 SET b = 0, c=1 WHERE a <=>0;
SELECT * FROM t1;
a b c
1 5 1
2 4 1
3 3 1
4 2 1
5 1 1
DROP TABLE t1;
#
# BUG#13256446 - ASSERTION QUICK->HEAD->READ_SET ==
# SAVE_READ_SET' FAILED IN OPT_RANGE.CC:1606
#
CREATE TABLE t1 (
f1 INT AUTO_INCREMENT,
f2 INT,
f3 INT,
f4 INT,
PRIMARY KEY (f1),KEY(f2)
) ENGINE=INNODB;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT f1,f2,f3,f4 FROM t1 WHERE f2=103;
INSERT INTO t1 VALUES (154,0,NULL,0),(0,NULL,9,0),
(NULL,102,NULL,3),(0,3,NULL,0), (9,0,NULL,0),(0,9,NULL,157);
SELECT * FROM v2;
f1 f2 f3 f4
UPDATE v2 SET f4=0, f2=NULL, f1=NULL WHERE f1 > 16 ORDER BY f1;
SELECT * FROM v2;
f1 f2 f3 f4
DROP TABLE t1;
DROP VIEW v2;
CREATE TABLE t1 (
f1 INT AUTO_INCREMENT,
f2 INT,
f3 INT,
f4 INT,
PRIMARY KEY (f1),KEY(f2)
) ENGINE=INNODB;
INSERT INTO t1 VALUES(1,NULL,NULL,0), (2,2,0,3), (9,0,107,18),
(10,0,0,0), (231,0,0,0), (232,0,8,0), (234,0,0,NULL), (235,8,0,3);
CREATE ALGORITHM=MERGE VIEW v3 AS SELECT f1,f2,f3,f4 FROM t1 WHERE f1<=85 ;
SELECT * FROM v3;
f1 f2 f3 f4
1 NULL NULL 0
2 2 0 3
9 0 107 18
10 0 0 0
UPDATE v3 SET f3=0, f4=4 WHERE f2=68 ORDER BY f1;
SELECT * FROM v3;
f1 f2 f3 f4
1 NULL NULL 0
2 2 0 3
9 0 107 18
10 0 0 0
DROP TABLE t1;
DROP VIEW v3;
#
# BUG#13731380: RANGE OPTIMIZER CALLS RECORDS_IN_RANGE() FOR OPEN RANGE
#
CREATE TABLE t1 (pk INT PRIMARY KEY);
INSERT INTO t1 VALUES (1),(3),(5);
SELECT * FROM t1 WHERE pk <> 3 OR pk < 4;
pk
1
3
5
DROP TABLE t1;
#
# BUG#13803810: TOO FEW ROWS RETURNED FOR RANGE ACCESS IN
# VARCHAR INDEX USING DATETIME VALUE
CREATE TABLE t1 (a DATETIME);
INSERT INTO t1 VALUES ('2001-01-01 00:00:00');
INSERT INTO t1 VALUES ('2001-01-01 11:22:33');
CREATE TABLE t2 (b VARCHAR(64), KEY (b)) CHARSET utf8mb4;
INSERT INTO t2 VALUES ('2001-01-01');
INSERT INTO t2 VALUES ('2001.01.01');
INSERT INTO t2 VALUES ('2001#01#01');
INSERT INTO t2 VALUES ('2001-01-01 00:00:00');
INSERT INTO t2 VALUES ('2001-01-01 11:22:33');
# range/ref access cannot be used for this query
EXPLAIN SELECT * FROM t2 WHERE b=CAST('2001-01-01' AS DATE);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL index b b 259 NULL 5 20.00 Using where; Using index
Warnings:
Warning 1739 Cannot use ref access on index 'b' due to type or collation conversion on field 'b'
Warning 1739 Cannot use range access on index 'b' due to type or collation conversion on field 'b'
Note 1003 /* select#1 */ select `test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = <cache>(cast('2001-01-01' as date)))
SELECT * FROM t2 WHERE b=CAST('2001-01-01' AS DATE);
b
2001#01#01
2001-01-01
2001-01-01 00:00:00
2001.01.01
Warning 4095 Delimiter '#' in position 4 in datetime value '2001#01#01' at row # is deprecated. Prefer the standard '-'.
Warning 4095 Delimiter '.' in position 4 in datetime value '2001.01.01' at row # is deprecated. Prefer the standard '-'.
Warnings:
# range/ref access cannot be used for any of the queries below.
# See BUG#13814468 about 'Range checked for each record'
EXPLAIN SELECT * FROM t1, t2 WHERE a=b ORDER BY BINARY a, BINARY b;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
1 SIMPLE t2 NULL index b b 259 NULL 5 20.00 Using where; Using index; Using join buffer (hash join)
Warnings:
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 1739 Cannot use ref access on index 'b' due to type or collation conversion on field 'b'
Warning 1739 Cannot use range access on index 'b' due to type or collation conversion on field 'b'
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = cast(`test`.`t2`.`b` as datetime(6))) order by cast(`test`.`t1`.`a` as char charset binary),cast(`test`.`t2`.`b` as char charset binary)
SELECT * FROM t1, t2 WHERE a=b ORDER BY BINARY a, BINARY b;
a b
2001-01-01 00:00:00 2001#01#01
2001-01-01 00:00:00 2001-01-01
2001-01-01 00:00:00 2001-01-01 00:00:00
2001-01-01 00:00:00 2001.01.01
2001-01-01 11:22:33 2001-01-01 11:22:33
Warnings:
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 4095 Delimiter '.' in position 4 in datetime value '2001.01.01' at row 1 is deprecated. Prefer the standard '-'.
Warning 4095 Delimiter '#' in position 4 in datetime value '2001#01#01' at row 1 is deprecated. Prefer the standard '-'.
EXPLAIN SELECT * FROM t1, t2 WHERE b=a ORDER BY BINARY a, BINARY b;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
1 SIMPLE t2 NULL index b b 259 NULL 5 20.00 Using where; Using index; Using join buffer (hash join)
Warnings:
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 1739 Cannot use ref access on index 'b' due to type or collation conversion on field 'b'
Warning 1739 Cannot use range access on index 'b' due to type or collation conversion on field 'b'
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (cast(`test`.`t2`.`b` as datetime(6)) = `test`.`t1`.`a`) order by cast(`test`.`t1`.`a` as char charset binary),cast(`test`.`t2`.`b` as char charset binary)
SELECT * FROM t1, t2 WHERE b=a ORDER BY BINARY a, BINARY b;
a b
2001-01-01 00:00:00 2001#01#01
2001-01-01 00:00:00 2001-01-01
2001-01-01 00:00:00 2001-01-01 00:00:00
2001-01-01 00:00:00 2001.01.01
2001-01-01 11:22:33 2001-01-01 11:22:33
Warnings:
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 1287 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead
Warning 4095 Delimiter '.' in position 4 in datetime value '2001.01.01' at row 1 is deprecated. Prefer the standard '-'.
Warning 4095 Delimiter '#' in position 4 in datetime value '2001#01#01' at row 1 is deprecated. Prefer the standard '-'.
DROP TABLE t1,t2;
#
# WL#7019: Add support for row value constructors in in predicates to
# range optimizer
#
CREATE TABLE t1 (a INT, b INT, c INT, KEY x(a, b));
INSERT INTO t1 VALUES (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5), (6, 6, 6),
(7, 7, 7), (8, 8, 8), (9, 9, 9);
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 SELECT * FROM t1;
INSERT INTO t1 VALUES (0, 0, 0), (1, 1, 1);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
CREATE TABLE t2 (a INT, b INT, c INT, d INT, KEY x(a, b));
INSERT INTO t2 VALUES (2, 2, 2, 2), (3, 3, 3, 3), (4, 4, 4, 4), (5, 5, 5, 5),
(6, 6, 6, 6), (7, 7, 7, 7), (8, 8, 8, 8), (9, 9, 9, 9);
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 VALUES (0, 0, 0, 0), (1, 1, 1, 1);
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
CREATE TABLE t3 (a INT, b INT, c INT, d INT, KEY x(a, b, c));
INSERT INTO t3 VALUES (2, 2, 2, 2), (3, 3, 3, 3), (4, 4, 4, 4), (5, 5, 5, 5),
(6, 6, 6, 6), (7, 7, 7, 7), (8, 8, 8, 8), (9, 9, 9, 9);
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t3;
INSERT INTO t3 VALUES (0, 0, 0, 0), (1, 1, 1, 1);
ANALYZE TABLE t3;
Table Op Msg_type Msg_text
test.t3 analyze status OK
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN ((NULL, NULL), (NULL, NULL));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in ((NULL,NULL),(NULL,NULL)))
EXPLAIN SELECT a, b FROM t1 WHERE (a = 0 AND b = 0) OR (a = 1 AND b = 1);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 10 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((`test`.`t1`.`b` = 0) and (`test`.`t1`.`a` = 0)) or ((`test`.`t1`.`b` = 1) and (`test`.`t1`.`a` = 1)))
FLUSH STATUS;
SELECT a, b FROM t1 WHERE (a = 0 AND b = 0) OR (a = 1 AND b = 1);
a b
0 0
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN ((0, 0));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref x x 10 const,const 1 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 0) and (`test`.`t1`.`a` = 0))
FLUSH STATUS;
SELECT a, b FROM t1 WHERE (a, b) IN ((0, 0));
a b
0 0
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 1
Handler_read_last 0
Handler_read_next 1
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN ((0, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 10 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in ((0,0),(1,1)))
FLUSH STATUS;
SELECT a, b FROM t1 WHERE (a, b) IN ((0, 0), (1, 1));
a b
0 0
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b, c FROM t2 WHERE (a, b, c) IN ((0, 0, 0), (1, 1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL range x x 10 NULL 2 20.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`c`) in ((0,0,0),(1,1,1)))
FLUSH STATUS;
SELECT a, b, c FROM t2 WHERE (a, b, c) IN ((0, 0, 0), (1, 1, 1));
a b c
0 0 0
1 1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b, c FROM t3 WHERE (a, b, c) IN ((0, 0, 0), (1, 1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 NULL range x x 15 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t3`.`c` AS `c` from `test`.`t3` where ((`test`.`t3`.`a`,`test`.`t3`.`b`,`test`.`t3`.`c`) in ((0,0,0),(1,1,1)))
FLUSH STATUS;
SELECT a, b, c FROM t3 WHERE (a, b, c) IN ((0, 0, 0), (1, 1, 1));
a b c
0 0 0
1 1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b FROM t1 WHERE a = 0 AND b = 0 OR (a, b) IN ((1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 10 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((`test`.`t1`.`b` = 0) and (`test`.`t1`.`a` = 0)) or ((`test`.`t1`.`b` = 1) and (`test`.`t1`.`a` = 1)))
FLUSH STATUS;
SELECT a, b FROM t1 WHERE a = 0 AND b = 0 OR (a, b) IN ((1, 1));
a b
0 0
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN ((1, 1)) OR a = 0 AND b = 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 10 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((`test`.`t1`.`b` = 1) and (`test`.`t1`.`a` = 1)) or ((`test`.`t1`.`b` = 0) and (`test`.`t1`.`a` = 0)))
FLUSH STATUS;
SELECT a, b FROM t1 WHERE (a, b) IN ((1, 1)) OR a = 0 AND b = 0;
a b
0 0
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b FROM t2 WHERE (a, b, c) IN ((1, 1, 1)) OR a = 0 AND b = 0 AND c = 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL range x x 10 NULL 2 19.00 Using index condition; Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (((`test`.`t2`.`c` = 1) and (`test`.`t2`.`b` = 1) and (`test`.`t2`.`a` = 1)) or ((`test`.`t2`.`c` = 0) and (`test`.`t2`.`b` = 0) and (`test`.`t2`.`a` = 0)))
FLUSH STATUS;
SELECT a, b FROM t2 WHERE (a, b, c) IN ((1, 1, 1)) OR a = 0 AND b = 0 AND c = 0;
a b
0 0
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b FROM t3 WHERE (a, b, c) IN ((1, 1, 1)) OR a = 0 AND b = 0 AND c = 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t3 NULL range x x 15 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t3` where (((`test`.`t3`.`c` = 1) and (`test`.`t3`.`b` = 1) and (`test`.`t3`.`a` = 1)) or ((`test`.`t3`.`c` = 0) and (`test`.`t3`.`b` = 0) and (`test`.`t3`.`a` = 0)))
FLUSH STATUS;
SELECT a, b FROM t3 WHERE (a, b, c) IN ((1, 1, 1)) OR a = 0 AND b = 0 AND c = 0;
a b
0 0
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN (((SELECT 1), 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref x x 10 const,const 1 100.00 Using index
Warnings:
Note 1249 Select 2 was reduced during optimization
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 1) and (`test`.`t1`.`a` = 1))
FLUSH STATUS;
SELECT a, b FROM t1 WHERE (a, b) IN (((SELECT 1), 1));
a b
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 1
Handler_read_last 0
Handler_read_next 1
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN (('0', 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 10 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in (('0',0),(1,1)))
FLUSH STATUS;
SELECT a, b FROM t1 WHERE (a, b) IN (('0', 0), (1, 1));
a b
0 0
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
SET @v = 0;
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN ((@v, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 10 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in (((@`v`),0),(1,1)))
FLUSH STATUS;
SELECT a, b FROM t1 WHERE (a, b) IN ((@v, 0), (1, 1));
a b
0 0
1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
CREATE TABLE t4 ( a INT, b INT );
INSERT INTO t4 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
INSERT INTO t4 SELECT a + 5, b + 5 FROM t4;
INSERT INTO t4 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t4;
# Inner table in a nested-loops join
EXPLAIN
SELECT t4.*, t1.a, t1.b
FROM t4 JOIN t1 USING(a, b)
WHERE (t4.a, t4.b) IN ((1, 1), (0, 0));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 640 2.00 Using where
1 SIMPLE t1 NULL ref x x 10 test.t4.a,test.t4.b 409 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t4` join `test`.`t1` where ((`test`.`t1`.`b` = `test`.`t4`.`b`) and (`test`.`t1`.`a` = `test`.`t4`.`a`) and ((`test`.`t4`.`a`,`test`.`t4`.`b`) in ((1,1),(0,0))))
# Join on IN
EXPLAIN
SELECT t4.*, t1.a, t1.b
FROM t4 JOIN t1
WHERE (t1.a, t1.b) IN ((t4.a, t4.b), (0, 0));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 640 100.00 NULL
1 SIMPLE t1 NULL index x x 10 NULL 4098 2.00 Using where; Using index; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t4` join `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in ((`test`.`t4`.`a`,`test`.`t4`.`b`),(0,0)))
EXPLAIN
SELECT t4.*, t1.a, t1.b
FROM t4 JOIN t1
WHERE (t1.a, t1.b) IN ((t4.a, t4.b), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 640 100.00 NULL
1 SIMPLE t1 NULL index x x 10 NULL 4098 2.00 Using where; Using index; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t4` join `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in ((`test`.`t4`.`a`,`test`.`t4`.`b`),(1,1)))
#
# Tests for non-deterministic functions.
#
CREATE FUNCTION f1() RETURNS INT NOT DETERMINISTIC RETURN 1;
# The statement immediately below should not use range access.
EXPLAIN SELECT a, b FROM t1 WHERE (a, b, c) IN ((0, 0, 0), (f1(), 1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL x NULL NULL NULL 4098 0.20 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`,`test`.`t1`.`c`) in ((0,0,0),(`f1`(),1,1)))
EXPLAIN SELECT a, b FROM t1 WHERE (a, b, c) IN ((0, 0, 0), (1, f1(), 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 10 NULL 2 20.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`,`test`.`t1`.`c`) in ((0,0,0),(1,`f1`(),1)))
EXPLAIN SELECT a, b FROM t1 WHERE (a, b, c) IN ((0, 0, 0), (1, 1, f1()));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 10 NULL 2 20.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`,`test`.`t1`.`c`) in ((0,0,0),(1,1,`f1`())))
# The statement immediately below should not use range access.
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN ((f1(), 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index x x 10 NULL 4098 1.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 1) and (`test`.`t1`.`a` = `f1`()))
DROP FUNCTION f1;
# The statement immediately below should not use range access.
EXPLAIN
SELECT a, b
FROM t1 AS t1o
WHERE EXISTS (SELECT /*+ NO_SEMIJOIN() */ 1
FROM t1
WHERE (a, b) IN ((t1o.a, t1o.b)) );
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1o NULL index NULL x 10 NULL 4098 100.00 Using where; Using index
2 DEPENDENT SUBQUERY t1 NULL ref x x 10 test.t1o.a,test.t1o.b 409 100.00 Using index
Warnings:
Note 1276 Field or reference 'test.t1o.a' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.t1o.b' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select /*+ NO_SEMIJOIN(@`select#2`) */ `test`.`t1o`.`a` AS `a`,`test`.`t1o`.`b` AS `b` from `test`.`t1` `t1o` where exists(/* select#2 */ select 1 from `test`.`t1` where ((`test`.`t1`.`a` = `test`.`t1o`.`a`) and (`test`.`t1`.`b` = `test`.`t1o`.`b`)))
#
# Tests of dynamic range access
#
CREATE TABLE t5 (a int, b int, KEY (a));
INSERT INTO t5 VALUES (1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1);
CREATE TABLE t6 (a int, b int, KEY (a));
INSERT INTO t6 VALUES (3, 2), (4, 2), (100, 100), (101, 201), (102, 102);
CREATE TABLE t7 (a int, b int, KEY (a, b));
INSERT INTO t7 VALUES (1, 1), (2, 2), (1000, 1000), (1001, 1001), (1002, 1002),
(1003, 1003), (1004, 1004);
EXPLAIN SELECT *
FROM t5 JOIN t6 ON t5.a = t6.a JOIN t7
WHERE t7.a IN (t5.b, t6.b);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t6 NULL ALL a NULL NULL NULL 5 100.00 Using where
1 SIMPLE t5 NULL ref a a 5 test.t6.a 1 100.00 NULL
1 SIMPLE t7 NULL ALL a NULL NULL NULL 7 28.57 Range checked for each record (index map: 0x1)
Warnings:
Note 1003 /* select#1 */ select `test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b` from `test`.`t5` join `test`.`t6` join `test`.`t7` where ((`test`.`t5`.`a` = `test`.`t6`.`a`) and (`test`.`t7`.`a` in (`test`.`t5`.`b`,`test`.`t6`.`b`)))
FLUSH STATUS;
SELECT *
FROM t5 JOIN t6 ON t5.a = t6.a JOIN t7
WHERE t7.a IN (t5.b, t6.b);
a b a b a b
3 1 3 2 1 1
3 1 3 2 2 2
4 1 4 2 1 1
4 1 4 2 2 2
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 1
Handler_read_key 10
Handler_read_last 0
Handler_read_next 6
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 6
EXPLAIN SELECT *
FROM t5 JOIN t6 ON t5.a = t6.a JOIN t7
WHERE (t7.a, t7.b) IN ((t5.b, 1), (t6.b, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t6 NULL ALL a NULL NULL NULL 5 100.00 Using where
1 SIMPLE t5 NULL ref a a 5 test.t6.a 1 100.00 NULL
1 SIMPLE t7 NULL ALL a NULL NULL NULL 7 14.29 Range checked for each record (index map: 0x1)
Warnings:
Note 1003 /* select#1 */ select `test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b` from `test`.`t5` join `test`.`t6` join `test`.`t7` where ((`test`.`t5`.`a` = `test`.`t6`.`a`) and ((`test`.`t7`.`a`,`test`.`t7`.`b`) in ((`test`.`t5`.`b`,1),(`test`.`t6`.`b`,1))))
FLUSH STATUS;
SELECT *
FROM t5 JOIN t6 ON t5.a = t6.a JOIN t7
WHERE (t7.a, t7.b) IN ((t5.b, 1), (t6.b, 1));
a b a b a b
3 1 3 2 1 1
4 1 4 2 1 1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 1
Handler_read_key 10
Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 6
#
# Regression tests of the worklog below.
#
# Make sure we process IN predicates only.
# The code around this is very unclear.
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) != (1, 1);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index x x 10 NULL 4098 99.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a` <> 1) or (`test`.`t1`.`b` <> 1))
# This should give us a ref scan, as it always did.
EXPLAIN SELECT a, b FROM t1 WHERE (a, b) IN ((0, 0));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref x x 10 const,const 1 100.00 Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 0) and (`test`.`t1`.`a` = 0))
EXPLAIN SELECT a, b FROM t1 WHERE (a, c) IN ((0, 0));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref x x 5 const 1 10.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`c` = 0) and (`test`.`t1`.`a` = 0))
# ref scan on x(a).
EXPLAIN SELECT * FROM t1 WHERE (a, c) IN ((0, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range x x 5 NULL 2 20.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`c`) in ((0,0),(1,1)))
DROP TABLE t1, t2, t3, t4, t5, t6, t7;
#
# Bug#17635476: CRASH IN GET_MM_PARTS() OR ASSERT IN
# GET_FUNC_MM_TREE_FROM_IN_PREDICATE()
#
CREATE TABLE t1 (
a INT,
b INT,
KEY (a)
) ENGINE = INNODB;
SELECT DISTINCT a FROM t1 WHERE (a, b) IN ((0, 0), (1, 1));
a
INSERT INTO t1 VALUES (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6),
(7, 7), (8, 8), (9, 9);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
CREATE TABLE t2 (
a INT,
b INT,
KEY (a, b)
);
INSERT INTO t2 SELECT * FROM t1;
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
EXPLAIN SELECT DISTINCT a FROM t1 WHERE (a, b) IN ((0, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 5 NULL 2 20.00 Using where
Warnings:
Note 1003 /* select#1 */ select distinct `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in ((0,0),(1,1)))
FLUSH STATUS;
SELECT DISTINCT a FROM t1 WHERE (a, b) IN ((0, 0), (1, 1));
a
0
1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
EXPLAIN SELECT DISTINCT a FROM t2 WHERE (a, b) IN ((0, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL range a a 10 NULL 2 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select distinct `test`.`t2`.`a` AS `a` from `test`.`t2` where ((`test`.`t2`.`a`,`test`.`t2`.`b`) in ((0,0),(1,1)))
FLUSH STATUS;
SELECT DISTINCT a FROM t2 WHERE (a, b) IN ((0, 0), (1, 1));
a
0
1
SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value
Handler_read_first 0
Handler_read_key 2
Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
Handler_read_rnd_next 0
# Should not use range scan.
EXPLAIN SELECT DISTINCT a FROM t1 WHERE (NULL, b) IN ((0, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index a a 5 NULL 10 20.00 Using where
Warnings:
Note 1003 /* select#1 */ select distinct `test`.`t1`.`a` AS `a` from `test`.`t1` where ((NULL,`test`.`t1`.`b`) in ((0,0),(1,1)))
# Should not use range scan.
EXPLAIN SELECT DISTINCT a FROM t2 WHERE (NULL, b) IN ((0, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL index a a 10 NULL 10 20.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select distinct `test`.`t2`.`a` AS `a` from `test`.`t2` where ((NULL,`test`.`t2`.`b`) in ((0,0),(1,1)))
DROP TABLE t1, t2;
#
# Bug#17755540 VALGRIND ERROR WHEN SETTING UP ROW COMPARATORS
#
CREATE TABLE t2 (a INT, b INT, c INT, d INT, KEY x(a, b));
INSERT INTO t2 VALUES (2, 2, 2, 2), (3, 3, 3, 3), (4, 4, 4, 4), (5, 5, 5, 5),
(6, 6, 6, 6), (7, 7, 7, 7), (8, 8, 8, 8), (9, 9, 9, 9);
INSERT INTO t2 SELECT * FROM t2;
INSERT INTO t2 VALUES (0, 0, 0, 0), (1, 1, 1, 1);
ANALYZE TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
SELECT a, b FROM t2 WHERE (a, b) IN ((0, 0), (1, 1));
a b
0 0
1 1
DROP TABLE t2;
#
# BUG#18364815: OPTIMIZER PREFERS TABLE SCAN WHEN
# USING "IN" WITH VALUE OF DIFFERENT TYPE
#
CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
INSERT INTO t1 VALUES (1,1), (2,1), (3,1), (4,1), (5,1), (6,1);
EXPLAIN SELECT * FROM t1 WHERE a IN (1, 2);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 4 NULL 2 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` in (1,2))
EXPLAIN SELECT * FROM t1 WHERE a IN (1, "2");
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 4 NULL 2 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` in (1,'2'))
SELECT * FROM t1 WHERE a IN (1, 2);
a b
1 1
2 1
SELECT * FROM t1 WHERE a IN (1, "2");
a b
1 1
2 1
DROP TABLE t1;
#
# Bug#18715670
# CRASH IN DECIMAL_ACTUAL_FRACTION COMPARING DECIMAL TO NULLS
#
CREATE TABLE t1(n DECIMAL(39,19) NOT NULL, KEY(n)) engine=innodb;
INSERT INTO t1 SET n=0;
SELECT 1 FROM t1 WHERE n NOT IN(NULL, NULL);
1
DROP TABLE t1;
#
# Bug#18759597 MISSING ROWS ON WHERE ..
# IN QUERY WITH VARIABLES AND CONCAT
#
CREATE TABLE t1 (
col_varchar_key varchar(2),
KEY col_varchar_key (col_varchar_key)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('n'),('xm');
SET @var1 = 't', @var2 = 'him',
@var3 = 'n', @var4 = 'n',
@var5 = 'n', @var6 = 'g',
@var7 = 'b', @var8 = 'o',
@var9 = 'm', @var10 = 'xm', @var11 = 'u'
;
SELECT col_varchar_key AS field1
FROM t1
WHERE ( col_varchar_key, col_varchar_key ) IN (
('m', @var1 ),
('n', @var3 ),
('a', @var5 ),
('l', @var7 ),
(CONCAT('x', @var9 ), @var10 )
);
field1
n
xm
DROP TABLE t1;
#
# Bug#18535226 DEBUG CRASH ON QUICK_RANGE_SELECT::RESET
#
SET @old_tmp_table_size=@@tmp_table_size;
SET tmp_table_size=1024;
CREATE TABLE t1 (
pk INT NOT NULL,
col_int_key INT,
col_date_key date,
col_date_nokey date,
col_time_key time,
col_time_nokey time,
col_datetime_key datetime,
col_datetime_nokey datetime,
col_varchar_key varchar(1),
col_varchar_nokey varchar(1),
PRIMARY KEY (pk),
KEY col_int_key (col_int_key)
) ENGINE=MyISAM;
INSERT INTO t1 VALUES
(5,0,'2001-05-06','2001-05-06','16:21:18','16:21:18','2001-11-08 21:02:12',
'2001-11-08 21:02:12','x','x'),(6,7,'2006-03-03','2006-03-03','18:56:33',
'18:56:33','2003-04-01 00:00:00','2003-04-01 00:00:00','i','i'),
(7,7,'2007-12-28','2007-12-28',NULL,NULL,'1900-01-01 00:00:00',
'1900-01-01 00:00:00','e','e'),(8,1,'2004-10-20','2004-10-20','09:29:08',
'09:29:08','2007-07-12 00:00:00','2007-07-12 00:00:00','p','p'),
(9,7,'2008-04-09','2008-04-09','19:11:10','19:11:10',
'2005-04-04 01:21:01','2005-04-04 01:21:01','s','s'),
(10,1,'2005-12-25','2005-12-25','11:57:26','11:57:26',
'1900-01-01 00:00:00','1900-01-01 00:00:00','j','j');
SELECT alias1.col_int_key
FROM
( SELECT SQ1_alias1.* FROM t1 AS SQ1_alias1, t1 AS SQ1_alias2 ) AS alias1,
(SELECT 7 AS col_int_nokey) AS alias2
WHERE
alias2.col_int_nokey = alias1.pk
AND alias1.col_varchar_nokey < alias1.col_varchar_key
ORDER BY alias1.col_varchar_key;
col_int_key
DROP TABLE t1;
SET tmp_table_size=@old_tmp_table_size;
SET sql_mode = default;
#
# Bug#19585938 Crash in get_full_func_mm_tree with null
# item_field->table_ref
#
CREATE TABLE t1(id INTEGER, col1 INTEGER, col2 INTEGER, PRIMARY KEY(id));
INSERT INTO t1 VALUES (1,2,3), (3,2,1);
SELECT (SELECT 1
FROM t1
WHERE SUM(1) < id
) AS c
FROM t1
GROUP BY col1;
c
1
SELECT (SELECT 1
FROM t1
WHERE id > SUM(1)
) AS c
FROM t1
GROUP BY col1;
c
1
SELECT (SELECT 1
FROM t1
WHERE SUM(1) BETWEEN id AND id+1
) AS c
FROM t1
GROUP BY col1;
c
1
SELECT (SELECT 1
FROM t1
WHERE id BETWEEN SUM(1) AND SUM(5)
) AS c
FROM t1
GROUP BY col1;
c
1
SELECT (SELECT 1
FROM t1
WHERE SUM(1) BETWEEN COUNT(*) AND id
) AS c
FROM t1
GROUP BY col1;
c
1
DROP TABLE t1;
#
# Bug#21415791 VALGRIND ERROR (CONDITIONAL JUMP) AT KEY_AND
# (RANGE_OPT_PARAM*, SEL_ARG*, SEL_AR
#
CREATE TABLE t1 (
col_varchar_10 VARCHAR(10),
pk INTEGER NOT NULL,
col_int_key INTEGER,
PRIMARY KEY (pk),
KEY col_int_key (col_int_key),
KEY col_varchar_10 (col_varchar_10)
) ENGINE=InnoDB;
INSERT INTO t1 (
pk, col_varchar_10, col_int_key) VALUES
(1, 'ttttt', 0), (2, 'zzzzz', 0), (3, 'ggggg', 0),
(4, 'hhhhh', 0), (5, 'kkkkk', 0), (6, 'lllll', 0);
CREATE TABLE t2 (
pk INTEGER NOT NULL,
col_varchar_10 VARCHAR(10),
PRIMARY KEY (pk),
KEY col_varchar_10 (col_varchar_10)
) ENGINE=InnoDB;
INSERT INTO t2 (
pk, col_varchar_10) VALUES
(1, '00000'), (2, '00000'), (3, '44444'), (4, '00000'),
(5, NULL), (6, NULL), (7, NULL);
SELECT COUNT(t1.col_int_key)
FROM t2 RIGHT OUTER JOIN t1 ON t2.col_varchar_10 <= t1.col_varchar_10
WHERE t2.pk <> 4 OR t2.pk != t1.col_int_key AND t2.pk <> 1000;
COUNT(t1.col_int_key)
24
DROP TABLE t1, t2;
#
# Bug #20229614: OR CONDITIONS ON MULTI-COLUMN INDEX MAY NOT USE ALL
# INDEX COLUMNS TO FILTER ROWS
#
CREATE TABLE t1 (
c1 INT,
c2 INT,
c3 INT,
PRIMARY KEY(c1, c2, c3)
) ENGINE=INNODB;
INSERT INTO t1 VALUES (1, 1, 1), (1, 1, 2), (1, 1, 3),
(1, 1, 4), (1, 1, 5);
INSERT INTO t1 SELECT c1, 2, c3 FROM t1;
INSERT INTO t1 SELECT c1, 3, c3 FROM t1 WHERE c2 = 1;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SELECT COUNT(*) FROM t1;
COUNT(*)
15
EXPLAIN SELECT c1, c2, c3
FROM t1
WHERE (c1 = 1 AND c2 = 1 AND c3 = 1) OR
(c1 = 1 AND c2 = 2 AND c3 = 2) OR
(c1 = 1 AND c2 = 2 AND c3 = 3);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 12 NULL 3 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3` from `test`.`t1` where (((`test`.`t1`.`c3` = 1) and (`test`.`t1`.`c2` = 1) and (`test`.`t1`.`c1` = 1)) or ((`test`.`t1`.`c3` = 2) and (`test`.`t1`.`c2` = 2) and (`test`.`t1`.`c1` = 1)) or ((`test`.`t1`.`c3` = 3) and (`test`.`t1`.`c2` = 2) and (`test`.`t1`.`c1` = 1)))
DROP TABLE t1;
#
# Bug#21139683: ASSERTION FAILED: TYPE_ARG == MAYBE_KEY ||
# TYPE_ARG == IMPOSSIBLE
#
CREATE TABLE t1 (
a BLOB,
PRIMARY KEY(a(1)),
KEY(a(1))
) ENGINE=INNODB;
SELECT 1 FROM t1 WHERE a <> 'a' OR a <> "";
1
DROP TABLE t1;
#
# Bug#19333852: RESULT DIFF IN QUERY HAVING DISTINCT
# WITH GROUP BY
#
CREATE TABLE t1 (
v1 VARCHAR(20) CHARACTER SET utf8 NOT NULL,
pk INTEGER NOT NULL,
PRIMARY KEY (pk),
KEY v1_key (v1(10))
) ENGINE=InnoDB;
Warnings:
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
INSERT INTO t1 VALUES ('ABCDE',19), ('JLVGO',14);
EXPLAIN SELECT * FROM t1 WHERE t1.v1 < CHAR(127);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range v1_key v1_key 32 NULL 2 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`v1` AS `v1`,`test`.`t1`.`pk` AS `pk` from `test`.`t1` where (`test`.`t1`.`v1` < <cache>(char(127)))
EXPLAIN SELECT * FROM t1 WHERE t1.v1 = CHAR(127);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref v1_key v1_key 32 const 1 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`v1` AS `v1`,`test`.`t1`.`pk` AS `pk` from `test`.`t1` where (`test`.`t1`.`v1` = <cache>(char(127)))
EXPLAIN SELECT * FROM t1 WHERE t1.v1 BETWEEN 'f' AND CHAR(127);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range v1_key v1_key 32 NULL 1 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`v1` AS `v1`,`test`.`t1`.`pk` AS `pk` from `test`.`t1` where (`test`.`t1`.`v1` between 'f' and <cache>(char(127)))
SELECT * FROM t1 WHERE t1.v1 < CHAR(127);
v1 pk
ABCDE 19
JLVGO 14
SELECT * FROM t1 WHERE t1.v1 = CHAR(127);
v1 pk
SELECT * FROM t1 WHERE t1.v1 BETWEEN 'f' AND CHAR(127);
v1 pk
JLVGO 14
DROP TABLE t1;
#
# Bug #21761867: ASSERTION `TYPE_ARG == MAYBE_KEY ||
# TYPE_ARG == IMPOSSIBLE' FAILED.
#
CREATE TABLE t1 (
c10 INT NOT NULL,
c12 INT NOT NULL,
c18 INT,
PRIMARY KEY (c10,c12),
UNIQUE KEY key_c12(c12),
KEY key_c18(c18));
INSERT INTO t1 VALUES(11,5,0), (12,6,1), (13,7,2), (14,8,3), (15,9,4);
CREATE TABLE t2 (
c10 INT NOT NULL,
c12 INT NOT NULL,
PRIMARY KEY(c10,c12));
CREATE TABLE t3 (c10 INT NOT NULL);
SELECT t2.c10
FROM t1
RIGHT JOIN t3
LEFT JOIN t2
ON t3.c10 = t2.c10
ON t1.c12 > t2.c12
WHERE
t1.c10 <= 25
AND
t1.c18 IS NOT NULL
OR
t1.c10 > 5
AND
t1.c18 IN (15,16,18);
c10
DROP TABLE t1, t2, t3;
#
# Bug #21318711: WRONG RESULTS FOR TRUNCATED COLUMN AND AGGREGATION
#
CREATE TABLE t1 (
col1 VARCHAR(5) CHARSET utf8mb4 COLLATE utf8mb4_bin,
col2 INT NOT NULL,
PRIMARY KEY (col1, col2)
);
INSERT INTO t1 VALUES ('abcde', 10);
EXPLAIN SELECT MAX(col2) FROM t1 WHERE col1 = 'abcdeaa';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref PRIMARY PRIMARY 22 const 1 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select max(`test`.`t1`.`col2`) AS `MAX(col2)` from `test`.`t1` where (`test`.`t1`.`col1` = 'abcdeaa')
EXPLAIN SELECT MAX(col2) FROM t1 WHERE col1 = 'abcde ';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
Warnings:
Note 1003 /* select#1 */ select max(`test`.`t1`.`col2`) AS `MAX(col2)` from `test`.`t1` where multiple equal('abcde ', `test`.`t1`.`col1`)
SELECT MAX(col2) FROM t1 WHERE col1 = 'abcdeaa';
MAX(col2)
NULL
SELECT MAX(col2) FROM t1 WHERE col1 = 'abcde ';
MAX(col2)
10
DROP TABLE t1;
#
# Bug# 22283790: RANGE OPTIMIZER UTILIZES TOO MUCH MEMORY WITH
# MANY OR CONDITIONS
#
CREATE TABLE t1 (
f1 INTEGER,
KEY (f1)
);
INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15);
SET @orig_range_optimizer_max_mem_size= @@range_optimizer_max_mem_size;
SET range_optimizer_max_mem_size= 5000;
EXPLAIN SELECT * FROM t1 WHERE f1=1 OR f1=2 OR f1=3 OR f1=4 OR f1=5
OR f1=6 OR f1=7 OR f1=8 OR f1=9 OR f1=10 OR f1=11;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range f1 f1 5 NULL 11 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where ((`test`.`t1`.`f1` = 1) or (`test`.`t1`.`f1` = 2) or (`test`.`t1`.`f1` = 3) or (`test`.`t1`.`f1` = 4) or (`test`.`t1`.`f1` = 5) or (`test`.`t1`.`f1` = 6) or (`test`.`t1`.`f1` = 7) or (`test`.`t1`.`f1` = 8) or (`test`.`t1`.`f1` = 9) or (`test`.`t1`.`f1` = 10) or (`test`.`t1`.`f1` = 11))
SET range_optimizer_max_mem_size= @orig_range_optimizer_max_mem_size;
DROP TABLE t1;
#
# Bug #23623110: REFACTOR USE_COUNT IN THE RANGE OPTIMIZER
#
# Tests deleting nodes in tree_delete() not from the end of the
# linked list.
#
CREATE TABLE t1 (
pk INTEGER,
PRIMARY KEY (pk)
);
SELECT * FROM t1 WHERE pk IN (3, 8) OR pk NOT IN (2);
pk
DROP TABLE t1;
#
# Bug #23623110: REFACTOR USE_COUNT IN THE RANGE OPTIMIZER
#
# Tests deleting nodes in tree_delete() not from the end of the
# linked list.
#
# Indirectly tests ORing with a tree that has a nonzero refcount,
# where nodes are also being skipped over. (There was a bug in
# refcounting such trees earlier.)
#
CREATE TABLE t1 (
col_int_key int,
pk int NOT NULL,
col_int int,
KEY test_idx (pk,col_int_key,col_int)
);
SELECT * FROM t1 WHERE
(col_int_key >= 6 AND pk > 6) OR
(pk > 2 AND col_int_key = 7 AND col_int > 6);
col_int_key pk col_int
DROP TABLE t1;
#
#
# Bug #23259872: OPTIMIZER CHOOSES TO USE NON PRIMARY
# INDEX, EVEN THOUGH COST IS HIGHER
#
CREATE TABLE `giant_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`one_id` int(11) NOT NULL,
`other_id` bigint(20) NOT NULL DEFAULT '0',
`some_other_id` int(11) DEFAULT 0 NOT NULL,
`something` double NOT NULL DEFAULT '0',
`comment` text COLLATE utf8_unicode_ci,
`flags` int(11) NOT NULL DEFAULT '0',
`time_created` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `time_created` (`time_created`),
KEY `some_other_id` (`some_other_id`),
KEY `one_other_idx` (`one_id`,`other_id`),
KEY `other_id` (`other_id`,`time_created`)
) ENGINE=InnoDB AUTO_INCREMENT=101651329
DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
Warnings:
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 3778 'utf8mb3_unicode_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 1681 Integer display width is deprecated and will be removed in a future release.
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
Warning 3778 'utf8mb3_unicode_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
CREATE TABLE t1 (c1 INT);
INSERT INTO t1 VALUES (66136540), (68983250), (89627210), (77869520),
(82543190), (67538270), (77282760), (77908170),
(70923370), (68066360);
CREATE PROCEDURE p()
BEGIN
SET @x = 1;
REPEAT
INSERT INTO giant_table(id,one_id)
SELECT c1 + @x, 0
FROM t1
WHERE c1 IN (66136540, 68985250, 89627210, 77869520 , 82543190, 67538270,
77282760, 77908170, 70923370, 68066360);
SET @x = @x + 1;
UNTIL @x > 30 END REPEAT;
END $
CALL p();
SELECT count(*) FROM giant_table;
count(*)
270
INSERT INTO giant_table (id,one_id) VALUES (66136539, 0), (68983258,1),
(89628210,1), (77869520,2);
INSERT INTO giant_table (id,one_id, some_other_id) VALUES(84673401, 0, 1),
(61069031, 1, 1);
EXPLAIN SELECT id, something, comment, time_created, one_id, other_id,
some_other_id, flags
FROM giant_table
WHERE id IN (66136539, 68983258, 89628210, 77869520, 82543198, 67538272,
84673401, 61069031, 68214385, 77282865, 76991297, 64569216,
89481638, 74534074, 70396537, 80076375, 63308530, 77908270,
70923271, 68066180)
AND (giant_table.flags & 0x01) = 0 AND giant_table.some_other_id = 0;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE giant_table NULL range PRIMARY,some_other_id PRIMARY 4 NULL 20 50.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`giant_table`.`id` AS `id`,`test`.`giant_table`.`something` AS `something`,`test`.`giant_table`.`comment` AS `comment`,`test`.`giant_table`.`time_created` AS `time_created`,`test`.`giant_table`.`one_id` AS `one_id`,`test`.`giant_table`.`other_id` AS `other_id`,`test`.`giant_table`.`some_other_id` AS `some_other_id`,`test`.`giant_table`.`flags` AS `flags` from `test`.`giant_table` where ((`test`.`giant_table`.`some_other_id` = 0) and (`test`.`giant_table`.`id` in (66136539,68983258,89628210,77869520,82543198,67538272,84673401,61069031,68214385,77282865,76991297,64569216,89481638,74534074,70396537,80076375,63308530,77908270,70923271,68066180)) and ((`test`.`giant_table`.`flags` & 0x01) = 0))
DROP PROCEDURE p;
DROP TABLE giant_table, t1;
#
# Bug#22671573: SIG11 IN SEL_ARG::RB_INSERT |SQL/OPT_RANGE.CC
#
# Tests creating an empty tree (impossible condition) and then ANDing with it.
#
CREATE TABLE t1 (
a INT,
b INT,
KEY test_idx (b, a)
);
SELECT * FROM t1 WHERE b BETWEEN 8 AND 8 AND a > 8 AND a <= 8;
a b
DROP TABLE t1;
#
# Indirectly tests inserting a node into an empty (impossible) tree.
#
CREATE TABLE t1 (
pk INT,
PRIMARY KEY ( pk )
);
SELECT * FROM t1 WHERE pk = 6 OR pk > 6;
pk
DROP TABLE t1;
#
# Indirectly tests ORing with an empty (impossible) tree.
#
CREATE TABLE t1 (
col_int_key INT,
KEY (col_int_key)
);
SELECT * FROM t1 WHERE col_int_key IS NULL OR col_int_key < 9 OR col_int_key = 9;
col_int_key
DROP TABLE t1;
#
# Indirectly tests deleting the last node from a tree
# (which makes it IMPOSSIBLE) and then inserting more than one node.
#
CREATE TABLE t1 (
a VARCHAR(64),
KEY a (a)
);
SELECT * FROM t1 WHERE a IS NULL OR a NOT IN ( 'foo', 'bar' );
a
DROP TABLE t1;
#
# Bug#25229315: ASSERTION TABLE->M_RECORD_BUFFER.RECORD_SIZE() ==
# RECORD_PREFIX_SIZE(TAB)' FAIL
#
CREATE TABLE t1 (pk INT PRIMARY KEY, vc VARCHAR(1)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, NULL), (2, 'w');
CREATE TABLE t2 (
i INT,
vc VARCHAR(1),
pk INT PRIMARY KEY,
KEY (i),
KEY (vc)
) ENGINE=InnoDB;
INSERT INTO t2 VALUES (1, 'p', 1), (9, 'w', 2), (NULL, 'r', 3);
ANALYZE TABLE t1, t2;
Table Op Msg_type Msg_text
test.t1 analyze status OK
test.t2 analyze status OK
EXPLAIN SELECT MIN(t1.pk) FROM t1, t2 WHERE t2.vc = t1.vc OR t2.i = t1.pk;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL PRIMARY NULL NULL NULL 2 100.00 NULL
1 SIMPLE t2 NULL ALL i,vc NULL NULL NULL 3 55.56 Range checked for each record (index map: 0x6)
Warnings:
Note 1003 /* select#1 */ select min(`test`.`t1`.`pk`) AS `MIN(t1.pk)` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`vc` = `test`.`t1`.`vc`) or (`test`.`t2`.`i` = `test`.`t1`.`pk`))
SELECT MIN(t1.pk) FROM t1, t2 WHERE t2.vc = t1.vc OR t2.i = t1.pk;
MIN(t1.pk)
1
DROP TABLE t1, t2;
#
# Bug #26727773: OPTIMIZER CHOSES COMPOSITE INDEX FOR REF OVER RANGE
#
CREATE TABLE transactions (
app_trans_id INT DEFAULT NULL,
id INT NOT NULL,
tbl INT NOT NULL DEFAULT 1,
created TIMESTAMP NOT NULL DEFAULT '2017-01-01 01:01:01',
trans_type INT NOT NULL,
description BLOB,
source_lvl1 INT DEFAULT NULL,
source_lvl2 INT DEFAULT NULL,
KEY tbl_id_idx (tbl,id),
KEY created_idx (created),
KEY trans_type_created_idx (trans_type,created),
KEY app_trans_id_idx (app_trans_id)
) ENGINE=INNODB ;
CREATE TABLE t1 (c1 INT);
INSERT INTO t1 VALUES (1), (1000), (2000), (3000), (4000), (5000), (6000),
(7000), (8000), (9000);
CREATE PROCEDURE p()
BEGIN
SET @x = 1;
REPEAT
INSERT IGNORE INTO transactions(id,trans_type, description)
SELECT c1 + @x, @x , 'abcd'
FROM t1;
SET @x = @x + 1;
UNTIL @x > 300 END REPEAT;
END $
CALL p();
SELECT count(*) FROM transactions;
count(*)
3000
INSERT IGNORE INTO transactions(id,trans_type, description, created)
SELECT 3, 3 , 'abcd', '2018-01-01 01:01:01'
FROM dual;
EXPLAIN SELECT '2017-10-23 01:01:01', HOUR(created), source_lvl1, source_lvl2,
COUNT(DISTINCT(app_trans_id))
FROM transactions
WHERE created > '2017-10-23 01:01:01' AND tbl = 1 AND trans_type in (3)
GROUP BY '2017-10-23 01:01:01', HOUR(created), source_lvl1, source_lvl2;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE transactions NULL range tbl_id_idx,created_idx,trans_type_created_idx created_idx 4 NULL # # Using index condition; Using where; Using filesort
Warnings:
Note 1003 /* select#1 */ select '2017-10-23 01:01:01' AS `2017-10-23 01:01:01`,hour(`test`.`transactions`.`created`) AS `HOUR(created)`,`test`.`transactions`.`source_lvl1` AS `source_lvl1`,`test`.`transactions`.`source_lvl2` AS `source_lvl2`,count(distinct `test`.`transactions`.`app_trans_id`) AS `COUNT(DISTINCT(app_trans_id))` from `test`.`transactions` where ((`test`.`transactions`.`trans_type` = 3) and (`test`.`transactions`.`tbl` = 1) and (`test`.`transactions`.`created` > TIMESTAMP'2017-10-23 01:01:01')) group by '2017-10-23 01:01:01',hour(`test`.`transactions`.`created`),`test`.`transactions`.`source_lvl1`,`test`.`transactions`.`source_lvl2`
SET optimizer_trace="enabled=on";
SELECT '2017-10-23 01:01:01', HOUR(created), source_lvl1, source_lvl2,
COUNT(DISTINCT(app_trans_id))
FROM transactions
WHERE created > '2017-10-23 01:01:01' AND tbl = 1 AND trans_type in (3)
GROUP BY '2017-10-23 01:01:01', HOUR(created), source_lvl1, source_lvl2;
2017-10-23 01:01:01 HOUR(created) source_lvl1 source_lvl2 COUNT(DISTINCT(app_trans_id))
2017-10-23 01:01:01 1 NULL NULL 0
SELECT TRACE INTO @trace FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
SELECT @trace RLIKE "range_uses_more_keyparts";
@trace RLIKE "range_uses_more_keyparts"
1
SET optimizer_trace="enabled=off";
DROP PROCEDURE p;
DROP TABLE t1, transactions;
#
# Bug #28086754: OPTIMIZER SKIP THE RANG SCAN ON SECOND COLUMN IN A
# COMPOSITE INDEX
#
CREATE TABLE test_ref (
a INT PRIMARY KEY,
b VARCHAR(20),
c VARCHAR(20) DEFAULT NULL,
d VARCHAR(3) DEFAULT NULL,
id INT DEFAULT NULL,
KEY idx1 (id, c),
KEY idx2 (id, d)) ENGINE=INNODB ;
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze Error Table 'test.t1' doesn't exist
test.t1 analyze status Operation failed
EXPLAIN SELECT *
FROM test_ref
WHERE id=3 AND c LIKE 'gh%'
ORDER BY c, a
LIMIT 1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE test_ref NULL range idx1,idx2 idx1 88 NULL 25 100.00 Using index condition
Warnings:
Note 1003 /* select#1 */ select `test`.`test_ref`.`a` AS `a`,`test`.`test_ref`.`b` AS `b`,`test`.`test_ref`.`c` AS `c`,`test`.`test_ref`.`d` AS `d`,`test`.`test_ref`.`id` AS `id` from `test`.`test_ref` where ((`test`.`test_ref`.`id` = 3) and (`test`.`test_ref`.`c` like 'gh%')) order by `test`.`test_ref`.`c`,`test`.`test_ref`.`a` limit 1
SELECT *
FROM test_ref
WHERE id=3 AND c LIKE 'gh%'
ORDER BY c, a
LIMIT 1;
a b c d id
34876 D003 gheennse S 3
EXPLAIN SELECT *
FROM test_ref
WHERE id=3 AND c LIKE 'gh%'
ORDER BY c DESC, a DESC
LIMIT 1;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE test_ref NULL range idx1,idx2 idx1 88 NULL 25 100.00 Using index condition; Backward index scan
Warnings:
Note 1003 /* select#1 */ select `test`.`test_ref`.`a` AS `a`,`test`.`test_ref`.`b` AS `b`,`test`.`test_ref`.`c` AS `c`,`test`.`test_ref`.`d` AS `d`,`test`.`test_ref`.`id` AS `id` from `test`.`test_ref` where ((`test`.`test_ref`.`id` = 3) and (`test`.`test_ref`.`c` like 'gh%')) order by `test`.`test_ref`.`c` desc,`test`.`test_ref`.`a` desc limit 1
SELECT *
FROM test_ref
WHERE id=3 AND c LIKE 'gh%'
ORDER BY c DESC, a DESC
LIMIT 1;
a b c d id
1770649 D003 gheennse S 3
DROP TABLE test_ref;
#
# Bug #30988735: SELECT QUERY WITH ERROR RESULT WITH "NOT IN"
# WHERE_CLAUSE
#
CREATE TABLE t(f1 INTEGER key, f2 INTEGER)ENGINE=INNODB;
INSERT INTO t VALUES(0,0);
ANALYZE TABLE t;
Table Op Msg_type Msg_text
test.t analyze status OK
SELECT f1,f2 FROM t WHERE f1 NOT IN(-0.1,0.1);
f1 f2
0 0
DROP TABLE t;
#
# Bug#32523520: OPTIMIZER LOSES PART OF RANGE WHEN OR MULTIPLE
# IDENTICAL RANGES IN RANGE PLAN
#
CREATE TABLE t1( a INTEGER, b INTEGER, c INTEGER,
d VARCHAR(10), PRIMARY KEY (a, b, c));
INSERT INTO t1 VALUES (1, 1, 1, 'a'), (2, 2, 2,'b'), (3, 3, 3, 'c');
EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE (a=1 AND b=1 AND c=1)
OR (a=1 AND b=1 AND c=1) OR (a=1 AND b=2 AND c=2);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range PRIMARY PRIMARY 12 NULL 2 100.00 Using where
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c`,`test`.`t1`.`d` AS `d` from `test`.`t1` FORCE INDEX (PRIMARY) where (((`test`.`t1`.`c` = 1) and (`test`.`t1`.`b` = 1) and (`test`.`t1`.`a` = 1)) or ((`test`.`t1`.`c` = 1) and (`test`.`t1`.`b` = 1) and (`test`.`t1`.`a` = 1)) or ((`test`.`t1`.`c` = 2) and (`test`.`t1`.`b` = 2) and (`test`.`t1`.`a` = 1)))
SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE (a=1 AND b=1 AND c=1)
OR (a=1 AND b=1 AND c=1) OR (a=1 AND b=2 AND c=2);
a b c d
1 1 1 a
DROP TABLE t1;
#
# Bug #31870920: WRONG RESULT WHEN SELECT INT COLUMN WITH RANGE
#
CREATE TABLE t1(f1 INTEGER, KEY(f1));
INSERT INTO t1 VALUES(0),(0),(0);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
EXPLAIN SELECT f1 FROM t1 WHERE f1 NOT IN (0.1, -0.1);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index f1 f1 5 NULL 3 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where (`test`.`t1`.`f1` not in (0.1,<cache>(-(0.1))))
SELECT f1 FROM t1 WHERE f1 NOT IN (0.1, -0.1);
f1
0
0
0
DROP TABLE t1;
#
# Bug#33067554: INDEX_MERGE: ASSERTION FAILURE:
# ROW0SEL.CC:5584:PREBUILT->CAN_PREFETCH_RECORDS() ||
# RECORD_BUFFER == NULLPTR
#
CREATE TABLE t (
a INTEGER,
b INTEGER,
pk TEXT NOT NULL,
PRIMARY KEY (pk(110)),
KEY (a),
KEY (b)
);
INSERT INTO t VALUES
(51,16777216,''), (-128,0,' nsj mizb'),
(0,5900842,' qdblp vgc'), (0,-128,'c z'),
(-1,-125,'d'), (95,3345,'dtphyrp'),
(97,14396343,'du'), (127,0,'fnwyz'),
(-128,0,'fszpsqd'), (-128,32767,'g uevfc'),
(-128,0,'hh lhozu '), (0,0,'m tkr'),
(0,246,'mgmtel'), (-1,2147483647,'n hjh'),
(127,0,'ssw'), (127,0,'t zl'), (0,-1,'uns');
ANALYZE TABLE t;
Table Op Msg_type Msg_text
test.t analyze status OK
SELECT b FROM t WHERE a = 0 AND b = 0;
b
0
DROP TABLE t;
# Bug#17769777 EXCESSIVE MEMORY CONSUMPTION WITH MANY AND / BETWEEN
# ITEMS
# Bug#17413040 USING MANY WHERE CONDITIONS MAKES RANGE SCAN DISABLED
CREATE TABLE t1 (
a INT,
b INT,
KEY (a)
)ENGINE=INNODB;
INSERT INTO t1 VALUES (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6),
(7, 7), (8, 8), (9, 9);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SET RANGE_OPTIMIZER_MAX_MEM_SIZE= 100;
EXPLAIN SELECT DISTINCT a FROM t1 WHERE (a, b) IN ((0, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL index a a 5 NULL 10 10.00 Using where
Warnings:
Warning 3170 Memory capacity of 100 bytes for 'range_optimizer_max_mem_size' exceeded. Range optimization was not done for this query.
Note 1003 /* select#1 */ select distinct `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in ((0,0),(1,1)))
SET RANGE_OPTIMIZER_MAX_MEM_SIZE= DEFAULT;
EXPLAIN SELECT DISTINCT a FROM t1 WHERE (a, b) IN ((0, 0), (1, 1));
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL range a a 5 NULL 2 20.00 Using where
Warnings:
Note 1003 /* select#1 */ select distinct `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a`,`test`.`t1`.`b`) in ((0,0),(1,1)))
DROP TABLE t1;
# End of test for Bug#17769777 and Bug#17413040
#
# Bug#33282123: Const table optimization for aggregates goes wrong with
# NO PAD collations
#
CREATE TABLE t1 (col1 VARCHAR(5), col2 INTEGER, PRIMARY KEY (col1, col2));
INSERT INTO t1 VALUES ('abcde', 10);
# Used to return 10. The expected result is NULL.
SELECT MAX(col2) FROM t1 WHERE col1 = 'abcde ';
MAX(col2)
NULL
DROP TABLE t1;
#
# Bug#33611112: Reverse index scan is not sorted on implicit InnoDB primary key
#
CREATE TABLE t1 (a INTEGER, b INTEGER, PRIMARY KEY (a), KEY (b));
INSERT INTO t1 VALUES (1, NULL), (2, NULL), (3, 3), (4, NULL);
SELECT a FROM t1 WHERE b IS NULL GROUP BY a ORDER BY a DESC;
a
4
2
1
DROP TABLE t1;
#
# Bug#34347116 - Range intersection is not available for a
# compound index when joining a derived table
#
CREATE TABLE t1 (a SERIAL, b INT);
INSERT INTO t1(b) VALUES (1),(2),(3),(100);
CREATE TABLE t2 (a SERIAL, b INT, c INT, INDEX(b,c));
INSERT INTO t2(b,c) VALUES (10,10),(100,100),(200,200);
ANALYZE TABLE t1, t2;
Table Op Msg_type Msg_text
test.t1 analyze status OK
test.t2 analyze status OK
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN (SELECT a,b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100) t ON t1.a=t.b;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL
1 SIMPLE t2 NULL range b b 10 NULL 1 100.00 Using where; Using index; Using join buffer (hash join)
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` left join (`test`.`t2`) on(((`test`.`t2`.`b` = 100) and (`test`.`t1`.`a` = `test`.`t2`.`b`) and (`test`.`t2`.`c` <= 100) and (`test`.`t2`.`c` >= 100))) where true
EXPLAIN SELECT b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 NULL range b b 10 NULL 1 100.00 Using where; Using index
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`b` = 100) and (`test`.`t2`.`c` <= 100) and (`test`.`t2`.`c` >= 100))
DROP TABLE t1, t2;
CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, c3 VARCHAR(1) , PRIMARY KEY(c1));
INSERT INTO t1 VALUES (1,1,'a'), (2,2,'b'), (3,4,'c'), (4,4,'z'),(5,5,'L');
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SELECT at1.c3 FROM (t1 AS at1 LEFT JOIN (SELECT at2.* FROM (t1 AS at2 JOIN t1 AS at3 ON ((1,2) IN (SELECT c1,c1 FROM t1 as at4)))) AS at5 ON at5.c1 = at1.c1);
c3
a
b
c
z
L
DROP TABLE t1;
# Bug#34856343: Assertion 'join->best_read < DBL_MAX'
CREATE TABLE t (f1 INTEGER, f2 INTEGER, KEY(f1));
INSERT INTO t VALUES(1, 10), (2, 20), (3, 30), (4, 40);
ANALYZE TABLE t;
Table Op Msg_type Msg_text
test.t analyze status OK
explain format=tree SELECT 1 FROM t AS t1 JOIN t AS t2 ON t2.f1 < NULL;
EXPLAIN
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1 FROM t AS t1 JOIN t AS t2 ON t2.f1 < NULL;
1
explain format=tree SELECT 1 FROM t AS t1 JOIN t AS t2 ON t2.f1 BETWEEN 2 AND 3;
EXPLAIN
-> Inner hash join (no condition) (rows=8)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t2 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1 FROM t AS t1 JOIN (SELECT * FROM t WHERE f1 < NULL) AS t2 ON TRUE;
EXPLAIN
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1 FROM t AS t1 JOIN (SELECT * FROM t WHERE f1 < NULL) AS t2 ON TRUE;
1
explain format=tree SELECT 1
FROM t AS t1 JOIN (SELECT * FROM t WHERE f1 BETWEEN 2 AND 3) AS t2 ON TRUE;
EXPLAIN
-> Inner hash join (no condition) (rows=8)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON t2.f1 < NULL;
EXPLAIN
-> Index scan on t1 using f1 (rows=4)
SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON t2.f1 < NULL;
1
1
1
1
1
explain format=tree SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON t2.f1 BETWEEN 2 AND 3;
EXPLAIN
-> Left hash join (no condition) (rows=8)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t2 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1 FROM t AS t1 LEFT JOIN (SELECT * FROM t WHERE f1 < NULL) AS t2 ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t.f1 < NULL) (rows=4)
-> Index scan on t using f1 (rows=4)
SELECT 1 FROM t AS t1 LEFT JOIN (SELECT * FROM t WHERE f1 < NULL) AS t2 ON TRUE;
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN (SELECT * FROM t AS t2 WHERE f1 BETWEEN 2 AND 3) AS t2
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=8)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t2 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON t1.f1 < NULL;
EXPLAIN
-> Left hash join (no condition), extra conditions: (t1.f1 < NULL) (rows=16)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Index scan on t2 using f1 (rows=4)
SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON t1.f1 < NULL;
1
1
1
1
1
explain format=tree SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON t1.f1 BETWEEN 2 AND 3;
EXPLAIN
-> Left hash join (no condition), extra conditions: (t1.f1 between 2 and 3) (rows=16)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Index scan on t2 using f1 (rows=4)
explain format=tree SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON TRUE WHERE t1.f1 < NULL;
EXPLAIN
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON TRUE WHERE t1.f1 < NULL;
1
explain format=tree SELECT 1 FROM t AS t1 LEFT JOIN t AS t2 ON TRUE WHERE t1.f1 BETWEEN 2 AND 3;
EXPLAIN
-> Left hash join (no condition) (rows=8)
-> Filter: (t1.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t1 using f1 over (2 <= f1 <= 3) (rows=2)
-> Hash
-> Index scan on t2 using f1 (rows=4)
explain format=tree SELECT 1 FROM (SELECT * FROM t WHERE f1 < NULL) AS t1 LEFT JOIN t AS t2 ON TRUE;
EXPLAIN
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1 FROM (SELECT * FROM t WHERE f1 < NULL) AS t1 LEFT JOIN t AS t2 ON TRUE;
1
explain format=tree SELECT 1
FROM (SELECT * FROM t WHERE f1 BETWEEN 2 AND 3) AS t1 LEFT JOIN t AS t2 ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=8)
-> Filter: (t.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t using f1 over (2 <= f1 <= 3) (rows=2)
-> Hash
-> Index scan on t2 using f1 (rows=4)
explain format=tree SELECT 1 FROM (SELECT * FROM t) AS t1 LEFT JOIN t AS t2 ON t1.f1 < NULL;
EXPLAIN
-> Left hash join (no condition), extra conditions: (t.f1 < NULL) (rows=16)
-> Index scan on t using f1 (rows=4)
-> Hash
-> Index scan on t2 using f1 (rows=4)
SELECT 1 FROM (SELECT * FROM t) AS t1 LEFT JOIN t AS t2 ON t1.f1 < NULL;
1
1
1
1
1
explain format=tree SELECT 1
FROM (SELECT * FROM t) AS t1 LEFT JOIN t AS t2 ON t1.f1 BETWEEN 2 AND 3;
EXPLAIN
-> Left hash join (no condition), extra conditions: (t.f1 between 2 and 3) (rows=16)
-> Index scan on t using f1 (rows=4)
-> Hash
-> Index scan on t2 using f1 (rows=4)
explain format=tree SELECT 1
FROM (SELECT * FROM t) AS t1 LEFT JOIN t AS t2 ON TRUE
WHERE t1.f1 < NULL;
EXPLAIN
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1
FROM (SELECT * FROM t) AS t1 LEFT JOIN t AS t2 ON TRUE
WHERE t1.f1 < NULL;
1
explain format=tree SELECT 1
FROM (SELECT * FROM t) AS t1 LEFT JOIN t AS t2 ON TRUE
WHERE t1.f1 BETWEEN 2 AND 3;
EXPLAIN
-> Left hash join (no condition) (rows=8)
-> Filter: (t.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t using f1 over (2 <= f1 <= 3) (rows=2)
-> Hash
-> Index scan on t2 using f1 (rows=4)
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 JOIN t AS t3 ON t2.f1 < NULL
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=16)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 < NULL) (rows=16)
-> Inner hash join (no condition) (rows=16)
-> Index scan on t3 using f1 (rows=4)
-> Hash
-> Index scan on t2 using f1 (rows=4)
SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 JOIN t AS t3 ON t2.f1 < NULL
ON TRUE;
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 JOIN t AS t3 ON t3.f1 < NULL
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=16)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t3.f1 < NULL) (rows=16)
-> Inner hash join (no condition) (rows=16)
-> Index scan on t2 using f1 (rows=4)
-> Hash
-> Index scan on t3 using f1 (rows=4)
SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 JOIN t AS t3 ON t3.f1 < NULL
ON TRUE;
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 JOIN t AS t3 ON t2.f1 BETWEEN 2 AND 3
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=32)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=8)
-> Inner hash join (no condition) (rows=8)
-> Index scan on t3 using f1 (rows=4)
-> Hash
-> Covering index range scan on t2 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 JOIN t AS t3 ON t3.f1 BETWEEN 2 AND 3
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=32)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t3.f1 between 2 and 3) (rows=8)
-> Inner hash join (no condition) (rows=8)
-> Index scan on t2 using f1 (rows=4)
-> Hash
-> Covering index range scan on t3 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT 1 FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL) AS t4
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=16)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 < NULL) (rows=16)
-> Inner hash join (no condition) (rows=16)
-> Index scan on t3 using f1 (rows=4)
-> Hash
-> Index scan on t2 using f1 (rows=4)
SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT 1 FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL) AS t4
ON TRUE;
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT 1 FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL) AS t4
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=16)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t3.f1 < NULL) (rows=16)
-> Inner hash join (no condition) (rows=16)
-> Index scan on t2 using f1 (rows=4)
-> Hash
-> Index scan on t3 using f1 (rows=4)
SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT 1 FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL) AS t4
ON TRUE;
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT 1 FROM t AS t2 JOIN t AS t3 ON t2.f1 BETWEEN 2 AND 3) AS t4
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=32)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=8)
-> Inner hash join (no condition) (rows=8)
-> Index scan on t3 using f1 (rows=4)
-> Hash
-> Covering index range scan on t2 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT 1 FROM t AS t2 JOIN t AS t3 ON t3.f1 BETWEEN 2 AND 3) AS t4
ON TRUE;
EXPLAIN
-> Left hash join (no condition) (rows=32)
-> Index scan on t1 using f1 (rows=4)
-> Hash
-> Filter: (t3.f1 between 2 and 3) (rows=8)
-> Inner hash join (no condition) (rows=8)
-> Index scan on t2 using f1 (rows=4)
-> Hash
-> Covering index range scan on t3 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 LEFT JOIN t AS t3 ON t3.f1 < NULL
ON t1.f1 = t2.f1;
EXPLAIN
-> Nested loop left join (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Nested loop left join (rows=1)
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
-> Filter: (t3.f1 < NULL) (rows=1)
-> Index scan on t3 using f1 (rows=4)
SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 LEFT JOIN t AS t3 ON t3.f1 < NULL
ON t1.f1 = t2.f1;
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
t AS t2 LEFT JOIN t AS t3 ON t3.f1 BETWEEN 2 AND 3
ON t1.f1 = t2.f1;
EXPLAIN
-> Filter: <if>(found_match(t3), true, true) (rows=8)
-> Nested loop left join (rows=8)
-> Index scan on t1 using f1 (rows=4)
-> Nested loop left join (rows=2)
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
-> Filter: (t3.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t3 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT t2.f1 FROM t AS t2 LEFT JOIN t AS t3 ON t3.f1 < NULL) AS t4
ON t1.f1 = t4.f1;
EXPLAIN
-> Nested loop left join (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Nested loop left join (rows=1)
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
-> Filter: (t3.f1 < NULL) (rows=1)
-> Index scan on t3 using f1 (rows=4)
SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT t2.f1 FROM t AS t2 LEFT JOIN t AS t3 ON t3.f1 < NULL) AS t4
ON t1.f1 = t4.f1;
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1 LEFT JOIN
(SELECT t2.f1 FROM t AS t2 LEFT JOIN t AS t3 ON t3.f1 BETWEEN 2 AND 3
) AS t4
ON t1.f1 = t4.f1;
EXPLAIN
-> Filter: <if>(found_match(t3), true, true) (rows=8)
-> Nested loop left join (rows=8)
-> Index scan on t1 using f1 (rows=4)
-> Nested loop left join (rows=2)
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
-> Filter: (t3.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t3 using f1 over (2 <= f1 <= 3) (rows=2)
explain format=tree SELECT 1 FROM t WHERE f2 IN (SELECT f1 FROM t WHERE f1 < NULL);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1 FROM t WHERE f2 IN (SELECT f1 FROM t WHERE f1 < NULL);
1
explain format=tree SELECT 1 FROM t WHERE f2 IN (SELECT f1 FROM t WHERE f1 BETWEEN 2 AND 3);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s)
-> Filter: (t.f1 between 2 and 3)
-> Covering index lookup on t using f1 (f1=<cache>(t.f2)) (rows=1)
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT f1 FROM (SELECT f1 FROM t WHERE f1 < NULL) AS t2);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1
FROM t
WHERE f2 IN (SELECT f1 FROM (SELECT f1 FROM t WHERE f1 < NULL) AS t2);
1
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT f1 FROM (SELECT f1 FROM t WHERE f1 BETWEEN 2 AND 3) AS t2);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s)
-> Filter: (t.f1 between 2 and 3)
-> Covering index lookup on t using f1 (f1=<cache>(t.f2)) (rows=1)
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1
FROM t
WHERE f2 IN (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL);
1
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1
FROM t
WHERE f2 IN (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL);
1
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t2.f1 BETWEEN 2 AND 3);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Inner hash join (no condition) (rows=4)
-> Index scan on t3 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=1)
-> Covering index lookup on t2 using f1 (f1=<cache>(t.f2)) (rows=1)
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t3.f1 BETWEEN 2 AND 3);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Inner hash join (no condition) (rows=2)
-> Filter: (t3.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t3 using f1 over (2 <= f1 <= 3) (rows=2)
-> Hash
-> Covering index lookup on t2 using f1 (f1=<cache>(t.f2)) (rows=1)
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT t4.f1
FROM (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL
) AS t4
);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1
FROM t
WHERE f2 IN (SELECT t4.f1
FROM (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL
) AS t4
);
1
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT t4.f1
FROM (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL
) AS t4
);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
SELECT 1
FROM t
WHERE f2 IN (SELECT t4.f1
FROM (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL
) AS t4
);
1
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT t4.f1
FROM (SELECT t2.f1
FROM t AS t2 JOIN t AS t3 ON t2.f1 BETWEEN 2 AND 3
) AS t4
);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Inner hash join (no condition) (rows=4)
-> Index scan on t3 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=1)
-> Covering index lookup on t2 using f1 (f1=<cache>(t.f2)) (rows=1)
explain format=tree SELECT 1
FROM t
WHERE f2 IN (SELECT t4.f1
FROM (SELECT t2.f1
FROM t AS t2 JOIN t AS t3 ON t3.f1 BETWEEN 2 AND 3
) AS t4
);
EXPLAIN
-> Filter: <in_optimizer>(t.f2,<exists>(select #2)) (rows=4)
-> Table scan on t (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Inner hash join (no condition) (rows=2)
-> Filter: (t3.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t3 using f1 over (2 <= f1 <= 3) (rows=2)
-> Hash
-> Covering index lookup on t2 using f1 (f1=<cache>(t.f2)) (rows=1)
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT * FROM t AS t2 WHERE t2.f1 < NULL AND t1.f1 = t2.f1);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT * FROM t AS t2 WHERE t2.f1 < NULL AND t1.f1 = t2.f1);
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM t AS t2
WHERE t2.f1 BETWEEN 2 AND 3 AND t1.f1 = t2.f1);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Filter: (t2.f1 between 2 and 3) (rows=1)
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT f1 FROM t AS t2 WHERE t2.f1 < NULL) AS t4
WHERE t1.f1 = t4.f1
);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT f1 FROM t AS t2 WHERE t2.f1 < NULL) AS t4
WHERE t1.f1 = t4.f1
);
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT f1 FROM t AS t2 WHERE t2.f1 BETWEEN 2 AND 3
) AS t4
WHERE t1.f1 = t4.f1
);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Filter: (t2.f1 between 2 and 3) (rows=1)
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL
WHERE t1.f1 = t2.f1);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL
WHERE t1.f1 = t2.f1);
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL
WHERE t1.f1 = t3.f1);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL
WHERE t1.f1 = t3.f1);
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM t AS t2 JOIN t AS t3 ON t2.f1 BETWEEN 2 AND 3
WHERE t1.f1 = t2.f1);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Inner hash join (no condition) (rows=4)
-> Index scan on t3 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=1)
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM t AS t2 JOIN t AS t3 ON t3.f1 BETWEEN 2 AND 3
WHERE t1.f1 = t2.f1);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Inner hash join (no condition) (rows=2)
-> Filter: (t3.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t3 using f1 over (2 <= f1 <= 3) (rows=2)
-> Hash
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL
) AS t4
WHERE t1.f1 = t4.f1
);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t2.f1 < NULL
) AS t4
WHERE t1.f1 = t4.f1
);
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL
) AS t4
WHERE t1.f1 = t4.f1
);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Zero rows (no matching row in const table) (rows=0)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT t2.f1 FROM t AS t2 JOIN t AS t3 ON t3.f1 < NULL
) AS t4
WHERE t1.f1 = t4.f1
);
1
1
1
1
1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT t2.f1
FROM t AS t2 JOIN t AS t3 ON t2.f1 BETWEEN 2 AND 3
) AS t4
WHERE t1.f1 = t4.f1
);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Inner hash join (no condition) (rows=4)
-> Index scan on t3 using f1 (rows=4)
-> Hash
-> Filter: (t2.f1 between 2 and 3) (rows=1)
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
explain format=tree SELECT 1
FROM t AS t1
WHERE NOT EXISTS (SELECT *
FROM (SELECT t2.f1
FROM t AS t2 JOIN t AS t3 ON t3.f1 BETWEEN 2 AND 3
) AS t4
WHERE t1.f1 = t4.f1
);
EXPLAIN
-> Filter: exists(select #2) is false (rows=4)
-> Index scan on t1 using f1 (rows=4)
-> Select #2 (subquery in condition; dependent)
-> Limit: 1 row(s) (rows=1)
-> Inner hash join (no condition) (rows=2)
-> Filter: (t3.f1 between 2 and 3) (rows=2)
-> Covering index range scan on t3 using f1 over (2 <= f1 <= 3) (rows=2)
-> Hash
-> Covering index lookup on t2 using f1 (f1=t1.f1) (rows=1)
Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
DROP TABLE t;
set optimizer_switch=default;
|