1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317
|
/* Copyright (c) 2013, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef PARSE_TREE_NODES_INCLUDED
#define PARSE_TREE_NODES_INCLUDED
#include <assert.h>
#include <sys/types.h> // TODO: replace with cstdint
#include <cctype> // std::isspace
#include <cstddef>
#include <memory>
#include "lex_string.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_bit.h" // is_single_bit
#include "my_inttypes.h" // TODO: replace with cstdint
#include "my_list.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "my_thread_local.h"
#include "my_time.h"
#include "mysqld_error.h"
#include "sql/check_stack.h"
#include "sql/enum_query_type.h"
#include "sql/handler.h"
#include "sql/key_spec.h"
#include "sql/mem_root_array.h"
#include "sql/opt_explain.h" // Sql_cmd_explain_other_thread
#include "sql/parse_location.h"
#include "sql/parse_tree_helpers.h" // PT_item_list
#include "sql/parse_tree_node_base.h"
#include "sql/parser_yystype.h"
#include "sql/partition_info.h"
#include "sql/resourcegroups/resource_group_basic_types.h"
#include "sql/resourcegroups/resource_group_sql_cmd.h"
#include "sql/set_var.h"
#include "sql/sql_admin.h" // Sql_cmd_shutdown etc.
#include "sql/sql_alter.h"
#include "sql/sql_check_constraint.h" // Sql_check_constraint_spec
#include "sql/sql_cmd_srs.h"
#include "sql/sql_exchange.h"
#include "sql/sql_lex.h" // LEX
#include "sql/sql_list.h"
#include "sql/sql_load.h" // Sql_cmd_load_table
#include "sql/sql_partition_admin.h"
#include "sql/sql_restart_server.h" // Sql_cmd_restart_server
#include "sql/sql_tablespace.h" // Tablespace_options
#include "sql/sql_truncate.h" // Sql_cmd_truncate_table
#include "sql/table.h" // Common_table_expr
#include "sql/window_lex.h"
#include "thr_lock.h"
class Item;
class Item_cache;
class Json_table_column;
class PT_column_attr_base;
class PT_field_def_base;
class PT_hint_list;
class PT_insert_values_list;
class PT_part_definition;
class PT_partition;
class PT_subquery;
class PT_type;
class PT_window_list;
class Sql_cmd;
class String;
class THD;
class Window;
class sp_head;
class sp_name;
struct CHARSET_INFO;
/**
@defgroup ptn Parse tree nodes
@ingroup Parser
*/
/**
@defgroup ptn_stmt Nodes representing SQL statements
@ingroup ptn
*/
/**
@defgroup ptn_create_table CREATE TABLE statement
@ingroup ptn_stmt
*/
/**
@defgroup ptn_alter_table ALTER TABLE statement
@ingroup ptn_stmt
*/
/**
@defgroup ptn_create_table_stuff Clauses of CREATE TABLE statement
@ingroup ptn_create_table
*/
/**
@defgroup ptn_partitioning CREATE/ALTER TABLE partitioning-related stuff
@ingroup ptn_create_table ptn_alter_table
*/
/**
@defgroup ptn_part_options Partition options in CREATE/ALTER TABLE
@ingroup ptn_partitioning
*/
/**
@defgroup ptn_create_or_alter_table_options Table options of CREATE/ALTER
TABLE
@anchor ptn_create_or_alter_table_options
@ingroup ptn_create_table ptn_alter_table
*/
/**
@defgroup ptn_col_types Column types in CREATE/ALTER TABLE
@ingroup ptn_create_table ptn_alter_table
*/
/**
@defgroup ptn_col_attrs Column attributes in CREATE/ALTER TABLE
@ingroup ptn_create_table ptn_alter_table
*/
/**
@defgroup ptn_not_gcol_attr Non-generated column attributes in CREATE/ALTER
TABLE
@ingroup ptn_col_attrs ptn_alter_table
*/
/**
Calls contextualize() on every node in the array.
*/
template <class Node_type, class Parse_context_type>
bool contextualize_nodes(Mem_root_array_YY<Node_type *> nodes,
Parse_context_type *pc) {
for (Node_type *i : nodes)
if (i->contextualize(pc)) return true;
return false;
}
/**
Base class for all top-level nodes of SQL statements
@ingroup ptn_stmt
*/
class Parse_tree_root {
Parse_tree_root(const Parse_tree_root &) = delete;
void operator=(const Parse_tree_root &) = delete;
protected:
virtual ~Parse_tree_root() = default;
Parse_tree_root() = default;
public:
virtual Sql_cmd *make_cmd(THD *thd) = 0;
};
class PT_table_ddl_stmt_base : public Parse_tree_root {
public:
explicit PT_table_ddl_stmt_base(MEM_ROOT *mem_root)
: m_alter_info(mem_root) {}
~PT_table_ddl_stmt_base() override = 0; // force abstract class
protected:
Alter_info m_alter_info;
};
inline PT_table_ddl_stmt_base::~PT_table_ddl_stmt_base() = default;
/**
Parse context for the table DDL (ALTER TABLE and CREATE TABLE) nodes.
For internal use in the contextualization code.
*/
struct Table_ddl_parse_context final : public Parse_context {
Table_ddl_parse_context(THD *thd_arg, Query_block *select_arg,
Alter_info *alter_info);
HA_CREATE_INFO *const create_info;
Alter_info *const alter_info;
KEY_CREATE_INFO *const key_create_info;
};
/**
Base class for all table DDL (ALTER TABLE and CREATE TABLE) nodes.
*/
typedef Parse_tree_node_tmpl<Table_ddl_parse_context> Table_ddl_node;
class PT_order_expr : public Parse_tree_node, public ORDER {
typedef Parse_tree_node super;
public:
PT_order_expr(Item *item_arg, enum_order dir) {
item_initial = item_arg;
direction = (dir == ORDER_DESC) ? ORDER_DESC : ORDER_ASC;
}
bool contextualize(Parse_context *pc) override;
};
class PT_order_list : public Parse_tree_node {
typedef Parse_tree_node super;
public:
SQL_I_List<ORDER> value;
public:
bool contextualize(Parse_context *pc) override {
if (super::contextualize(pc)) return true;
for (ORDER *o = value.first; o != nullptr; o = o->next) {
if (static_cast<PT_order_expr *>(o)->contextualize(pc)) return true;
}
return false;
}
void push_back(PT_order_expr *order) {
order->used_alias = false;
order->used = 0;
value.link_in_list(order, &order->next);
}
};
class PT_gorder_list : public PT_order_list {
typedef PT_order_list super;
public:
bool contextualize(Parse_context *pc) override {
return super::contextualize(pc);
}
};
/**
Represents an element of the WITH list:
WITH [...], [...] SELECT ...,
^ or ^
i.e. a Common Table Expression (CTE, or Query Name in SQL99 terms).
*/
class PT_common_table_expr : public Parse_tree_node {
typedef Parse_tree_node super;
public:
explicit PT_common_table_expr(const LEX_STRING &name,
const LEX_STRING &subq_text,
uint subq_text_offset, PT_subquery *sn,
const Create_col_name_list *column_names,
MEM_ROOT *mem_root);
/// The name after AS
const LEX_STRING &name() const { return m_name; }
/**
@param thd Thread handler
@param[out] node PT_subquery
@returns a PT_subquery to attach to a table reference for this CTE
*/
bool make_subquery_node(THD *thd, PT_subquery **node);
/**
@param tl Table reference to match
@param in_self If this is a recursive reference
@param[out] found Is set to true/false if matches or not
@returns true if error
*/
bool match_table_ref(Table_ref *tl, bool in_self, bool *found);
/**
@returns true if 'other' is the same instance as 'this'
*/
bool is(const Common_table_expr *other) const {
return other == &m_postparse;
}
void print(const THD *thd, String *str, enum_query_type query_type);
private:
LEX_STRING m_name;
/// Raw text of query expression (including parentheses)
const LEX_STRING m_subq_text;
/**
Offset in bytes of m_subq_text in original statement which had the WITH
clause.
*/
uint m_subq_text_offset;
/// Parsed version of subq_text
PT_subquery *const m_subq_node;
/// List of explicitly specified column names; if empty, no list.
const Create_col_name_list m_column_names;
/**
A Table_ref representing a CTE needs access to the WITH list
element it derives from. However, in order to:
- limit the members which Table_ref can access
- avoid including this header file everywhere Table_ref needs to
access these members, these members are relocated into a separate inferior
object whose declaration is in table.h, like that of Table_ref. It's
the "postparse" part. Table_ref accesses this inferior object only.
*/
Common_table_expr m_postparse;
friend bool Query_expression::clear_correlated_query_blocks();
};
/**
Represents the WITH list.
WITH [...], [...] SELECT ...,
^^^^^^^^^^^^
*/
class PT_with_list : public Parse_tree_node {
typedef Parse_tree_node super;
public:
/// @param mem_root where interior objects are allocated
explicit PT_with_list(MEM_ROOT *mem_root) : m_elements(mem_root) {}
bool push_back(PT_common_table_expr *el);
const Mem_root_array<PT_common_table_expr *> &elements() const {
return m_elements;
}
private:
Mem_root_array<PT_common_table_expr *> m_elements;
};
/**
Represents the WITH clause:
WITH [...], [...] SELECT ...,
^^^^^^^^^^^^^^^^^
*/
class PT_with_clause : public Parse_tree_node {
typedef Parse_tree_node super;
public:
PT_with_clause(const PT_with_list *l, bool r)
: m_list(l), m_recursive(r), m_most_inner_in_parsing(nullptr) {}
bool contextualize(Parse_context *pc) override;
/**
Looks up a table reference into the list of CTEs.
@param tl Table reference to look up
@param[out] found Is set to true/false if found or not
@returns true if error
*/
bool lookup(Table_ref *tl, PT_common_table_expr **found);
/**
Call this to record in the WITH clause that we are contextualizing the
CTE definition inserted in table reference 'tl'.
@returns information which the caller must provide to
leave_parsing_definition().
*/
const Table_ref *enter_parsing_definition(Table_ref *tl) {
auto old = m_most_inner_in_parsing;
m_most_inner_in_parsing = tl;
return old;
}
void leave_parsing_definition(const Table_ref *old) {
m_most_inner_in_parsing = old;
}
void print(const THD *thd, String *str, enum_query_type query_type);
private:
/// All CTEs of this clause
const PT_with_list *const m_list;
/// True if the user has specified the RECURSIVE keyword.
const bool m_recursive;
/**
The innermost CTE reference which we're parsing at the
moment. Used to detect forward references, loops and recursiveness.
*/
const Table_ref *m_most_inner_in_parsing;
friend bool Query_expression::clear_correlated_query_blocks();
};
class PT_select_item_list : public PT_item_list {
typedef PT_item_list super;
public:
bool contextualize(Parse_context *pc) override;
};
class PT_limit_clause : public Parse_tree_node {
typedef Parse_tree_node super;
Limit_options limit_options;
public:
PT_limit_clause(const Limit_options &limit_options_arg)
: limit_options(limit_options_arg) {}
bool contextualize(Parse_context *pc) override;
friend class PT_query_expression;
};
class PT_cross_join;
class PT_joined_table;
class PT_table_reference : public Parse_tree_node {
public:
Table_ref *m_table_ref;
/**
Lets us build a parse tree top-down, which is necessary due to the
context-dependent nature of the join syntax. This function adds
the @<table_ref@> cross join as the left-most leaf in this join tree
rooted at this node.
@todo: comment on non-join PT_table_reference objects
@param cj This @<table ref@> will be added if it represents a cross join.
@return The new top-level join.
*/
virtual PT_joined_table *add_cross_join(PT_cross_join *cj);
};
class PT_table_factor_table_ident : public PT_table_reference {
typedef PT_table_reference super;
Table_ident *table_ident;
List<String> *opt_use_partition;
const char *const opt_table_alias;
List<Index_hint> *opt_key_definition;
public:
PT_table_factor_table_ident(Table_ident *table_ident_arg,
List<String> *opt_use_partition_arg,
const LEX_CSTRING &opt_table_alias_arg,
List<Index_hint> *opt_key_definition_arg)
: table_ident(table_ident_arg),
opt_use_partition(opt_use_partition_arg),
opt_table_alias(opt_table_alias_arg.str),
opt_key_definition(opt_key_definition_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_json_table_column : public Parse_tree_node {
public:
virtual Json_table_column *get_column() = 0;
};
class PT_table_factor_function : public PT_table_reference {
typedef PT_table_reference super;
public:
PT_table_factor_function(Item *expr, Item *path,
Mem_root_array<PT_json_table_column *> *nested_cols,
const LEX_STRING &table_alias)
: m_expr(expr),
m_path(path),
m_nested_columns(nested_cols),
m_table_alias(table_alias) {}
bool contextualize(Parse_context *pc) override;
private:
Item *m_expr;
Item *m_path;
Mem_root_array<PT_json_table_column *> *m_nested_columns;
const LEX_STRING m_table_alias;
};
class PT_table_reference_list_parens : public PT_table_reference {
typedef PT_table_reference super;
Mem_root_array_YY<PT_table_reference *> table_list;
public:
explicit PT_table_reference_list_parens(
const Mem_root_array_YY<PT_table_reference *> table_list)
: table_list(table_list) {}
bool contextualize(Parse_context *pc) override;
};
class PT_derived_table : public PT_table_reference {
typedef PT_table_reference super;
public:
PT_derived_table(bool lateral, PT_subquery *subquery,
const LEX_CSTRING &table_alias,
Create_col_name_list *column_names);
bool contextualize(Parse_context *pc) override;
private:
bool m_lateral;
PT_subquery *m_subquery;
const char *const m_table_alias;
/// List of explicitly specified column names; if empty, no list.
const Create_col_name_list column_names;
};
class PT_table_factor_joined_table : public PT_table_reference {
typedef PT_table_reference super;
public:
PT_table_factor_joined_table(PT_joined_table *joined_table)
: m_joined_table(joined_table) {}
bool contextualize(Parse_context *pc) override;
private:
PT_joined_table *m_joined_table;
};
class PT_joined_table : public PT_table_reference {
typedef PT_table_reference super;
protected:
PT_table_reference *m_left_pt_table;
POS m_join_pos;
PT_joined_table_type m_type;
PT_table_reference *m_right_pt_table;
Table_ref *m_left_table_ref{nullptr};
Table_ref *m_right_table_ref{nullptr};
public:
PT_joined_table(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
PT_joined_table_type type, PT_table_reference *tab2_node_arg)
: m_left_pt_table(tab1_node_arg),
m_join_pos(join_pos_arg),
m_type(type),
m_right_pt_table(tab2_node_arg) {
static_assert(is_single_bit(JTT_INNER), "not a single bit");
static_assert(is_single_bit(JTT_STRAIGHT), "not a single bit");
static_assert(is_single_bit(JTT_NATURAL), "not a single bit");
static_assert(is_single_bit(JTT_LEFT), "not a single bit");
static_assert(is_single_bit(JTT_RIGHT), "not a single bit");
assert(type == JTT_INNER || type == JTT_STRAIGHT_INNER ||
type == JTT_NATURAL_INNER || type == JTT_NATURAL_LEFT ||
type == JTT_NATURAL_RIGHT || type == JTT_LEFT || type == JTT_RIGHT);
}
/**
Adds the cross join to this join operation. The cross join is nested as
the table reference on the left-hand side.
*/
PT_joined_table *add_cross_join(PT_cross_join *cj) override {
m_left_pt_table = m_left_pt_table->add_cross_join(cj);
return this;
}
/// Adds the table reference as the right-hand side of this join.
void add_rhs(PT_table_reference *table) {
assert(m_right_pt_table == nullptr);
m_right_pt_table = table;
}
bool contextualize(Parse_context *pc) override;
/// This class is being inherited, it should thus be abstract.
~PT_joined_table() override = 0;
protected:
bool contextualize_tabs(Parse_context *pc);
};
inline PT_joined_table::~PT_joined_table() = default;
class PT_cross_join : public PT_joined_table {
typedef PT_joined_table super;
public:
PT_cross_join(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
PT_joined_table_type Type_arg,
PT_table_reference *tab2_node_arg)
: PT_joined_table(tab1_node_arg, join_pos_arg, Type_arg, tab2_node_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_joined_table_on : public PT_joined_table {
typedef PT_joined_table super;
Item *on;
public:
PT_joined_table_on(PT_table_reference *tab1_node_arg, const POS &join_pos_arg,
PT_joined_table_type type,
PT_table_reference *tab2_node_arg, Item *on_arg)
: super(tab1_node_arg, join_pos_arg, type, tab2_node_arg), on(on_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_joined_table_using : public PT_joined_table {
typedef PT_joined_table super;
List<String> *using_fields;
public:
PT_joined_table_using(PT_table_reference *tab1_node_arg,
const POS &join_pos_arg, PT_joined_table_type type,
PT_table_reference *tab2_node_arg,
List<String> *using_fields_arg)
: super(tab1_node_arg, join_pos_arg, type, tab2_node_arg),
using_fields(using_fields_arg) {}
/// A PT_joined_table_using without a list of columns denotes a natural join.
PT_joined_table_using(PT_table_reference *tab1_node_arg,
const POS &join_pos_arg, PT_joined_table_type type,
PT_table_reference *tab2_node_arg)
: PT_joined_table_using(tab1_node_arg, join_pos_arg, type, tab2_node_arg,
nullptr) {}
bool contextualize(Parse_context *pc) override;
};
class PT_group : public Parse_tree_node {
typedef Parse_tree_node super;
PT_order_list *group_list;
olap_type olap;
public:
PT_group(PT_order_list *group_list_arg, olap_type olap_arg)
: group_list(group_list_arg), olap(olap_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_order : public Parse_tree_node {
typedef Parse_tree_node super;
public:
PT_order_list *order_list;
explicit PT_order(PT_order_list *order_list_arg)
: order_list(order_list_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_locking_clause : public Parse_tree_node {
public:
PT_locking_clause(Lock_strength strength, Locked_row_action action)
: m_lock_strength(strength), m_locked_row_action(action) {}
bool contextualize(Parse_context *pc) final;
virtual bool set_lock_for_tables(Parse_context *pc) = 0;
Locked_row_action action() const { return m_locked_row_action; }
protected:
Lock_descriptor get_lock_descriptor() const {
thr_lock_type lock_type = TL_IGNORE;
switch (m_lock_strength) {
case Lock_strength::UPDATE:
lock_type = TL_WRITE;
break;
case Lock_strength::SHARE:
lock_type = TL_READ_WITH_SHARED_LOCKS;
break;
}
return {lock_type, static_cast<thr_locked_row_action>(action())};
}
private:
Lock_strength m_lock_strength;
Locked_row_action m_locked_row_action;
};
class PT_query_block_locking_clause : public PT_locking_clause {
public:
explicit PT_query_block_locking_clause(
Lock_strength strength,
Locked_row_action action = Locked_row_action::WAIT)
: PT_locking_clause(strength, action) {}
bool set_lock_for_tables(Parse_context *pc) override;
};
class PT_table_locking_clause : public PT_locking_clause {
public:
typedef Mem_root_array_YY<Table_ident *> Table_ident_list;
PT_table_locking_clause(Lock_strength strength,
Mem_root_array_YY<Table_ident *> tables,
Locked_row_action action)
: PT_locking_clause(strength, action), m_tables(tables) {}
bool set_lock_for_tables(Parse_context *pc) override;
private:
/// @todo Move this function to Table_ident?
void print_table_ident(const THD *thd, const Table_ident *ident, String *s);
bool raise_error(THD *thd, const Table_ident *name, int error);
bool raise_error(int error);
Table_ident_list m_tables;
};
class PT_locking_clause_list : public Parse_tree_node {
public:
PT_locking_clause_list(MEM_ROOT *mem_root) {
m_locking_clauses.init(mem_root);
}
bool push_back(PT_locking_clause *locking_clause) {
return m_locking_clauses.push_back(locking_clause);
}
bool contextualize(Parse_context *pc) override {
for (auto locking_clause : m_locking_clauses)
if (locking_clause->contextualize(pc)) return true;
return false;
}
private:
Mem_root_array_YY<PT_locking_clause *> m_locking_clauses;
};
class PT_query_expression_body : public Parse_tree_node {
public:
enum Setop_type { NONE, UNION, INTERSECT, EXCEPT };
virtual Setop_type type() const { return NONE; }
virtual bool is_set_operation() const = 0;
/**
True if this query expression can absorb an extraneous order by/limit
clause. The `ORDER BY`/`LIMIT` syntax is mostly consistestent, i.e. a
trailing clause may not refer to the tables in the `<query primary>`, with
one glaring exception:
(...( SELECT ... )...) ORDER BY ...
If the nested query expression doesn't contain `ORDER BY`, the statement
is interpreted as if the `ORDER BY` was absorbed by the innermost query
expression, i.e.:
(...( SELECT ... ORDER BY ... )...)
There is no rewriting of the parse tree nor AST happening here, the
transformation is done by the contextualizer (see
PT_query_expression::contextualize_order_and_limit), which interprets the
parse tree, and builds the AST according to this interpretation. This
interpretation is governed by the following rule: An `ORDER BY` can be
absorbed if none the nested query expressions contains an `ORDER BY` *or*
`LIMIT`. The rule is complex, so here are some examples for illustration:
In these cases the `ORDER BY` *is* absorbed:
( SELECT * FROM t1 ) ORDER BY t1.a;
(( SELECT * FROM t1 )) ORDER BY t1.a;
In these cases the ORDER BY is *not* absorbed:
( SELECT * FROM t1 ORDER BY 1 ) ORDER BY t1.a;
(( SELECT * FROM t1 ) ORDER BY 1 ) ORDER BY t1.a;
( SELECT * FROM t1 LIMIT 1 ) ORDER BY t1.a;
(( SELECT * FROM t1 ) LIMIT 1 ) ORDER BY t1.a;
The same happens with `LIMIT`, obviously, but the optimizer is freeer to
choose when to apply the limit, and there are name no resolution issues
involved.
@param order True if the outer query block has the ORDER BY clause.
@param limit True if the outer query block has the LIMIT clause.
*/
virtual bool can_absorb_order_and_limit(bool order, bool limit) const = 0;
virtual bool has_into_clause() const = 0;
virtual bool has_trailing_into_clause() const = 0;
virtual bool is_table_value_constructor() const = 0;
virtual PT_insert_values_list *get_row_value_list() const = 0;
};
class PT_set_scoped_system_variable : public Parse_tree_node {
typedef Parse_tree_node super;
public:
PT_set_scoped_system_variable(const POS &pos, const LEX_CSTRING &opt_prefix,
const LEX_CSTRING &name, Item *opt_expr)
: m_pos{pos},
m_opt_prefix{opt_prefix},
m_name{name},
m_opt_expr{opt_expr} {}
bool contextualize(Parse_context *pc) override;
private:
const POS m_pos;
const LEX_CSTRING m_opt_prefix;
const LEX_CSTRING m_name;
Item *m_opt_expr;
};
class PT_option_value_no_option_type : public Parse_tree_node {};
class PT_set_variable : public PT_option_value_no_option_type {
typedef PT_option_value_no_option_type super;
public:
PT_set_variable(const POS &pos, const LEX_CSTRING &opt_prefix,
const LEX_CSTRING &name, const POS &expr_pos, Item *opt_expr)
: m_pos{pos},
m_opt_prefix{opt_prefix},
m_name{name},
m_expr_pos{expr_pos},
m_opt_expr{opt_expr} {}
bool contextualize(Parse_context *pc) override;
private:
const POS m_pos;
const LEX_CSTRING m_opt_prefix;
const LEX_CSTRING m_name;
const POS m_expr_pos;
Item *m_opt_expr;
};
class PT_option_value_no_option_type_user_var
: public PT_option_value_no_option_type {
typedef PT_option_value_no_option_type super;
LEX_STRING name;
Item *expr;
public:
PT_option_value_no_option_type_user_var(const LEX_STRING &name_arg,
Item *expr_arg)
: name(name_arg), expr(expr_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_set_system_variable : public PT_option_value_no_option_type {
typedef PT_option_value_no_option_type super;
public:
PT_set_system_variable(enum_var_type scope, const POS &name_pos,
const LEX_CSTRING &opt_prefix, const LEX_CSTRING &name,
Item *opt_expr)
: m_scope{scope},
m_name_pos{name_pos},
m_opt_prefix{opt_prefix},
m_name{name},
m_opt_expr{opt_expr} {}
bool contextualize(Parse_context *pc) override;
private:
const enum_var_type m_scope;
const POS m_name_pos;
const LEX_CSTRING m_opt_prefix;
const LEX_CSTRING m_name;
Item *m_opt_expr;
};
class PT_option_value_no_option_type_charset
: public PT_option_value_no_option_type {
typedef PT_option_value_no_option_type super;
const CHARSET_INFO *opt_charset;
public:
PT_option_value_no_option_type_charset(const CHARSET_INFO *opt_charset_arg)
: opt_charset(opt_charset_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_option_value_no_option_type_names
: public PT_option_value_no_option_type {
typedef PT_option_value_no_option_type super;
POS pos;
public:
explicit PT_option_value_no_option_type_names(const POS &pos) : pos(pos) {}
bool contextualize(Parse_context *pc) override;
};
class PT_set_names : public PT_option_value_no_option_type {
typedef PT_option_value_no_option_type super;
const CHARSET_INFO *opt_charset;
const CHARSET_INFO *opt_collation;
public:
PT_set_names(const CHARSET_INFO *opt_charset_arg,
const CHARSET_INFO *opt_collation_arg)
: opt_charset(opt_charset_arg), opt_collation(opt_collation_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_start_option_value_list : public Parse_tree_node {};
class PT_option_value_no_option_type_password
: public PT_start_option_value_list {
typedef PT_start_option_value_list super;
const char *password;
const char *current_password;
bool retain_current_password;
bool random_password_generator;
POS expr_pos;
public:
PT_option_value_no_option_type_password(const char *password_arg,
const char *current_password_arg,
bool retain_current,
bool random_password,
const POS &expr_pos_arg)
: password(password_arg),
current_password(current_password_arg),
retain_current_password(retain_current),
random_password_generator(random_password),
expr_pos(expr_pos_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_option_value_no_option_type_password_for
: public PT_start_option_value_list {
typedef PT_start_option_value_list super;
LEX_USER *user;
const char *password;
const char *current_password;
bool retain_current_password;
bool random_password_generator;
POS expr_pos;
public:
PT_option_value_no_option_type_password_for(LEX_USER *user_arg,
const char *password_arg,
const char *current_password_arg,
bool retain_current,
bool random_pass,
const POS &expr_pos_arg)
: user(user_arg),
password(password_arg),
current_password(current_password_arg),
retain_current_password(retain_current),
random_password_generator(random_pass),
expr_pos(expr_pos_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_option_value_type : public Parse_tree_node {
typedef Parse_tree_node super;
enum_var_type type;
PT_set_scoped_system_variable *value;
public:
PT_option_value_type(enum_var_type type_arg,
PT_set_scoped_system_variable *value_arg)
: type(type_arg), value(value_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_option_value_list_head : public Parse_tree_node {
typedef Parse_tree_node super;
POS delimiter_pos;
Parse_tree_node *value;
POS value_pos;
public:
PT_option_value_list_head(const POS &delimiter_pos_arg,
Parse_tree_node *value_arg,
const POS &value_pos_arg)
: delimiter_pos(delimiter_pos_arg),
value(value_arg),
value_pos(value_pos_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_option_value_list : public PT_option_value_list_head {
typedef PT_option_value_list_head super;
PT_option_value_list_head *head;
public:
PT_option_value_list(PT_option_value_list_head *head_arg,
const POS &delimiter_pos_arg, Parse_tree_node *tail,
const POS &tail_pos)
: super(delimiter_pos_arg, tail, tail_pos), head(head_arg) {}
bool contextualize(Parse_context *pc) override {
uchar dummy;
if (check_stack_overrun(pc->thd, STACK_MIN_SIZE, &dummy)) return true;
return head->contextualize(pc) || super::contextualize(pc);
}
};
class PT_start_option_value_list_no_type : public PT_start_option_value_list {
typedef PT_start_option_value_list super;
PT_option_value_no_option_type *head;
POS head_pos;
PT_option_value_list_head *tail;
public:
PT_start_option_value_list_no_type(PT_option_value_no_option_type *head_arg,
const POS &head_pos_arg,
PT_option_value_list_head *tail_arg)
: head(head_arg), head_pos(head_pos_arg), tail(tail_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_transaction_characteristic : public Parse_tree_node {
typedef Parse_tree_node super;
const char *name;
int32 value;
public:
PT_transaction_characteristic(const char *name_arg, int32 value_arg)
: name(name_arg), value(value_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_transaction_access_mode : public PT_transaction_characteristic {
typedef PT_transaction_characteristic super;
public:
explicit PT_transaction_access_mode(bool is_read_only)
: super("transaction_read_only", (int32)is_read_only) {}
};
class PT_isolation_level : public PT_transaction_characteristic {
typedef PT_transaction_characteristic super;
public:
explicit PT_isolation_level(enum_tx_isolation level)
: super("transaction_isolation", (int32)level) {}
};
class PT_transaction_characteristics : public Parse_tree_node {
typedef Parse_tree_node super;
PT_transaction_characteristic *head;
PT_transaction_characteristic *opt_tail;
public:
PT_transaction_characteristics(PT_transaction_characteristic *head_arg,
PT_transaction_characteristic *opt_tail_arg)
: head(head_arg), opt_tail(opt_tail_arg) {}
bool contextualize(Parse_context *pc) override {
return (super::contextualize(pc) || head->contextualize(pc) ||
(opt_tail != nullptr && opt_tail->contextualize(pc)));
}
};
class PT_start_option_value_list_transaction
: public PT_start_option_value_list {
typedef PT_start_option_value_list super;
PT_transaction_characteristics *characteristics;
POS end_pos;
public:
PT_start_option_value_list_transaction(
PT_transaction_characteristics *characteristics_arg,
const POS &end_pos_arg)
: characteristics(characteristics_arg), end_pos(end_pos_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_start_option_value_list_following_option_type
: public Parse_tree_node {};
class PT_start_option_value_list_following_option_type_eq
: public PT_start_option_value_list_following_option_type {
typedef PT_start_option_value_list_following_option_type super;
PT_set_scoped_system_variable *head;
POS head_pos;
PT_option_value_list_head *opt_tail;
public:
PT_start_option_value_list_following_option_type_eq(
PT_set_scoped_system_variable *head_arg, const POS &head_pos_arg,
PT_option_value_list_head *opt_tail_arg)
: head(head_arg), head_pos(head_pos_arg), opt_tail(opt_tail_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_start_option_value_list_following_option_type_transaction
: public PT_start_option_value_list_following_option_type {
typedef PT_start_option_value_list_following_option_type super;
PT_transaction_characteristics *characteristics;
POS characteristics_pos;
public:
PT_start_option_value_list_following_option_type_transaction(
PT_transaction_characteristics *characteristics_arg,
const POS &characteristics_pos_arg)
: characteristics(characteristics_arg),
characteristics_pos(characteristics_pos_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_start_option_value_list_type : public PT_start_option_value_list {
typedef PT_start_option_value_list super;
enum_var_type type;
PT_start_option_value_list_following_option_type *list;
public:
PT_start_option_value_list_type(
enum_var_type type_arg,
PT_start_option_value_list_following_option_type *list_arg)
: type(type_arg), list(list_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_set : public Parse_tree_node {
typedef Parse_tree_node super;
POS set_pos;
PT_start_option_value_list *list;
public:
PT_set(const POS &set_pos_arg, PT_start_option_value_list *list_arg)
: set_pos(set_pos_arg), list(list_arg) {}
bool contextualize(Parse_context *pc) override;
};
class PT_into_destination : public Parse_tree_node {
typedef Parse_tree_node super;
POS m_pos;
protected:
PT_into_destination(const POS &pos) : m_pos(pos) {}
public:
bool contextualize(Parse_context *pc) override;
};
class PT_into_destination_outfile final : public PT_into_destination {
typedef PT_into_destination super;
public:
PT_into_destination_outfile(const POS &pos, const LEX_STRING &file_name_arg,
const CHARSET_INFO *charset_arg,
const Field_separators &field_term_arg,
const Line_separators &line_term_arg)
: PT_into_destination(pos), m_exchange(file_name_arg.str, false) {
m_exchange.cs = charset_arg;
m_exchange.field.merge_field_separators(field_term_arg);
m_exchange.line.merge_line_separators(line_term_arg);
}
bool contextualize(Parse_context *pc) override;
private:
sql_exchange m_exchange;
};
class PT_into_destination_dumpfile final : public PT_into_destination {
typedef PT_into_destination super;
public:
PT_into_destination_dumpfile(const POS &pos, const LEX_STRING &file_name_arg)
: PT_into_destination(pos), m_exchange(file_name_arg.str, true) {}
bool contextualize(Parse_context *pc) override;
private:
sql_exchange m_exchange;
};
class PT_select_var : public Parse_tree_node {
public:
const LEX_STRING name;
explicit PT_select_var(const LEX_STRING &name_arg) : name(name_arg) {}
virtual bool is_local() const { return false; }
virtual uint get_offset() const {
assert(0);
return 0;
}
};
class PT_select_sp_var : public PT_select_var {
typedef PT_select_var super;
uint offset;
#ifndef NDEBUG
/*
Routine to which this Item_splocal belongs. Used for checking if correct
runtime context is used for variable handling.
*/
sp_head *sp;
#endif
public:
PT_select_sp_var(const LEX_STRING &name_arg) : super(name_arg) {}
bool is_local() const override { return true; }
uint get_offset() const override { return offset; }
bool contextualize(Parse_context *pc) override;
};
class PT_select_var_list : public PT_into_destination {
typedef PT_into_destination super;
public:
explicit PT_select_var_list(const POS &pos) : PT_into_destination(pos) {}
List<PT_select_var> value;
bool contextualize(Parse_context *pc) override;
bool push_back(PT_select_var *var) { return value.push_back(var); }
};
/**
Parse tree node for a single of a window extent's borders,
cf. \<window frame extent\> in SQL 2003.
*/
class PT_border : public Parse_tree_node {
friend class Window;
Item *m_value{nullptr}; ///< only relevant iff m_border_type == WBT_VALUE_*
public:
enum_window_border_type m_border_type;
const bool m_date_time;
interval_type m_int_type;
///< For unbounded border
PT_border(enum_window_border_type type)
: m_border_type(type), m_date_time(false) {
assert(type != WBT_VALUE_PRECEDING && type != WBT_VALUE_FOLLOWING);
}
///< For bounded non-temporal border, e.g. 2 PRECEDING: 'value' is 2.
PT_border(enum_window_border_type type, Item *value)
: m_value(value), m_border_type(type), m_date_time(false) {}
///< For bounded INTERVAL 2 DAYS, 'value' is 2, int_type is DAYS.
PT_border(enum_window_border_type type, Item *value, interval_type int_type)
: m_value(value),
m_border_type(type),
m_date_time(true),
m_int_type(int_type) {}
///< @returns the '2' in '2 PRECEDING' or 'INTERVAL 2 DAYS PRECEDING'
Item *border() const { return m_value; }
/// Need such low-level access so that fix_fields updates the right pointer
Item **border_ptr() { return &m_value; }
/**
@returns Addition operator for computation of frames, nullptr if error.
@param order_expr Expression to add to/subtract from
@param prec true if PRECEDING
@param asc true if ASC
@param window only used for error generation
*/
Item *build_addop(Item_cache *order_expr, bool prec, bool asc,
const Window *window);
};
/**
Parse tree node for one or both of a window extent's borders, cf.
\<window frame extent\> in SQL 2003.
*/
class PT_borders : public Parse_tree_node {
PT_border *m_borders[2];
friend class PT_frame;
public:
/**
Constructor.
Frames of the form "frame_start no_frame_end" are translated during
parsing to "BETWEEN frame_start AND CURRENT ROW". So both 'start' and
'end' are non-nullptr.
*/
PT_borders(PT_border *start, PT_border *end) {
m_borders[0] = start;
m_borders[1] = end;
}
};
/**
Parse tree node for a window frame's exclusions, cf. the
\<window frame exclusion\> clause in SQL 2003.
*/
class PT_exclusion : public Parse_tree_node {
enum_window_frame_exclusion m_exclusion;
public:
PT_exclusion(enum_window_frame_exclusion e) : m_exclusion(e) {}
// enum_window_frame_exclusion exclusion() { return m_exclusion; }
};
/**
Parse tree node for a window's frame, cf. the \<window frame clause\>
in SQL 2003.
*/
class PT_frame : public Parse_tree_node {
public:
enum_window_frame_unit m_query_expression;
PT_border *m_from;
PT_border *m_to;
PT_exclusion *m_exclusion;
/// If true, this is an artificial frame, not specified by the user
bool m_originally_absent = false;
PT_frame(enum_window_frame_unit unit, PT_borders *from_to,
PT_exclusion *exclusion)
: m_query_expression(unit),
m_from(from_to->m_borders[0]),
m_to(from_to->m_borders[1]),
m_exclusion(exclusion) {}
};
class PT_query_primary : public PT_query_expression_body {};
class PT_query_specification : public PT_query_primary {
typedef PT_query_primary super;
PT_hint_list *opt_hints;
Query_options options;
PT_item_list *item_list;
PT_into_destination *opt_into1;
const bool m_is_from_clause_implicit;
Mem_root_array_YY<PT_table_reference *> from_clause; // empty list for DUAL
Item *opt_where_clause;
PT_group *opt_group_clause;
Item *opt_having_clause;
PT_window_list *opt_window_clause;
public:
PT_query_specification(
PT_hint_list *opt_hints_arg, const Query_options &options_arg,
PT_item_list *item_list_arg, PT_into_destination *opt_into1_arg,
const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
Item *opt_where_clause_arg, PT_group *opt_group_clause_arg,
Item *opt_having_clause_arg, PT_window_list *opt_window_clause_arg,
bool implicit_from_clause)
: opt_hints(opt_hints_arg),
options(options_arg),
item_list(item_list_arg),
opt_into1(opt_into1_arg),
m_is_from_clause_implicit{implicit_from_clause},
from_clause(from_clause_arg),
opt_where_clause(opt_where_clause_arg),
opt_group_clause(opt_group_clause_arg),
opt_having_clause(opt_having_clause_arg),
opt_window_clause(opt_window_clause_arg) {
assert(implicit_from_clause ? from_clause.empty() : true);
}
PT_query_specification(
const Query_options &options_arg, PT_item_list *item_list_arg,
const Mem_root_array_YY<PT_table_reference *> &from_clause_arg,
Item *opt_where_clause_arg)
: opt_hints(nullptr),
options(options_arg),
item_list(item_list_arg),
opt_into1(nullptr),
m_is_from_clause_implicit{true},
from_clause(from_clause_arg),
opt_where_clause(opt_where_clause_arg),
opt_group_clause(nullptr),
opt_having_clause(nullptr),
opt_window_clause(nullptr) {}
PT_query_specification(const Query_options &options_arg,
PT_item_list *item_list_arg)
: opt_hints(nullptr),
options(options_arg),
item_list(item_list_arg),
opt_into1(nullptr),
m_is_from_clause_implicit{false},
from_clause{},
opt_where_clause(nullptr),
opt_group_clause(nullptr),
opt_having_clause(nullptr),
opt_window_clause(nullptr) {}
bool contextualize(Parse_context *pc) override;
bool has_into_clause() const override { return opt_into1 != nullptr; }
bool has_trailing_into_clause() const override {
return (has_into_clause() && is_implicit_from_clause() &&
opt_where_clause == nullptr && opt_group_clause == nullptr &&
opt_having_clause == nullptr && opt_window_clause == nullptr);
}
bool is_set_operation() const override { return false; }
bool can_absorb_order_and_limit(bool, bool) const override { return true; }
bool is_table_value_constructor() const override { return false; }
PT_insert_values_list *get_row_value_list() const override { return nullptr; }
private:
bool is_implicit_from_clause() const { return m_is_from_clause_implicit; }
};
class PT_table_value_constructor : public PT_query_primary {
typedef PT_query_primary super;
PT_insert_values_list *const row_value_list;
public:
explicit PT_table_value_constructor(PT_insert_values_list *row_value_list_arg)
: row_value_list(row_value_list_arg) {}
bool contextualize(Parse_context *pc) override;
bool has_into_clause() const override { return false; }
bool has_trailing_into_clause() const override { return false; }
bool is_set_operation() const override { return false; }
bool can_absorb_order_and_limit(bool, bool) const override { return true; }
bool is_table_value_constructor() const override { return true; }
PT_insert_values_list *get_row_value_list() const override {
return row_value_list;
}
};
class PT_explicit_table : public PT_query_specification {
using super = PT_query_specification;
public:
PT_explicit_table(
const Query_options &options_arg, PT_item_list *item_list_arg,
const Mem_root_array_YY<PT_table_reference *> &from_clause_arg)
: super(options_arg, item_list_arg, from_clause_arg, nullptr) {}
};
class PT_query_expression final : public PT_query_expression_body {
public:
PT_query_expression(PT_with_clause *with_clause,
PT_query_expression_body *body, PT_order *order,
PT_limit_clause *limit)
: m_body(body),
m_order(order),
m_limit(limit),
m_with_clause(with_clause) {}
PT_query_expression(PT_query_expression_body *body, PT_order *order,
PT_limit_clause *limit)
: PT_query_expression(nullptr, body, order, limit) {}
explicit PT_query_expression(PT_query_expression_body *body)
: PT_query_expression(body, nullptr, nullptr) {}
bool contextualize(Parse_context *pc) override;
bool is_set_operation() const override { return m_body->is_set_operation(); }
bool has_into_clause() const override { return m_body->has_into_clause(); }
bool has_trailing_into_clause() const override {
return (m_body->has_trailing_into_clause() && m_order == nullptr &&
m_limit == nullptr);
}
bool contextualize_deferred_hints(Parse_context *pc) {
pc->thd->lex->opt_hints_global->deferred_hints_flag = true;
pc->thd->lex->opt_hints_global->deferred_hints->contextualize(pc);
pc->thd->lex->opt_hints_global->deferred_hints_flag = false;
return false;
}
bool can_absorb_order_and_limit(bool order, bool limit) const override {
if (m_body->is_set_operation()) {
return false;
}
if (m_order == nullptr && m_limit == nullptr) {
/*
It is safe to push ORDER and/or LIMIT down in:
(SELECT ...<no order or limit clauses>) ORDER BY ... LIMIT ...;
(SELECT ...<no order or limit clauses>) ORDER BY ...;
(SELECT ...<no order or limit clauses>) LIMIT ...;
*/
return true;
}
if (m_limit != nullptr && !order && limit) {
/*
In MySQL, it is ok(*) to push LIMIT down in:
(SELECT ... [ORDER BY ...] LIMIT a) LIMIT b;
*) MySQL doesn't follow the standard when overwriting `LIMIT a` with
`LIMIT b` if a < b. Moreover, the result of:
(SELECT ... ORDER BY order1 LIMIT a) ORDER BY order1 LIMIT b; (1)
can diverge from:
(SELECT ... ORDER BY order1 LIMIT a) LIMIT b; (2)
since the example (1) never overwrites `LIMIT a` with `LIMIT b`,
while the example (2) does overwrite.
TODO: add a warning, deprecate and replace this behavior with the
standard one.
*/
return true;
}
if (m_order != nullptr && m_limit == nullptr && !order && limit) {
/*
Allow pushdown of LIMIT into body with ORDER BY, e.g
(SELECT ... ORDER BY order1) LIMIT a;
*/
return true;
}
return false;
}
bool is_table_value_constructor() const override {
return m_body->is_table_value_constructor();
}
PT_insert_values_list *get_row_value_list() const override {
return m_body->get_row_value_list();
}
private:
/**
Contextualizes the order and limit clauses, re-interpreting them according
to the rules. If the `<query expression body>` can absorb the clauses,
they are simply contextualized into the current Query_block. If not, we
have to create the "fake" Query_block unless there is one already
(Query_expression::new_set_operation_query() is known to do this.)
@see PT_query_expression::can_absorb_order_and_limit()
*/
bool contextualize_order_and_limit(Parse_context *pc);
PT_query_expression_body *m_body;
PT_order *m_order;
PT_limit_clause *m_limit;
PT_with_clause *m_with_clause;
};
/*
After the removal of the `... <locking_clause> <into_clause>` syntax
PT_locking will disappear.
*/
class PT_locking final : public PT_query_expression_body {
using super = PT_query_expression_body;
public:
PT_locking(PT_query_expression_body *qe,
PT_locking_clause_list *locking_clauses)
: m_query_expression{qe}, m_locking_clauses{locking_clauses} {}
bool contextualize(Parse_context *pc) override {
return (super::contextualize(pc) || m_query_expression->contextualize(pc) ||
m_locking_clauses->contextualize(pc));
}
bool is_set_operation() const override {
return m_query_expression->is_set_operation();
}
bool has_into_clause() const override {
return m_query_expression->has_into_clause();
}
bool has_trailing_into_clause() const override { return false; }
bool can_absorb_order_and_limit(bool order, bool limit) const override {
return m_query_expression->can_absorb_order_and_limit(order, limit);
}
bool is_table_value_constructor() const override {
return m_query_expression->is_table_value_constructor();
}
PT_insert_values_list *get_row_value_list() const override {
return m_query_expression->get_row_value_list();
}
private:
PT_query_expression_body *const m_query_expression;
PT_locking_clause_list *const m_locking_clauses;
};
class PT_subquery : public Parse_tree_node {
typedef Parse_tree_node super;
PT_query_expression_body *qe;
POS pos;
Query_block *query_block;
public:
bool m_is_derived_table;
PT_subquery(POS p, PT_query_expression_body *query_expression)
: qe(query_expression),
pos(p),
query_block(nullptr),
m_is_derived_table(false) {}
bool contextualize(Parse_context *pc) override;
Query_block *value() { return query_block; }
};
class PT_set_operation : public PT_query_expression_body {
using super = PT_query_expression_body;
public:
PT_set_operation(PT_query_expression_body *lhs, bool is_distinct,
PT_query_expression_body *rhs,
bool is_rhs_in_parentheses = false)
: m_is_distinct(is_distinct),
m_is_rhs_in_parentheses{is_rhs_in_parentheses} {
m_list.push_back(lhs);
m_list.push_back(rhs);
}
void merge_descendants(Parse_context *pc, Query_term_set_op *setop,
QueryLevel &ql);
bool is_set_operation() const override { return true; }
bool has_into_clause() const override {
return std::any_of(m_list.cbegin(), m_list.cend(),
[](const PT_query_expression_body &body) {
return body.has_into_clause();
});
}
bool has_trailing_into_clause() const override {
return !m_is_rhs_in_parentheses &&
m_list[m_list.elements - 1]->has_trailing_into_clause();
}
bool can_absorb_order_and_limit(bool, bool) const override { return false; }
bool is_table_value_constructor() const override { return false; }
PT_insert_values_list *get_row_value_list() const override { return nullptr; }
bool is_distinct() const { return m_is_distinct; }
List<PT_query_expression_body> m_list;
void set_is_rhs_in_parentheses(bool v) { m_is_rhs_in_parentheses = v; }
protected:
bool contextualize_setop(Parse_context *pc, Query_term_type setop_type,
Surrounding_context context);
void merge_children(Query_term_set_op *setop, Query_term_set_op *lower);
bool m_is_distinct;
PT_into_destination *m_into;
bool m_is_rhs_in_parentheses;
};
class PT_union : public PT_set_operation {
using super = PT_set_operation;
public:
using PT_set_operation::PT_set_operation;
bool contextualize(Parse_context *pc) override;
enum Setop_type type() const override { return UNION; }
};
class PT_except : public PT_set_operation {
using super = PT_set_operation;
public:
using PT_set_operation::PT_set_operation;
bool contextualize(Parse_context *pc) override;
enum Setop_type type() const override { return EXCEPT; }
};
class PT_intersect : public PT_set_operation {
using super = PT_set_operation;
public:
using PT_set_operation::PT_set_operation;
bool contextualize(Parse_context *pc) override;
enum Setop_type type() const override { return INTERSECT; }
};
class PT_select_stmt : public Parse_tree_root {
typedef Parse_tree_root super;
public:
/**
@param qe The query expression.
@param sql_command The type of SQL command.
*/
PT_select_stmt(enum_sql_command sql_command, PT_query_expression_body *qe)
: m_sql_command(sql_command),
m_qe(qe),
m_into(nullptr),
m_has_trailing_locking_clauses{false} {}
/**
Creates a SELECT command. Only SELECT commands can have into.
@param qe The query expression.
@param into The own INTO destination.
@param has_trailing_locking_clauses True if there are locking clauses (like
`FOR UPDATE`) at the end of the
statement.
*/
explicit PT_select_stmt(PT_query_expression_body *qe,
PT_into_destination *into = nullptr,
bool has_trailing_locking_clauses = false)
: m_sql_command{SQLCOM_SELECT},
m_qe{qe},
m_into{into},
m_has_trailing_locking_clauses{has_trailing_locking_clauses} {}
Sql_cmd *make_cmd(THD *thd) override;
private:
enum_sql_command m_sql_command;
PT_query_expression_body *m_qe;
PT_into_destination *m_into;
const bool m_has_trailing_locking_clauses;
};
/**
Top-level node for the DELETE statement
@ingroup ptn_stmt
*/
class PT_delete final : public Parse_tree_root {
private:
PT_with_clause *m_with_clause;
PT_hint_list *opt_hints;
const int opt_delete_options;
Table_ident *table_ident;
const char *const opt_table_alias;
Mem_root_array_YY<Table_ident *> table_list;
List<String> *opt_use_partition;
Mem_root_array_YY<PT_table_reference *> join_table_list;
Item *opt_where_clause;
PT_order *opt_order_clause;
Item *opt_delete_limit_clause;
SQL_I_List<Table_ref> delete_tables;
public:
// single-table DELETE node constructor:
PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
int opt_delete_options_arg, Table_ident *table_ident_arg,
const LEX_CSTRING &opt_table_alias_arg,
List<String> *opt_use_partition_arg, Item *opt_where_clause_arg,
PT_order *opt_order_clause_arg, Item *opt_delete_limit_clause_arg)
: m_with_clause(with_clause_arg),
opt_hints(opt_hints_arg),
opt_delete_options(opt_delete_options_arg),
table_ident(table_ident_arg),
opt_table_alias(opt_table_alias_arg.str),
opt_use_partition(opt_use_partition_arg),
opt_where_clause(opt_where_clause_arg),
opt_order_clause(opt_order_clause_arg),
opt_delete_limit_clause(opt_delete_limit_clause_arg) {
table_list.init_empty_const();
join_table_list.init_empty_const();
}
// multi-table DELETE node constructor:
PT_delete(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
int opt_delete_options_arg,
const Mem_root_array_YY<Table_ident *> &table_list_arg,
const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
Item *opt_where_clause_arg)
: m_with_clause(with_clause_arg),
opt_hints(opt_hints_arg),
opt_delete_options(opt_delete_options_arg),
table_ident(nullptr),
opt_table_alias(nullptr),
table_list(table_list_arg),
opt_use_partition(nullptr),
join_table_list(join_table_list_arg),
opt_where_clause(opt_where_clause_arg),
opt_order_clause(nullptr),
opt_delete_limit_clause(nullptr) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
bool is_multitable() const {
assert((table_ident != nullptr) ^ (table_list.size() > 0));
return table_ident == nullptr;
}
bool add_table(Parse_context *pc, Table_ident *table);
};
/**
Top-level node for the UPDATE statement
@ingroup ptn_stmt
*/
class PT_update : public Parse_tree_root {
PT_with_clause *m_with_clause;
PT_hint_list *opt_hints;
thr_lock_type opt_low_priority;
bool opt_ignore;
Mem_root_array_YY<PT_table_reference *> join_table_list;
PT_item_list *column_list;
PT_item_list *value_list;
Item *opt_where_clause;
PT_order *opt_order_clause;
Item *opt_limit_clause;
public:
PT_update(PT_with_clause *with_clause_arg, PT_hint_list *opt_hints_arg,
thr_lock_type opt_low_priority_arg, bool opt_ignore_arg,
const Mem_root_array_YY<PT_table_reference *> &join_table_list_arg,
PT_item_list *column_list_arg, PT_item_list *value_list_arg,
Item *opt_where_clause_arg, PT_order *opt_order_clause_arg,
Item *opt_limit_clause_arg)
: m_with_clause(with_clause_arg),
opt_hints(opt_hints_arg),
opt_low_priority(opt_low_priority_arg),
opt_ignore(opt_ignore_arg),
join_table_list(join_table_list_arg),
column_list(column_list_arg),
value_list(value_list_arg),
opt_where_clause(opt_where_clause_arg),
opt_order_clause(opt_order_clause_arg),
opt_limit_clause(opt_limit_clause_arg) {}
Sql_cmd *make_cmd(THD *thd) override;
};
class PT_insert_values_list : public Parse_tree_node {
typedef Parse_tree_node super;
mem_root_deque<List_item *> many_values;
public:
explicit PT_insert_values_list(MEM_ROOT *mem_root) : many_values(mem_root) {}
bool contextualize(Parse_context *pc) override;
bool push_back(mem_root_deque<Item *> *x) {
many_values.push_back(x);
return false;
}
virtual mem_root_deque<List_item *> &get_many_values() {
assert(is_contextualized());
return many_values;
}
};
/**
Top-level node for the INSERT statement
@ingroup ptn_stmt
*/
class PT_insert final : public Parse_tree_root {
const bool is_replace;
PT_hint_list *opt_hints;
const thr_lock_type lock_option;
const bool ignore;
Table_ident *const table_ident;
List<String> *const opt_use_partition;
PT_item_list *const column_list;
PT_insert_values_list *row_value_list;
PT_query_expression_body *insert_query_expression;
const char *const opt_values_table_alias;
Create_col_name_list *const opt_values_column_list;
PT_item_list *const opt_on_duplicate_column_list;
PT_item_list *const opt_on_duplicate_value_list;
public:
PT_insert(bool is_replace_arg, PT_hint_list *opt_hints_arg,
thr_lock_type lock_option_arg, bool ignore_arg,
Table_ident *table_ident_arg, List<String> *opt_use_partition_arg,
PT_item_list *column_list_arg,
PT_insert_values_list *row_value_list_arg,
PT_query_expression_body *insert_query_expression_arg,
const LEX_CSTRING &opt_values_table_alias_arg,
Create_col_name_list *opt_values_column_list_arg,
PT_item_list *opt_on_duplicate_column_list_arg,
PT_item_list *opt_on_duplicate_value_list_arg)
: is_replace(is_replace_arg),
opt_hints(opt_hints_arg),
lock_option(lock_option_arg),
ignore(ignore_arg),
table_ident(table_ident_arg),
opt_use_partition(opt_use_partition_arg),
column_list(column_list_arg),
row_value_list(row_value_list_arg),
insert_query_expression(insert_query_expression_arg),
opt_values_table_alias(opt_values_table_alias_arg.str),
opt_values_column_list(opt_values_column_list_arg),
opt_on_duplicate_column_list(opt_on_duplicate_column_list_arg),
opt_on_duplicate_value_list(opt_on_duplicate_value_list_arg) {
// REPLACE statement can't have IGNORE flag:
assert(!is_replace || !ignore);
// REPLACE statement can't have ON DUPLICATE KEY UPDATE clause:
assert(!is_replace || opt_on_duplicate_column_list == nullptr);
// INSERT/REPLACE ... SELECT can't have VALUES clause:
assert((row_value_list != nullptr) ^ (insert_query_expression != nullptr));
// ON DUPLICATE KEY UPDATE: column and value arrays must have same sizes:
assert((opt_on_duplicate_column_list == nullptr &&
opt_on_duplicate_value_list == nullptr) ||
(opt_on_duplicate_column_list->elements() ==
opt_on_duplicate_value_list->elements()));
}
Sql_cmd *make_cmd(THD *thd) override;
private:
bool has_query_block() const { return insert_query_expression != nullptr; }
};
class PT_call final : public Parse_tree_root {
sp_name *proc_name;
PT_item_list *opt_expr_list;
public:
PT_call(sp_name *proc_name_arg, PT_item_list *opt_expr_list_arg)
: proc_name(proc_name_arg), opt_expr_list(opt_expr_list_arg) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/**
Top-level node for the SHUTDOWN statement
@ingroup ptn_stmt
*/
class PT_shutdown final : public Parse_tree_root {
Sql_cmd_shutdown sql_cmd;
public:
Sql_cmd *make_cmd(THD *) override { return &sql_cmd; }
};
/**
Top-level node for the CREATE [OR REPLACE] SPATIAL REFERENCE SYSTEM statement.
@ingroup ptn_stmt
*/
class PT_create_srs final : public Parse_tree_root {
/// The SQL command object.
Sql_cmd_create_srs sql_cmd;
/// Whether OR REPLACE is specified.
bool m_or_replace;
/// Whether IF NOT EXISTS is specified.
bool m_if_not_exists;
/// SRID of the SRS to create.
///
/// The range is larger than that of gis::srid_t, so it must be
/// verified to be less than the uint32 maximum value.
unsigned long long m_srid;
/// All attributes except SRID.
const Sql_cmd_srs_attributes m_attributes;
/// Check if a UTF-8 string contains control characters.
///
/// @note This function only checks single byte control characters (U+0000 to
/// U+001F, and U+007F). There are some control characters at U+0080 to U+00A0
/// that are not detected by this function.
///
/// @param str The string.
/// @param length Length of the string.
///
/// @retval false The string contains no control characters.
/// @retval true The string contains at least one control character.
bool contains_control_char(char *str, size_t length) {
for (size_t pos = 0; pos < length; pos++) {
if (std::iscntrl(str[pos])) return true;
}
return false;
}
public:
PT_create_srs(unsigned long long srid,
const Sql_cmd_srs_attributes &attributes, bool or_replace,
bool if_not_exists)
: m_or_replace(or_replace),
m_if_not_exists(if_not_exists),
m_srid(srid),
m_attributes(attributes) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/**
Top-level node for the DROP SPATIAL REFERENCE SYSTEM statement.
@ingroup ptn_stmt
*/
class PT_drop_srs final : public Parse_tree_root {
/// The SQL command object.
Sql_cmd_drop_srs sql_cmd;
/// SRID of the SRS to drop.
///
/// The range is larger than that of gis::srid_t, so it must be
/// verified to be less than the uint32 maximum value.
unsigned long long m_srid;
public:
PT_drop_srs(unsigned long long srid, bool if_exists)
: sql_cmd(srid, if_exists), m_srid(srid) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/**
Top-level node for the ALTER INSTANCE statement
@ingroup ptn_stmt
*/
class PT_alter_instance final : public Parse_tree_root {
Sql_cmd_alter_instance sql_cmd;
public:
explicit PT_alter_instance(
enum alter_instance_action_enum alter_instance_action,
const LEX_CSTRING &channel)
: sql_cmd(alter_instance_action, channel) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/**
A template-free base class for index options that we can predeclare in
sql_lex.h
*/
class PT_base_index_option : public Table_ddl_node {};
/**
A key part specification.
This can either be a "normal" key part (a key part that points to a column),
or this can be a functional key part (a key part that points to an
expression).
*/
class PT_key_part_specification : public Parse_tree_node {
typedef Parse_tree_node super;
public:
/**
Constructor for a functional key part.
@param expression The expression to index.
@param order The direction of the index.
*/
PT_key_part_specification(Item *expression, enum_order order);
/**
Constructor for a "normal" key part. That is a key part that points to a
column and not an expression.
@param column_name The column name that this key part points to.
@param order The direction of the index.
@param prefix_length How many bytes or characters this key part should
index, or zero if it should index the entire column.
*/
PT_key_part_specification(const LEX_CSTRING &column_name, enum_order order,
int prefix_length);
/**
Contextualize this key part specification. This will also call itemize on
the indexed expression if this is a functional key part.
@param pc The parse context
@retval true on error
@retval false on success
*/
bool contextualize(Parse_context *pc) override;
/**
Get the indexed expression. The caller must ensure that has_expression()
returns true before calling this.
@returns The indexed expression
*/
Item *get_expression() const {
assert(has_expression());
return m_expression;
}
/**
@returns The direction of the index: ORDER_ASC, ORDER_DESC or
ORDER_NOT_RELEVANT in case the user didn't explicitly specify a
direction.
*/
enum_order get_order() const { return m_order; }
/**
@retval true if the user explicitly specified a direction (asc/desc).
@retval false if the user didn't explicitly specify a direction.
*/
bool is_explicit() const { return get_order() != ORDER_NOT_RELEVANT; }
/**
@retval true if the key part contains an expression (and thus is a
functional key part).
@retval false if the key part doesn't contain an expression.
*/
bool has_expression() const { return m_expression != nullptr; }
/**
Get the column that this key part points to. This is only valid if this
key part isn't a functional index. The caller must thus check the return
value of has_expression() before calling this function.
@returns The column that this key part points to.
*/
LEX_CSTRING get_column_name() const {
assert(!has_expression());
return m_column_name;
}
/**
@returns The number of bytes that this key part should index. If the column
this key part points to is a non-binary column, this is the number
of characters. Returns zero if the entire column should be indexed.
*/
int get_prefix_length() const { return m_prefix_length; }
private:
/**
The indexed expression in case this is a functional key part. Only valid if
has_expression() returns true.
*/
Item *m_expression;
/// The direction of the index.
enum_order m_order;
/// The name of the column that this key part indexes.
LEX_CSTRING m_column_name;
/**
If this is greater than zero, it represents how many bytes of the column
that is indexed. Note that for non-binary columns (VARCHAR, TEXT etc), this
is the number of characters.
*/
int m_prefix_length;
};
/**
A template for options that set a single `<alter option>` value in
thd->lex->key_create_info.
@tparam Option_type The data type of the option.
@tparam Property Pointer-to-member for the option of KEY_CREATE_INFO.
*/
template <typename Option_type, Option_type KEY_CREATE_INFO::*Property>
class PT_index_option : public PT_base_index_option {
public:
/// @param option_value The value of the option.
PT_index_option(Option_type option_value) : m_option_value(option_value) {}
bool contextualize(Table_ddl_parse_context *pc) override {
pc->key_create_info->*Property = m_option_value;
return false;
}
private:
Option_type m_option_value;
};
/**
A template for options that set a single property in a KEY_CREATE_INFO, and
also records if the option was explicitly set.
*/
template <typename Option_type, Option_type KEY_CREATE_INFO::*Property,
bool KEY_CREATE_INFO::*Property_is_explicit>
class PT_traceable_index_option : public PT_base_index_option {
public:
PT_traceable_index_option(Option_type option_value)
: m_option_value(option_value) {}
bool contextualize(Table_ddl_parse_context *pc) override {
pc->key_create_info->*Property = m_option_value;
pc->key_create_info->*Property_is_explicit = true;
return false;
}
private:
Option_type m_option_value;
};
typedef Mem_root_array_YY<PT_base_index_option *> Index_options;
typedef PT_index_option<ulong, &KEY_CREATE_INFO::block_size> PT_block_size;
typedef PT_index_option<LEX_CSTRING, &KEY_CREATE_INFO::comment>
PT_index_comment;
typedef PT_index_option<LEX_CSTRING, &KEY_CREATE_INFO::parser_name>
PT_fulltext_index_parser_name;
typedef PT_index_option<bool, &KEY_CREATE_INFO::is_visible> PT_index_visibility;
/**
The data structure (B-tree, Hash, etc) used for an index is called
'index_type' in the manual. Internally, this is stored in
KEY_CREATE_INFO::algorithm, while what the manual calls 'algorithm' is
stored in partition_info::key_algorithm. In an `<create_index_stmt>`
it's ignored. The terminology is somewhat confusing, but we stick to the
manual in the parser.
*/
typedef PT_traceable_index_option<ha_key_alg, &KEY_CREATE_INFO::algorithm,
&KEY_CREATE_INFO::is_algorithm_explicit>
PT_index_type;
class PT_create_index_stmt final : public PT_table_ddl_stmt_base {
public:
PT_create_index_stmt(MEM_ROOT *mem_root, keytype type_par,
const LEX_STRING &name_arg, PT_base_index_option *type,
Table_ident *table_ident,
List<PT_key_part_specification> *cols,
Index_options options,
Alter_info::enum_alter_table_algorithm algo,
Alter_info::enum_alter_table_lock lock)
: PT_table_ddl_stmt_base(mem_root),
m_keytype(type_par),
m_name(name_arg),
m_type(type),
m_table_ident(table_ident),
m_columns(cols),
m_options(options),
m_algo(algo),
m_lock(lock) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
keytype m_keytype;
LEX_STRING m_name;
PT_base_index_option *m_type;
Table_ident *m_table_ident;
List<PT_key_part_specification> *m_columns;
Index_options m_options;
const Alter_info::enum_alter_table_algorithm m_algo;
const Alter_info::enum_alter_table_lock m_lock;
};
/**
Base class for column/constraint definitions in CREATE %TABLE
@ingroup ptn_create_table_stuff
*/
class PT_table_element : public Table_ddl_node {};
class PT_table_constraint_def : public PT_table_element {};
class PT_inline_index_definition : public PT_table_constraint_def {
typedef PT_table_constraint_def super;
public:
PT_inline_index_definition(keytype type_par, const LEX_STRING &name_arg,
PT_base_index_option *type,
List<PT_key_part_specification> *cols,
Index_options options)
: m_keytype(type_par),
m_name(name_arg),
m_type(type),
m_columns(cols),
m_options(options) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
keytype m_keytype;
const LEX_STRING m_name;
PT_base_index_option *m_type;
List<PT_key_part_specification> *m_columns;
Index_options m_options;
};
class PT_foreign_key_definition : public PT_table_constraint_def {
typedef PT_table_constraint_def super;
public:
PT_foreign_key_definition(const LEX_STRING &constraint_name,
const LEX_STRING &key_name,
List<PT_key_part_specification> *columns,
Table_ident *referenced_table,
List<Key_part_spec> *ref_list,
fk_match_opt fk_match_option,
fk_option fk_update_opt, fk_option fk_delete_opt)
: m_constraint_name(constraint_name),
m_key_name(key_name),
m_columns(columns),
m_referenced_table(referenced_table),
m_ref_list(ref_list),
m_fk_match_option(fk_match_option),
m_fk_update_opt(fk_update_opt),
m_fk_delete_opt(fk_delete_opt) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
const LEX_STRING m_constraint_name;
const LEX_STRING m_key_name;
List<PT_key_part_specification> *m_columns;
Table_ident *m_referenced_table;
List<Key_part_spec> *m_ref_list;
fk_match_opt m_fk_match_option;
fk_option m_fk_update_opt;
fk_option m_fk_delete_opt;
};
/**
Common base class for CREATE TABLE and ALTER TABLE option nodes
@ingroup ptn_create_or_alter_table_options
*/
class PT_ddl_table_option : public Table_ddl_node {
public:
~PT_ddl_table_option() override = 0; // Force abstract class declaration
virtual bool is_rename_table() const { return false; }
};
inline PT_ddl_table_option::~PT_ddl_table_option() = default;
/**
Base class for CREATE TABLE option nodes
@ingroup ptn_create_or_alter_table_options
*/
class PT_create_table_option : public PT_ddl_table_option {
typedef PT_ddl_table_option super;
public:
~PT_create_table_option() override = 0; // Force abstract class declaration
bool contextualize(Table_ddl_parse_context *pc) override {
if (super::contextualize(pc)) return true;
pc->alter_info->flags |= Alter_info::ALTER_OPTIONS;
return false;
}
};
inline PT_create_table_option::~PT_create_table_option() = default;
/**
A template for options that set a single property in HA_CREATE_INFO, and
also records if the option was explicitly set.
*/
template <typename Option_type, Option_type HA_CREATE_INFO::*Property,
uint64_t Property_flag>
class PT_traceable_create_table_option : public PT_create_table_option {
typedef PT_create_table_option super;
const Option_type value;
public:
explicit PT_traceable_create_table_option(Option_type value) : value(value) {}
bool contextualize(Table_ddl_parse_context *pc) override {
if (super::contextualize(pc)) return true;
pc->create_info->*Property = value;
pc->create_info->used_fields |= Property_flag;
return false;
}
};
#define TYPE_AND_REF(x) decltype(x), &x
/**
Node for the @SQL{MAX_ROWS [=] @B{@<integer@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
typedef PT_traceable_create_table_option<TYPE_AND_REF(HA_CREATE_INFO::max_rows),
HA_CREATE_USED_MAX_ROWS>
PT_create_max_rows_option;
/**
Node for the @SQL{MIN_ROWS [=] @B{@<integer@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
typedef PT_traceable_create_table_option<TYPE_AND_REF(HA_CREATE_INFO::min_rows),
HA_CREATE_USED_MIN_ROWS>
PT_create_min_rows_option;
/**
Node for the @SQL{AVG_ROW_LENGTH_ROWS [=] @B{@<integer@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::avg_row_length), HA_CREATE_USED_AVG_ROW_LENGTH>
PT_create_avg_row_length_option;
/**
Node for the @SQL{PASSWORD [=] @B{@<string@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
typedef PT_traceable_create_table_option<TYPE_AND_REF(HA_CREATE_INFO::password),
HA_CREATE_USED_PASSWORD>
PT_create_password_option;
/**
Node for the @SQL{COMMENT [=] @B{@<string@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
typedef PT_traceable_create_table_option<TYPE_AND_REF(HA_CREATE_INFO::comment),
HA_CREATE_USED_COMMENT>
PT_create_commen_option;
/**
Node for the @SQL{COMPRESSION [=] @B{@<string@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
typedef PT_traceable_create_table_option<TYPE_AND_REF(HA_CREATE_INFO::compress),
HA_CREATE_USED_COMPRESS>
PT_create_compress_option;
/**
Node for the @SQL{ENGRYPTION [=] @B{@<string@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::encrypt_type), HA_CREATE_USED_ENCRYPT>
PT_create_encryption_option;
/**
Node for the @SQL{AUTO_INCREMENT [=] @B{@<integer@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::auto_increment_value), HA_CREATE_USED_AUTO>
PT_create_auto_increment_option;
typedef PT_traceable_create_table_option<TYPE_AND_REF(HA_CREATE_INFO::row_type),
HA_CREATE_USED_ROW_FORMAT>
PT_create_row_format_option;
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::merge_insert_method),
HA_CREATE_USED_INSERT_METHOD>
PT_create_insert_method_option;
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::data_file_name), HA_CREATE_USED_DATADIR>
PT_create_data_directory_option;
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::index_file_name), HA_CREATE_USED_INDEXDIR>
PT_create_index_directory_option;
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::tablespace), HA_CREATE_USED_TABLESPACE>
PT_create_tablespace_option;
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::connect_string), HA_CREATE_USED_CONNECTION>
PT_create_connection_option;
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::key_block_size), HA_CREATE_USED_KEY_BLOCK_SIZE>
PT_create_key_block_size_option;
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::m_transactional_ddl),
HA_CREATE_USED_START_TRANSACTION>
PT_create_start_transaction_option;
typedef PT_traceable_create_table_option<
TYPE_AND_REF(HA_CREATE_INFO::m_implicit_tablespace_autoextend_size),
HA_CREATE_USED_AUTOEXTEND_SIZE>
PT_create_ts_autoextend_size_option;
typedef decltype(HA_CREATE_INFO::table_options) table_options_t;
/**
A template for options that set HA_CREATE_INFO::table_options and
also records if the option was explicitly set.
*/
template <ulong Property_flag, table_options_t Default, table_options_t Yes,
table_options_t No>
class PT_ternary_create_table_option : public PT_create_table_option {
typedef PT_create_table_option super;
const Ternary_option value;
public:
explicit PT_ternary_create_table_option(Ternary_option value)
: value(value) {}
bool contextualize(Table_ddl_parse_context *pc) override {
if (super::contextualize(pc)) return true;
pc->create_info->table_options &= ~(Yes | No);
switch (value) {
case Ternary_option::ON:
pc->create_info->table_options |= Yes;
break;
case Ternary_option::OFF:
pc->create_info->table_options |= No;
break;
case Ternary_option::DEFAULT:
break;
default:
assert(false);
}
pc->create_info->used_fields |= Property_flag;
return false;
}
};
/**
Node for the @SQL{PACK_KEYS [=] @B{1|0|DEFAULT}} table option
@ingroup ptn_create_or_alter_table_options
PACK_KEYS | Constructor parameter
----------|----------------------
1 | Ternary_option::ON
0 | Ternary_option::OFF
DEFAULT | Ternary_option::DEFAULT
*/
typedef PT_ternary_create_table_option<HA_CREATE_USED_PACK_KEYS, // flag
0, // DEFAULT
HA_OPTION_PACK_KEYS, // ON
HA_OPTION_NO_PACK_KEYS> // OFF
PT_create_pack_keys_option;
/**
Node for the @SQL{STATS_PERSISTENT [=] @B{1|0|DEFAULT}} table option
@ingroup ptn_create_or_alter_table_options
STATS_PERSISTENT | Constructor parameter
-----------------|----------------------
1 | Ternary_option::ON
0 | Ternary_option::OFF
DEFAULT | Ternary_option::DEFAULT
*/
typedef PT_ternary_create_table_option<HA_CREATE_USED_STATS_PERSISTENT, // flag
0, // DEFAULT
HA_OPTION_STATS_PERSISTENT, // ON
HA_OPTION_NO_STATS_PERSISTENT> // OFF
PT_create_stats_persistent_option;
/**
A template for options that set HA_CREATE_INFO::table_options and
also records if the option was explicitly set.
*/
template <ulong Property_flag, table_options_t Yes, table_options_t No>
class PT_bool_create_table_option : public PT_create_table_option {
typedef PT_create_table_option super;
const bool value;
public:
explicit PT_bool_create_table_option(bool value) : value(value) {}
bool contextualize(Table_ddl_parse_context *pc) override {
if (super::contextualize(pc)) return true;
pc->create_info->table_options &= ~(Yes | No);
pc->create_info->table_options |= value ? Yes : No;
pc->create_info->used_fields |= Property_flag;
return false;
}
};
/**
Node for the @SQL{CHECKSUM|TABLE_CHECKSUM [=] @B{0|@<not 0@>}} table option
@ingroup ptn_create_or_alter_table_options
TABLE_CHECKSUM | Constructor parameter
---------------|----------------------
0 | false
not 0 | true
*/
typedef PT_bool_create_table_option<HA_CREATE_USED_CHECKSUM, // flag
HA_OPTION_CHECKSUM, // ON
HA_OPTION_NO_CHECKSUM // OFF
>
PT_create_checksum_option;
/**
Node for the @SQL{DELAY_KEY_WRITE [=] @B{0|@<not 0@>}} table option
@ingroup ptn_create_or_alter_table_options
TABLE_CHECKSUM | Constructor parameter
---------------|----------------------
0 | false
not 0 | true
*/
typedef PT_bool_create_table_option<HA_CREATE_USED_DELAY_KEY_WRITE, // flag
HA_OPTION_DELAY_KEY_WRITE, // ON
HA_OPTION_NO_DELAY_KEY_WRITE> // OFF
PT_create_delay_key_write_option;
/**
Node for the @SQL{ENGINE [=] @B{@<identifier@>|@<string@>}} table option
@ingroup ptn_create_or_alter_table_options
*/
class PT_create_table_engine_option : public PT_create_table_option {
typedef PT_create_table_option super;
const LEX_CSTRING engine;
public:
/**
@param engine Storage engine name.
*/
explicit PT_create_table_engine_option(const LEX_CSTRING &engine)
: engine(engine) {}
bool contextualize(Table_ddl_parse_context *pc) override;
};
/**
Node for the @SQL{SECONDARY_ENGINE [=] @B{@<identifier@>|@<string@>|NULL}}
table option.
@ingroup ptn_create_or_alter_table_options
*/
class PT_create_table_secondary_engine_option : public PT_create_table_option {
using super = PT_create_table_option;
public:
explicit PT_create_table_secondary_engine_option() = default;
explicit PT_create_table_secondary_engine_option(
const LEX_CSTRING &secondary_engine)
: m_secondary_engine(secondary_engine) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
const LEX_CSTRING m_secondary_engine{nullptr, 0};
};
/**
Node for the @SQL{STATS_AUTO_RECALC [=] @B{@<0|1|DEFAULT@>})} table option
@ingroup ptn_create_or_alter_table_options
*/
class PT_create_stats_auto_recalc_option : public PT_create_table_option {
typedef PT_create_table_option super;
const Ternary_option value;
public:
/**
@param value
STATS_AUTO_RECALC | value
------------------|----------------------
1 | Ternary_option::ON
0 | Ternary_option::OFF
DEFAULT | Ternary_option::DEFAULT
*/
PT_create_stats_auto_recalc_option(Ternary_option value) : value(value) {}
bool contextualize(Table_ddl_parse_context *pc) override;
};
/**
Node for the @SQL{STATS_SAMPLE_PAGES [=] @B{@<integer@>|DEFAULT}} table option
@ingroup ptn_create_or_alter_table_options
*/
class PT_create_stats_stable_pages : public PT_create_table_option {
typedef PT_create_table_option super;
typedef decltype(HA_CREATE_INFO::stats_sample_pages) value_t;
const value_t value;
public:
/**
Constructor for implicit number of pages
@param value Number of pages, 1@<=N@<=65535.
*/
explicit PT_create_stats_stable_pages(value_t value) : value(value) {
assert(value != 0 && value <= 0xFFFF);
}
/**
Constructor for the DEFAULT number of pages
*/
PT_create_stats_stable_pages() : value(0) {} // DEFAULT
bool contextualize(Table_ddl_parse_context *pc) override;
};
class PT_create_union_option : public PT_create_table_option {
typedef PT_create_table_option super;
const Mem_root_array<Table_ident *> *tables;
public:
explicit PT_create_union_option(const Mem_root_array<Table_ident *> *tables)
: tables(tables) {}
bool contextualize(Table_ddl_parse_context *pc) override;
};
class PT_create_storage_option : public PT_create_table_option {
typedef PT_create_table_option super;
const ha_storage_media value;
public:
explicit PT_create_storage_option(ha_storage_media value) : value(value) {}
bool contextualize(Table_ddl_parse_context *pc) override {
if (super::contextualize(pc)) return true;
pc->create_info->storage_media = value;
return false;
}
};
class PT_create_table_default_charset : public PT_create_table_option {
typedef PT_create_table_option super;
const CHARSET_INFO *value;
public:
explicit PT_create_table_default_charset(const CHARSET_INFO *value)
: value(value) {
assert(value != nullptr);
}
bool contextualize(Table_ddl_parse_context *pc) override;
};
class PT_create_table_default_collation : public PT_create_table_option {
typedef PT_create_table_option super;
const CHARSET_INFO *value;
public:
explicit PT_create_table_default_collation(const CHARSET_INFO *value)
: value(value) {
assert(value != nullptr);
}
bool contextualize(Table_ddl_parse_context *pc) override;
};
class PT_check_constraint final : public PT_table_constraint_def {
typedef PT_table_constraint_def super;
Sql_check_constraint_spec cc_spec;
public:
explicit PT_check_constraint(LEX_STRING &name, Item *expr, bool is_enforced) {
cc_spec.name = name;
cc_spec.check_expr = expr;
cc_spec.is_enforced = is_enforced;
}
void set_column_name(const LEX_STRING &name) { cc_spec.column_name = name; }
bool contextualize(Table_ddl_parse_context *pc) override;
};
class PT_column_def : public PT_table_element {
typedef PT_table_element super;
const LEX_STRING field_ident;
PT_field_def_base *field_def;
// Currently we ignore that constraint in the executor.
PT_table_constraint_def *opt_column_constraint;
const char *opt_place;
public:
PT_column_def(const LEX_STRING &field_ident, PT_field_def_base *field_def,
PT_table_constraint_def *opt_column_constraint,
const char *opt_place = nullptr)
: field_ident(field_ident),
field_def(field_def),
opt_column_constraint(opt_column_constraint),
opt_place(opt_place) {}
bool contextualize(Table_ddl_parse_context *pc) override;
};
/**
Top-level node for the CREATE %TABLE statement
@ingroup ptn_create_table
*/
class PT_create_table_stmt final : public PT_table_ddl_stmt_base {
bool is_temporary;
bool only_if_not_exists;
Table_ident *table_name;
const Mem_root_array<PT_table_element *> *opt_table_element_list;
const Mem_root_array<PT_create_table_option *> *opt_create_table_options;
PT_partition *opt_partitioning;
On_duplicate on_duplicate;
PT_query_expression_body *opt_query_expression;
Table_ident *opt_like_clause;
HA_CREATE_INFO m_create_info;
public:
/**
@param mem_root MEM_ROOT to use for allocation
@param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}
@param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}
@param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}
@param opt_table_element_list NULL or a list of table column and
constraint definitions.
@param opt_create_table_options NULL or a list of
@ref ptn_create_or_alter_table_options
"table options".
@param opt_partitioning NULL or the @SQL{PARTITION BY} clause.
@param on_duplicate DUPLICATE, IGNORE or fail with an error
on data duplication errors (relevant
for @SQL{CREATE TABLE ... SELECT}
statements).
@param opt_query_expression NULL or the @SQL{@B{SELECT}} clause.
*/
PT_create_table_stmt(
MEM_ROOT *mem_root, bool is_temporary, bool only_if_not_exists,
Table_ident *table_name,
const Mem_root_array<PT_table_element *> *opt_table_element_list,
const Mem_root_array<PT_create_table_option *> *opt_create_table_options,
PT_partition *opt_partitioning, On_duplicate on_duplicate,
PT_query_expression_body *opt_query_expression)
: PT_table_ddl_stmt_base(mem_root),
is_temporary(is_temporary),
only_if_not_exists(only_if_not_exists),
table_name(table_name),
opt_table_element_list(opt_table_element_list),
opt_create_table_options(opt_create_table_options),
opt_partitioning(opt_partitioning),
on_duplicate(on_duplicate),
opt_query_expression(opt_query_expression),
opt_like_clause(nullptr) {}
/**
@param mem_root MEM_ROOT to use for allocation
@param is_temporary True if @SQL{CREATE @B{TEMPORARY} %TABLE}.
@param only_if_not_exists True if @SQL{CREATE %TABLE ... @B{IF NOT EXISTS}}.
@param table_name @SQL{CREATE %TABLE ... @B{@<table name@>}}.
@param opt_like_clause NULL or the @SQL{@B{LIKE @<table name@>}} clause.
*/
PT_create_table_stmt(MEM_ROOT *mem_root, bool is_temporary,
bool only_if_not_exists, Table_ident *table_name,
Table_ident *opt_like_clause)
: PT_table_ddl_stmt_base(mem_root),
is_temporary(is_temporary),
only_if_not_exists(only_if_not_exists),
table_name(table_name),
opt_table_element_list(nullptr),
opt_create_table_options(nullptr),
opt_partitioning(nullptr),
on_duplicate(On_duplicate::ERROR),
opt_query_expression(nullptr),
opt_like_clause(opt_like_clause) {}
Sql_cmd *make_cmd(THD *thd) override;
};
class PT_create_role final : public Parse_tree_root {
Sql_cmd_create_role sql_cmd;
public:
PT_create_role(bool if_not_exists, const List<LEX_USER> *roles)
: sql_cmd(if_not_exists, roles) {}
Sql_cmd *make_cmd(THD *thd) override;
};
class PT_drop_role final : public Parse_tree_root {
Sql_cmd_drop_role sql_cmd;
public:
explicit PT_drop_role(bool ignore_errors, const List<LEX_USER> *roles)
: sql_cmd(ignore_errors, roles) {}
Sql_cmd *make_cmd(THD *thd) override;
};
class PT_set_role : public Parse_tree_root {
Sql_cmd_set_role sql_cmd;
public:
explicit PT_set_role(role_enum role_type,
const List<LEX_USER> *opt_except_roles = nullptr)
: sql_cmd(role_type, opt_except_roles) {
assert(role_type == role_enum::ROLE_ALL || opt_except_roles == nullptr);
}
explicit PT_set_role(const List<LEX_USER> *roles) : sql_cmd(roles) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/**
This class is used for representing both static and dynamic privileges on
global as well as table and column level.
*/
struct Privilege {
enum privilege_type { STATIC, DYNAMIC };
privilege_type type;
const Mem_root_array<LEX_CSTRING> *columns;
explicit Privilege(privilege_type type,
const Mem_root_array<LEX_CSTRING> *columns)
: type(type), columns(columns) {}
};
struct Static_privilege : public Privilege {
const uint grant;
Static_privilege(uint grant, const Mem_root_array<LEX_CSTRING> *columns_arg)
: Privilege(STATIC, columns_arg), grant(grant) {}
};
struct Dynamic_privilege : public Privilege {
const LEX_STRING ident;
Dynamic_privilege(const LEX_STRING &ident,
const Mem_root_array<LEX_CSTRING> *columns_arg)
: Privilege(DYNAMIC, columns_arg), ident(ident) {}
};
class PT_role_or_privilege : public Parse_tree_node {
private:
POS pos;
public:
explicit PT_role_or_privilege(const POS &pos) : pos(pos) {}
virtual LEX_USER *get_user(THD *thd);
virtual Privilege *get_privilege(THD *thd);
};
class PT_role_at_host final : public PT_role_or_privilege {
LEX_STRING role;
LEX_STRING host;
public:
PT_role_at_host(const POS &pos, const LEX_STRING &role,
const LEX_STRING &host)
: PT_role_or_privilege(pos), role(role), host(host) {}
LEX_USER *get_user(THD *thd) override;
};
class PT_role_or_dynamic_privilege final : public PT_role_or_privilege {
LEX_STRING ident;
public:
PT_role_or_dynamic_privilege(const POS &pos, const LEX_STRING &ident)
: PT_role_or_privilege(pos), ident(ident) {}
LEX_USER *get_user(THD *thd) override;
Privilege *get_privilege(THD *thd) override;
};
class PT_static_privilege final : public PT_role_or_privilege {
const uint grant;
const Mem_root_array<LEX_CSTRING> *columns;
public:
PT_static_privilege(const POS &pos, uint grant,
const Mem_root_array<LEX_CSTRING> *columns = nullptr)
: PT_role_or_privilege(pos), grant(grant), columns(columns) {}
Privilege *get_privilege(THD *thd) override;
};
class PT_dynamic_privilege final : public PT_role_or_privilege {
LEX_STRING ident;
public:
PT_dynamic_privilege(const POS &pos, const LEX_STRING &ident)
: PT_role_or_privilege(pos), ident(ident) {}
Privilege *get_privilege(THD *thd) override;
};
class PT_grant_roles final : public Parse_tree_root {
const Mem_root_array<PT_role_or_privilege *> *roles;
const List<LEX_USER> *users;
const bool with_admin_option;
public:
PT_grant_roles(const Mem_root_array<PT_role_or_privilege *> *roles,
const List<LEX_USER> *users, bool with_admin_option)
: roles(roles), users(users), with_admin_option(with_admin_option) {}
Sql_cmd *make_cmd(THD *thd) override;
};
class PT_revoke_roles final : public Parse_tree_root {
const Mem_root_array<PT_role_or_privilege *> *roles;
const List<LEX_USER> *users;
public:
PT_revoke_roles(Mem_root_array<PT_role_or_privilege *> *roles,
const List<LEX_USER> *users)
: roles(roles), users(users) {}
Sql_cmd *make_cmd(THD *thd) override;
};
class PT_alter_user_default_role final : public Parse_tree_root {
Sql_cmd_alter_user_default_role sql_cmd;
public:
PT_alter_user_default_role(bool if_exists, const List<LEX_USER> *users,
const List<LEX_USER> *roles,
const role_enum role_type)
: sql_cmd(if_exists, users, roles, role_type) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/// Base class for Parse tree nodes of SHOW statements
class PT_show_base : public Parse_tree_root {
protected:
PT_show_base(const POS &pos, enum_sql_command sql_command)
: m_pos(pos), m_sql_command(sql_command) {}
/// Textual location of a token just parsed.
POS m_pos;
/// SQL command
enum_sql_command m_sql_command;
};
/// Base class for Parse tree nodes of SHOW statements with LIKE/WHERE parameter
class PT_show_filter_base : public PT_show_base {
protected:
PT_show_filter_base(const POS &pos, enum_sql_command sql_command,
const LEX_STRING &wild, Item *where)
: PT_show_base(pos, sql_command), m_wild(wild), m_where(where) {
assert(m_wild.str == nullptr || m_where == nullptr);
}
/// Wild or where clause used in the statement.
LEX_STRING m_wild;
Item *m_where;
};
/// Base class for Parse tree nodes of SHOW statements with schema parameter.
class PT_show_schema_base : public PT_show_base {
protected:
PT_show_schema_base(const POS &pos, enum_sql_command sql_command,
char *opt_db, const LEX_STRING &wild, Item *where)
: PT_show_base(pos, sql_command),
m_opt_db(opt_db),
m_wild(wild),
m_where(where) {
assert(m_wild.str == nullptr || m_where == nullptr);
}
/// Optional schema name in FROM/IN clause.
char *m_opt_db;
/// Wild or where clause used in the statement.
LEX_STRING m_wild;
Item *m_where;
};
/// Base class for Parse tree nodes of SHOW COLUMNS/SHOW INDEX statements.
class PT_show_table_base : public PT_show_filter_base {
protected:
PT_show_table_base(const POS &pos, enum_sql_command sql_command,
Table_ident *table_ident, const LEX_STRING &wild,
Item *where)
: PT_show_filter_base(pos, sql_command, wild, where),
m_table_ident(table_ident) {}
bool make_table_base_cmd(THD *thd, bool *temporary);
/// Table used in the statement.
Table_ident *m_table_ident;
};
/// Parse tree node for SHOW FUNCTION/PROCEDURE CODE statements.
class PT_show_routine_code : public PT_show_base {
protected:
PT_show_routine_code(const POS &pos, enum_sql_command sql_command,
const sp_name *routine_name)
: PT_show_base(pos, sql_command), m_sql_cmd(sql_command, routine_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_routine_code m_sql_cmd;
};
/// Parse tree node for SHOW BINLOG EVENTS statement
class PT_show_binlog_events final : public PT_show_base {
public:
PT_show_binlog_events(const POS &pos, const LEX_STRING opt_log_file_name = {},
PT_limit_clause *opt_limit_clause = nullptr)
: PT_show_base(pos, SQLCOM_SHOW_BINLOG_EVENTS),
m_opt_log_file_name(opt_log_file_name),
m_opt_limit_clause(opt_limit_clause) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
const LEX_STRING m_opt_log_file_name;
PT_limit_clause *const m_opt_limit_clause;
Sql_cmd_show_binlog_events m_sql_cmd;
};
/// Parse tree node for SHOW BINLOGS statement
class PT_show_binlogs final : public PT_show_base {
public:
PT_show_binlogs(const POS &pos) : PT_show_base(pos, SQLCOM_SHOW_BINLOGS) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_binlogs m_sql_cmd;
};
/// Parse tree node for SHOW CHARACTER SET statement
class PT_show_charsets final : public PT_show_filter_base {
public:
PT_show_charsets(const POS &pos, const LEX_STRING &wild, Item *where)
: PT_show_filter_base(pos, SQLCOM_SHOW_CHARSETS, wild, where) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_charsets m_sql_cmd;
};
/// Parse tree node for SHOW COLLATIONS statement
class PT_show_collations final : public PT_show_filter_base {
public:
PT_show_collations(const POS &pos, const LEX_STRING &wild, Item *where)
: PT_show_filter_base(pos, SQLCOM_SHOW_COLLATIONS, wild, where) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_collations m_sql_cmd;
};
/// Base class for Parse tree nodes of SHOW COUNT(*) { WARNINGS | ERRORS }
/// statements.
class PT_show_count_base : public PT_show_base {
public:
explicit PT_show_count_base(const POS &pos)
: PT_show_base{pos, SQLCOM_SELECT} {}
protected:
Sql_cmd *make_cmd_generic(THD *thd, LEX_CSTRING diagnostic_variable_name);
};
/// Parse tree node for SHOW COUNT(*) ERRORS
class PT_show_count_errors final : public PT_show_count_base {
public:
explicit PT_show_count_errors(const POS &pos) : PT_show_count_base(pos) {}
Sql_cmd *make_cmd(THD *thd) override {
return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("error_count")});
}
};
/// Parse tree node for SHOW COUNT(*) WARNINGS
class PT_show_count_warnings final : public PT_show_count_base {
public:
explicit PT_show_count_warnings(const POS &pos) : PT_show_count_base(pos) {}
Sql_cmd *make_cmd(THD *thd) override {
return make_cmd_generic(thd, LEX_CSTRING{STRING_WITH_LEN("warning_count")});
}
};
/// Parse tree node for SHOW CREATE DATABASE statement
class PT_show_create_database final : public PT_show_base {
public:
PT_show_create_database(const POS &pos, bool if_not_exists,
const LEX_STRING &name)
: PT_show_base(pos, SQLCOM_SHOW_CREATE_DB),
m_if_not_exists(if_not_exists),
m_name(name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
const bool m_if_not_exists;
const LEX_STRING m_name;
Sql_cmd_show_create_database m_sql_cmd;
};
/// Parse tree node for SHOW CREATE EVENT statement
class PT_show_create_event final : public PT_show_base {
public:
PT_show_create_event(const POS &pos, sp_name *event_name)
: PT_show_base(pos, SQLCOM_SHOW_CREATE_EVENT), m_spname(event_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
sp_name *const m_spname;
Sql_cmd_show_create_event m_sql_cmd;
};
/// Parse tree node for SHOW CREATE FUNCTION statement
class PT_show_create_function final : public PT_show_base {
public:
PT_show_create_function(const POS &pos, sp_name *function_name)
: PT_show_base(pos, SQLCOM_SHOW_CREATE_FUNC), m_spname(function_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
sp_name *const m_spname;
Sql_cmd_show_create_function m_sql_cmd;
};
/// Parse tree node for SHOW CREATE PROCEDURE statement
class PT_show_create_procedure final : public PT_show_base {
public:
PT_show_create_procedure(const POS &pos, sp_name *procedure_name)
: PT_show_base(pos, SQLCOM_SHOW_CREATE_PROC), m_spname(procedure_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
sp_name *const m_spname;
Sql_cmd_show_create_procedure m_sql_cmd;
};
/// Parse tree node for SHOW CREATE TABLE and VIEW statements
class PT_show_create_table final : public PT_show_base {
public:
PT_show_create_table(const POS &pos, Table_ident *table_ident)
: PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(false, table_ident) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_create_table m_sql_cmd;
};
/// Parse tree node for SHOW CREATE TRIGGER statement
class PT_show_create_trigger final : public PT_show_base {
public:
PT_show_create_trigger(const POS &pos, sp_name *trigger_name)
: PT_show_base(pos, SQLCOM_SHOW_CREATE_TRIGGER), m_spname(trigger_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
sp_name *const m_spname;
Sql_cmd_show_create_trigger m_sql_cmd;
};
/// Parse tree node for SHOW CREATE USER statement
class PT_show_create_user final : public PT_show_base {
public:
PT_show_create_user(const POS &pos, LEX_USER *user)
: PT_show_base(pos, SQLCOM_SHOW_CREATE_USER), m_user(user) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
LEX_USER *const m_user;
Sql_cmd_show_create_user m_sql_cmd;
};
/// Parse tree node for SHOW CREATE VIEW statement
class PT_show_create_view final : public PT_show_base {
public:
PT_show_create_view(const POS &pos, Table_ident *table_ident)
: PT_show_base(pos, SQLCOM_SHOW_CREATE), m_sql_cmd(true, table_ident) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_create_table m_sql_cmd;
};
/// Parse tree node for SHOW DATABASES statement
class PT_show_databases final : public PT_show_filter_base {
public:
PT_show_databases(const POS &pos, const LEX_STRING &wild, Item *where)
: PT_show_filter_base(pos, SQLCOM_SHOW_DATABASES, wild, where) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_databases m_sql_cmd;
};
/// Parse tree node for SHOW ENGINE statements
class PT_show_engine_base : public PT_show_base {
protected:
PT_show_engine_base(const POS &pos, enum enum_sql_command sql_command,
const LEX_STRING opt_engine = {})
: PT_show_base(pos, sql_command),
m_engine(opt_engine),
m_all(opt_engine.str == nullptr) {}
LEX_STRING m_engine;
bool m_all;
};
/// Parse tree node for SHOW ENGINE LOGS statement
class PT_show_engine_logs final : public PT_show_engine_base {
public:
PT_show_engine_logs(const POS &pos, LEX_STRING opt_engine = {})
: PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_LOGS, opt_engine) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_engine_logs m_sql_cmd;
};
/// Parse tree node for SHOW ENGINE MUTEX statement
class PT_show_engine_mutex final : public PT_show_engine_base {
public:
PT_show_engine_mutex(const POS &pos, LEX_STRING opt_engine = {})
: PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_MUTEX, opt_engine) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_engine_mutex m_sql_cmd;
};
/// Parse tree node for SHOW ENGINE STATUS statement
class PT_show_engine_status final : public PT_show_engine_base {
public:
PT_show_engine_status(const POS &pos, LEX_STRING opt_engine = {})
: PT_show_engine_base(pos, SQLCOM_SHOW_ENGINE_STATUS, opt_engine) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_engine_status m_sql_cmd;
};
/// Parse tree node for SHOW ENGINES statement
class PT_show_engines final : public PT_show_base {
public:
PT_show_engines(const POS &pos)
: PT_show_base(pos, SQLCOM_SHOW_STORAGE_ENGINES) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_engines m_sql_cmd;
};
/// Parse tree node for SHOW ERRORS statement
class PT_show_errors final : public PT_show_base {
public:
PT_show_errors(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
: PT_show_base(pos, SQLCOM_SHOW_ERRORS),
m_opt_limit_clause(opt_limit_clause) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
PT_limit_clause *const m_opt_limit_clause;
Sql_cmd_show_errors m_sql_cmd;
};
/// Parse tree node for SHOW EVENTS statement
class PT_show_events final : public PT_show_schema_base {
public:
PT_show_events(const POS &pos, char *opt_db, const LEX_STRING &wild,
Item *where)
: PT_show_schema_base(pos, SQLCOM_SHOW_EVENTS, opt_db, wild, where) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_events m_sql_cmd;
};
/// Parse tree node for SHOW COLUMNS statement.
class PT_show_fields final : public PT_show_table_base {
typedef PT_show_table_base super;
public:
PT_show_fields(const POS &pos, Show_cmd_type show_cmd_type,
Table_ident *table, LEX_STRING opt_wild = {},
Item *opt_where = nullptr)
: PT_show_table_base(pos, SQLCOM_SHOW_FIELDS, table, opt_wild, opt_where),
m_show_cmd_type(show_cmd_type) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Show_cmd_type m_show_cmd_type;
Sql_cmd_show_columns m_sql_cmd;
};
/// Parse tree node for SHOW FUNCTION CODE statement.
class PT_show_function_code final : public PT_show_routine_code {
public:
PT_show_function_code(const POS &pos, const sp_name *function_name)
: PT_show_routine_code(pos, SQLCOM_SHOW_FUNC_CODE, function_name) {}
};
/// Parse tree node for SHOW GRANTS statement.
class PT_show_grants final : public PT_show_base {
public:
PT_show_grants(const POS &pos, const LEX_USER *opt_for_user,
const List<LEX_USER> *opt_using_users)
: PT_show_base(pos, SQLCOM_SHOW_GRANTS),
sql_cmd(opt_for_user, opt_using_users) {
assert(opt_using_users == nullptr || opt_for_user != nullptr);
}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_grants sql_cmd;
};
/// Parse tree node for SHOW INDEX statement.
class PT_show_keys final : public PT_show_table_base {
public:
PT_show_keys(const POS &pos, bool extended_show, Table_ident *table,
Item *where)
: PT_show_table_base(pos, SQLCOM_SHOW_KEYS, table, NULL_STR, where),
m_extended_show(extended_show) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
typedef PT_show_table_base super;
// Flag to indicate EXTENDED keyword usage in the statement.
bool m_extended_show;
Sql_cmd_show_keys m_sql_cmd;
};
/// Parse tree node for SHOW MASTER STATUS statement
class PT_show_master_status final : public PT_show_base {
public:
PT_show_master_status(const POS &pos)
: PT_show_base(pos, SQLCOM_SHOW_MASTER_STAT) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_master_status m_sql_cmd;
};
/// Parse tree node for SHOW OPEN TABLES statement
class PT_show_open_tables final : public PT_show_schema_base {
public:
PT_show_open_tables(const POS &pos, char *opt_db, const LEX_STRING &wild,
Item *where)
: PT_show_schema_base(pos, SQLCOM_SHOW_OPEN_TABLES, opt_db, wild, where) {
}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_open_tables m_sql_cmd;
};
/// Parse tree node for SHOW PLUGINS statement
class PT_show_plugins final : public PT_show_base {
public:
PT_show_plugins(const POS &pos) : PT_show_base(pos, SQLCOM_SHOW_PLUGINS) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_plugins m_sql_cmd;
};
/// Parse tree node for SHOW PRIVILEGES statement
class PT_show_privileges final : public PT_show_base {
public:
PT_show_privileges(const POS &pos)
: PT_show_base(pos, SQLCOM_SHOW_PRIVILEGES) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_privileges m_sql_cmd;
};
/// Parse tree node for SHOW FUNCTION CODE statement.
class PT_show_procedure_code final : public PT_show_routine_code {
public:
PT_show_procedure_code(const POS &pos, const sp_name *procedure_name)
: PT_show_routine_code(pos, SQLCOM_SHOW_PROC_CODE, procedure_name) {}
};
/// Parse tree node for SHOW PROCESSLIST statement
class PT_show_processlist final : public PT_show_base {
public:
PT_show_processlist(const POS &pos, bool verbose)
: PT_show_base(pos, SQLCOM_SHOW_PROCESSLIST), m_sql_cmd(verbose) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_processlist m_sql_cmd;
};
/// Parse tree node for SHOW PROFILE statement
class PT_show_profile final : public PT_show_base {
public:
PT_show_profile(const POS &pos, uint opt_profile_options = 0,
my_thread_id opt_query_id = 0,
PT_limit_clause *opt_limit_clause = nullptr)
: PT_show_base(pos, SQLCOM_SHOW_PROFILE),
m_opt_profile_options(opt_profile_options),
m_opt_query_id(opt_query_id),
m_opt_limit_clause(opt_limit_clause) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
uint m_opt_profile_options;
my_thread_id m_opt_query_id;
PT_limit_clause *const m_opt_limit_clause;
Sql_cmd_show_profile m_sql_cmd;
};
/// Parse tree node for SHOW PROFILES statement
class PT_show_profiles final : public PT_show_base {
public:
PT_show_profiles(const POS &pos) : PT_show_base(pos, SQLCOM_SHOW_PROFILES) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_profiles m_sql_cmd;
};
/// Parse tree node for SHOW RELAYLOG EVENTS statement
class PT_show_relaylog_events final : public PT_show_base {
public:
PT_show_relaylog_events(const POS &pos,
const LEX_STRING opt_log_file_name = {},
PT_limit_clause *opt_limit_clause = nullptr,
LEX_CSTRING opt_channel_name = {})
: PT_show_base(pos, SQLCOM_SHOW_RELAYLOG_EVENTS),
m_opt_log_file_name(opt_log_file_name),
m_opt_limit_clause(opt_limit_clause),
m_opt_channel_name(opt_channel_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
const LEX_STRING m_opt_log_file_name;
PT_limit_clause *const m_opt_limit_clause;
const LEX_CSTRING m_opt_channel_name;
Sql_cmd_show_relaylog_events m_sql_cmd;
};
/// Parse tree node for SHOW REPLICAS statement
class PT_show_replicas final : public PT_show_base {
public:
PT_show_replicas(const POS &pos)
: PT_show_base(pos, SQLCOM_SHOW_SLAVE_HOSTS) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_replicas m_sql_cmd;
};
/// Parse tree node for SHOW REPLICA STATUS statement
class PT_show_replica_status final : public PT_show_base {
public:
PT_show_replica_status(const POS &pos, LEX_CSTRING opt_channel_name = {})
: PT_show_base(pos, SQLCOM_SHOW_SLAVE_STAT),
m_opt_channel_name(opt_channel_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
const LEX_CSTRING m_opt_channel_name;
Sql_cmd_show_replica_status m_sql_cmd;
};
/// Parse tree node for SHOW STATUS statement
class PT_show_status final : public PT_show_filter_base {
public:
PT_show_status(const POS &pos, enum_var_type var_type, const LEX_STRING &wild,
Item *where)
: PT_show_filter_base(pos, SQLCOM_SHOW_STATUS, wild, where),
m_var_type(var_type) {
assert(m_var_type == OPT_SESSION || m_var_type == OPT_GLOBAL);
}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_status m_sql_cmd;
enum_var_type m_var_type;
};
/// Parse tree node for SHOW STATUS FUNCTION statement
class PT_show_status_func final : public PT_show_filter_base {
public:
PT_show_status_func(const POS &pos, const LEX_STRING &wild, Item *where)
: PT_show_filter_base(pos, SQLCOM_SHOW_STATUS_FUNC, wild, where) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_status_func m_sql_cmd;
};
/// Parse tree node for SHOW STATUS PROCEDURE statement
class PT_show_status_proc final : public PT_show_filter_base {
public:
PT_show_status_proc(const POS &pos, const LEX_STRING &wild, Item *where)
: PT_show_filter_base(pos, SQLCOM_SHOW_STATUS_PROC, wild, where) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_status_proc m_sql_cmd;
};
/// Parse tree node for SHOW TABLE STATUS statement
class PT_show_table_status final : public PT_show_schema_base {
public:
PT_show_table_status(const POS &pos, char *opt_db, const LEX_STRING &wild,
Item *where)
: PT_show_schema_base(pos, SQLCOM_SHOW_TABLE_STATUS, opt_db, wild,
where) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_table_status m_sql_cmd;
};
/// Parse tree node for SHOW TABLES statement
class PT_show_tables final : public PT_show_schema_base {
public:
PT_show_tables(const POS &pos, Show_cmd_type show_cmd_type, char *opt_db,
const LEX_STRING &wild, Item *where)
: PT_show_schema_base(pos, SQLCOM_SHOW_TABLES, opt_db, wild, where),
m_show_cmd_type(show_cmd_type) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_tables m_sql_cmd;
Show_cmd_type m_show_cmd_type;
};
/// Parse tree node for SHOW TRIGGERS statement
class PT_show_triggers final : public PT_show_schema_base {
public:
PT_show_triggers(const POS &pos, bool full, char *opt_db,
const LEX_STRING &wild, Item *where)
: PT_show_schema_base(pos, SQLCOM_SHOW_TRIGGERS, opt_db, wild, where),
m_full(full) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_triggers m_sql_cmd;
bool m_full;
};
/// Parse tree node for SHOW VARIABLES statement
class PT_show_variables final : public PT_show_filter_base {
public:
PT_show_variables(const POS &pos, enum_var_type var_type,
const LEX_STRING &wild, Item *where)
: PT_show_filter_base(pos, SQLCOM_SHOW_VARIABLES, wild, where),
m_var_type(var_type) {
assert(m_var_type == OPT_SESSION || m_var_type == OPT_GLOBAL);
}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_show_variables m_sql_cmd;
enum_var_type m_var_type;
};
/// Parse tree node for SHOW WARNINGS statement
class PT_show_warnings final : public PT_show_base {
public:
PT_show_warnings(const POS &pos, PT_limit_clause *opt_limit_clause = nullptr)
: PT_show_base(pos, SQLCOM_SHOW_WARNS),
m_opt_limit_clause(opt_limit_clause) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
PT_limit_clause *const m_opt_limit_clause;
Sql_cmd_show_warnings m_sql_cmd;
};
class PT_alter_table_action : public PT_ddl_table_option {
typedef PT_ddl_table_option super;
protected:
explicit PT_alter_table_action(Alter_info::Alter_info_flag flag)
: flag(flag) {}
public:
bool contextualize(Table_ddl_parse_context *pc) override;
protected:
/**
A routine used by the parser to decide whether we are specifying a full
partitioning or if only partitions to add or to reorganize.
@retval true ALTER TABLE ADD/REORGANIZE PARTITION.
@retval false Something else.
*/
bool is_add_or_reorganize_partition() const {
return (flag == Alter_info::ALTER_ADD_PARTITION ||
flag == Alter_info::ALTER_REORGANIZE_PARTITION);
}
public:
const Alter_info::Alter_info_flag flag;
};
class PT_alter_table_add_column final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_add_column(const LEX_STRING &field_ident,
PT_field_def_base *field_def,
PT_table_constraint_def *opt_column_constraint,
const char *opt_place)
: super(Alter_info::ALTER_ADD_COLUMN),
m_column_def(field_ident, field_def, opt_column_constraint, opt_place) {
}
bool contextualize(Table_ddl_parse_context *pc) override {
return super::contextualize(pc) || m_column_def.contextualize(pc);
}
private:
PT_column_def m_column_def;
};
class PT_alter_table_add_columns final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
explicit PT_alter_table_add_columns(
const Mem_root_array<PT_table_element *> *columns)
: super(Alter_info::ALTER_ADD_COLUMN), m_columns(columns) {}
bool contextualize(Table_ddl_parse_context *pc) override {
if (super::contextualize(pc)) return true;
for (auto *column : *m_columns)
if (column->contextualize(pc)) return true;
return false;
}
private:
const Mem_root_array<PT_table_element *> *m_columns;
};
class PT_alter_table_add_constraint final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
explicit PT_alter_table_add_constraint(PT_table_constraint_def *constraint)
: super(Alter_info::ALTER_ADD_INDEX), m_constraint(constraint) {}
bool contextualize(Table_ddl_parse_context *pc) override {
return super::contextualize(pc) || m_constraint->contextualize(pc);
}
private:
PT_table_constraint_def *m_constraint;
};
class PT_alter_table_change_column final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_change_column(const LEX_STRING &old_name,
const LEX_STRING &new_name,
PT_field_def_base *field_def,
const char *opt_place)
: super(Alter_info::ALTER_CHANGE_COLUMN),
m_old_name(old_name),
m_new_name(new_name),
m_field_def(field_def),
m_opt_place(opt_place) {}
PT_alter_table_change_column(const LEX_STRING &name,
PT_field_def_base *field_def,
const char *opt_place)
: PT_alter_table_change_column(name, name, field_def, opt_place) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
const LEX_STRING m_old_name;
const LEX_STRING m_new_name;
PT_field_def_base *m_field_def;
const char *m_opt_place;
};
class PT_alter_table_drop : public PT_alter_table_action {
typedef PT_alter_table_action super;
protected:
PT_alter_table_drop(Alter_drop::drop_type drop_type,
Alter_info::Alter_info_flag alter_info_flag,
const char *name)
: super(alter_info_flag), m_alter_drop(drop_type, name) {}
public:
bool contextualize(Table_ddl_parse_context *pc) override {
return (super::contextualize(pc) ||
pc->alter_info->drop_list.push_back(&m_alter_drop));
}
private:
Alter_drop m_alter_drop;
};
class PT_alter_table_drop_column final : public PT_alter_table_drop {
public:
explicit PT_alter_table_drop_column(const char *name)
: PT_alter_table_drop(Alter_drop::COLUMN, Alter_info::ALTER_DROP_COLUMN,
name) {}
};
class PT_alter_table_drop_foreign_key final : public PT_alter_table_drop {
public:
explicit PT_alter_table_drop_foreign_key(const char *name)
: PT_alter_table_drop(Alter_drop::FOREIGN_KEY,
Alter_info::DROP_FOREIGN_KEY, name) {}
};
class PT_alter_table_drop_key final : public PT_alter_table_drop {
public:
explicit PT_alter_table_drop_key(const char *name)
: PT_alter_table_drop(Alter_drop::KEY, Alter_info::ALTER_DROP_INDEX,
name) {}
};
class PT_alter_table_drop_check_constraint final : public PT_alter_table_drop {
public:
explicit PT_alter_table_drop_check_constraint(const char *name)
: PT_alter_table_drop(Alter_drop::CHECK_CONSTRAINT,
Alter_info::DROP_CHECK_CONSTRAINT, name) {}
};
class PT_alter_table_drop_constraint final : public PT_alter_table_drop {
public:
explicit PT_alter_table_drop_constraint(const char *name)
: PT_alter_table_drop(Alter_drop::ANY_CONSTRAINT,
Alter_info::DROP_ANY_CONSTRAINT, name) {}
};
class PT_alter_table_enforce_constraint : public PT_alter_table_action {
typedef PT_alter_table_action super;
protected:
PT_alter_table_enforce_constraint(
Alter_constraint_enforcement::Type alter_type,
Alter_info::Alter_info_flag alter_info_flag, const char *name,
bool is_enforced)
: super(alter_info_flag),
m_constraint_enforcement(alter_type, name, is_enforced) {}
public:
explicit PT_alter_table_enforce_constraint(const char *name, bool is_enforced)
: super(is_enforced ? Alter_info::ENFORCE_ANY_CONSTRAINT
: Alter_info::SUSPEND_ANY_CONSTRAINT),
m_constraint_enforcement(
Alter_constraint_enforcement::Type::ANY_CONSTRAINT, name,
is_enforced) {}
bool contextualize(Table_ddl_parse_context *pc) override {
return (super::contextualize(pc) ||
pc->alter_info->alter_constraint_enforcement_list.push_back(
&m_constraint_enforcement));
}
private:
Alter_constraint_enforcement m_constraint_enforcement;
};
class PT_alter_table_enforce_check_constraint final
: public PT_alter_table_enforce_constraint {
public:
explicit PT_alter_table_enforce_check_constraint(const char *name,
bool is_enforced)
: PT_alter_table_enforce_constraint(
Alter_constraint_enforcement::Type::CHECK_CONSTRAINT,
is_enforced ? Alter_info::ENFORCE_CHECK_CONSTRAINT
: Alter_info::SUSPEND_CHECK_CONSTRAINT,
name, is_enforced) {}
};
class PT_alter_table_enable_keys final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
explicit PT_alter_table_enable_keys(bool enable)
: super(Alter_info::ALTER_KEYS_ONOFF), m_enable(enable) {}
bool contextualize(Table_ddl_parse_context *pc) override {
pc->alter_info->keys_onoff =
m_enable ? Alter_info::ENABLE : Alter_info::DISABLE;
return super::contextualize(pc);
}
private:
bool m_enable;
};
class PT_alter_table_set_default final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_set_default(const char *col_name, Item *opt_default_expr)
: super(Alter_info::ALTER_CHANGE_COLUMN_DEFAULT),
m_name(col_name),
m_expr(opt_default_expr) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
const char *m_name;
Item *m_expr;
};
class PT_alter_table_column_visibility final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_column_visibility(const char *col_name, bool is_visible)
: super(Alter_info::ALTER_COLUMN_VISIBILITY),
m_alter_column(col_name, is_visible) {}
bool contextualize(Table_ddl_parse_context *pc) override {
return (super::contextualize(pc) ||
pc->alter_info->alter_list.push_back(&m_alter_column));
}
private:
Alter_column m_alter_column;
};
class PT_alter_table_index_visible final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_index_visible(const char *name, bool visible)
: super(Alter_info::ALTER_INDEX_VISIBILITY),
m_alter_index_visibility(name, visible) {}
bool contextualize(Table_ddl_parse_context *pc) override {
return (super::contextualize(pc) ||
pc->alter_info->alter_index_visibility_list.push_back(
&m_alter_index_visibility));
}
private:
Alter_index_visibility m_alter_index_visibility;
};
class PT_alter_table_rename final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
explicit PT_alter_table_rename(const Table_ident *ident)
: super(Alter_info::ALTER_RENAME), m_ident(ident) {}
bool contextualize(Table_ddl_parse_context *pc) override;
bool is_rename_table() const override { return true; }
private:
const Table_ident *const m_ident;
};
class PT_alter_table_rename_key final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_rename_key(const char *from, const char *to)
: super(Alter_info::ALTER_RENAME_INDEX), m_rename_key(from, to) {}
bool contextualize(Table_ddl_parse_context *pc) override {
return super::contextualize(pc) ||
pc->alter_info->alter_rename_key_list.push_back(&m_rename_key);
}
private:
Alter_rename_key m_rename_key;
};
class PT_alter_table_rename_column final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_rename_column(const char *from, const char *to)
: super(Alter_info::ALTER_CHANGE_COLUMN), m_rename_column(from, to) {}
bool contextualize(Table_ddl_parse_context *pc) override {
return super::contextualize(pc) ||
pc->alter_info->alter_list.push_back(&m_rename_column);
}
private:
Alter_column m_rename_column;
};
class PT_alter_table_convert_to_charset final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_convert_to_charset(const CHARSET_INFO *charset,
const CHARSET_INFO *opt_collation)
: super(Alter_info::ALTER_OPTIONS),
m_charset(charset),
m_collation(opt_collation) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
const CHARSET_INFO *const m_charset;
const CHARSET_INFO *const m_collation;
};
class PT_alter_table_force final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_force() : super(Alter_info::ALTER_RECREATE) {}
};
class PT_alter_table_order final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
explicit PT_alter_table_order(PT_order_list *order)
: super(Alter_info::ALTER_ORDER), m_order(order) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
PT_order_list *const m_order;
};
class PT_alter_table_partition_by final : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
explicit PT_alter_table_partition_by(PT_partition *partition)
: super(Alter_info::ALTER_PARTITION), m_partition(partition) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
PT_partition *const m_partition;
};
class PT_alter_table_remove_partitioning : public PT_alter_table_action {
typedef PT_alter_table_action super;
public:
PT_alter_table_remove_partitioning()
: super(Alter_info::ALTER_REMOVE_PARTITIONING) {}
};
class PT_alter_table_standalone_action : public PT_alter_table_action {
typedef PT_alter_table_action super;
friend class PT_alter_table_standalone_stmt; // to access make_cmd()
protected:
PT_alter_table_standalone_action(Alter_info::Alter_info_flag alter_info_flag)
: super(alter_info_flag) {}
private:
virtual Sql_cmd *make_cmd(Table_ddl_parse_context *pc) = 0;
};
/**
Node for the @SQL{ALTER TABLE ADD PARTITION} statement
@ingroup ptn_alter_table
*/
class PT_alter_table_add_partition : public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
explicit PT_alter_table_add_partition(bool no_write_to_binlog)
: super(Alter_info::ALTER_ADD_PARTITION),
m_no_write_to_binlog(no_write_to_binlog) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) final {
return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
}
protected:
partition_info m_part_info;
private:
const bool m_no_write_to_binlog;
};
/**
Node for the @SQL{ALTER TABLE ADD PARTITION (@<partition list@>)} statement
@ingroup ptn_alter_table
*/
class PT_alter_table_add_partition_def_list final
: public PT_alter_table_add_partition {
typedef PT_alter_table_add_partition super;
public:
PT_alter_table_add_partition_def_list(
bool no_write_to_binlog,
const Mem_root_array<PT_part_definition *> *def_list)
: super(no_write_to_binlog), m_def_list(def_list) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
const Mem_root_array<PT_part_definition *> *m_def_list;
};
/**
Node for the @SQL{ALTER TABLE ADD PARTITION PARTITIONS (@<n>@)} statement
@ingroup ptn_alter_table
*/
class PT_alter_table_add_partition_num final
: public PT_alter_table_add_partition {
typedef PT_alter_table_add_partition super;
public:
PT_alter_table_add_partition_num(bool no_write_to_binlog, uint num_parts)
: super(no_write_to_binlog) {
m_part_info.num_parts = num_parts;
}
};
class PT_alter_table_drop_partition final
: public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
explicit PT_alter_table_drop_partition(const List<String> &partitions)
: super(Alter_info::ALTER_DROP_PARTITION), m_partitions(partitions) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) final {
return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
}
private:
const List<String> m_partitions;
};
class PT_alter_table_partition_list_or_all
: public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
explicit PT_alter_table_partition_list_or_all(
Alter_info::Alter_info_flag alter_info_flag,
const List<String> *opt_partition_list)
: super(alter_info_flag), m_opt_partition_list(opt_partition_list) {}
bool contextualize(Table_ddl_parse_context *pc) override {
assert(pc->alter_info->partition_names.is_empty());
if (m_opt_partition_list == nullptr)
pc->alter_info->flags |= Alter_info::ALTER_ALL_PARTITION;
else
pc->alter_info->partition_names = *m_opt_partition_list;
return super::contextualize(pc);
}
private:
const List<String> *m_opt_partition_list;
};
class PT_alter_table_rebuild_partition final
: public PT_alter_table_partition_list_or_all {
typedef PT_alter_table_partition_list_or_all super;
public:
PT_alter_table_rebuild_partition(bool no_write_to_binlog,
const List<String> *opt_partition_list)
: super(Alter_info::ALTER_REBUILD_PARTITION, opt_partition_list),
m_no_write_to_binlog(no_write_to_binlog) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
}
private:
const bool m_no_write_to_binlog;
};
class PT_alter_table_optimize_partition final
: public PT_alter_table_partition_list_or_all {
typedef PT_alter_table_partition_list_or_all super;
public:
PT_alter_table_optimize_partition(bool no_write_to_binlog,
const List<String> *opt_partition_list)
: super(Alter_info::ALTER_ADMIN_PARTITION, opt_partition_list),
m_no_write_to_binlog(no_write_to_binlog) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root)
Sql_cmd_alter_table_optimize_partition(pc->alter_info);
}
private:
const bool m_no_write_to_binlog;
};
class PT_alter_table_analyze_partition
: public PT_alter_table_partition_list_or_all {
typedef PT_alter_table_partition_list_or_all super;
public:
PT_alter_table_analyze_partition(bool no_write_to_binlog,
const List<String> *opt_partition_list)
: super(Alter_info::ALTER_ADMIN_PARTITION, opt_partition_list),
m_no_write_to_binlog(no_write_to_binlog) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root)
Sql_cmd_alter_table_analyze_partition(pc->thd, pc->alter_info);
}
private:
const bool m_no_write_to_binlog;
};
class PT_alter_table_check_partition
: public PT_alter_table_partition_list_or_all {
typedef PT_alter_table_partition_list_or_all super;
public:
PT_alter_table_check_partition(const List<String> *opt_partition_list,
uint flags, uint sql_flags)
: super(Alter_info::ALTER_ADMIN_PARTITION, opt_partition_list),
m_flags(flags),
m_sql_flags(sql_flags) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root)
Sql_cmd_alter_table_check_partition(pc->alter_info);
}
private:
uint m_flags;
uint m_sql_flags;
};
class PT_alter_table_repair_partition
: public PT_alter_table_partition_list_or_all {
typedef PT_alter_table_partition_list_or_all super;
public:
PT_alter_table_repair_partition(bool no_write_to_binlog,
const List<String> *opt_partition_list,
uint flags, uint sql_flags)
: super(Alter_info::ALTER_ADMIN_PARTITION, opt_partition_list),
m_no_write_to_binlog(no_write_to_binlog),
m_flags(flags),
m_sql_flags(sql_flags) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root)
Sql_cmd_alter_table_repair_partition(pc->alter_info);
}
private:
const bool m_no_write_to_binlog;
uint m_flags;
uint m_sql_flags;
};
class PT_alter_table_coalesce_partition final
: public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
PT_alter_table_coalesce_partition(bool no_write_to_binlog, uint num_parts)
: super(Alter_info::ALTER_COALESCE_PARTITION),
m_no_write_to_binlog(no_write_to_binlog),
m_num_parts(num_parts) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
}
private:
const bool m_no_write_to_binlog;
const uint m_num_parts;
};
class PT_alter_table_truncate_partition
: public PT_alter_table_partition_list_or_all {
typedef PT_alter_table_partition_list_or_all super;
public:
explicit PT_alter_table_truncate_partition(
const List<String> *opt_partition_list)
: super(static_cast<Alter_info::Alter_info_flag>(
Alter_info::ALTER_ADMIN_PARTITION |
Alter_info::ALTER_TRUNCATE_PARTITION),
opt_partition_list) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root)
Sql_cmd_alter_table_truncate_partition(pc->alter_info);
}
};
class PT_alter_table_reorganize_partition final
: public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
explicit PT_alter_table_reorganize_partition(bool no_write_to_binlog)
: super(Alter_info::ALTER_TABLE_REORG),
m_no_write_to_binlog(no_write_to_binlog) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
}
private:
const bool m_no_write_to_binlog;
partition_info m_partition_info;
};
class PT_alter_table_reorganize_partition_into final
: public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
explicit PT_alter_table_reorganize_partition_into(
bool no_write_to_binlog, const List<String> &partition_names,
const Mem_root_array<PT_part_definition *> *into)
: super(Alter_info::ALTER_REORGANIZE_PARTITION),
m_no_write_to_binlog(no_write_to_binlog),
m_partition_names(partition_names),
m_into(into) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_alter_table(pc->alter_info);
}
private:
const bool m_no_write_to_binlog;
const List<String> m_partition_names;
const Mem_root_array<PT_part_definition *> *m_into;
partition_info m_partition_info;
};
class PT_alter_table_exchange_partition final
: public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
PT_alter_table_exchange_partition(const LEX_STRING &partition_name,
Table_ident *table_name,
Alter_info::enum_with_validation validation)
: super(Alter_info::ALTER_EXCHANGE_PARTITION),
m_partition_name(partition_name),
m_table_name(table_name),
m_validation(validation) {}
bool contextualize(Table_ddl_parse_context *pc) override;
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root)
Sql_cmd_alter_table_exchange_partition(pc->alter_info);
}
private:
const LEX_STRING m_partition_name;
Table_ident *m_table_name;
const Alter_info::enum_with_validation m_validation;
};
class PT_alter_table_secondary_load final
: public PT_alter_table_standalone_action {
using super = PT_alter_table_standalone_action;
public:
explicit PT_alter_table_secondary_load()
: super(Alter_info::ALTER_SECONDARY_LOAD) {}
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_secondary_load_unload(pc->alter_info);
}
};
class PT_alter_table_secondary_unload final
: public PT_alter_table_standalone_action {
using super = PT_alter_table_standalone_action;
public:
explicit PT_alter_table_secondary_unload()
: super(Alter_info::ALTER_SECONDARY_UNLOAD) {}
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_secondary_load_unload(pc->alter_info);
}
};
class PT_alter_table_discard_partition_tablespace final
: public PT_alter_table_partition_list_or_all {
typedef PT_alter_table_partition_list_or_all super;
public:
explicit PT_alter_table_discard_partition_tablespace(
const List<String> *opt_partition_list)
: super(Alter_info::ALTER_DISCARD_TABLESPACE, opt_partition_list) {}
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_discard_import_tablespace(pc->alter_info);
}
};
class PT_alter_table_import_partition_tablespace final
: public PT_alter_table_partition_list_or_all {
typedef PT_alter_table_partition_list_or_all super;
public:
explicit PT_alter_table_import_partition_tablespace(
const List<String> *opt_partition_list)
: super(Alter_info::ALTER_IMPORT_TABLESPACE, opt_partition_list) {}
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_discard_import_tablespace(pc->alter_info);
}
};
class PT_alter_table_discard_tablespace final
: public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
PT_alter_table_discard_tablespace()
: super(Alter_info::ALTER_DISCARD_TABLESPACE) {}
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_discard_import_tablespace(pc->alter_info);
}
};
class PT_alter_table_import_tablespace final
: public PT_alter_table_standalone_action {
typedef PT_alter_table_standalone_action super;
public:
PT_alter_table_import_tablespace()
: super(Alter_info::ALTER_IMPORT_TABLESPACE) {}
Sql_cmd *make_cmd(Table_ddl_parse_context *pc) override {
return new (pc->mem_root) Sql_cmd_discard_import_tablespace(pc->alter_info);
}
};
class PT_alter_table_stmt final : public PT_table_ddl_stmt_base {
public:
explicit PT_alter_table_stmt(
MEM_ROOT *mem_root, Table_ident *table_name,
Mem_root_array<PT_ddl_table_option *> *opt_actions,
Alter_info::enum_alter_table_algorithm algo,
Alter_info::enum_alter_table_lock lock,
Alter_info::enum_with_validation validation)
: PT_table_ddl_stmt_base(mem_root),
m_table_name(table_name),
m_opt_actions(opt_actions),
m_algo(algo),
m_lock(lock),
m_validation(validation) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Table_ident *const m_table_name;
Mem_root_array<PT_ddl_table_option *> *const m_opt_actions;
const Alter_info::enum_alter_table_algorithm m_algo;
const Alter_info::enum_alter_table_lock m_lock;
const Alter_info::enum_with_validation m_validation;
HA_CREATE_INFO m_create_info;
};
class PT_alter_table_standalone_stmt final : public PT_table_ddl_stmt_base {
public:
explicit PT_alter_table_standalone_stmt(
MEM_ROOT *mem_root, Table_ident *table_name,
PT_alter_table_standalone_action *action,
Alter_info::enum_alter_table_algorithm algo,
Alter_info::enum_alter_table_lock lock,
Alter_info::enum_with_validation validation)
: PT_table_ddl_stmt_base(mem_root),
m_table_name(table_name),
m_action(action),
m_algo(algo),
m_lock(lock),
m_validation(validation) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Table_ident *const m_table_name;
PT_alter_table_standalone_action *const m_action;
const Alter_info::enum_alter_table_algorithm m_algo;
const Alter_info::enum_alter_table_lock m_lock;
const Alter_info::enum_with_validation m_validation;
HA_CREATE_INFO m_create_info;
};
class PT_repair_table_stmt final : public PT_table_ddl_stmt_base {
public:
PT_repair_table_stmt(MEM_ROOT *mem_root, bool no_write_to_binlog,
Mem_root_array<Table_ident *> *table_list,
decltype(HA_CHECK_OPT::flags) flags,
decltype(HA_CHECK_OPT::sql_flags) sql_flags)
: PT_table_ddl_stmt_base(mem_root),
m_no_write_to_binlog(no_write_to_binlog),
m_table_list(table_list),
m_flags(flags),
m_sql_flags(sql_flags) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
bool m_no_write_to_binlog;
Mem_root_array<Table_ident *> *m_table_list;
decltype(HA_CHECK_OPT::flags) m_flags;
decltype(HA_CHECK_OPT::sql_flags) m_sql_flags;
};
class PT_analyze_table_stmt final : public PT_table_ddl_stmt_base {
public:
PT_analyze_table_stmt(MEM_ROOT *mem_root, bool no_write_to_binlog,
Mem_root_array<Table_ident *> *table_list,
Sql_cmd_analyze_table::Histogram_command command,
int num_buckets, List<String> *columns, LEX_STRING data)
: PT_table_ddl_stmt_base(mem_root),
m_no_write_to_binlog(no_write_to_binlog),
m_table_list(table_list),
m_command(command),
m_num_buckets(num_buckets),
m_columns(columns),
m_data{data} {}
Sql_cmd *make_cmd(THD *thd) override;
private:
const bool m_no_write_to_binlog;
const Mem_root_array<Table_ident *> *m_table_list;
const Sql_cmd_analyze_table::Histogram_command m_command;
const int m_num_buckets;
List<String> *m_columns;
const LEX_STRING m_data;
};
class PT_check_table_stmt final : public PT_table_ddl_stmt_base {
public:
PT_check_table_stmt(MEM_ROOT *mem_root,
Mem_root_array<Table_ident *> *table_list,
decltype(HA_CHECK_OPT::flags) flags,
decltype(HA_CHECK_OPT::sql_flags) sql_flags)
: PT_table_ddl_stmt_base(mem_root),
m_table_list(table_list),
m_flags(flags),
m_sql_flags(sql_flags) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Mem_root_array<Table_ident *> *m_table_list;
decltype(HA_CHECK_OPT::flags) m_flags;
decltype(HA_CHECK_OPT::sql_flags) m_sql_flags;
};
class PT_optimize_table_stmt final : public PT_table_ddl_stmt_base {
public:
PT_optimize_table_stmt(MEM_ROOT *mem_root, bool no_write_to_binlog,
Mem_root_array<Table_ident *> *table_list)
: PT_table_ddl_stmt_base(mem_root),
m_no_write_to_binlog(no_write_to_binlog),
m_table_list(table_list) {}
Sql_cmd *make_cmd(THD *thd) override;
bool m_no_write_to_binlog;
Mem_root_array<Table_ident *> *m_table_list;
};
class PT_drop_index_stmt final : public PT_table_ddl_stmt_base {
public:
PT_drop_index_stmt(MEM_ROOT *mem_root, const char *index_name,
Table_ident *table,
Alter_info::enum_alter_table_algorithm algo,
Alter_info::enum_alter_table_lock lock)
: PT_table_ddl_stmt_base(mem_root),
m_index_name(index_name),
m_table(table),
m_algo(algo),
m_lock(lock),
m_alter_drop(Alter_drop::KEY, m_index_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
const char *m_index_name;
Table_ident *m_table;
Alter_info::enum_alter_table_algorithm m_algo;
Alter_info::enum_alter_table_lock m_lock;
Alter_drop m_alter_drop;
};
class PT_truncate_table_stmt final : public Parse_tree_root {
public:
explicit PT_truncate_table_stmt(Table_ident *table) : m_table(table) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Table_ident *m_table;
Sql_cmd_truncate_table m_cmd_truncate_table;
};
class PT_assign_to_keycache final : public Table_ddl_node {
typedef Table_ddl_node super;
public:
PT_assign_to_keycache(Table_ident *table, List<Index_hint> *index_hints)
: m_table(table), m_index_hints(index_hints) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
Table_ident *m_table;
List<Index_hint> *m_index_hints;
};
class PT_adm_partition final : public Table_ddl_node {
typedef Table_ddl_node super;
public:
explicit PT_adm_partition(List<String> *opt_partitions)
: m_opt_partitions(opt_partitions) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
List<String> *m_opt_partitions;
};
class PT_cache_index_stmt final : public PT_table_ddl_stmt_base {
public:
PT_cache_index_stmt(MEM_ROOT *mem_root,
Mem_root_array<PT_assign_to_keycache *> *tbl_index_lists,
LEX_CSTRING key_cache_name)
: PT_table_ddl_stmt_base(mem_root),
m_tbl_index_lists(tbl_index_lists),
m_key_cache_name(key_cache_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Mem_root_array<PT_assign_to_keycache *> *m_tbl_index_lists;
const LEX_CSTRING m_key_cache_name;
};
class PT_cache_index_partitions_stmt : public PT_table_ddl_stmt_base {
public:
PT_cache_index_partitions_stmt(MEM_ROOT *mem_root, Table_ident *table,
PT_adm_partition *partitions,
List<Index_hint> *opt_key_usage_list,
LEX_CSTRING key_cache_name)
: PT_table_ddl_stmt_base(mem_root),
m_table(table),
m_partitions(partitions),
m_opt_key_usage_list(opt_key_usage_list),
m_key_cache_name(key_cache_name) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Table_ident *m_table;
PT_adm_partition *m_partitions;
List<Index_hint> *m_opt_key_usage_list;
const LEX_CSTRING m_key_cache_name;
};
class PT_preload_keys final : public Table_ddl_node {
typedef Table_ddl_node super;
public:
PT_preload_keys(Table_ident *table, List<Index_hint> *opt_cache_key_list,
bool ignore_leaves)
: m_table(table),
m_opt_cache_key_list(opt_cache_key_list),
m_ignore_leaves(ignore_leaves) {}
bool contextualize(Table_ddl_parse_context *pc) override;
private:
Table_ident *m_table;
List<Index_hint> *m_opt_cache_key_list;
bool m_ignore_leaves;
};
class PT_load_index_partitions_stmt final : public PT_table_ddl_stmt_base {
public:
PT_load_index_partitions_stmt(MEM_ROOT *mem_root, Table_ident *table,
PT_adm_partition *partitions,
List<Index_hint> *opt_cache_key_list,
bool ignore_leaves)
: PT_table_ddl_stmt_base(mem_root),
m_table(table),
m_partitions(partitions),
m_opt_cache_key_list(opt_cache_key_list),
m_ignore_leaves(ignore_leaves) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Table_ident *m_table;
PT_adm_partition *m_partitions;
List<Index_hint> *m_opt_cache_key_list;
bool m_ignore_leaves;
};
class PT_load_index_stmt final : public PT_table_ddl_stmt_base {
public:
PT_load_index_stmt(MEM_ROOT *mem_root,
Mem_root_array<PT_preload_keys *> *preload_list)
: PT_table_ddl_stmt_base(mem_root), m_preload_list(preload_list) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Mem_root_array<PT_preload_keys *> *m_preload_list;
};
class PT_json_table_column_for_ordinality final : public PT_json_table_column {
typedef PT_json_table_column super;
public:
explicit PT_json_table_column_for_ordinality(LEX_STRING name);
~PT_json_table_column_for_ordinality() override;
bool contextualize(Parse_context *pc) override;
Json_table_column *get_column() override { return m_column.get(); }
private:
unique_ptr_destroy_only<Json_table_column> m_column;
const char *m_name;
};
class PT_json_table_column_with_path final : public PT_json_table_column {
typedef PT_json_table_column super;
public:
PT_json_table_column_with_path(
unique_ptr_destroy_only<Json_table_column> column, LEX_STRING name,
PT_type *type, const CHARSET_INFO *collation);
~PT_json_table_column_with_path() override;
bool contextualize(Parse_context *pc) override;
Json_table_column *get_column() override { return m_column.get(); }
private:
unique_ptr_destroy_only<Json_table_column> m_column;
const char *m_name;
PT_type *m_type;
const CHARSET_INFO *m_collation;
};
class PT_json_table_column_with_nested_path final
: public PT_json_table_column {
typedef PT_json_table_column super;
public:
PT_json_table_column_with_nested_path(
Item *path, Mem_root_array<PT_json_table_column *> *nested_cols)
: m_path(path), m_nested_columns(nested_cols) {}
bool contextualize(Parse_context *pc) override;
Json_table_column *get_column() override { return m_column; }
private:
Item *m_path;
const Mem_root_array<PT_json_table_column *> *m_nested_columns;
Json_table_column *m_column{nullptr};
};
struct Alter_tablespace_parse_context : public Tablespace_options {
THD *const thd;
MEM_ROOT *const mem_root;
explicit Alter_tablespace_parse_context(THD *thd);
};
typedef Parse_tree_node_tmpl<Alter_tablespace_parse_context>
PT_alter_tablespace_option_base;
template <typename Option_type, Option_type Tablespace_options::*Option>
class PT_alter_tablespace_option final
: public PT_alter_tablespace_option_base /* purecov: inspected */
{
typedef PT_alter_tablespace_option_base super;
public:
explicit PT_alter_tablespace_option(Option_type value) : m_value(value) {}
bool contextualize(Alter_tablespace_parse_context *pc) override {
pc->*Option = m_value;
return super::contextualize(pc);
}
private:
const Option_type m_value;
};
typedef PT_alter_tablespace_option<
decltype(Tablespace_options::autoextend_size),
&Tablespace_options::autoextend_size>
PT_alter_tablespace_option_autoextend_size;
typedef PT_alter_tablespace_option<decltype(Tablespace_options::extent_size),
&Tablespace_options::extent_size>
PT_alter_tablespace_option_extent_size;
typedef PT_alter_tablespace_option<decltype(Tablespace_options::initial_size),
&Tablespace_options::initial_size>
PT_alter_tablespace_option_initial_size;
typedef PT_alter_tablespace_option<decltype(Tablespace_options::max_size),
&Tablespace_options::max_size>
PT_alter_tablespace_option_max_size;
typedef PT_alter_tablespace_option<
decltype(Tablespace_options::redo_buffer_size),
&Tablespace_options::redo_buffer_size>
PT_alter_tablespace_option_redo_buffer_size;
typedef PT_alter_tablespace_option<
decltype(Tablespace_options::undo_buffer_size),
&Tablespace_options::undo_buffer_size>
PT_alter_tablespace_option_undo_buffer_size;
typedef PT_alter_tablespace_option<
decltype(Tablespace_options::wait_until_completed),
&Tablespace_options::wait_until_completed>
PT_alter_tablespace_option_wait_until_completed;
typedef PT_alter_tablespace_option<decltype(Tablespace_options::encryption),
&Tablespace_options::encryption>
PT_alter_tablespace_option_encryption;
class PT_alter_tablespace_option_nodegroup final
: public PT_alter_tablespace_option_base /* purecov: inspected */
{
typedef PT_alter_tablespace_option_base super;
typedef decltype(Tablespace_options::nodegroup_id) option_type;
public:
explicit PT_alter_tablespace_option_nodegroup(option_type nodegroup_id)
: m_nodegroup_id(nodegroup_id) {}
bool contextualize(Alter_tablespace_parse_context *pc) override;
private:
const option_type m_nodegroup_id;
};
class PT_alter_tablespace_option_comment final
: public PT_alter_tablespace_option_base /* purecov: inspected */
{
typedef PT_alter_tablespace_option_base super;
typedef decltype(Tablespace_options::ts_comment) option_type;
public:
explicit PT_alter_tablespace_option_comment(option_type comment)
: m_comment(comment) {}
bool contextualize(Alter_tablespace_parse_context *pc) override {
if (super::contextualize(pc)) return true; /* purecov: inspected */ // OOM
if (pc->ts_comment.str) {
my_error(ER_FILEGROUP_OPTION_ONLY_ONCE, MYF(0), "COMMENT");
return true;
}
pc->ts_comment = m_comment;
return false;
}
private:
const option_type m_comment;
};
class PT_alter_tablespace_option_engine final
: public PT_alter_tablespace_option_base /* purecov: inspected */
{
typedef PT_alter_tablespace_option_base super;
typedef decltype(Tablespace_options::engine_name) option_type;
public:
explicit PT_alter_tablespace_option_engine(option_type engine_name)
: m_engine_name(engine_name) {}
bool contextualize(Alter_tablespace_parse_context *pc) override {
if (super::contextualize(pc)) return true; /* purecov: inspected */ // OOM
if (pc->engine_name.str) {
my_error(ER_FILEGROUP_OPTION_ONLY_ONCE, MYF(0), "STORAGE ENGINE");
return true;
}
pc->engine_name = m_engine_name;
return false;
}
private:
const option_type m_engine_name;
};
class PT_alter_tablespace_option_file_block_size final
: public PT_alter_tablespace_option_base /* purecov: inspected */
{
typedef PT_alter_tablespace_option_base super;
typedef decltype(Tablespace_options::file_block_size) option_type;
public:
explicit PT_alter_tablespace_option_file_block_size(
option_type file_block_size)
: m_file_block_size(file_block_size) {}
bool contextualize(Alter_tablespace_parse_context *pc) override {
if (super::contextualize(pc)) return true; /* purecov: inspected */ // OOM
if (pc->file_block_size != 0) {
my_error(ER_FILEGROUP_OPTION_ONLY_ONCE, MYF(0), "FILE_BLOCK_SIZE");
return true;
}
pc->file_block_size = m_file_block_size;
return false;
}
private:
const option_type m_file_block_size;
};
/**
Parse tree node for CREATE RESOURCE GROUP statement.
*/
class PT_create_resource_group final : public Parse_tree_root {
resourcegroups::Sql_cmd_create_resource_group sql_cmd;
const bool has_priority;
public:
PT_create_resource_group(
const LEX_CSTRING &name, const resourcegroups::Type type,
const Mem_root_array<resourcegroups::Range> *cpu_list,
const Value_or_default<int> &opt_priority, bool enabled)
: sql_cmd(name, type, cpu_list,
opt_priority.is_default ? 0 : opt_priority.value, enabled),
has_priority(!opt_priority.is_default) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/**
Parse tree node for ALTER RESOURCE GROUP statement.
*/
class PT_alter_resource_group final : public Parse_tree_root {
resourcegroups::Sql_cmd_alter_resource_group sql_cmd;
public:
PT_alter_resource_group(const LEX_CSTRING &name,
const Mem_root_array<resourcegroups::Range> *cpu_list,
const Value_or_default<int> &opt_priority,
const Value_or_default<bool> &enable, bool force)
: sql_cmd(name, cpu_list,
opt_priority.is_default ? 0 : opt_priority.value,
enable.is_default ? false : enable.value, force,
!enable.is_default) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/**
Parse tree node for DROP RESOURCE GROUP statement.
*/
class PT_drop_resource_group final : public Parse_tree_root {
resourcegroups::Sql_cmd_drop_resource_group sql_cmd;
public:
PT_drop_resource_group(const LEX_CSTRING &resource_group_name, bool force)
: sql_cmd(resource_group_name, force) {}
Sql_cmd *make_cmd(THD *thd) override;
};
/**
Parse tree node for SET RESOURCE GROUP statement.
*/
class PT_set_resource_group final : public Parse_tree_root {
resourcegroups::Sql_cmd_set_resource_group sql_cmd;
public:
PT_set_resource_group(const LEX_CSTRING &name,
Mem_root_array<ulonglong> *thread_id_list)
: sql_cmd(name, thread_id_list) {}
Sql_cmd *make_cmd(THD *thd) override;
};
class PT_explain_for_connection final : public Parse_tree_root {
public:
explicit PT_explain_for_connection(my_thread_id thread_id)
: m_cmd(thread_id) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_explain_other_thread m_cmd;
};
class PT_explain final : public Parse_tree_root {
public:
PT_explain(Explain_format_type format, bool is_analyze,
bool is_explicit_format, Parse_tree_root *explainable_stmt)
: m_format(format),
m_analyze(is_analyze),
m_explicit_format(is_explicit_format),
m_explainable_stmt(explainable_stmt) {}
Sql_cmd *make_cmd(THD *thd) override;
private:
const Explain_format_type m_format;
const bool m_analyze;
const bool m_explicit_format;
Parse_tree_root *const m_explainable_stmt;
};
class PT_load_table final : public Parse_tree_root {
public:
PT_load_table(enum_filetype filetype, thr_lock_type lock_type,
bool is_local_file, enum_source_type, const LEX_STRING filename,
ulong, bool, On_duplicate on_duplicate, Table_ident *table,
List<String> *opt_partitions, const CHARSET_INFO *opt_charset,
String *opt_xml_rows_identified_by,
const Field_separators &opt_field_separators,
const Line_separators &opt_line_separators,
ulong opt_ignore_lines, PT_item_list *opt_fields_or_vars,
PT_item_list *opt_set_fields, PT_item_list *opt_set_exprs,
List<String> *opt_set_expr_strings, bool)
: m_cmd(filetype, is_local_file, filename, on_duplicate, table,
opt_partitions, opt_charset, opt_xml_rows_identified_by,
opt_field_separators, opt_line_separators, opt_ignore_lines,
opt_fields_or_vars ? &opt_fields_or_vars->value : nullptr,
opt_set_fields ? &opt_set_fields->value : nullptr,
opt_set_exprs ? &opt_set_exprs->value : nullptr,
opt_set_expr_strings),
m_lock_type(lock_type) {
assert((opt_set_fields == nullptr) ^ (opt_set_exprs != nullptr));
assert(opt_set_fields == nullptr ||
opt_set_fields->value.size() == opt_set_exprs->value.size());
}
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_load_table m_cmd;
const thr_lock_type m_lock_type;
};
/**
Top-level node for the SHUTDOWN statement
@ingroup ptn_stmt
*/
class PT_restart_server final : public Parse_tree_root {
public:
Sql_cmd *make_cmd(THD *thd) override;
private:
Sql_cmd_restart_server sql_cmd;
};
class PT_install_component final : public Parse_tree_root {
private:
Mem_root_array_YY<LEX_STRING> m_urns;
List<PT_install_component_set_element> *m_set_elements;
public:
PT_install_component(THD *thd, const Mem_root_array_YY<LEX_STRING> urns,
List<PT_install_component_set_element> *set_elements);
Sql_cmd *make_cmd(THD *thd) override;
};
PT_alter_tablespace_option_base *make_tablespace_engine_attribute(MEM_ROOT *,
LEX_CSTRING);
PT_create_table_option *make_table_engine_attribute(MEM_ROOT *, LEX_CSTRING);
PT_create_table_option *make_table_secondary_engine_attribute(MEM_ROOT *,
LEX_CSTRING);
PT_column_attr_base *make_column_engine_attribute(MEM_ROOT *, LEX_CSTRING);
PT_column_attr_base *make_column_secondary_engine_attribute(MEM_ROOT *,
LEX_CSTRING);
PT_base_index_option *make_index_engine_attribute(MEM_ROOT *, LEX_CSTRING);
PT_base_index_option *make_index_secondary_engine_attribute(MEM_ROOT *,
LEX_CSTRING);
/**
Helper function to imitate \c dynamic_cast for \c PT_set_operation hierarchy.
Template parameter @p To is the destination type (@c PT_union, \c PT_except or
\c PT_intersect). For \c PT_intersect we return nullptr if ALL due to impl.
restriction: we cannot merge INTERSECT ALL.
@param from source item
@param is_distinct true if distinct
@return typecast item to the type To or NULL
*/
template <class To, PT_set_operation::Setop_type Tag>
To *setop_cast(PT_query_expression_body *from, bool is_distinct) {
return (from->type() == Tag &&
down_cast<PT_set_operation *>(from)->is_distinct() == is_distinct &&
(Tag != PT_query_expression_body::INTERSECT || is_distinct))
? static_cast<To *>(from)
: nullptr;
}
/**
Flatten set operators at parse time
This function flattens UNION ALL/DISTINCT, EXCEPT All/DISTINCT
and INTERSECT DISTINCT (not ALL due to implementation restrictions) operators
at parse time if applicable, otherwise it creates
new \c PT_<setop> nodes respectively of the two input operands.
Template parameter @p Class is @c PT_union or @c PT_intersect
Template parameter @p Tag is @c PT_query_specification::UNION or
@c ::INTERSECT
@param mem_root MEM_ROOT
@param left left argument of the operator
@param is_distinct true if DISTINCT
@param right right argument of the operator
@param is_right_in_parentheses
true if right hand size is parenthesized
@return resulting parse tree Item
*/
template <class Class, PT_set_operation::Setop_type Tag>
PT_set_operation *flatten_equal_set_ops(MEM_ROOT *mem_root,
PT_query_expression_body *left,
bool is_distinct,
PT_query_expression_body *right,
bool is_right_in_parentheses) {
if (left == nullptr || right == nullptr) return nullptr;
Class *left_setop = setop_cast<Class, Tag>(left, is_distinct);
Class *right_setop [[maybe_unused]] =
setop_cast<Class, Tag>(right, is_distinct);
assert(right_setop == nullptr); // doesn't happen
if (left_setop != nullptr) {
// X1 op X2 op Y ==> op (X1, X2, Y)
left_setop->m_list.push_back(right);
left_setop->set_is_rhs_in_parentheses(is_right_in_parentheses);
return left_setop;
} else {
/* X op Y */
return new (mem_root)
Class(left, is_distinct, right, is_right_in_parentheses);
}
}
#endif /* PARSE_TREE_NODES_INCLUDED */
|