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
|
set optimizer_switch='block_nested_loop=off,batched_key_access=off';
set optimizer_switch='mrr_cost_based=off';
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
DROP DATABASE IF EXISTS world;
set names utf8;
CREATE DATABASE world;
use world;
CREATE TABLE Country (
Code char(3) NOT NULL default '',
Name char(52) NOT NULL default '',
SurfaceArea float(10,2) NOT NULL default '0.00',
Population int(11) NOT NULL default '0',
Capital int(11) default NULL
);
CREATE TABLE City (
ID int(11) NOT NULL,
Name char(35) NOT NULL default '',
Country char(3) NOT NULL default '',
Population int(11) NOT NULL default '0'
);
CREATE TABLE CountryLanguage (
Country char(3) NOT NULL default '',
Language char(30) NOT NULL default '',
Percentage float(3,1) NOT NULL default '0.0'
);
SELECT COUNT(*) FROM Country;
COUNT(*)
239
SELECT COUNT(*) FROM City;
COUNT(*)
4079
SELECT COUNT(*) FROM CountryLanguage;
COUNT(*)
984
show variables like 'join_buffer_size';
Variable_name Value
join_buffer_size 262144
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
Name Name
?iauliai Lithuania
Beirut Lebanon
Bengasi Libyan Arab Jamahiriya
Daugavpils Latvia
Kaunas Lithuania
Klaipeda Lithuania
Maseru Lesotho
Misrata Libyan Arab Jamahiriya
Monrovia Liberia
Panevezys Lithuania
Riga Latvia
Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
Name Name Language
La Ceiba Honduras Spanish
La Habana Cuba Spanish
La Matanza Argentina Spanish
La Paz Bolivia Spanish
La Paz Mexico Spanish
La Paz Mexico Spanish
La Plata Argentina Spanish
La Rioja Argentina Spanish
La Romana Dominican Republic Spanish
La Serena Chile Spanish
La Spezia Italy Italian
Lafayette United States English
Lages Brazil Portuguese
Lagos de Moreno Mexico Spanish
Lahti Finland Finnish
Laiwu China Chinese
Laiyang China Chinese
Laizhou China Chinese
Lakewood United States English
Lalitapur Nepal Nepali
Lambaré Paraguay Spanish
Lancaster United States English
Langfang China Chinese
Lansing United States English
Lanzhou China Chinese
Lanús Argentina Spanish
Laohekou China Chinese
Laredo United States English
Larisa Greece Greek
Las Heras Argentina Spanish
Las Margaritas Mexico Spanish
Las Palmas de Gran Canaria Spain Spanish
Las Vegas United States English
Lashio (Lasho) Myanmar Burmese
Latakia Syria Arabic
Latina Italy Italian
Lauro de Freitas Brazil Portuguese
Lausanne Switzerland German
Laval Canada English
Le Havre France French
Le Mans France French
Le-Cap-Haïtien Haiti Haiti Creole
Lecce Italy Italian
Leeds United Kingdom English
Leganés Spain Spanish
Legnica Poland Polish
Leicester United Kingdom English
Leiden Netherlands Dutch
Leipzig Germany German
Leiyang China Chinese
Lengshuijiang China Chinese
Leninsk-Kuznetski Russian Federation Russian
Lerdo Mexico Spanish
Lerma Mexico Spanish
Leshan China Chinese
Leverkusen Germany German
Lexington-Fayette United States English
León Mexico Spanish
León Nicaragua Spanish
León Spain Spanish
Lhasa China Chinese
Liangcheng China Chinese
Lianyuan China Chinese
Lianyungang China Chinese
Liaocheng China Chinese
Liaoyang China Chinese
Liaoyuan China Chinese
Liberec Czech Republic Czech
Lida Belarus Belorussian
Liling China Chinese
Lille France French
Lilongwe Malawi Chichewa
Lima Peru Spanish
Limeira Brazil Portuguese
Limoges France French
Linchuan China Chinese
Lincoln United States English
Linfen China Chinese
Linhai China Chinese
Linhares Brazil Portuguese
Linhe China Chinese
Linköping Sweden Swedish
Linqing China Chinese
Linyi China Chinese
Linz Austria German
Lipetsk Russian Federation Russian
Lisboa Portugal Portuguese
Little Rock United States English
Liupanshui China Chinese
Liuzhou China Chinese
Liu´an China Chinese
Liverpool United Kingdom English
Livonia United States English
Livorno Italy Italian
Liyang China Chinese
Liège Belgium Dutch
Ljubertsy Russian Federation Russian
Lleida (Lérida) Spain Spanish
Logroño Spain Spanish
Loja Ecuador Spanish
Lomas de Zamora Argentina Spanish
London Canada English
London United Kingdom English
Londrina Brazil Portuguese
Long Beach United States English
Long Xuyen Vietnam Vietnamese
Longjing China Chinese
Longkou China Chinese
Longueuil Canada English
Longyan China Chinese
Los Angeles Chile Spanish
Los Angeles United States English
Los Cabos Mexico Spanish
Los Teques Venezuela Spanish
Loudi China Chinese
Louisville United States English
Lowell United States English
Lower Hutt New Zealand English
Lubbock United States English
Lublin Poland Polish
Luchou Taiwan Min
Ludwigshafen am Rhein Germany German
Lugansk Ukraine Ukrainian
Lund Sweden Swedish
Lungtan Taiwan Min
Luohe China Chinese
Luoyang China Chinese
Luton United Kingdom English
Lutsk Ukraine Ukrainian
Luxor Egypt Arabic
Luzhou China Chinese
Luziânia Brazil Portuguese
Lviv Ukraine Ukrainian
Lyon France French
Lysyt?ansk Ukraine Ukrainian
L´Hospitalet de Llobregat Spain Spanish
Lázaro Cárdenas Mexico Spanish
Lódz Poland Polish
Lübeck Germany German
Lünen Germany German
set join_buffer_size=256;
show variables like 'join_buffer_size';
Variable_name Value
join_buffer_size 256
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
Name Name
?iauliai Lithuania
Beirut Lebanon
Bengasi Libyan Arab Jamahiriya
Daugavpils Latvia
Kaunas Lithuania
Klaipeda Lithuania
Maseru Lesotho
Misrata Libyan Arab Jamahiriya
Monrovia Liberia
Panevezys Lithuania
Riga Latvia
Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where
1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
Name Name Language
La Ceiba Honduras Spanish
La Habana Cuba Spanish
La Matanza Argentina Spanish
La Paz Bolivia Spanish
La Paz Mexico Spanish
La Paz Mexico Spanish
La Plata Argentina Spanish
La Rioja Argentina Spanish
La Romana Dominican Republic Spanish
La Serena Chile Spanish
La Spezia Italy Italian
Lafayette United States English
Lages Brazil Portuguese
Lagos de Moreno Mexico Spanish
Lahti Finland Finnish
Laiwu China Chinese
Laiyang China Chinese
Laizhou China Chinese
Lakewood United States English
Lalitapur Nepal Nepali
Lambaré Paraguay Spanish
Lancaster United States English
Langfang China Chinese
Lansing United States English
Lanzhou China Chinese
Lanús Argentina Spanish
Laohekou China Chinese
Laredo United States English
Larisa Greece Greek
Las Heras Argentina Spanish
Las Margaritas Mexico Spanish
Las Palmas de Gran Canaria Spain Spanish
Las Vegas United States English
Lashio (Lasho) Myanmar Burmese
Latakia Syria Arabic
Latina Italy Italian
Lauro de Freitas Brazil Portuguese
Lausanne Switzerland German
Laval Canada English
Le Havre France French
Le Mans France French
Le-Cap-Haïtien Haiti Haiti Creole
Lecce Italy Italian
Leeds United Kingdom English
Leganés Spain Spanish
Legnica Poland Polish
Leicester United Kingdom English
Leiden Netherlands Dutch
Leipzig Germany German
Leiyang China Chinese
Lengshuijiang China Chinese
Leninsk-Kuznetski Russian Federation Russian
Lerdo Mexico Spanish
Lerma Mexico Spanish
Leshan China Chinese
Leverkusen Germany German
Lexington-Fayette United States English
León Mexico Spanish
León Nicaragua Spanish
León Spain Spanish
Lhasa China Chinese
Liangcheng China Chinese
Lianyuan China Chinese
Lianyungang China Chinese
Liaocheng China Chinese
Liaoyang China Chinese
Liaoyuan China Chinese
Liberec Czech Republic Czech
Lida Belarus Belorussian
Liling China Chinese
Lille France French
Lilongwe Malawi Chichewa
Lima Peru Spanish
Limeira Brazil Portuguese
Limoges France French
Linchuan China Chinese
Lincoln United States English
Linfen China Chinese
Linhai China Chinese
Linhares Brazil Portuguese
Linhe China Chinese
Linköping Sweden Swedish
Linqing China Chinese
Linyi China Chinese
Linz Austria German
Lipetsk Russian Federation Russian
Lisboa Portugal Portuguese
Little Rock United States English
Liupanshui China Chinese
Liuzhou China Chinese
Liu´an China Chinese
Liverpool United Kingdom English
Livonia United States English
Livorno Italy Italian
Liyang China Chinese
Liège Belgium Dutch
Ljubertsy Russian Federation Russian
Lleida (Lérida) Spain Spanish
Logroño Spain Spanish
Loja Ecuador Spanish
Lomas de Zamora Argentina Spanish
London Canada English
London United Kingdom English
Londrina Brazil Portuguese
Long Beach United States English
Long Xuyen Vietnam Vietnamese
Longjing China Chinese
Longkou China Chinese
Longueuil Canada English
Longyan China Chinese
Los Angeles Chile Spanish
Los Angeles United States English
Los Cabos Mexico Spanish
Los Teques Venezuela Spanish
Loudi China Chinese
Louisville United States English
Lowell United States English
Lower Hutt New Zealand English
Lubbock United States English
Lublin Poland Polish
Luchou Taiwan Min
Ludwigshafen am Rhein Germany German
Lugansk Ukraine Ukrainian
Lund Sweden Swedish
Lungtan Taiwan Min
Luohe China Chinese
Luoyang China Chinese
Luton United Kingdom English
Lutsk Ukraine Ukrainian
Luxor Egypt Arabic
Luzhou China Chinese
Luziânia Brazil Portuguese
Lviv Ukraine Ukrainian
Lyon France French
Lysyt?ansk Ukraine Ukrainian
L´Hospitalet de Llobregat Spain Spanish
Lázaro Cárdenas Mexico Spanish
Lódz Poland Polish
Lübeck Germany German
Lünen Germany German
set join_buffer_size=default;
show variables like 'join_buffer_size';
Variable_name Value
join_buffer_size 262144
DROP DATABASE world;
CREATE DATABASE world;
use world;
CREATE TABLE Country (
Code char(3) NOT NULL default '',
Name char(52) NOT NULL default '',
SurfaceArea float(10,2) NOT NULL default '0.00',
Population int(11) NOT NULL default '0',
Capital int(11) default NULL,
PRIMARY KEY (Code),
UNIQUE INDEX (Name)
);
CREATE TABLE City (
ID int(11) NOT NULL auto_increment,
Name char(35) NOT NULL default '',
Country char(3) NOT NULL default '',
Population int(11) NOT NULL default '0',
PRIMARY KEY (ID),
INDEX (Population),
INDEX (Country)
);
CREATE TABLE CountryLanguage (
Country char(3) NOT NULL default '',
Language char(30) NOT NULL default '',
Percentage float(3,1) NOT NULL default '0.0',
PRIMARY KEY (Country, Language),
INDEX (Percentage)
);
show variables like 'join_buffer_size';
Variable_name Value
join_buffer_size 262144
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
1 SIMPLE City ref Population,Country Country 3 world.Country.Code 18 Using where
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
Name Name
?iauliai Lithuania
Beirut Lebanon
Bengasi Libyan Arab Jamahiriya
Daugavpils Latvia
Kaunas Lithuania
Klaipeda Lithuania
Maseru Lesotho
Misrata Libyan Arab Jamahiriya
Monrovia Liberia
Panevezys Lithuania
Riga Latvia
Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE CountryLanguage range PRIMARY,Percentage Percentage 4 NULL # Using index condition; Using MRR
1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.CountryLanguage.Country 1 Using where
1 SIMPLE City ref Country Country 3 world.CountryLanguage.Country 18 Using where
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
Name Name Language
La Ceiba Honduras Spanish
La Habana Cuba Spanish
La Matanza Argentina Spanish
La Paz Bolivia Spanish
La Paz Mexico Spanish
La Paz Mexico Spanish
La Plata Argentina Spanish
La Rioja Argentina Spanish
La Romana Dominican Republic Spanish
La Serena Chile Spanish
La Spezia Italy Italian
Lafayette United States English
Lages Brazil Portuguese
Lagos de Moreno Mexico Spanish
Lahti Finland Finnish
Laiwu China Chinese
Laiyang China Chinese
Laizhou China Chinese
Lakewood United States English
Lalitapur Nepal Nepali
Lambaré Paraguay Spanish
Lancaster United States English
Langfang China Chinese
Lansing United States English
Lanzhou China Chinese
Lanús Argentina Spanish
Laohekou China Chinese
Laredo United States English
Larisa Greece Greek
Las Heras Argentina Spanish
Las Margaritas Mexico Spanish
Las Palmas de Gran Canaria Spain Spanish
Las Vegas United States English
Lashio (Lasho) Myanmar Burmese
Latakia Syria Arabic
Latina Italy Italian
Lauro de Freitas Brazil Portuguese
Lausanne Switzerland German
Laval Canada English
Le Havre France French
Le Mans France French
Le-Cap-Haïtien Haiti Haiti Creole
Lecce Italy Italian
Leeds United Kingdom English
Leganés Spain Spanish
Legnica Poland Polish
Leicester United Kingdom English
Leiden Netherlands Dutch
Leipzig Germany German
Leiyang China Chinese
Lengshuijiang China Chinese
Leninsk-Kuznetski Russian Federation Russian
Lerdo Mexico Spanish
Lerma Mexico Spanish
Leshan China Chinese
Leverkusen Germany German
Lexington-Fayette United States English
León Mexico Spanish
León Nicaragua Spanish
León Spain Spanish
Lhasa China Chinese
Liangcheng China Chinese
Lianyuan China Chinese
Lianyungang China Chinese
Liaocheng China Chinese
Liaoyang China Chinese
Liaoyuan China Chinese
Liberec Czech Republic Czech
Lida Belarus Belorussian
Liling China Chinese
Lille France French
Lilongwe Malawi Chichewa
Lima Peru Spanish
Limeira Brazil Portuguese
Limoges France French
Linchuan China Chinese
Lincoln United States English
Linfen China Chinese
Linhai China Chinese
Linhares Brazil Portuguese
Linhe China Chinese
Linköping Sweden Swedish
Linqing China Chinese
Linyi China Chinese
Linz Austria German
Lipetsk Russian Federation Russian
Lisboa Portugal Portuguese
Little Rock United States English
Liupanshui China Chinese
Liuzhou China Chinese
Liu´an China Chinese
Liverpool United Kingdom English
Livonia United States English
Livorno Italy Italian
Liyang China Chinese
Liège Belgium Dutch
Ljubertsy Russian Federation Russian
Lleida (Lérida) Spain Spanish
Logroño Spain Spanish
Loja Ecuador Spanish
Lomas de Zamora Argentina Spanish
London Canada English
London United Kingdom English
Londrina Brazil Portuguese
Long Beach United States English
Long Xuyen Vietnam Vietnamese
Longjing China Chinese
Longkou China Chinese
Longueuil Canada English
Longyan China Chinese
Los Angeles Chile Spanish
Los Angeles United States English
Los Cabos Mexico Spanish
Los Teques Venezuela Spanish
Loudi China Chinese
Louisville United States English
Lowell United States English
Lower Hutt New Zealand English
Lubbock United States English
Lublin Poland Polish
Luchou Taiwan Min
Ludwigshafen am Rhein Germany German
Lugansk Ukraine Ukrainian
Lund Sweden Swedish
Lungtan Taiwan Min
Luohe China Chinese
Luoyang China Chinese
Luton United Kingdom English
Lutsk Ukraine Ukrainian
Luxor Egypt Arabic
Luzhou China Chinese
Luziânia Brazil Portuguese
Lviv Ukraine Ukrainian
Lyon France French
Lysyt?ansk Ukraine Ukrainian
L´Hospitalet de Llobregat Spain Spanish
Lázaro Cárdenas Mexico Spanish
Lódz Poland Polish
Lübeck Germany German
Lünen Germany German
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
1 SIMPLE City ref Population,Country Country 3 world.Country.Code 18 Using where
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
Name
?iauliai
Beirut
Bengasi
Daugavpils
Kaunas
Klaipeda
Maseru
Misrata
Monrovia
Panevezys
Riga
Tripoli
Tripoli
Vientiane
Vilnius
EXPLAIN
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
WHERE
Country.Population > 10000000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where
1 SIMPLE CountryLanguage eq_ref PRIMARY PRIMARY 33 world.Country.Code,const 1 Using where
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
WHERE
Country.Population > 10000000;
Name IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
Afghanistan NULL
Algeria NULL
Angola NULL
Argentina NULL
Australia 81.2
Bangladesh NULL
Belarus NULL
Belgium NULL
Brazil NULL
Burkina Faso NULL
Cambodia NULL
Cameroon NULL
Canada 60.4
Chile NULL
China NULL
Colombia NULL
Congo, The Democratic Republic of the NULL
Cuba NULL
Czech Republic NULL
Côte d?Ivoire NULL
Ecuador NULL
Egypt NULL
Ethiopia NULL
France NULL
Germany NULL
Ghana NULL
Greece NULL
Guatemala NULL
Hungary NULL
India NULL
Indonesia NULL
Iran NULL
Iraq NULL
Italy NULL
Japan 0.1
Kazakstan NULL
Kenya NULL
Madagascar NULL
Malawi NULL
Malaysia 1.6
Mali NULL
Mexico NULL
Morocco NULL
Mozambique NULL
Myanmar NULL
Nepal NULL
Netherlands NULL
Niger NULL
Nigeria NULL
North Korea NULL
Pakistan NULL
Peru NULL
Philippines NULL
Poland NULL
Romania NULL
Russian Federation NULL
Saudi Arabia NULL
Somalia NULL
South Africa 8.5
South Korea NULL
Spain NULL
Sri Lanka NULL
Sudan NULL
Syria NULL
Taiwan NULL
Tanzania NULL
Thailand NULL
Turkey NULL
Uganda NULL
Ukraine NULL
United Kingdom 97.3
United States 86.2
Uzbekistan NULL
Venezuela NULL
Vietnam NULL
Yemen NULL
Yugoslavia NULL
Zimbabwe 2.2
set join_buffer_size=256;
show variables like 'join_buffer_size';
Variable_name Value
join_buffer_size 256
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
1 SIMPLE City ref Population,Country Country 3 world.Country.Code 18 Using where
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
Name Name
?iauliai Lithuania
Beirut Lebanon
Bengasi Libyan Arab Jamahiriya
Daugavpils Latvia
Kaunas Lithuania
Klaipeda Lithuania
Maseru Lesotho
Misrata Libyan Arab Jamahiriya
Monrovia Liberia
Panevezys Lithuania
Riga Latvia
Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE CountryLanguage range PRIMARY,Percentage Percentage 4 NULL # Using index condition; Using MRR
1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.CountryLanguage.Country 1 Using where
1 SIMPLE City ref Country Country 3 world.CountryLanguage.Country 18 Using where
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
Name Name Language
La Ceiba Honduras Spanish
La Habana Cuba Spanish
La Matanza Argentina Spanish
La Paz Bolivia Spanish
La Paz Mexico Spanish
La Paz Mexico Spanish
La Plata Argentina Spanish
La Rioja Argentina Spanish
La Romana Dominican Republic Spanish
La Serena Chile Spanish
La Spezia Italy Italian
Lafayette United States English
Lages Brazil Portuguese
Lagos de Moreno Mexico Spanish
Lahti Finland Finnish
Laiwu China Chinese
Laiyang China Chinese
Laizhou China Chinese
Lakewood United States English
Lalitapur Nepal Nepali
Lambaré Paraguay Spanish
Lancaster United States English
Langfang China Chinese
Lansing United States English
Lanzhou China Chinese
Lanús Argentina Spanish
Laohekou China Chinese
Laredo United States English
Larisa Greece Greek
Las Heras Argentina Spanish
Las Margaritas Mexico Spanish
Las Palmas de Gran Canaria Spain Spanish
Las Vegas United States English
Lashio (Lasho) Myanmar Burmese
Latakia Syria Arabic
Latina Italy Italian
Lauro de Freitas Brazil Portuguese
Lausanne Switzerland German
Laval Canada English
Le Havre France French
Le Mans France French
Le-Cap-Haïtien Haiti Haiti Creole
Lecce Italy Italian
Leeds United Kingdom English
Leganés Spain Spanish
Legnica Poland Polish
Leicester United Kingdom English
Leiden Netherlands Dutch
Leipzig Germany German
Leiyang China Chinese
Lengshuijiang China Chinese
Leninsk-Kuznetski Russian Federation Russian
Lerdo Mexico Spanish
Lerma Mexico Spanish
Leshan China Chinese
Leverkusen Germany German
Lexington-Fayette United States English
León Mexico Spanish
León Nicaragua Spanish
León Spain Spanish
Lhasa China Chinese
Liangcheng China Chinese
Lianyuan China Chinese
Lianyungang China Chinese
Liaocheng China Chinese
Liaoyang China Chinese
Liaoyuan China Chinese
Liberec Czech Republic Czech
Lida Belarus Belorussian
Liling China Chinese
Lille France French
Lilongwe Malawi Chichewa
Lima Peru Spanish
Limeira Brazil Portuguese
Limoges France French
Linchuan China Chinese
Lincoln United States English
Linfen China Chinese
Linhai China Chinese
Linhares Brazil Portuguese
Linhe China Chinese
Linköping Sweden Swedish
Linqing China Chinese
Linyi China Chinese
Linz Austria German
Lipetsk Russian Federation Russian
Lisboa Portugal Portuguese
Little Rock United States English
Liupanshui China Chinese
Liuzhou China Chinese
Liu´an China Chinese
Liverpool United Kingdom English
Livonia United States English
Livorno Italy Italian
Liyang China Chinese
Liège Belgium Dutch
Ljubertsy Russian Federation Russian
Lleida (Lérida) Spain Spanish
Logroño Spain Spanish
Loja Ecuador Spanish
Lomas de Zamora Argentina Spanish
London Canada English
London United Kingdom English
Londrina Brazil Portuguese
Long Beach United States English
Long Xuyen Vietnam Vietnamese
Longjing China Chinese
Longkou China Chinese
Longueuil Canada English
Longyan China Chinese
Los Angeles Chile Spanish
Los Angeles United States English
Los Cabos Mexico Spanish
Los Teques Venezuela Spanish
Loudi China Chinese
Louisville United States English
Lowell United States English
Lower Hutt New Zealand English
Lubbock United States English
Lublin Poland Polish
Luchou Taiwan Min
Ludwigshafen am Rhein Germany German
Lugansk Ukraine Ukrainian
Lund Sweden Swedish
Lungtan Taiwan Min
Luohe China Chinese
Luoyang China Chinese
Luton United Kingdom English
Lutsk Ukraine Ukrainian
Luxor Egypt Arabic
Luzhou China Chinese
Luziânia Brazil Portuguese
Lviv Ukraine Ukrainian
Lyon France French
Lysyt?ansk Ukraine Ukrainian
L´Hospitalet de Llobregat Spain Spanish
Lázaro Cárdenas Mexico Spanish
Lódz Poland Polish
Lübeck Germany German
Lünen Germany German
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
1 SIMPLE City ref Population,Country Country 3 world.Country.Code 18 Using where
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
Name
?iauliai
Beirut
Bengasi
Daugavpils
Kaunas
Klaipeda
Maseru
Misrata
Monrovia
Panevezys
Riga
Tripoli
Tripoli
Vientiane
Vilnius
set join_buffer_size=default;
show variables like 'join_buffer_size';
Variable_name Value
join_buffer_size 262144
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND City.Population > 3000000;
Name Name
Alexandria Egypt
Ankara Turkey
Baghdad Iraq
Bangkok Thailand
Berlin Germany
Cairo Egypt
Calcutta [Kolkata] India
Chengdu China
Chennai (Madras) India
Chongqing China
Ciudad de México Mexico
Delhi India
Dhaka Bangladesh
Harbin China
Ho Chi Minh City Vietnam
Istanbul Turkey
Jakarta Indonesia
Jokohama [Yokohama] Japan
Kanton [Guangzhou] China
Karachi Pakistan
Kinshasa Congo, The Democratic Republic of the
Lahore Pakistan
Lima Peru
London United Kingdom
Los Angeles United States
Moscow Russian Federation
Mumbai (Bombay) India
New York United States
Peking China
Pusan South Korea
Rangoon (Yangon) Myanmar
Rio de Janeiro Brazil
Riyadh Saudi Arabia
Santafé de Bogotá Colombia
Santiago de Chile Chile
Seoul South Korea
Shanghai China
Shenyang China
Singapore Singapore
St Petersburg Russian Federation
Sydney Australia
São Paulo Brazil
Teheran Iran
Tianjin China
Tokyo Japan
Wuhan China
set join_buffer_size=256;
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND City.Population > 3000000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City range Population,Country Population 4 NULL # Using index condition; Using MRR
1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country # NULL
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND City.Population > 3000000;
Name Name
Alexandria Egypt
Ankara Turkey
Baghdad Iraq
Bangkok Thailand
Berlin Germany
Cairo Egypt
Calcutta [Kolkata] India
Chengdu China
Chennai (Madras) India
Chongqing China
Ciudad de México Mexico
Delhi India
Dhaka Bangladesh
Harbin China
Ho Chi Minh City Vietnam
Istanbul Turkey
Jakarta Indonesia
Jokohama [Yokohama] Japan
Kanton [Guangzhou] China
Karachi Pakistan
Kinshasa Congo, The Democratic Republic of the
Lahore Pakistan
Lima Peru
London United Kingdom
Los Angeles United States
Moscow Russian Federation
Mumbai (Bombay) India
New York United States
Peking China
Pusan South Korea
Rangoon (Yangon) Myanmar
Rio de Janeiro Brazil
Riyadh Saudi Arabia
Santafé de Bogotá Colombia
Santiago de Chile Chile
Seoul South Korea
Shanghai China
Shenyang China
Singapore Singapore
St Petersburg Russian Federation
Sydney Australia
São Paulo Brazil
Teheran Iran
Tianjin China
Tokyo Japan
Wuhan China
set join_buffer_size=default;
ALTER TABLE Country MODIFY Name varchar(52) NOT NULL default '';
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
Name Name
?iauliai Lithuania
Beirut Lebanon
Bengasi Libyan Arab Jamahiriya
Daugavpils Latvia
Kaunas Lithuania
Klaipeda Lithuania
Maseru Lesotho
Misrata Libyan Arab Jamahiriya
Monrovia Liberia
Panevezys Lithuania
Riga Latvia
Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
ALTER TABLE Country MODIFY Name varchar(300) NOT NULL default '';
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
Name Name
?iauliai Lithuania
Beirut Lebanon
Bengasi Libyan Arab Jamahiriya
Daugavpils Latvia
Kaunas Lithuania
Klaipeda Lithuania
Maseru Lesotho
Misrata Libyan Arab Jamahiriya
Monrovia Liberia
Panevezys Lithuania
Riga Latvia
Tripoli Lebanon
Tripoli Libyan Arab Jamahiriya
Vientiane Laos
Vilnius Lithuania
ALTER TABLE Country ADD COLUMN PopulationBar text;
UPDATE Country
SET PopulationBar=REPEAT('x', CAST(Population/100000 AS unsigned int));
SELECT City.Name, Country.Name, Country.PopulationBar FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
Name Name PopulationBar
?iauliai Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Beirut Lebanon xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Bengasi Libyan Arab Jamahiriya xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Daugavpils Latvia xxxxxxxxxxxxxxxxxxxxxxxx
Kaunas Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Klaipeda Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Maseru Lesotho xxxxxxxxxxxxxxxxxxxxxx
Misrata Libyan Arab Jamahiriya xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Monrovia Liberia xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Panevezys Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Riga Latvia xxxxxxxxxxxxxxxxxxxxxxxx
Tripoli Lebanon xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Tripoli Libyan Arab Jamahiriya xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Vientiane Laos xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Vilnius Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
set join_buffer_size=256;
SELECT City.Name, Country.Name, Country.PopulationBar FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
Name Name PopulationBar
?iauliai Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Beirut Lebanon xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Bengasi Libyan Arab Jamahiriya xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Daugavpils Latvia xxxxxxxxxxxxxxxxxxxxxxxx
Kaunas Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Klaipeda Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Maseru Lesotho xxxxxxxxxxxxxxxxxxxxxx
Misrata Libyan Arab Jamahiriya xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Monrovia Liberia xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Panevezys Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Riga Latvia xxxxxxxxxxxxxxxxxxxxxxxx
Tripoli Lebanon xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Tripoli Libyan Arab Jamahiriya xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Vientiane Laos xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Vilnius Lithuania xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
set join_buffer_size=default;
DROP DATABASE world;
use test;
CREATE TABLE t1(
affiliatetometaid int NOT NULL default '0',
uniquekey int NOT NULL default '0',
metaid int NOT NULL default '0',
affiliateid int NOT NULL default '0',
xml text,
isactive char(1) NOT NULL default 'Y',
PRIMARY KEY (affiliatetometaid)
);
CREATE UNIQUE INDEX t1_uniquekey ON t1(uniquekey);
CREATE INDEX t1_affiliateid ON t1(affiliateid);
CREATE INDEX t1_metaid on t1 (metaid);
INSERT INTO t1 VALUES
(1616, 1571693233, 1391, 2, NULL, 'Y'), (1943, 1993216749, 1726, 2, NULL, 'Y');
CREATE TABLE t2(
metaid int NOT NULL default '0',
name varchar(80) NOT NULL default '',
dateadded timestamp NOT NULL ,
xml text,
status int default NULL,
origin int default NULL,
gid int NOT NULL default '1',
formattypeid int default NULL,
PRIMARY KEY (metaid)
);
CREATE INDEX t2_status ON t2(status);
CREATE INDEX t2_gid ON t2(gid);
CREATE INDEX t2_formattypeid ON t2(formattypeid);
INSERT INTO t2 VALUES
(1391, "I Just Died", "2003-10-02 10:07:37", "", 1, NULL, 3, NULL),
(1726, "Me, Myself & I", "2003-12-05 11:24:36", " ", 1, NULL, 3, NULL);
CREATE TABLE t3(
mediaid int NOT NULL ,
metaid int NOT NULL default '0',
formatid int NOT NULL default '0',
status int default NULL,
path varchar(100) NOT NULL default '',
datemodified timestamp NOT NULL ,
resourcetype int NOT NULL default '1',
parameters text,
signature int default NULL,
quality int NOT NULL default '255',
PRIMARY KEY (mediaid)
);
CREATE INDEX t3_metaid ON t3(metaid);
CREATE INDEX t3_formatid ON t3(formatid);
CREATE INDEX t3_status ON t3(status);
CREATE INDEX t3_metaidformatid ON t3(metaid,formatid);
CREATE INDEX t3_signature ON t3(signature);
CREATE INDEX t3_quality ON t3(quality);
INSERT INTO t3 VALUES
(6, 4, 8, 0, "010101_anastacia_spmidi.mid", "2004-03-16 13:40:00", 1, NULL, NULL, 255),
(3343, 3, 8, 1, "010102_4VN4bsPwnxRQUJW5Zp1RhG2IL9vvl_8.mid", "2004-03-16 13:40:00", 1, NULL, NULL, 255);
CREATE TABLE t4(
formatid int NOT NULL ,
name varchar(60) NOT NULL default '',
formatclassid int NOT NULL default '0',
mime varchar(60) default NULL,
extension varchar(10) default NULL,
priority int NOT NULL default '0',
canaddtocapability char(1) NOT NULL default 'Y',
PRIMARY KEY (formatid)
);
CREATE INDEX t4_formatclassid ON t4(formatclassid);
CREATE INDEX t4_formats_idx ON t4(canaddtocapability);
INSERT INTO t4 VALUES
(19, "XHTML", 11, "text/html", "xhtml", 10, 'Y'),
(54, "AMR (wide band)", 13, "audio/amr-wb", "awb", 0, 'Y');
CREATE TABLE t5(
formatclassid int NOT NULL ,
name varchar(60) NOT NULL default '',
priority int NOT NULL default '0',
formattypeid int NOT NULL default '0',
PRIMARY KEY (formatclassid)
);
CREATE INDEX t5_formattypeid on t5(formattypeid);
INSERT INTO t5 VALUES
(11, "Info", 0, 4), (13, "Digital Audio", 0, 2);
CREATE TABLE t6(
formattypeid int NOT NULL ,
name varchar(60) NOT NULL default '',
priority int default NULL,
PRIMARY KEY (formattypeid)
);
INSERT INTO t6 VALUES
(2, "Ringtones", 0);
CREATE TABLE t7(
metaid int NOT NULL default '0',
artistid int NOT NULL default '0',
PRIMARY KEY (metaid,artistid)
);
INSERT INTO t7 VALUES
(4, 5), (3, 4);
CREATE TABLE t8(
artistid int NOT NULL ,
name varchar(80) NOT NULL default '',
PRIMARY KEY (artistid)
);
INSERT INTO t8 VALUES
(5, "Anastacia"), (4, "John Mayer");
CREATE TABLE t9(
subgenreid int NOT NULL default '0',
metaid int NOT NULL default '0',
PRIMARY KEY (subgenreid,metaid)
) ;
CREATE INDEX t9_subgenreid ON t9(subgenreid);
CREATE INDEX t9_metaid ON t9(metaid);
INSERT INTO t9 VALUES
(138, 4), (31, 3);
CREATE TABLE t10(
subgenreid int NOT NULL ,
genreid int NOT NULL default '0',
name varchar(80) NOT NULL default '',
PRIMARY KEY (subgenreid)
) ;
CREATE INDEX t10_genreid ON t10(genreid);
INSERT INTO t10 VALUES
(138, 19, ''), (31, 3, '');
CREATE TABLE t11(
genreid int NOT NULL default '0',
name char(80) NOT NULL default '',
priority int NOT NULL default '0',
masterclip char(1) default NULL,
PRIMARY KEY (genreid)
) ;
CREATE INDEX t11_masterclip ON t11( masterclip);
INSERT INTO t11 VALUES
(19, "Pop & Dance", 95, 'Y'), (3, "Rock & Alternative", 100, 'Y');
EXPLAIN
SELECT t1.uniquekey, t1.xml AS affiliateXml,
t8.name AS artistName, t8.artistid,
t11.name AS genreName, t11.genreid, t11.priority AS genrePriority,
t10.subgenreid, t10.name AS subgenreName,
t2.name AS metaName, t2.metaid, t2.xml AS metaXml,
t4.priority + t5.priority + t6.priority AS overallPriority,
t3.path AS path, t3.mediaid,
t4.formatid, t4.name AS formatName,
t5.formatclassid, t5.name AS formatclassName,
t6.formattypeid, t6.name AS formattypeName
FROM t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11
WHERE t7.metaid = t2.metaid AND t7.artistid = t8.artistid AND
t9.metaid = t2.metaid AND t9.subgenreid = t10.subgenreid AND
t10.genreid = t11.genreid AND t3.metaid = t2.metaid AND
t3.formatid = t4.formatid AND t4.formatclassid = t5.formatclassid AND
t4.canaddtocapability = 'Y' AND t5.formattypeid = t6.formattypeid AND
t6.formattypeid IN (2) AND (t3.formatid IN (31, 8, 76)) AND
t1.metaid = t2.metaid AND t1.affiliateid = '2';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 system PRIMARY NULL NULL NULL 1 NULL
1 SIMPLE t1 ref t1_affiliateid,t1_metaid t1_affiliateid 4 const 1 NULL
1 SIMPLE t4 ref PRIMARY,t4_formatclassid,t4_formats_idx t4_formats_idx 1 const 1 Using index condition; Using where
1 SIMPLE t5 eq_ref PRIMARY,t5_formattypeid PRIMARY 4 test.t4.formatclassid 1 Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.metaid 1 NULL
1 SIMPLE t7 ref PRIMARY PRIMARY 4 test.t1.metaid 1 Using index
1 SIMPLE t8 eq_ref PRIMARY PRIMARY 4 test.t7.artistid 1 NULL
1 SIMPLE t9 ref PRIMARY,t9_subgenreid,t9_metaid t9_metaid 4 test.t1.metaid 2 NULL
1 SIMPLE t10 eq_ref PRIMARY,t10_genreid PRIMARY 4 test.t9.subgenreid 1 NULL
1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t10.genreid 1 NULL
1 SIMPLE t3 ref t3_metaid,t3_formatid,t3_metaidformatid t3_metaid 4 test.t1.metaid 2 Using where
SELECT t1.uniquekey, t1.xml AS affiliateXml,
t8.name AS artistName, t8.artistid,
t11.name AS genreName, t11.genreid, t11.priority AS genrePriority,
t10.subgenreid, t10.name AS subgenreName,
t2.name AS metaName, t2.metaid, t2.xml AS metaXml,
t4.priority + t5.priority + t6.priority AS overallPriority,
t3.path AS path, t3.mediaid,
t4.formatid, t4.name AS formatName,
t5.formatclassid, t5.name AS formatclassName,
t6.formattypeid, t6.name AS formattypeName
FROM t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11
WHERE t7.metaid = t2.metaid AND t7.artistid = t8.artistid AND
t9.metaid = t2.metaid AND t9.subgenreid = t10.subgenreid AND
t10.genreid = t11.genreid AND t3.metaid = t2.metaid AND
t3.formatid = t4.formatid AND t4.formatclassid = t5.formatclassid AND
t4.canaddtocapability = 'Y' AND t5.formattypeid = t6.formattypeid AND
t6.formattypeid IN (2) AND (t3.formatid IN (31, 8, 76)) AND
t1.metaid = t2.metaid AND t1.affiliateid = '2';
uniquekey affiliateXml artistName artistid genreName genreid genrePriority subgenreid subgenreName metaName metaid metaXml overallPriority path mediaid formatid formatName formatclassid formatclassName formattypeid formattypeName
DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
CREATE TABLE t1 (a1 int, filler1 char(64) default ' ' );
CREATE TABLE t2 (
a2 int, b2 int, filler2 char(64) default ' ',
PRIMARY KEY idx(a2,b2,filler2)
) ;
CREATE TABLE t3 (b3 int, c3 int, INDEX idx(b3));
INSERT INTO t1(a1) VALUES
(4), (7), (1), (9), (8), (5), (3), (6), (2);
INSERT INTO t2(a2,b2) VALUES
(1,30), (3,40), (2,61), (6,73), (8,92), (9,27), (4,18), (5,84), (7,56),
(4,14), (6,76), (8,98), (7,55), (1,39), (2,68), (3,45), (9,21), (5,81),
(5,88), (2,65), (6,74), (9,23), (1,37), (3,44), (4,17), (8,99), (7,51),
(9,28), (7,52), (1,33), (4,13), (5,87), (3,43), (8,91), (2,62), (6,79),
(3,49), (8,93), (7,34), (5,82), (6,78), (2,63), (1,32), (9,22), (4,11);
INSERT INTO t3 VALUES
(30,302), (92,923), (18,187), (45,459), (30,309),
(39,393), (68,685), (45,458), (21,210), (81,817),
(40,405), (61,618), (73,738), (92,929), (27,275),
(18,188), (84,846), (56,564), (14,144), (76,763),
(98,982), (55,551), (17,174), (99,998), (51,513),
(28,282), (52,527), (33,336), (13,138), (87,878),
(43,431), (91,916), (62,624), (79,797), (49,494),
(93,933), (34,347), (82,829), (78,780), (63,634),
(32,329), (22,228), (11,114), (74,749), (23,236);
EXPLAIN
SELECT a1<>a2, a1, a2, b2, b3, c3,
SUBSTR(filler1,1,1) AS s1, SUBSTR(filler2,1,1) AS s2
FROM t1,t2,t3 WHERE a1=a2 AND b2=b3 AND MOD(c3,10)>7;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 Using where
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 Using index
1 SIMPLE t3 ref idx idx 5 test.t2.b2 5 Using where
SELECT a1<>a2, a1, a2, b2, b3, c3,
SUBSTR(filler1,1,1) AS s1, SUBSTR(filler2,1,1) AS s2
FROM t1,t2,t3 WHERE a1=a2 AND b2=b3 AND MOD(c3,10)>7;
a1<>a2 a1 a2 b2 b3 c3 s1 s2
0 1 1 30 30 309
0 1 1 32 32 329
0 2 2 61 61 618
0 3 3 45 45 458
0 3 3 45 45 459
0 4 4 13 13 138
0 4 4 18 18 188
0 5 5 82 82 829
0 5 5 87 87 878
0 6 6 73 73 738
0 6 6 74 74 749
0 8 8 92 92 929
0 8 8 99 99 998
0 9 9 22 22 228
set join_buffer_size=512;
EXPLAIN
SELECT a1<>a2, a1, a2, b2, b3, c3,
SUBSTR(filler1,1,1) AS s1, SUBSTR(filler2,1,1) AS s2
FROM t1,t2,t3 WHERE a1=a2 AND b2=b3 AND MOD(c3,10)>7;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 Using where
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 Using index
1 SIMPLE t3 ref idx idx 5 test.t2.b2 5 Using where
SELECT a1<>a2, a1, a2, b2, b3, c3,
SUBSTR(filler1,1,1) AS s1, SUBSTR(filler2,1,1) AS s2
FROM t1,t2,t3 WHERE a1=a2 AND b2=b3 AND MOD(c3,10)>7;
a1<>a2 a1 a2 b2 b3 c3 s1 s2
0 1 1 30 30 309
0 1 1 32 32 329
0 2 2 61 61 618
0 3 3 45 45 458
0 3 3 45 45 459
0 4 4 13 13 138
0 4 4 18 18 188
0 5 5 82 82 829
0 5 5 87 87 878
0 6 6 73 73 738
0 6 6 74 74 749
0 8 8 92 92 929
0 8 8 99 99 998
0 9 9 22 22 228
DROP TABLE t1,t2,t3;
CREATE TABLE t1 (a int, b int, INDEX idx(b));
CREATE TABLE t2 (a int, b int, INDEX idx(a));
INSERT INTO t1 VALUES (5,30), (3,20), (7,40), (2,10), (8,30), (1,10), (4,20);
INSERT INTO t2 VALUES (7,10), (1,20), (2,20), (8,20), (8,10), (1,20);
INSERT INTO t2 VALUES (1,10), (4,20), (3,20), (7,20), (7,10), (1,20);
set join_buffer_size=32;
Warnings:
Warning 1292 Truncated incorrect join_buffer_size value: '32'
EXPLAIN SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range idx idx 5 NULL 4 Using index condition; Using where; Using MRR
1 SIMPLE t2 ref idx idx 5 test.t1.a 2 NULL
SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30;
a b a b
7 40 7 10
7 40 7 10
7 40 7 20
8 30 8 10
8 30 8 20
DROP TABLE t1,t2;
BUG#40136: Group by is ignored when join buffer is used for an outer join
create table t1(a int PRIMARY KEY, b int);
insert into t1 values
(5, 10), (2, 70), (7, 80), (6, 20), (1, 50), (9, 40), (8, 30), (3, 60);
create table t2 (p int, a int, INDEX i_a(a));
insert into t2 values
(103, 7), (109, 3), (102, 3), (108, 1), (106, 3),
(107, 7), (105, 1), (101, 3), (100, 7), (110, 1);
explain
select t1.a, count(t2.p) as count
from t1 left join t2 on t1.a=t2.a and t2.p % 2 = 1 group by t1.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 8 Using index
1 SIMPLE t2 ref i_a i_a 5 test.t1.a 2 Using where
select t1.a, count(t2.p) as count
from t1 left join t2 on t1.a=t2.a and t2.p % 2 = 1 group by t1.a;
a count
1 1
2 0
3 2
5 0
6 0
7 2
8 0
9 0
drop table t1, t2;
#
# Bug #40134: outer join with not exists optimization and join buffer
#
set join_buffer_size=default;
CREATE TABLE t1 (a int NOT NULL);
INSERT INTO t1 VALUES (2), (4), (3), (5), (1);
CREATE TABLE t2 (a int NOT NULL, b int NOT NULL, INDEX i_a(a));
INSERT INTO t2 VALUES (4,10), (2,10), (2,30), (2,20), (4,20);
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE t2.b IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 NULL
1 SIMPLE t2 ref i_a i_a 4 test.t1.a 2 Using where; Not exists
SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE t2.b IS NULL;
a a b
3 NULL NULL
5 NULL NULL
1 NULL NULL
DROP TABLE t1, t2;
#
# BUG#40268: Nested outer join with not null-rejecting where condition
# over an inner table which is not the last in the nest
#
CREATE TABLE t2 (a int, b int, c int);
CREATE TABLE t3 (a int, b int, c int);
CREATE TABLE t4 (a int, b int, c int);
INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
INSERT INTO t3 VALUES (1,2,0), (2,2,0);
INSERT INTO t4 VALUES (3,2,0), (4,2,0);
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM t2 LEFT JOIN (t3, t4) ON t2.b=t4.b
WHERE t3.a+2<t2.a OR t3.c IS NULL;
a b a b a b
3 3 NULL NULL NULL NULL
4 2 1 2 3 2
4 2 1 2 4 2
5 3 NULL NULL NULL NULL
DROP TABLE t2, t3, t4;
#
# Bug #40192: outer join with where clause when using BNL
#
create table t1 (a int, b int);
insert into t1 values (2, 20), (3, 30), (1, 10);
create table t2 (a int, c int);
insert into t2 values (1, 101), (3, 102), (1, 100);
select * from t1 left join t2 on t1.a=t2.a;
a b a c
1 10 1 100
1 10 1 101
2 20 NULL NULL
3 30 3 102
explain select * from t1 left join t2 on t1.a=t2.a where t2.c=102 or t2.c is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 NULL
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where
select * from t1 left join t2 on t1.a=t2.a where t2.c=102 or t2.c is null;
a b a c
2 20 NULL NULL
3 30 3 102
drop table t1, t2;
#
# Bug #40317: outer join with with constant on expression equal to FALSE
#
create table t1 (a int);
insert into t1 values (30), (40), (20);
create table t2 (b int);
insert into t2 values (200), (100);
select * from t1 left join t2 on (1=0);
a b
30 NULL
40 NULL
20 NULL
explain select * from t1 left join t2 on (1=0) where a=40;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where
select * from t1 left join t2 on (1=0) where a=40;
a b
40 NULL
drop table t1, t2;
#
# Bug #41204: small buffer with big rec_per_key for ref access
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (0);
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1 VALUES (20000), (10000);
CREATE TABLE t2 (pk int AUTO_INCREMENT PRIMARY KEY, b int, c int, INDEX idx(b));
INSERT INTO t2(b,c) VALUES (10000, 3), (20000, 7), (20000, 1), (10000, 9), (20000, 5);
INSERT INTO t2(b,c) SELECT b,c FROM t2;
INSERT INTO t2(b,c) SELECT b,c FROM t2;
INSERT INTO t2(b,c) SELECT b,c FROM t2;
INSERT INTO t2(b,c) SELECT b,c FROM t2;
INSERT INTO t2(b,c) SELECT b,c FROM t2;
INSERT INTO t2(b,c) SELECT b,c FROM t2;
INSERT INTO t2(b,c) SELECT b,c FROM t2;
INSERT INTO t2(b,c) SELECT b,c FROM t2;
ANALYZE TABLE t1,t2;
set join_buffer_size=1024;
EXPLAIN SELECT AVG(c) FROM t1,t2 WHERE t1.a=t2.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2050 Using where
1 SIMPLE t2 ref idx idx 5 test.t1.a 640 NULL
SELECT AVG(c) FROM t1,t2 WHERE t1.a=t2.b;
AVG(c)
5.0000
set join_buffer_size=default;
DROP TABLE t1, t2;
#
# Bug #41894: big join buffer of level 7 used to join records
# with null values in place of varchar strings
#
CREATE TABLE t1 (a int NOT NULL AUTO_INCREMENT PRIMARY KEY,
b varchar(127) DEFAULT NULL);
INSERT INTO t1(a) VALUES (1);
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
INSERT INTO t1(b) SELECT b FROM t1;
CREATE TABLE t2 (a int NOT NULL PRIMARY KEY, b varchar(127) DEFAULT NULL);
INSERT INTO t2 SELECT * FROM t1;
CREATE TABLE t3 (a int NOT NULL PRIMARY KEY, b varchar(127) DEFAULT NULL);
INSERT INTO t3 SELECT * FROM t1;
set join_buffer_size=1024*1024;
EXPLAIN
SELECT COUNT(*) FROM t1,t2,t3
WHERE t1.a=t2.a AND t2.a=t3.a AND
t1.b IS NULL AND t2.b IS NULL AND t3.b IS NULL;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 16384 Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where
SELECT COUNT(*) FROM t1,t2,t3
WHERE t1.a=t2.a AND t2.a=t3.a AND
t1.b IS NULL AND t2.b IS NULL AND t3.b IS NULL;
COUNT(*)
16384
set join_buffer_size=default;
DROP TABLE t1,t2,t3;
#
# Bug #42020: join buffer is used for outer join with fields of
# several outer tables in join buffer
#
CREATE TABLE t1 (
a bigint NOT NULL,
PRIMARY KEY (a)
);
INSERT INTO t1 VALUES
(2), (1);
CREATE TABLE t2 (
a bigint NOT NULL,
b bigint NOT NULL,
PRIMARY KEY (a,b)
);
INSERT INTO t2 VALUES
(2,30), (2,40), (2,50), (2,60), (2,70), (2,80),
(1,10), (1, 20), (1,30), (1,40), (1,50);
CREATE TABLE t3 (
pk bigint NOT NULL AUTO_INCREMENT,
a bigint NOT NULL,
b bigint NOT NULL,
val bigint DEFAULT '0',
PRIMARY KEY (pk),
KEY idx (a,b)
);
INSERT INTO t3(a,b) VALUES
(2,30), (2,40), (2,50), (2,60), (2,70), (2,80),
(4,30), (4,40), (4,50), (4,60), (4,70), (4,80),
(5,30), (5,40), (5,50), (5,60), (5,70), (5,80),
(7,30), (7,40), (7,50), (7,60), (7,70), (7,80);
SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
WHERE t1.a=t2.a;
a a a b b val
1 1 NULL 10 NULL NULL
1 1 NULL 20 NULL NULL
1 1 NULL 30 NULL NULL
1 1 NULL 40 NULL NULL
1 1 NULL 50 NULL NULL
2 2 2 30 30 0
2 2 2 40 40 0
2 2 2 50 50 0
2 2 2 60 60 0
2 2 2 70 70 0
2 2 2 80 80 0
set join_buffer_size=256;
EXPLAIN
SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
WHERE t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 8 NULL 2 Using index
1 SIMPLE t2 ref PRIMARY PRIMARY 8 test.t1.a 1 Using index
1 SIMPLE t3 ref idx idx 16 test.t1.a,test.t2.b 2 NULL
SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
WHERE t1.a=t2.a;
a a a b b val
1 1 NULL 10 NULL NULL
1 1 NULL 20 NULL NULL
1 1 NULL 30 NULL NULL
1 1 NULL 40 NULL NULL
1 1 NULL 50 NULL NULL
2 2 2 30 30 0
2 2 2 40 40 0
2 2 2 50 50 0
2 2 2 60 60 0
2 2 2 70 70 0
2 2 2 80 80 0
DROP INDEX idx ON t3;
EXPLAIN
SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
WHERE t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 8 NULL 2 Using index
1 SIMPLE t2 ref PRIMARY PRIMARY 8 test.t1.a 1 Using index
1 SIMPLE t3 ALL NULL NULL NULL NULL 24 Using where
SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
WHERE t1.a=t2.a;
a a a b b val
1 1 NULL 10 NULL NULL
1 1 NULL 20 NULL NULL
1 1 NULL 30 NULL NULL
1 1 NULL 40 NULL NULL
1 1 NULL 50 NULL NULL
2 2 2 30 30 0
2 2 2 40 40 0
2 2 2 50 50 0
2 2 2 60 60 0
2 2 2 70 70 0
2 2 2 80 80 0
set join_buffer_size=default;
DROP TABLE t1,t2,t3;
create table t1(f1 int, f2 int);
insert into t1 values (1,1),(2,2),(3,3);
create table t2(f1 int not null, f2 int not null, f3 char(200), key(f1,f2));
insert into t2 values (1,1, 'qwerty'),(1,2, 'qwerty'),(1,3, 'qwerty');
insert into t2 values (2,1, 'qwerty'),(2,2, 'qwerty'),(2,3, 'qwerty'),
(2,4, 'qwerty'),(2,5, 'qwerty');
insert into t2 values (3,1, 'qwerty'),(3,4, 'qwerty');
insert into t2 values (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'),
(4,4, 'qwerty');
insert into t2 values (1,1, 'qwerty'),(1,2, 'qwerty'),(1,3, 'qwerty');
insert into t2 values (2,1, 'qwerty'),(2,2, 'qwerty'),(2,3, 'qwerty'),
(2,4, 'qwerty'),(2,5, 'qwerty');
insert into t2 values (3,1, 'qwerty'),(3,4, 'qwerty');
insert into t2 values (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'),
(4,4, 'qwerty');
select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
f1 f2 f3
1 1 qwerty
1 1 qwerty
2 2 qwerty
2 2 qwerty
explain select t2.f1, t2.f2, t2.f3 from t1,t2
where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition
drop table t1,t2;
#
# Bug #42955: join with GROUP BY/ORDER BY and when BKA is enabled
#
create table t1 (d int, id1 int, index idx1 (d, id1));
insert into t1 values
(3, 20), (2, 40), (3, 10), (1, 10), (3, 20), (1, 40), (2, 30), (3, 30);
create table t2 (id1 int, id2 int, index idx2 (id1));
insert into t2 values
(20, 100), (30, 400), (20, 400), (30, 200), (10, 300), (10, 200), (40, 100),
(40, 200), (30, 300), (10, 400), (20, 200), (20, 300);
explain
select t1.id1, sum(t2.id2) from t1 join t2 on t1.id1=t2.id1
where t1.d=3 group by t1.id1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref idx1 idx1 5 const 4 Using where; Using index
1 SIMPLE t2 ref idx2 idx2 5 test.t1.id1 2 NULL
select t1.id1, sum(t2.id2) from t1 join t2 on t1.id1=t2.id1
where t1.d=3 group by t1.id1;
id1 sum(t2.id2)
10 900
20 2000
30 900
explain
select t1.id1 from t1 join t2 on t1.id1=t2.id1
where t1.d=3 and t2.id2 > 200 order by t1.id1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref idx1 idx1 5 const 4 Using where; Using index
1 SIMPLE t2 ref idx2 idx2 5 test.t1.id1 2 Using where
select t1.id1 from t1 join t2 on t1.id1=t2.id1
where t1.d=3 and t2.id2 > 200 order by t1.id1;
id1
10
10
20
20
20
20
30
30
drop table t1,t2;
#
# Bug #44019: star-like multi-join query executed optimizer_join_cache_level=6
#
create table t1 (a int, b int, c int, d int);
create table t2 (b int, e varchar(16), index idx(b));
create table t3 (d int, f varchar(16), index idx(d));
create table t4 (c int, g varchar(16), index idx(c));
insert into t1 values
(5, 50, 500, 5000), (3, 30, 300, 3000), (9, 90, 900, 9000),
(2, 20, 200, 2000), (4, 40, 400, 4000), (8, 80, 800, 800),
(7, 70, 700, 7000);
insert into t2 values
(30, 'bbb'), (10, 'b'), (70, 'bbbbbbb'), (60, 'bbbbbb'),
(31, 'bbb'), (11, 'b'), (71, 'bbbbbbb'), (61, 'bbbbbb'),
(32, 'bbb'), (12, 'b'), (72, 'bbbbbbb'), (62, 'bbbbbb');
insert into t3 values
(4000, 'dddd'), (3000, 'ddd'), (1000, 'd'), (8000, 'dddddddd'),
(4001, 'dddd'), (3001, 'ddd'), (1001, 'd'), (8001, 'dddddddd'),
(4002, 'dddd'), (3002, 'ddd'), (1002, 'd'), (8002, 'dddddddd');
insert into t4 values
(200, 'cc'), (600, 'cccccc'), (300, 'ccc'), (500, 'ccccc'),
(201, 'cc'), (601, 'cccccc'), (301, 'ccc'), (501, 'ccccc'),
(202, 'cc'), (602, 'cccccc'), (302, 'ccc'), (502, 'ccccc');
analyze table t2,t3,t4;
explain
select t1.a, t1.b, t1.c, t1.d, t2.e, t3.f, t4.g from t1,t2,t3,t4
where t2.b=t1.b and t3.d=t1.d and t4.c=t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where
1 SIMPLE t2 ref idx idx 5 test.t1.b 1 NULL
1 SIMPLE t3 ref idx idx 5 test.t1.d 1 NULL
1 SIMPLE t4 ref idx idx 5 test.t1.c 1 NULL
select t1.a, t1.b, t1.c, t1.d, t2.e, t3.f, t4.g from t1,t2,t3,t4
where t2.b=t1.b and t3.d=t1.d and t4.c=t1.c;
a b c d e f g
3 30 300 3000 bbb ddd ccc
drop table t1,t2,t3,t4;
#
# Bug #44250: Corruption of linked join buffers when using BKA
#
CREATE TABLE t1 (
id1 bigint(20) DEFAULT NULL,
id2 bigint(20) DEFAULT NULL,
id3 bigint(20) DEFAULT NULL,
num1 bigint(20) DEFAULT NULL,
num2 int(11) DEFAULT NULL,
num3 bigint(20) DEFAULT NULL
);
CREATE TABLE t2 (
id3 bigint(20) NOT NULL DEFAULT '0',
id4 bigint(20) DEFAULT NULL,
enum1 enum('Enabled','Disabled','Paused') DEFAULT NULL,
PRIMARY KEY (id3)
);
CREATE TABLE t3 (
id4 bigint(20) NOT NULL DEFAULT '0',
text1 text,
PRIMARY KEY (id4)
);
CREATE TABLE t4 (
id2 bigint(20) NOT NULL DEFAULT '0',
dummy int(11) DEFAULT '0',
PRIMARY KEY (id2)
);
CREATE TABLE t5 (
id1 bigint(20) NOT NULL DEFAULT '0',
id2 bigint(20) NOT NULL DEFAULT '0',
enum2 enum('Active','Deleted','Paused') DEFAULT NULL,
PRIMARY KEY (id1,id2)
);
set join_buffer_size=2048;
EXPLAIN
SELECT STRAIGHT_JOIN t1.id1, t1.num3, t3.text1, t3.id4, t2.id3, t4.dummy
FROM t1 JOIN t2 JOIN t3 JOIN t4 JOIN t5
WHERE t1.id1=t5.id1 AND t1.id2=t5.id2 and t4.id2=t1.id2 AND
t5.enum2='Active' AND t3.id4=t2.id4 AND t2.id3=t1.id3 AND t3.text1<'D';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 349 Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 8 test.t1.id3 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.id4 1 Using where
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 8 test.t1.id2 1 NULL
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 16 test.t1.id1,test.t1.id2 1 Using where
SELECT STRAIGHT_JOIN t1.id1, t1.num3, t3.text1, t3.id4, t2.id3, t4.dummy
FROM t1 JOIN t2 JOIN t3 JOIN t4 JOIN t5
WHERE t1.id1=t5.id1 AND t1.id2=t5.id2 and t4.id2=t1.id2 AND
t5.enum2='Active' AND t3.id4=t2.id4 AND t2.id3=t1.id3 AND t3.text1<'D';
id1 num3 text1 id4 id3 dummy
228172702 134 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2567095402 2667134182 0
228172702 14 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2567095402 2667134182 0
228172702 15 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2567095402 2667134182 0
228172702 3 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2567095402 2667134182 0
228808822 1 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 1 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 1 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 10 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 13 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 13 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 14 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 17 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 18 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 19 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 26 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 28 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 3 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 3 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 3 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 3 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 4 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 4 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 4 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 50 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 6 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 60 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 61 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 826928662 935693782 0
228808822 62 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 84 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 89 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
228808822 9 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 2381969632 2482416112 0
set join_buffer_size=default;
DROP TABLE t1,t2,t3,t4,t5;
#
# Bug #46328: Use of aggregate function without GROUP BY clause
# returns many rows (vs. one )
#
CREATE TABLE t1 (
int_key int(11) NOT NULL,
KEY int_key (int_key)
);
INSERT INTO t1 VALUES
(0),(2),(2),(2),(3),(4),(5),(5),(6),(6),(8),(8),(9),(9);
CREATE TABLE t2 (
int_key int(11) NOT NULL,
KEY int_key (int_key)
);
INSERT INTO t2 VALUES (2),(3);
# The query shall return 1 record with a max value 9 and one of the
# int_key values inserted above (undefined which one). A changed
# execution plan may change the value in the second column
SELECT MAX(t1.int_key), t1.int_key
FROM t1 STRAIGHT_JOIN t2
ORDER BY t1.int_key;
MAX(t1.int_key) int_key
9 0
explain
SELECT MAX(t1.int_key), t1.int_key
FROM t1 STRAIGHT_JOIN t2
ORDER BY t1.int_key;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL int_key 4 NULL 14 Using index
1 SIMPLE t2 index NULL int_key 4 NULL 2 Using index
DROP TABLE t1,t2;
#
# Bug #45019: join buffer contains two blob columns one of which is
# used in the key employed to access the joined table
#
CREATE TABLE t1 (c1 int, c2 int, key (c2));
INSERT INTO t1 VALUES (1,1);
INSERT INTO t1 VALUES (2,2);
CREATE TABLE t2 (c1 text, c2 text);
INSERT INTO t2 VALUES('tt', 'uu');
INSERT INTO t2 VALUES('zzzz', 'xxxxxxxxx');
ANALYZE TABLE t1,t2;
SELECT t1.*, t2.*, LENGTH(t2.c1), LENGTH(t2.c2) FROM t1,t2
WHERE t1.c2=LENGTH(t2.c2) and t1.c1=LENGTH(t2.c1);
c1 c2 c1 c2 LENGTH(t2.c1) LENGTH(t2.c2)
2 2 tt uu 2 2
DROP TABLE t1,t2;
#
# Regression test for
# Bug#46733 - NULL value not returned for aggregate on empty result
# set w/ semijoin on
CREATE TABLE t1 (
i int(11) NOT NULL,
v varchar(1) DEFAULT NULL,
PRIMARY KEY (i)
);
INSERT INTO t1 VALUES (10,'a'),(11,'b'),(12,'c'),(13,'d');
CREATE TABLE t2 (
i int(11) NOT NULL,
v varchar(1) DEFAULT NULL,
PRIMARY KEY (i)
);
INSERT INTO t2 VALUES (1,'x'),(2,'y');
SELECT MAX(t1.i)
FROM t1 JOIN t2 ON t2.v
ORDER BY t2.v;
MAX(t1.i)
NULL
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'x'
Warning 1292 Truncated incorrect INTEGER value: 'y'
EXPLAIN
SELECT MAX(t1.i)
FROM t1 JOIN t2 ON t2.v
ORDER BY t2.v;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 Using index
DROP TABLE t1,t2;
#
# Bug#51092: Linked join buffer gives wrong result
# for 3-way cross join
#
CREATE TABLE t1 (a INT, b INT);
INSERT INTO t1 VALUES (1,1),(2,2);
CREATE TABLE t2 (a INT, b INT);
INSERT INTO t2 VALUES (1,1),(2,2);
CREATE TABLE t3 (a INT, b INT);
INSERT INTO t3 VALUES (1,1),(2,2);
EXPLAIN SELECT t1.* FROM t1,t2,t3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 NULL
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 NULL
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 NULL
SELECT t1.* FROM t1,t2,t3;
a b
1 1
1 1
1 1
1 1
2 2
2 2
2 2
2 2
DROP TABLE t1,t2,t3;
#
# BUG#52394 Segfault in JOIN_CACHE::get_offset () at sql_select.h:445
#
CREATE TABLE C(a int);
INSERT INTO C VALUES(1),(2),(3),(4),(5);
CREATE TABLE D (a int(11), b varchar(1));
INSERT INTO D VALUES (6,'r'),(27,'o');
CREATE TABLE E (a int(11) primary key, b varchar(1));
INSERT INTO E VALUES
(14,'d'),(15,'z'),(16,'e'),(17,'h'),(18,'b'),(19,'s'),(20,'e'),(21,'j'),(22,'e'),(23,'f'),(24,'v'),(25,'x'),(26,'m'),(27,'c');
SELECT 1 FROM C,D,E WHERE D.a = E.a AND D.b = E.b;
1
DROP TABLE C,D,E;
#
# BUG#52540 Crash in JOIN_CACHE::set_match_flag_if_none () at sql_join_cache.cc:1883
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (2);
CREATE TABLE t2 (a varchar(10));
INSERT INTO t2 VALUES ('f'),('x');
CREATE TABLE t3 (pk int(11) PRIMARY KEY);
INSERT INTO t3 VALUES (2);
CREATE TABLE t4 (a varchar(10));
EXPLAIN SELECT 1
FROM t2 LEFT JOIN
((t1 JOIN t3 ON t1.a = t3.pk)
LEFT JOIN t4 ON 1 )
ON 1 ;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 NULL
1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index
1 SIMPLE t4 ALL NULL NULL NULL NULL 0 Using where
SELECT 1
FROM t2 LEFT JOIN
((t1 JOIN t3 ON t1.a = t3.pk)
LEFT JOIN t4 ON 1 )
ON 1 ;
1
1
1
DROP TABLE t1,t2,t3,t4;
#
# Bug#51084: Batched key access crashes for SELECT with
# derived table and LEFT JOIN
#
CREATE TABLE t1 (
carrier int,
id int PRIMARY KEY
);
INSERT INTO t1 VALUES (1,11),(1,12),(2,13);
CREATE TABLE t2 (
scan_date int,
package_id int
);
INSERT INTO t2 VALUES (2008,21),(2008,22);
CREATE TABLE t3 (
carrier int PRIMARY KEY,
id int
);
INSERT INTO t3 VALUES (1,31);
CREATE TABLE t4 (
carrier_id int,
INDEX carrier_id(carrier_id)
);
INSERT INTO t4 VALUES (31),(32);
SELECT COUNT(*)
FROM (t2 JOIN t1) LEFT JOIN (t3 JOIN t4 ON t3.id = t4.carrier_id)
ON t3.carrier = t1.carrier;
COUNT(*)
6
EXPLAIN
SELECT COUNT(*)
FROM (t2 JOIN t1) LEFT JOIN (t3 JOIN t4 ON t3.id = t4.carrier_id)
ON t3.carrier = t1.carrier;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 NULL
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 NULL
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.carrier 1 NULL
1 SIMPLE t4 ref carrier_id carrier_id 5 test.t3.id 2 Using index
DROP TABLE t1,t2,t3,t4;
#
# Bug#45267: Incomplete check caused wrong result.
#
CREATE TABLE t1 (
`pk` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
);
CREATE TABLE t3 (
`pk` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
);
INSERT INTO t3 VALUES
(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),
(16),(17),(18),(19),(20);
CREATE TABLE t2 (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`int_nokey` int(11) NOT NULL,
`time_key` time NOT NULL,
PRIMARY KEY (`pk`),
KEY `time_key` (`time_key`)
);
INSERT INTO t2 VALUES (10,9,'22:36:46'),(11,0,'08:46:46');
SELECT DISTINCT t1.`pk`
FROM t1 RIGHT JOIN t2 STRAIGHT_JOIN t3 ON t2.`int_nokey` ON t2.`time_key`
GROUP BY 1;
pk
NULL
DROP TABLE IF EXISTS t1, t2, t3;
#
# BUG#52636 6.0 allowing JOINs on NULL values w/ optimizer_join_cache_level = 5-8
#
CREATE TABLE t1 (b int);
INSERT INTO t1 VALUES (NULL),(3);
CREATE TABLE t2 (a int, b int, KEY (b));
INSERT INTO t2 VALUES (100,NULL),(150,200);
EXPLAIN SELECT t2.a FROM t1 LEFT JOIN t2 FORCE INDEX (b) ON t2.b = t1.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 NULL
1 SIMPLE t2 ref b b 5 test.t1.b 2 NULL
SELECT t2.a FROM t1 LEFT JOIN t2 FORCE INDEX (b) ON t2.b = t1.b;
a
NULL
NULL
delete from t1;
INSERT INTO t1 VALUES (NULL),(NULL);
EXPLAIN SELECT t2.a FROM t1 LEFT JOIN t2 FORCE INDEX (b) ON t2.b = t1.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 NULL
1 SIMPLE t2 ref b b 5 test.t1.b 2 NULL
SELECT t2.a FROM t1 LEFT JOIN t2 FORCE INDEX (b) ON t2.b = t1.b;
a
NULL
NULL
DROP TABLE t1,t2;
CREATE TABLE t1 (b varchar(100));
INSERT INTO t1 VALUES (NULL),("some varchar");
CREATE TABLE t2 (a int, b varchar(100), KEY (b));
INSERT INTO t2 VALUES (100,NULL),(150,"varchar"),(200,NULL),(250,"long long varchar");
explain SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b = t1.b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 NULL
1 SIMPLE t2 ref b b 103 test.t1.b 2 NULL
SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b = t1.b;
a
NULL
NULL
DROP TABLE t1,t2;
#
# BUG#54359 "Extra rows with join_cache_level=7,8 and two joins
# --and multi-column index"
#
CREATE TABLE t1 (
`pk` int(11) NOT NULL,
`col_int_key` int(11) DEFAULT NULL,
`col_varchar_key` varchar(1) DEFAULT NULL,
`col_varchar_nokey` varchar(1) DEFAULT NULL,
KEY `col_varchar_key` (`col_varchar_key`,`col_int_key`))
;
INSERT INTO t1 VALUES (4,9,'k','k');
INSERT INTO t1 VALUES (12,5,'k','k');
explain SELECT table2 .`col_int_key` FROM t1 table2,
t1 table3 force index (`col_varchar_key`)
where table3 .`pk` and table3 .`col_int_key` >= table2 .`pk`
and table3 .`col_varchar_key` = table2 .`col_varchar_nokey`;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE table2 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE table3 ref col_varchar_key col_varchar_key 4 test.table2.col_varchar_nokey 1 Using index condition; Using where
SELECT table2 .`col_int_key` FROM t1 table2,
t1 table3 force index (`col_varchar_key`)
where table3 .`pk` and table3 .`col_int_key` >= table2 .`pk`
and table3 .`col_varchar_key` = table2 .`col_varchar_nokey`;
col_int_key
9
9
drop table t1;
#
# BUG#54481 "GROUP BY loses effect with JOIN + ORDER BY + LIMIT
# and join_cache_level=5-8"
#
CREATE TABLE t1 (
`col_int_key` int,
`col_datetime` datetime,
KEY `col_int_key` (`col_int_key`)
);
INSERT INTO t1 VALUES (2,'2003-02-11 21:19:41');
INSERT INTO t1 VALUES (3,'2009-10-18 02:27:49');
INSERT INTO t1 VALUES (0,'2000-09-26 07:45:57');
CREATE TABLE t2 (
`col_int` int,
`col_int_key` int,
KEY `col_int_key` (`col_int_key`)
);
INSERT INTO t2 VALUES (14,1);
INSERT INTO t2 VALUES (98,1);
explain SELECT t1.col_int_key, t1.col_datetime
FROM t1,t2
WHERE t2.col_int_key = 1 AND t2.col_int >= 3
GROUP BY t1.col_int_key
ORDER BY t1.col_int_key, t1.col_datetime
LIMIT 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL col_int_key NULL NULL NULL 3 Using temporary; Using filesort
1 SIMPLE t2 ref col_int_key col_int_key 5 const 1 Using where
SELECT t1.col_int_key, t1.col_datetime
FROM t1,t2
WHERE t2.col_int_key = 1 AND t2.col_int >= 3
GROUP BY t1.col_int_key
ORDER BY t1.col_int_key, t1.col_datetime
LIMIT 2;
col_int_key col_datetime
0 2000-09-26 07:45:57
2 2003-02-11 21:19:41
explain SELECT t1.col_int_key, t1.col_datetime
FROM t1 force index (col_int_key), t2 ignore index (col_int_key)
WHERE t2.col_int_key = 1 AND t2.col_int >= 3
GROUP BY t1.col_int_key
ORDER BY t1.col_int_key, t1.col_datetime
LIMIT 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index col_int_key col_int_key 5 NULL 3 Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where
SELECT t1.col_int_key, t1.col_datetime
FROM t1 force index (col_int_key), t2 ignore index (col_int_key)
WHERE t2.col_int_key = 1 AND t2.col_int >= 3
GROUP BY t1.col_int_key
ORDER BY t1.col_int_key, t1.col_datetime
LIMIT 2;
col_int_key col_datetime
0 2000-09-26 07:45:57
2 2003-02-11 21:19:41
drop table t1,t2;
# Bug#11766522 "59651: ASSERTION `TABLE_REF->HAS_RECORD' FAILED
# WITH JOIN_CACHE_LEVEL=3"
CREATE TABLE t1 (
b varchar(20)
) ;
INSERT INTO t1 VALUES ('1'),('1');
CREATE TABLE t4 (
col253 text
) ;
INSERT INTO t4 VALUES (''),('pf');
CREATE TABLE t6 (
col282 timestamp
) ;
INSERT INTO t6 VALUES ('2010-11-07 01:04:45'),('2010-12-13 01:36:32');
CREATE TABLE t7 (
col319 timestamp NOT NULL,
UNIQUE KEY idx263 (col319)
) ;
insert into t7 values("2000-01-01"),("2000-01-02");
CREATE TABLE t3 (
col582 char(230) CHARACTER SET utf8 DEFAULT NULL
) ;
INSERT INTO t3 VALUES ('cymej'),('spb');
CREATE TABLE t5 (
col712 time
) ;
insert into t5 values(0),(0);
CREATE TABLE t8 (
col804 char(169),
col805 varchar(51)
) ;
INSERT INTO t8 VALUES ('tmqcb','pwk');
CREATE TABLE t2 (
col841 varchar(10)
) ;
INSERT INTO t2 VALUES (''),('');
set join_buffer_size=1;
Warnings:
Warning 1292 Truncated incorrect join_buffer_size value: '1'
select @@join_buffer_size;
@@join_buffer_size
128
select count(*) from
(t1 join t2 join t3)
left join t4 on 1
left join t5 on 1 like t4.col253
left join t6 on t5.col712 is null
left join t7 on t1.b <=>t7.col319
left join t8 on t3.col582 <= 1;
count(*)
32
drop table t1,t2,t3,t4,t5,t6,t7,t8;
#
# Bug#12616131 - JCL: NULL VS DATE + TWICE AS MANY ROWS
# RETURNED WHEN JCL>=7
#
CREATE TABLE t1 (t1a int, t1b int);
INSERT INTO t1 VALUES (99, NULL),(99, 3),(99,0);
CREATE TABLE t2 (t2a int, t2b int, KEY idx (t2b));
INSERT INTO t2 VALUES (100,0),(150,200),(999, 0),(999, NULL);
# t2b is NULL-able
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 force index (idx) ON t2.t2b = t1.t1b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 NULL
1 SIMPLE t2 ref idx idx 5 test.t1.t1b 2 NULL
SELECT * FROM t1 LEFT JOIN t2 force index (idx) ON t2.t2b = t1.t1b;
t1a t1b t2a t2b
99 NULL NULL NULL
99 3 NULL NULL
99 0 100 0
99 0 999 0
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 force index (idx) ON t2.t2b <=> t1.t1b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 NULL
1 SIMPLE t2 ref idx idx 5 test.t1.t1b 2 Using where
SELECT * FROM t1 LEFT JOIN t2 force index (idx) ON t2.t2b <=> t1.t1b;
t1a t1b t2a t2b
99 NULL 999 NULL
99 3 NULL NULL
99 0 100 0
99 0 999 0
DROP TABLE t2;
CREATE TABLE t2 (t2a int, t2b int NOT NULL, KEY idx (t2b));
INSERT INTO t2 VALUES (100,0),(150,200),(999, 0);
# t2b is NOT NULL
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 force index (idx) ON t2.t2b = t1.t1b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 NULL
1 SIMPLE t2 ref idx idx 4 test.t1.t1b 2 NULL
SELECT * FROM t1 LEFT JOIN t2 force index (idx) ON t2.t2b = t1.t1b;
t1a t1b t2a t2b
99 NULL NULL NULL
99 3 NULL NULL
99 0 100 0
99 0 999 0
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 force index (idx) ON t2.t2b <=> t1.t1b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 NULL
1 SIMPLE t2 ref idx idx 4 test.t1.t1b 2 Using where
SELECT * FROM t1 LEFT JOIN t2 force index (idx) ON t2.t2b <=> t1.t1b;
t1a t1b t2a t2b
99 NULL NULL NULL
99 3 NULL NULL
99 0 100 0
99 0 999 0
DROP TABLE t1,t2;
#
# BUG#12619399 - JCL: NO ROWS VS 3X NULL QUERY OUTPUT WHEN JCL>=5
#
CREATE TABLE t1 (
c1 INTEGER NOT NULL,
c2_key INTEGER NOT NULL,
KEY col_int_key (c2_key)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES (24,204);
CREATE TABLE t2 (
pk INTEGER NOT NULL,
PRIMARY KEY (pk)
) ENGINE=InnoDB;
INSERT INTO t2 VALUES (10);
CREATE TABLE t3 (
c1 INTEGER,
KEY k1 (c1)
) ENGINE=InnoDB;
INSERT INTO t3 VALUES (NULL), (NULL);
set @old_opt_switch=@@optimizer_switch;
explain SELECT t3.c1 FROM t3
WHERE t3.c1 = SOME (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1)
XOR TRUE;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index NULL k1 5 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 ref col_int_key col_int_key 4 func 1 Using where; Full scan on NULL key
2 DEPENDENT SUBQUERY t2 ALL PRIMARY NULL NULL NULL 1 Range checked for each record (index map: 0x1)
explain SELECT t3.c1 FROM t3
WHERE t3.c1 = ANY (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1)
XOR TRUE;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index NULL k1 5 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 ref col_int_key col_int_key 4 func 1 Using where; Full scan on NULL key
2 DEPENDENT SUBQUERY t2 ALL PRIMARY NULL NULL NULL 1 Range checked for each record (index map: 0x1)
explain SELECT t3.c1 FROM t3
WHERE t3.c1 IN (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1)
XOR TRUE;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index NULL k1 5 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 ref col_int_key col_int_key 4 func 1 Using where; Full scan on NULL key
2 DEPENDENT SUBQUERY t2 ALL PRIMARY NULL NULL NULL 1 Range checked for each record (index map: 0x1)
explain SELECT t3.c1 FROM t3
WHERE t3.c1 NOT IN (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index NULL k1 5 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 ref col_int_key col_int_key 4 func 1 Using where; Full scan on NULL key
2 DEPENDENT SUBQUERY t2 ALL PRIMARY NULL NULL NULL 1 Range checked for each record (index map: 0x1)
explain SELECT t3.c1 FROM t3
WHERE t3.c1 IN (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL col_int_key NULL NULL NULL 1 Start temporary
1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 1 Range checked for each record (index map: 0x1)
1 SIMPLE t3 ref k1 k1 5 test.t1.c2_key 1 Using index; End temporary
SELECT t3.c1 FROM t3
WHERE t3.c1 = SOME (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1)
XOR TRUE;
c1
SELECT t3.c1 FROM t3
WHERE t3.c1 = ANY (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1)
XOR TRUE;
c1
SELECT t3.c1 FROM t3
WHERE t3.c1 IN (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1)
XOR TRUE;
c1
SELECT t3.c1 FROM t3
WHERE t3.c1 NOT IN (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1);
c1
SELECT t3.c1 FROM t3
WHERE t3.c1 IN (SELECT t1.c2_key FROM t2 JOIN t1 ON t2.pk < t1.c1);
c1
set @@optimizer_switch=@old_opt_switch;
DROP TABLE t1, t2, t3;
set @@join_buffer_size=default;
# BUG#12586926 "EXTRA ROW WITH JOIN + GROUP BY + ORDER BY WITH
# JCL>=5 AND MRR ENABLED"
CREATE TABLE t1 ( col_int_key int(11) NOT NULL,
col_varchar_key varchar(1) NOT NULL,
KEY col_int_key (col_int_key),
KEY col_varchar_key (col_varchar_key,col_int_key)
) ENGINE=innodb;
INSERT INTO t1 VALUES (0,'j'),(4,'b'),(4,'d');
CREATE TABLE t2 (
col_datetime_key datetime NOT NULL,
col_varchar_key varchar(1) NOT NULL,
KEY col_varchar_key (col_varchar_key)
) ENGINE=innodb;
INSERT INTO t2 VALUES ('2003-08-21 00:00:00','b');
explain SELECT MIN(t2.col_datetime_key) AS field1,
t1.col_int_key AS field2
FROM t1
LEFT JOIN t2 force index (col_varchar_key)
ON t1.col_varchar_key = t2.col_varchar_key
GROUP BY field2
ORDER BY field1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index col_int_key,col_varchar_key col_int_key 4 NULL 3 Using temporary; Using filesort
1 SIMPLE t2 ref col_varchar_key col_varchar_key 3 test.t1.col_varchar_key 1 NULL
SELECT MIN(t2.col_datetime_key) AS field1,
t1.col_int_key AS field2
FROM t1
LEFT JOIN t2 force index (col_varchar_key)
ON t1.col_varchar_key = t2.col_varchar_key
GROUP BY field2
ORDER BY field1;
field1 field2
NULL 0
2003-08-21 00:00:00 4
DROP TABLE t1,t2;
# BUG#12619510 "JCL: MORE ROWS AND DIFFERENT OUTPUT WITH JCL>=5"
CREATE TABLE t1 (
col_int_key int(11) NOT NULL,
col_datetime_key datetime NOT NULL,
col_varchar_nokey varchar(1) NOT NULL,
KEY col_int_key (col_int_key),
KEY col_datetime_key (col_datetime_key)
);
INSERT INTO t1 VALUES (7,'2004-06-06 04:22:12','v');
INSERT INTO t1 VALUES (0,'2005-11-13 01:12:31','s');
INSERT INTO t1 VALUES (9,'2002-05-04 01:50:00','l');
INSERT INTO t1 VALUES (3,'2004-10-27 10:28:45','y');
INSERT INTO t1 VALUES (4,'2006-07-22 05:24:23','c');
INSERT INTO t1 VALUES (2,'2002-05-16 21:34:03','i');
INSERT INTO t1 VALUES (5,'2008-04-17 10:45:30','h');
INSERT INTO t1 VALUES (3,'2009-04-21 02:58:02','q');
INSERT INTO t1 VALUES (1,'2008-01-11 11:01:51','a');
INSERT INTO t1 VALUES (3,'1900-01-01 00:00:00','v');
INSERT INTO t1 VALUES (6,'2007-05-17 18:24:57','u');
INSERT INTO t1 VALUES (7,'2007-08-07 00:00:00','s');
INSERT INTO t1 VALUES (5,'2001-08-28 00:00:00','y');
INSERT INTO t1 VALUES (1,'2004-04-16 00:27:28','z');
INSERT INTO t1 VALUES (204,'2005-05-03 07:06:22','h');
INSERT INTO t1 VALUES (224,'2009-03-11 17:09:50','p');
INSERT INTO t1 VALUES (9,'2007-12-08 01:54:28','e');
INSERT INTO t1 VALUES (5,'2009-07-28 18:19:54','i');
INSERT INTO t1 VALUES (0,'2008-06-08 00:00:00','y');
INSERT INTO t1 VALUES (3,'2005-02-09 09:20:26','w');
CREATE TABLE t2 (
pk int(11) NOT NULL,
col_varchar_key varchar(1) NOT NULL,
PRIMARY KEY (pk)
);
INSERT INTO t2 VALUES
(1,'j'),(2,'v'),(3,'c'),(4,'m'),(5,'d'),(6,'d'),(7,'y'),
(8,'t'),(9,'d'),(10,'s'),(11,'r'),(12,'m'),(13,'b'),(14,'x'),
(15,'g'),(16,'p'),(17,'q'),(18,'w'),(19,'d'),(20,'e');
explain SELECT t2.col_varchar_key AS field1 , COUNT(DISTINCT t1.col_varchar_nokey), t2.pk AS field4
FROM t1
RIGHT JOIN t2 ON t2.pk = t1.col_int_key
GROUP BY field1 , field4
ORDER BY t1.col_datetime_key ;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
1 SIMPLE t1 ref col_int_key col_int_key 4 test.t2.pk 2 NULL
SELECT t2.col_varchar_key AS field1 , COUNT(DISTINCT t1.col_varchar_nokey), t2.pk AS field4
FROM t1
RIGHT JOIN t2 ON t2.pk = t1.col_int_key
GROUP BY field1 , field4
ORDER BY t1.col_datetime_key ;
field1 COUNT(DISTINCT t1.col_varchar_nokey) field4
b 0 13
c 4 3
d 0 19
d 1 6
d 2 9
d 3 5
e 0 20
g 0 15
j 2 1
m 0 12
m 1 4
p 0 16
q 0 17
r 0 11
s 0 10
t 0 8
v 1 2
w 0 18
x 0 14
y 2 7
DROP TABLE t1,t2;
# BUG#12619868 "JCL: MORE ROWS OF OUTPUT WHEN JCL>=5"
CREATE TABLE t1 (col_varchar_key varchar(1));
CREATE TABLE t2 (
pk int(11) NOT NULL,
col_int_nokey int(11) NOT NULL,
col_int_key int(11) NOT NULL,
PRIMARY KEY (pk),
KEY col_int_key (col_int_key)
);
INSERT INTO t2 VALUES (5,3,9);
INSERT INTO t2 VALUES (6,246,24);
INSERT INTO t2 VALUES (7,2,6);
INSERT INTO t2 VALUES (8,9,1);
INSERT INTO t2 VALUES (9,3,6);
INSERT INTO t2 VALUES (10,8,2);
INSERT INTO t2 VALUES (11,1,4);
INSERT INTO t2 VALUES (12,8,8);
INSERT INTO t2 VALUES (13,8,4);
INSERT INTO t2 VALUES (14,5,4);
INSERT INTO t2 VALUES (15,7,7);
INSERT INTO t2 VALUES (16,5,4);
INSERT INTO t2 VALUES (17,1,1);
INSERT INTO t2 VALUES (18,6,9);
INSERT INTO t2 VALUES (19,2,4);
INSERT INTO t2 VALUES (20,9,8);
explain SELECT t1.col_varchar_key AS field1, alias2.col_int_key AS field4
FROM t2 AS alias2 STRAIGHT_JOIN t2 AS alias3 ON alias3.pk =
alias2.col_int_nokey
left join t1
ON alias3.col_int_nokey
GROUP BY field1, field4
LIMIT 15;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found
1 SIMPLE alias2 index NULL col_int_key 4 NULL 15 NULL
1 SIMPLE alias3 eq_ref PRIMARY PRIMARY 4 test.alias2.col_int_nokey 1 NULL
SELECT t1.col_varchar_key AS field1, alias2.col_int_key AS field4
FROM t2 AS alias2 STRAIGHT_JOIN t2 AS alias3 ON alias3.pk =
alias2.col_int_nokey
left join t1
ON alias3.col_int_nokey
GROUP BY field1, field4
LIMIT 15;
field1 field4
NULL 1
NULL 2
NULL 4
NULL 7
NULL 8
NULL 9
DROP TABLE t1,t2;
# BUG#12722133 - JCL: JOIN QUERY GIVES DIFFERENT RESULTS AT
# JCL=6 ONLY [NULL VERSUS NULL+#INTS]
CREATE TABLE t1 (pk INTEGER PRIMARY KEY, k INTEGER, i INTEGER, KEY k(k));
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 LIKE t1;
CREATE TABLE t4 LIKE t1;
INSERT INTO t1 VALUES (6,NULL,6),(0,1,11);
INSERT INTO t2 VALUES (1,NULL,NULL),(4,7,NULL);
INSERT INTO t3 VALUES (2,3,0),(3,4,4);
INSERT INTO t4 VALUES (1,9,-1),(4,7,NULL);
EXPLAIN SELECT t2.pk as t2_pk, t4.pk as t4_pk, t4.k as t4_k, t4.i
as t4_i FROM t1
LEFT JOIN t2 ON t1.k = t2.pk
LEFT JOIN t3 ON t3.i
LEFT JOIN t4 ON t4.pk = t2.pk;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL k 5 NULL 2 Using index
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.k 1 Using index
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t2.pk 1 NULL
SELECT t2.pk as t2_pk, t4.pk as t4_pk, t4.k as t4_k, t4.i
as t4_i FROM t1
LEFT JOIN t2 ON t1.k = t2.pk
LEFT JOIN t3 ON t3.i
LEFT JOIN t4 ON t4.pk = t2.pk;
t2_pk t4_pk t4_k t4_i
NULL NULL NULL NULL
1 1 9 -1
DROP TABLE t1, t2, t3, t4;
# BUG#12827509 - BNL/BKA: SELECT LEFT/RIGHT JOIN QUERY GIVES
# DIFFERENT OUTPUT ON BNL=OFF+BKA=ON
# (Duplicate of BUG#12722133)
CREATE TABLE t1 (
col_int INTEGER
);
INSERT INTO t1 VALUES (3), (7), (2), (8), (6);
CREATE TABLE t2 (
pk INTEGER,
col_int INTEGER,
PRIMARY KEY (pk)
);
INSERT INTO t2 VALUES (1,5), (2,8), (6,3), (8,7), (9,9);
CREATE TABLE t3 (
pk INTEGER,
col_int INTEGER,
PRIMARY KEY (pk)
);
INSERT INTO t3 VALUES (3,2), (4,3), (8,2);
CREATE TABLE t4 (
pk INTEGER,
col_int INTEGER,
PRIMARY KEY (pk)
);
INSERT INTO t4 VALUES (2,3), (6,1), (8,2);
EXPLAIN SELECT t4.col_int
FROM t1
LEFT JOIN t2 ON t1.col_int = t2.col_int
LEFT JOIN t3 ON t2.pk = t3.pk
LEFT JOIN t4 ON t4.pk = t2.pk
WHERE t1.col_int OR t3.col_int;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 NULL
1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.pk 1 Using where
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t2.pk 1 NULL
SELECT t4.col_int
FROM t1
LEFT JOIN t2 ON t1.col_int = t2.col_int
LEFT JOIN t3 ON t2.pk = t3.pk
LEFT JOIN t4 ON t4.pk = t2.pk
WHERE t1.col_int OR t3.col_int;
col_int
1
2
NULL
3
NULL
DROP TABLE t1, t2, t3, t4;
#
# Bug#12997905: VALGRIND: SYSCALL PARAM PWRITE64(BUF)
# POINTS TO UNINITIALISED BYTE(S)
#
CREATE TABLE t1 (
col1 varchar(10),
col2 varchar(1024)
) ENGINE=innodb;
INSERT INTO t1 VALUES ('a','a');
CREATE TABLE t2 (i varchar(10)) ENGINE=innodb;
INSERT INTO t2 VALUES ('a');
SELECT t1.col1
FROM t1 JOIN t2 ON t1.col1 = t2.i
GROUP BY t1.col2;
col1
a
DROP TABLE t1,t2;
# End of Bug#12997905
#
# Bug 13596330 - EXTRA ROW ON SELECT WITH NESTED IN CLAUSE + IS
# NULL WHEN SEMIJOIN + BNL IS ON
#
CREATE TABLE t1 (
col_int_nokey int
);
INSERT INTO t1 VALUES(-1),(-1);
CREATE TABLE t2 (
col_int_nokey int,
col_datetime_nokey datetime NOT NULL,
col_varchar_key varchar(1),
KEY col_varchar_key (col_varchar_key)
);
INSERT INTO t2 VALUES (9, '2002-08-25 20:35:06', 'e'),
(9, '2002-08-25 20:35:06', 'e');
set @optimizer_switch_saved=@@session.optimizer_switch;
set @@session.optimizer_switch='semijoin=off';
EXPLAIN SELECT PARENT1.col_varchar_key
FROM t2 AS PARENT1 LEFT JOIN t1 USING (col_int_nokey)
WHERE PARENT1.col_varchar_key IN
( SELECT col_varchar_key FROM t2 AS CHILD1
WHERE PARENT1.col_datetime_nokey IS NULL
AND t1.col_int_nokey IS NULL )
;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY PARENT1 ALL NULL NULL NULL NULL 2 NULL
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 DEPENDENT SUBQUERY CHILD1 index_subquery col_varchar_key col_varchar_key 4 func 2 Using index; Using where
SELECT PARENT1.col_varchar_key
FROM t2 AS PARENT1 LEFT JOIN t1 USING (col_int_nokey)
WHERE PARENT1.col_varchar_key IN
( SELECT col_varchar_key FROM t2 AS CHILD1
WHERE PARENT1.col_datetime_nokey IS NULL
AND t1.col_int_nokey IS NULL )
;
col_varchar_key
set @@session.optimizer_switch=@optimizer_switch_saved;
DROP TABLE t1,t2;
set optimizer_switch = default;
|