ob_schema_struct.h 238.7 KB
Newer Older
O
oceanbase-admin 已提交
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
/**
 * Copyright (c) 2021 OceanBase
 * OceanBase CE is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#ifndef _OB_OCEANBASE_SCHEMA_SCHEMA_STRUCT_H
#define _OB_OCEANBASE_SCHEMA_SCHEMA_STRUCT_H

#include <stdint.h>
#include "lib/hash/ob_hashset.h"
#include "lib/hash/ob_placement_hashset.h"
#include "lib/net/ob_addr.h"
#include "common/ob_range.h"
#include "common/row/ob_row_util.h"
#include "share/ob_replica_info.h"
#include "share/ob_duplicate_scope_define.h"
#include "share/sequence/ob_sequence_option.h"
#include "share/system_variable/ob_system_variable_factory.h"
#include "share/schema/ob_priv_type.h"
#include "share/ob_priv_common.h"

#ifdef __cplusplus
extern "C" {
#endif
struct _ParseNode;
typedef struct _ParseNode ParseNode;
#ifdef __cplusplus
}
#endif

namespace oceanbase {
namespace common {
class ObIAllocator;
class ObSqlString;
class ObString;
class ObDataTypeCastParams;
class ObPartitionKey;
}  // namespace common
namespace sql {
class ObSQLSessionInfo;
class ObPartitionExecutorUtils;
}  // namespace sql
namespace rootserver {
class ObRandomZoneSelector;
class ObReplicaAddr;
}  // namespace rootserver
namespace share {
namespace schema {
typedef common::Ob2DArray<common::ObObjParam, common::OB_MALLOC_BIG_BLOCK_SIZE, common::ObWrapperAllocator, false>
    ParamStore;
class ObSchemaGetterGuard;
class ObSimpleTableSchemaV2;
class ObTableSchema;
class ObColumnSchemaV2;
#define ASSIGN_STRING(dst, src, field, buffer, skip)           \
  (dst)->field.assign(buffer + offset, (src)->field.length()); \
  offset += (src)->field.length() + (skip);

#define ASSIGN_CONST_STRING(dst, src, field, buffer, skip)                              \
  (const_cast<ObString&>((dst)->field)).assign(buffer + offset, (src)->field.length()); \
  offset += (src)->field.length() + (skip);

// match the default now func
#define IS_DEFAULT_NOW_STR(data_type, def_str) \
  ((ObDateTimeType == data_type || ObTimestampType == data_type) && (def_str == N_UPPERCASE_CUR_TIMESTAMP))

#define IS_DEFAULT_NOW_OBJ(def_obj) \
  (ObExtendType == def_obj.get_type() && ObActionFlag::OP_DEFAULT_NOW_FLAG == def_obj.get_ext())

#define OB_ORACLE_CONS_OR_IDX_CUTTED_NAME_LEN 60

// the lower 32-bit flag need be store in __all_column
static const uint64_t OB_MIN_ID = 0;  // used for lower_bound
#define NON_CASCADE_FLAG INT64_C(0)
#define VIRTUAL_GENERATED_COLUMN_FLAG (INT64_C(1) << 0)
#define STORED_GENERATED_COLUMN_FLAG (INT64_C(1) << 1)
#define CTE_GENERATED_COLUMN_FLAG (INT64_C(1) << 2)
#define DEFAULT_EXPR_V2_COLUMN_FLAG (INT64_C(1) << 3)
#define PRIMARY_VP_COLUMN_FLAG (INT64_C(1) << 4)
#define RESERVED_COLUMN_FLAG (INT64_C(1) << 5)
#define INVISIBLE_COLUMN_FLAG (INT64_C(1) << 6)
// The logic of the new table without a primary key changes the column (partition key) to the primary key
#define HEAP_ALTER_ROWKEY_FLAG (INT64_C(1) << 8)
// the high 32-bit flag isn't stored in __all_column
#define GENERATED_DEPS_CASCADE_FLAG (INT64_C(1) << 32)
#define GENERATED_CTXCAT_CASCADE_FLAG (INT64_C(1) << 33)
#define TABLE_PART_KEY_COLUMN_FLAG (INT64_C(1) << 34)

#define STORED_COLUMN_FLAGS_MASK 0xFFFFFFFF
//-------enum defenition
enum ObTableLoadType {
  TABLE_LOAD_TYPE_IN_DISK = 0,
  TABLE_LOAD_TYPE_IN_RAM = 1,
  TABLE_LOAD_TYPE_MAX = 2,
};
// the defination type of table
enum ObTableDefType {
  TABLE_DEF_TYPE_INTERNAL = 0,
  TABLE_DEF_TYPE_USER = 1,
  TABLE_DEF_TYPE_MAX = 2,
};
// level of patition
enum ObPartitionLevel {
  PARTITION_LEVEL_ZERO = 0,  // means non-partitioned table
  PARTITION_LEVEL_ONE = 1,
  PARTITION_LEVEL_TWO = 2,
  PARTITION_LEVEL_MAX,
};
// type of hash name to generate
enum ObHashNameType { FIRST_PART = 0, TEMPLATE_SUB_PART = 1, INDIVIDUAL_SUB_PART = 2 };

OB_INLINE int64_t generate_phy_part_id(int64_t part_idx, int64_t sub_part_idx, ObPartitionLevel part_level)
{
  return (PARTITION_LEVEL_TWO == part_level) ? common::generate_phy_part_id(part_idx, sub_part_idx) : part_idx;
}

enum ObPartitionFuncType {
  // TODO add other type
  PARTITION_FUNC_TYPE_HASH = 0,
  PARTITION_FUNC_TYPE_KEY,
  PARTITION_FUNC_TYPE_KEY_IMPLICIT,
  PARTITION_FUNC_TYPE_RANGE,
  PARTITION_FUNC_TYPE_RANGE_COLUMNS,
  PARTITION_FUNC_TYPE_LIST,
  PARTITION_FUNC_TYPE_KEY_V2,
  PARTITION_FUNC_TYPE_LIST_COLUMNS,
  PARTITION_FUNC_TYPE_HASH_V2,
  PARTITION_FUNC_TYPE_KEY_V3,
  PARTITION_FUNC_TYPE_KEY_IMPLICIT_V2,
  PARTITION_FUNC_TYPE_MAX,
};

int get_part_type_str(ObPartitionFuncType type, common::ObString& str, bool can_change = true);

inline bool is_hash_part(const ObPartitionFuncType part_type)
{
  return PARTITION_FUNC_TYPE_HASH == part_type || PARTITION_FUNC_TYPE_HASH_V2 == part_type;
}

inline bool is_hash_like_part(const ObPartitionFuncType part_type)
{
  return PARTITION_FUNC_TYPE_HASH == part_type || PARTITION_FUNC_TYPE_HASH_V2 == part_type ||
         PARTITION_FUNC_TYPE_KEY == part_type || PARTITION_FUNC_TYPE_KEY_IMPLICIT == part_type ||
         PARTITION_FUNC_TYPE_KEY_IMPLICIT_V2 == part_type || PARTITION_FUNC_TYPE_KEY_V2 == part_type ||
         PARTITION_FUNC_TYPE_KEY_V3 == part_type;
}

inline bool is_key_part(const ObPartitionFuncType part_type)
{
  return PARTITION_FUNC_TYPE_KEY == part_type || PARTITION_FUNC_TYPE_KEY_V2 == part_type ||
         PARTITION_FUNC_TYPE_KEY_IMPLICIT == part_type || PARTITION_FUNC_TYPE_KEY_IMPLICIT_V2 == part_type ||
         PARTITION_FUNC_TYPE_KEY_V3 == part_type;
}

inline bool is_range_part(const ObPartitionFuncType part_type)
{
  return PARTITION_FUNC_TYPE_RANGE == part_type || PARTITION_FUNC_TYPE_RANGE_COLUMNS == part_type;
}

inline bool is_list_part(const ObPartitionFuncType part_type)
{
  return PARTITION_FUNC_TYPE_LIST == part_type || PARTITION_FUNC_TYPE_LIST_COLUMNS == part_type;
}

int is_sys_table_name(uint64_t database_id, const common::ObString& table_name, bool& is_sys_table);

// adding new table type, take care ObRootUtils::is_balance_target_schema() interface
// This structure indicates whether the tableSchema of this type is the object of load balancing,
// and the judgment is based on whether the table schema has physical partitions of entities,
// and only non-system tables are load-balanced.
enum ObTableType {
  SYSTEM_TABLE = 0,
  SYSTEM_VIEW,
  VIRTUAL_TABLE,
  USER_TABLE,
  USER_VIEW,
  USER_INDEX,          // urgly, compatible with uniform process in ddl_service
                       // will add index for sys table???
  TMP_TABLE,           // Temporary table in mysql compatibility mode
  MATERIALIZED_VIEW,   // Must be put behind, otherwise compatibility will fail
  TMP_TABLE_ORA_SESS,  // Temporary table in oracle compatibility mode, session level
  TMP_TABLE_ORA_TRX,   // Temporary tables in oracle compatibility mode, transaction level
  TMP_TABLE_ALL,       // All types of temporary tables, only used for alter system statements
  AUX_VERTIAL_PARTITION_TABLE,
  MAX_TABLE_TYPE
};

// ObTableType=>const char* ; used for show tables
const char* ob_table_type_str(ObTableType type);
const char* ob_mysql_table_type_str(ObTableType type);

ObTableType get_inner_table_type_by_id(const uint64_t tid);

enum ObIndexType {
  INDEX_TYPE_IS_NOT = 0,  // is not index table
  INDEX_TYPE_NORMAL_LOCAL = 1,
  INDEX_TYPE_UNIQUE_LOCAL = 2,
  INDEX_TYPE_NORMAL_GLOBAL = 3,
  INDEX_TYPE_UNIQUE_GLOBAL = 4,
  INDEX_TYPE_PRIMARY = 5,
  INDEX_TYPE_DOMAIN_CTXCAT = 6,
  INDEX_TYPE_NORMAL_GLOBAL_LOCAL_STORAGE = 7,
  INDEX_TYPE_UNIQUE_GLOBAL_LOCAL_STORAGE = 8,
  INDEX_TYPE_MAX = 9,
};

// using type for index
enum ObIndexUsingType {
  USING_BTREE = 0,
  USING_HASH,
  USING_TYPE_MAX,
};

enum ViewCheckOption {
  VIEW_CHECK_OPTION_NONE = 0,
  VIEW_CHECK_OPTION_LOCAL = 1,
  VIEW_CHECK_OPTION_CASCADED = 2,
  VIEW_CHECK_OPTION_MAX = 3,
};

const char* ob_view_check_option_str(const ViewCheckOption option);
enum ObIndexStatus {
  // this is used in index virtual table:__index_process_info:means the table may be deleted when you get it
  INDEX_STATUS_NOT_FOUND = 0,
  INDEX_STATUS_UNAVAILABLE = 1,
  INDEX_STATUS_AVAILABLE = 2,
  INDEX_STATUS_UNIQUE_CHECKING = 3,    // not used anymore
  INDEX_STATUS_UNIQUE_INELIGIBLE = 4,  // not used anymore
  INDEX_STATUS_INDEX_ERROR = 5,
  INDEX_STATUS_RESTORE_INDEX_ERROR = 6,
  INDEX_STATUS_UNUSABLE = 7,
  INDEX_STATUS_MAX = 8,
};

enum ObPartitionStatus {
  PARTITION_STATUS_INVALID = -1,
  PARTITION_STATUS_ACTIVE = 0,
  PARTITION_STATUS_LOGICAL_SPLITTING = 1,
  PARTITION_STATUS_MERGE = 2,
  PARTITION_STATUS_PHYSICAL_SPLITTING = 3,
  PARTITION_STATUS_MAX,
};

enum ObAlterColumnMode {
  ALTER_COLUMN_MODE_FORBIDDEN = 0,
  ALTER_COLUMN_MODE_ALLOWED = 1,
  ALTER_COLUMN_MODE_FORBIDDEN_WHEN_MAJOR = 2,
};

struct ObRefreshSchemaStatus {
  public:
  ObRefreshSchemaStatus()
      : tenant_id_(common::OB_INVALID_TENANT_ID),
        snapshot_timestamp_(common::OB_INVALID_TIMESTAMP),
        readable_schema_version_(common::OB_INVALID_VERSION),
        created_schema_version_(common::OB_INVALID_VERSION)
  {}

  ObRefreshSchemaStatus(const uint64_t tenant_id, const int64_t snapshot_timestamp,
      const int64_t readable_schema_version, const int64_t created_schema_version)
      : tenant_id_(tenant_id),
        snapshot_timestamp_(snapshot_timestamp),
        readable_schema_version_(readable_schema_version),
        created_schema_version_(created_schema_version)
  {}

  void reset()
  {
    tenant_id_ = common::OB_INVALID_TENANT_ID;
    snapshot_timestamp_ = common::OB_INVALID_TIMESTAMP;
    readable_schema_version_ = common::OB_INVALID_VERSION;
    created_schema_version_ = common::OB_INVALID_VERSION;
  }

  bool is_valid() const
  {
    return common::OB_INVALID_TENANT_ID != tenant_id_;
  }

  bool operator==(const ObRefreshSchemaStatus& other) const
  {
    return ((this == &other) ||
            (this->tenant_id_ == other.tenant_id_ && this->snapshot_timestamp_ == other.snapshot_timestamp_ &&
                this->readable_schema_version_ == other.readable_schema_version_ &&
                this->created_schema_version_ == other.created_schema_version_));
  }

  TO_STRING_KV(K_(tenant_id), K_(snapshot_timestamp), K_(readable_schema_version), K_(created_schema_version));

  public:
  // tenant_id_ is OB_INVALID_TENANT_ID which means non-split mode, effectively means split mode
  uint64_t tenant_id_;
  // snapshot_timestamp_ > 0 Indicates that a weakly consistent read is required, and is used in standalone cluster mode
  int64_t snapshot_timestamp_;
  int64_t readable_schema_version_;
  int64_t created_schema_version_;
};

struct ObRefreshSchemaInfo {
  OB_UNIS_VERSION(1);

  public:
  ObRefreshSchemaInfo()
      : schema_version_(common::OB_INVALID_VERSION),
        tenant_id_(common::OB_INVALID_TENANT_ID),
        sequence_id_(common::OB_INVALID_ID),
        split_schema_version_(common::OB_INVALID_VERSION)
  {}
  ObRefreshSchemaInfo(const ObRefreshSchemaInfo& other);
  virtual ~ObRefreshSchemaInfo()
  {}
  int assign(const ObRefreshSchemaInfo& other);
  void reset();
  bool is_valid() const;
  void set_tenant_id(const uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  void set_schema_version(const int64_t schema_version)
  {
    schema_version_ = schema_version;
  }
  void set_sequence_id(const uint64_t sequence_id)
  {
    sequence_id_ = sequence_id;
  }
  void set_split_schema_version(const int64_t split_schema_version)
  {
    split_schema_version_ = split_schema_version;
  }
  uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  int64_t get_schema_version() const
  {
    return schema_version_;
  }
  uint64_t get_sequence_id() const
  {
    return sequence_id_;
  }
  int64_t get_split_schema_version() const
  {
    return split_schema_version_;
  }
  TO_STRING_KV(K_(schema_version), K_(tenant_id), K_(sequence_id), K_(split_schema_version));

  private:
  int64_t schema_version_;
  uint64_t tenant_id_;
  uint64_t sequence_id_;
  int64_t split_schema_version_;
};

class ObDropTenantInfo {
  public:
  ObDropTenantInfo() : tenant_id_(common::OB_INVALID_TENANT_ID), schema_version_(common::OB_INVALID_VERSION)
  {}
  virtual ~ObDropTenantInfo(){};
  void reset();
  bool is_valid() const;
  uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  int64_t get_schema_version() const
  {
    return schema_version_;
  }
  void set_tenant_id(const uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  void set_schema_version(const int64_t schema_version)
  {
    schema_version_ = schema_version;
  }
  TO_STRING_KV(K_(tenant_id), K_(schema_version));

  private:
  uint64_t tenant_id_;
  int64_t schema_version_;
};

struct ObIndexTableStat {
  ObIndexTableStat()
      : index_id_(common::OB_INVALID_ID), index_status_(share::schema::INDEX_STATUS_UNAVAILABLE), is_drop_schema_(false)
  {}
  ObIndexTableStat(const uint64_t index_id, const share::schema::ObIndexStatus index_status, const bool is_drop_schema)
      : index_id_(index_id), index_status_(index_status), is_drop_schema_(is_drop_schema)
  {}
  TO_STRING_KV(K_(index_id), K_(index_status), K_(is_drop_schema));
  uint64_t index_id_;
  share::schema::ObIndexStatus index_status_;
  bool is_drop_schema_;
};

inline bool is_final_invalid_index_status(const ObIndexStatus index_status, const bool is_drop_schema)
{
  bool ret_bool = !(index_status >= INDEX_STATUS_UNAVAILABLE && index_status <= INDEX_STATUS_UNIQUE_CHECKING);

  if (!ret_bool) {
    ret_bool = is_drop_schema;
  }
  return ret_bool;
}

inline bool is_final_index_status(const ObIndexStatus index_status, const bool is_dropped_schema)
{
  return INDEX_STATUS_AVAILABLE == index_status || INDEX_STATUS_INDEX_ERROR == index_status ||
         INDEX_STATUS_RESTORE_INDEX_ERROR == index_status || INDEX_STATUS_UNUSABLE == index_status || is_dropped_schema;
}

inline bool is_error_index_status(const ObIndexStatus index_status, const bool is_dropped_schema)
{
  return INDEX_STATUS_INDEX_ERROR == index_status || INDEX_STATUS_RESTORE_INDEX_ERROR == index_status ||
         INDEX_STATUS_UNUSABLE == index_status || is_dropped_schema;
}

inline bool is_available_index_status(const ObIndexStatus index_status)
{
  return INDEX_STATUS_AVAILABLE == index_status;
}

const char* ob_index_status_str(ObIndexStatus status);

struct ObTenantTableId {
  ObTenantTableId() : tenant_id_(common::OB_INVALID_ID), table_id_(common::OB_INVALID_ID)
  {}
  ObTenantTableId(const uint64_t tenant_id, const uint64_t table_id) : tenant_id_(tenant_id), table_id_(table_id)
  {}
  bool operator==(const ObTenantTableId& rv) const
  {
    return (tenant_id_ == rv.tenant_id_) && (table_id_ == rv.table_id_);
  }
  ObTenantTableId& operator=(const ObTenantTableId& tenant_table_id);
  int64_t hash() const
  {
    return table_id_;
  }
  bool operator<(const ObTenantTableId& rv) const
  {
    bool res = tenant_id_ < rv.tenant_id_;
    if (tenant_id_ == rv.tenant_id_) {
      res = table_id_ < rv.table_id_;
    }
    return res;
  }
  void reset()
  {
    tenant_id_ = common::OB_INVALID_ID;
    table_id_ = common::OB_INVALID_ID;
  }
  bool is_valid() const
  {
    return (common::OB_INVALID_ID != tenant_id_) && (common::OB_INVALID_ID != table_id_);
  }

  TO_STRING_KV(K_(tenant_id), K_(table_id));

  uint64_t tenant_id_;
  uint64_t table_id_;
};

struct ObTenantDatabaseId {
  ObTenantDatabaseId() : tenant_id_(common::OB_INVALID_ID), database_id_(common::OB_INVALID_ID)
  {}
  ObTenantDatabaseId(const uint64_t tenant_id, const uint64_t database_id)
      : tenant_id_(tenant_id), database_id_(database_id)
  {}
  bool operator==(const ObTenantDatabaseId& rv) const
  {
    return ((tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_));
  }
  int64_t hash() const
  {
    return database_id_;
  }
  bool operator<(const ObTenantDatabaseId& rv) const
  {
    bool res = tenant_id_ < rv.tenant_id_;
    if (tenant_id_ == rv.tenant_id_) {
      res = database_id_ < rv.database_id_;
    }
    return res;
  }
  void reset()
  {
    tenant_id_ = common::OB_INVALID_ID;
    database_id_ = common::OB_INVALID_ID;
  }
  bool is_valid() const
  {
    return (common::OB_INVALID_ID != tenant_id_) && (common::OB_INVALID_ID != database_id_);
  }

  TO_STRING_KV(K_(tenant_id), K_(database_id));

  uint64_t tenant_id_;
  uint64_t database_id_;
};

struct ObTenantTablegroupId {
  ObTenantTablegroupId() : tenant_id_(common::OB_INVALID_ID), tablegroup_id_(common::OB_INVALID_ID)
  {}
  ObTenantTablegroupId(const uint64_t tenant_id, const uint64_t tablegroup_id)
      : tenant_id_(tenant_id), tablegroup_id_(tablegroup_id)
  {}
  bool operator==(const ObTenantTablegroupId& rv) const
  {
    return (tenant_id_ == rv.tenant_id_) && (tablegroup_id_ == rv.tablegroup_id_);
  }
  int64_t hash() const
  {
    return tablegroup_id_;
  }
  bool operator<(const ObTenantTablegroupId& rv) const
  {
    bool res = tenant_id_ < rv.tenant_id_;
    if (tenant_id_ == rv.tenant_id_) {
      res = tablegroup_id_ < rv.tablegroup_id_;
    }
    return res;
  }
  bool is_valid() const
  {
    return (common::OB_INVALID_ID != tenant_id_) && (common::OB_INVALID_ID != tablegroup_id_);
  }
  void reset()
  {
    tenant_id_ = common::OB_INVALID_ID;
    tablegroup_id_ = common::OB_INVALID_ID;
  }

  TO_STRING_KV(K_(tenant_id), K_(tablegroup_id));

  uint64_t tenant_id_;
  uint64_t tablegroup_id_;
};

typedef enum {
  TENANT_SCHEMA = 0,
  OUTLINE_SCHEMA = 1,
  USER_SCHEMA = 2,
  DATABASE_SCHEMA = 3,
  TABLEGROUP_SCHEMA = 4,
  TABLE_SCHEMA = 5,
  DATABASE_PRIV = 6,
  TABLE_PRIV = 7,
  ROUTINE_SCHEMA = 8,
  SYNONYM_SCHEMA = 9,
  PLAN_BASELINE_SCHEMA = 10,
  PACKAGE_SCHEMA = 12,
  UDF_SCHEMA = 13,
  SEQUENCE_SCHEMA = 14,
  SYS_VARIABLE_SCHEMA = 15,
  UDT_SCHEMA = 16,
  // At present, only liboblog constructs simple table schema in real time in lazy mode, ob does not use it temporarily
  TABLE_SIMPLE_SCHEMA = 17,
  TABLESPACE_SCHEMA = 18,
  TRIGGER_SCHEMA = 19,
  KEYSTORE_SCHEMA = 20,
  PROFILE_SCHEMA = 25,
  AUDIT_SCHEMA = 26,  // UNUSED
  SYS_PRIV = 27,
  OBJ_PRIV = 28,
  DBLINK_SCHEMA = 29,
  LINK_TABLE_SCHEMA = 30,
  ///<<< add schema type before this line
  OB_MAX_SCHEMA
} ObSchemaType;

// The user tenant system table schema is taken from the system tenant, and the schema_id needs to be changed
int need_change_schema_id(const ObSchemaType schema_type, const uint64_t schema_id, bool& need_change);

const char* schema_type_str(const ObSchemaType schema_type);

bool is_normal_schema(const ObSchemaType schema_type);

struct ObSchemaStatisticsInfo {
  ObSchemaStatisticsInfo(ObSchemaType schema_type, int64_t size = 0, int64_t count = 0)
      : schema_type_(schema_type), size_(size), count_(count)
  {}
  ObSchemaStatisticsInfo() : schema_type_(OB_MAX_SCHEMA), size_(0), count_(0)
  {}
  ~ObSchemaStatisticsInfo()
  {}
  bool is_valid() const
  {
    return OB_MAX_SCHEMA != schema_type_;
  }
  void reset()
  {
    schema_type_ = OB_MAX_SCHEMA;
    size_ = 0;
    count_ = 0;
  }
  TO_STRING_KV(K_(schema_type), K_(size), K_(count));
  ObSchemaType schema_type_;
  int64_t size_;
  int64_t count_;
};

class ObPartition;
class PartIdPartitionArrayCmp {
  public:
  PartIdPartitionArrayCmp() : ret_(common::OB_SUCCESS)
  {}
  bool operator()(const share::schema::ObPartition* left, const share::schema::ObPartition* right);

  public:
  int get_ret() const
  {
    return ret_;
  }

  private:
  int ret_;
};

class ObSubPartition;
class SubPartIdPartitionArrayCmp {
  public:
  SubPartIdPartitionArrayCmp() : ret_(common::OB_SUCCESS)
  {}
  bool operator()(const share::schema::ObSubPartition* left, const share::schema::ObSubPartition* right);

  public:
  int get_ret() const
  {
    return ret_;
  }

  private:
  int ret_;
};

struct ObSimpleTableSchema {
  uint64_t tenant_id_;
  uint64_t database_id_;
  uint64_t tablegroup_id_;
  uint64_t table_id_;
  uint64_t data_table_id_;
  common::ObString table_name_;
  int64_t schema_version_;
  ObTableType table_type_;
  ObSimpleTableSchema()
      : tenant_id_(common::OB_INVALID_ID),
        database_id_(common::OB_INVALID_ID),
        tablegroup_id_(common::OB_INVALID_ID),
        table_id_(common::OB_INVALID_ID),
        data_table_id_(common::OB_INVALID_ID),
        schema_version_(common::OB_INVALID_VERSION),
        table_type_(MAX_TABLE_TYPE)
  {}
  void reset()
  {
    tenant_id_ = common::OB_INVALID_ID;
    database_id_ = common::OB_INVALID_ID;
    tablegroup_id_ = common::OB_INVALID_ID;
    table_id_ = common::OB_INVALID_ID;
    data_table_id_ = common::OB_INVALID_ID;
    table_name_.reset();
    schema_version_ = common::OB_INVALID_VERSION;
    table_type_ = MAX_TABLE_TYPE;
  }
  TO_STRING_KV(K_(tenant_id), K_(database_id), K_(tablegroup_id), K_(table_id), K_(data_table_id), K_(table_name),
      K_(schema_version), K_(table_type));
  bool is_valid() const
  {
    return (common::OB_INVALID_ID != tenant_id_ && common::OB_INVALID_ID != database_id_ &&
            common::OB_INVALID_ID != tablegroup_id_ && common::OB_INVALID_ID != table_id_ &&
            common::OB_INVALID_ID != data_table_id_ && !table_name_.empty() && schema_version_ >= 0 &&
            table_type_ != MAX_TABLE_TYPE);
  }
};

enum TableStatus {
  TABLE_STATUS_INVALID = -1,
  // The current schema version does not exist, it is a future table
  TABLE_NOT_CREATE,
  TABLE_EXIST,    // table exist
  TABLE_DELETED,  // table is deleted
};

enum TenantStatus {
  TENANT_STATUS_INVALID = -1,
  TENANT_NOT_CREATE,
  TENANT_EXIST,
  TENANT_DELETED,
};

inline const char* print_table_status(const TableStatus status_no)
{
  const char* status_str = "UNKNOWN";
  switch (status_no) {
    case TABLE_NOT_CREATE:
      status_str = "TABLE_NOT_CREATE";
      break;
    case TABLE_EXIST:
      status_str = "TABLE_EXIST";
      break;
    case TABLE_DELETED:
      status_str = "TABLE_DELETED";
      break;
    default:
      status_str = "UNKNOWN";
      break;
  }
  return status_str;
}

enum PartitionStatus {
  PART_STATUS_INVALID = -1,
  // The current schema version has not been created, it is a future partition
  PART_NOT_CREATE,
  PART_EXIST,    // schema exist
  PART_DELETED,  // partition is deleted
};

inline const char* print_part_status(const PartitionStatus status)
{
  const char* str = "UNKNOWN";
  switch (status) {
    case PART_STATUS_INVALID:
      str = "PART_STATUS_INVALID";
      break;
    case PART_NOT_CREATE:
      str = "PART_NOT_CREATE";
      break;
    case PART_EXIST:
      str = "PART_EXIST";
      break;
    case PART_DELETED:
      str = "PART_DELETED";
      break;
    default:
      str = "UNKNOWN";
      break;
  }
  return str;
}

enum ObDependencyTableType {
  DEPENDENCY_INVALID = 0,
  DEPENDENCY_TABLE = 1,
  DEPENDENCY_VIEW = 2,
  DEPENDENCY_SYNONYM = 3,
  DEPENDENCY_PROCEDURE = 4,
  DEPENDENCY_OUTLINE = 5,
  DEPENDENCY_FUNCTION = 6,
  DEPENDENCY_PACKAGE = 7,
  DEPENDENCY_PACKAGE_BODY = 8,
  DEPENDENCY_SEQUENCE = 9,
  DEPENDENCY_TYPE = 10,
  DEPENDENCY_TABLESPACE = 15,
  DEPENDENCY_UDT = 16,
  DEPENDENCY_UDT_BODY = 17
};

enum class ObObjectType {
  INVALID = 0,
  TABLE,
  SEQUENCE,
  PACKAGE,
  TYPE,
  PACKAGE_BODY,
  TYPE_BODY,
  TRIGGER,
  VIEW,
  FUNCTION,
  DIRECTORY,
  INDEX,
  PROCEDURE,
  SYNONYM,
  MAX_TYPE,
};
struct ObSchemaObjVersion {
  ObSchemaObjVersion()
      : object_id_(common::OB_INVALID_ID),
        version_(0),
        // The default is table, which is compatible with the current logic
        object_type_(DEPENDENCY_TABLE),
        is_db_explicit_(false),
        is_existed_(true)
  {}

  ObSchemaObjVersion(int64_t object_id, int64_t version, ObDependencyTableType object_type)
      : object_id_(object_id), version_(version), object_type_(object_type), is_db_explicit_(false), is_existed_(true)
  {}

  inline void reset()
  {
    object_id_ = common::OB_INVALID_ID;
    version_ = 0;
    // The default is table, which is compatible with the current logic
    object_type_ = DEPENDENCY_TABLE;
    is_db_explicit_ = false;
    is_existed_ = true;
  }
  inline int64_t get_object_id() const
  {
    return object_id_;
  }
  inline int64_t get_version() const
  {
    return version_;
  }
  inline ObDependencyTableType get_type() const
  {
    return object_type_;
  }
  inline bool operator==(const ObSchemaObjVersion& other) const
  {
    return object_id_ == other.object_id_ && version_ == other.version_ && object_type_ == other.object_type_ &&
           is_db_explicit_ == other.is_db_explicit_ && is_existed_ == other.is_existed_;
  }
  inline bool operator!=(const ObSchemaObjVersion& other) const
  {
    return !operator==(other);
  }
  ObSchemaType get_schema_type() const
  {
    ObSchemaType ret_type = OB_MAX_SCHEMA;
    switch (object_type_) {
      case DEPENDENCY_TABLE:
      case DEPENDENCY_VIEW:
        ret_type = TABLE_SCHEMA;
        break;
      case DEPENDENCY_SYNONYM:
        ret_type = SYNONYM_SCHEMA;
        break;
      case DEPENDENCY_PROCEDURE:
      case DEPENDENCY_FUNCTION:
        ret_type = ROUTINE_SCHEMA;
        break;
      case DEPENDENCY_PACKAGE:
      case DEPENDENCY_PACKAGE_BODY:
        ret_type = PACKAGE_SCHEMA;
        break;
      case DEPENDENCY_OUTLINE:
        ret_type = OUTLINE_SCHEMA;
        break;
      case DEPENDENCY_SEQUENCE:
        ret_type = SEQUENCE_SCHEMA;
        break;
      case DEPENDENCY_TABLESPACE:
        ret_type = TABLESPACE_SCHEMA;
        break;
      case DEPENDENCY_TYPE:
        ret_type = UDT_SCHEMA;
        break;
      default:
        break;
    }
    return ret_type;
  }
  ObObjectType get_schema_object_type() const
  {
    ObObjectType ret_type = ObObjectType::MAX_TYPE;
    switch (object_type_) {
      case DEPENDENCY_TABLE:
        ret_type = ObObjectType::TABLE;
        break;
      case DEPENDENCY_VIEW:
        ret_type = ObObjectType::VIEW;
        break;
      case DEPENDENCY_PROCEDURE:
        ret_type = ObObjectType::PROCEDURE;
        break;
      case DEPENDENCY_FUNCTION:
        ret_type = ObObjectType::FUNCTION;
        break;
      case DEPENDENCY_PACKAGE:
        ret_type = ObObjectType::PACKAGE;
        break;
      case DEPENDENCY_PACKAGE_BODY:
        ret_type = ObObjectType::PACKAGE_BODY;
        break;
      case DEPENDENCY_SEQUENCE:
        ret_type = ObObjectType::SEQUENCE;
        break;
      case DEPENDENCY_TYPE:
        ret_type = ObObjectType::TYPE;
        break;
      default:
        break;
    }
    return ret_type;
  }
  inline bool is_valid() const
  {
    return common::OB_INVALID_ID != object_id_;
  }
  inline bool is_base_table() const
  {
    return DEPENDENCY_TABLE == object_type_;
  }
  inline bool is_synonym() const
  {
    return DEPENDENCY_SYNONYM == object_type_;
  }
  inline bool is_procedure() const
  {
    return DEPENDENCY_PROCEDURE == object_type_;
  }
  inline bool is_db_explicit() const
  {
    return is_db_explicit_;
  }
  inline bool is_existed() const
  {
    return is_existed_;
  }

  int64_t object_id_;
  int64_t version_;
  ObDependencyTableType object_type_;
  bool is_db_explicit_;
  bool is_existed_;

  TO_STRING_KV(N_TID, object_id_, N_SCHEMA_VERSION, version_, K_(object_type), K_(is_db_explicit), K_(is_existed));
  OB_UNIS_VERSION(1);
};

struct ObSysParam {
  ObSysParam();
  ~ObSysParam();

  int init(const uint64_t tenant_id, const common::ObZone& zone, const common::ObString& name, const int64_t data_type,
      const common::ObString& value, const common::ObString& min_val, const common::ObString& max_val,
      const common::ObString& info, const int64_t flags);
  void reset();
  inline bool is_valid() const;
  int64_t to_string(char* buf, const int64_t buf_len) const;

  uint64_t tenant_id_;
  common::ObZone zone_;
  char name_[common::OB_MAX_SYS_PARAM_NAME_LENGTH];
  int64_t data_type_;
  char value_[common::OB_MAX_SYS_PARAM_VALUE_LENGTH];
  char min_val_[common::OB_MAX_SYS_PARAM_VALUE_LENGTH];
  char max_val_[common::OB_MAX_SYS_PARAM_VALUE_LENGTH];
  char info_[common::OB_MAX_SYS_PARAM_INFO_LENGTH];
  int64_t flags_;
};

bool ObSysParam::is_valid() const
{
  return common::OB_INVALID_ID != tenant_id_;
}
typedef common::ObFixedBitSet<common::OB_MAX_USER_DEFINED_COLUMNS_COUNT> ColumnReferenceSet;

// this is used for schema, and zone in this is a ObString,
// Caution: zone_ here doesn't have buffer, users should manange
//          the buffer memory all by themselves.
struct ObZoneScore {
  ObZoneScore(common::ObString& zone, int64_t score) : zone_(zone), score_(score)
  {}
  ObZoneScore() : zone_(), score_(INT64_MAX)
  {}
  virtual ~ObZoneScore()
  {}
  bool operator<(const ObZoneScore& that)
  {
    return score_ < that.score_;
  }
  void reset()
  {
    zone_.reset();
    score_ = INT64_MAX;
  }
  TO_STRING_KV(K(zone_), K(score_));

  common::ObString zone_;
  int64_t score_;
};
// ObZoneRegion is used to construct the primary zone array of TableSchema/DataBaseSchema/TenantSchema.
// It is only an intermediate variable during the construction process. ObZoneRegion will not be saved
// in the schema eventually. This structure saves the zone and the region in which the zone is located.
struct ObZoneRegion {
  ObZoneRegion() : zone_(), region_()
  {}
  ObZoneRegion(const ObZoneRegion& that) : zone_(that.zone_), region_(that.region_)
  {}
  ObZoneRegion(const common::ObZone& zone, const common::ObRegion& region) : zone_(zone), region_(region)
  {}
  virtual ~ObZoneRegion()
  {}
  void reset()
  {
    zone_.reset();
    region_.reset();
  }
  int assign(const ObZoneRegion& that)
  {
    int ret = common::OB_SUCCESS;
    if (OB_FAIL(zone_.assign(that.zone_.ptr()))) {
      SHARE_LOG(WARN, "fail to assign zone", K(ret));
    } else if (OB_FAIL(region_.assign(that.region_.ptr()))) {
      SHARE_LOG(WARN, "fail to assign region", K(ret));
    } else {
    }
    return ret;
  }
  TO_STRING_KV(K(zone_), K(region_));

  common::ObZone zone_;
  common::ObRegion region_;
};

typedef common::ObIArray<share::ObZoneReplicaAttrSet> ZoneLocalityIArray;
typedef common::ObArrayHelper<share::SchemaZoneReplicaAttrSet> ZoneLocalityArray;

class ObCompareNameWithTenantID {
  public:
  ObCompareNameWithTenantID()
      : tenant_id_(common::OB_INVALID_ID),
        name_case_mode_(common::OB_NAME_CASE_INVALID),
        database_id_(common::OB_INVALID_ID)
  {}
  ObCompareNameWithTenantID(uint64_t tenant_id)
      : tenant_id_(tenant_id), name_case_mode_(common::OB_NAME_CASE_INVALID), database_id_(common::OB_INVALID_ID)
  {}
  ObCompareNameWithTenantID(uint64_t tenant_id, common::ObNameCaseMode mode)
      : tenant_id_(tenant_id), name_case_mode_(mode), database_id_(common::OB_INVALID_ID)
  {}
  ObCompareNameWithTenantID(uint64_t tenant_id, common::ObNameCaseMode mode, uint64_t database_id)
      : tenant_id_(tenant_id), name_case_mode_(mode), database_id_(database_id)
  {}
  ~ObCompareNameWithTenantID()
  {}
  int compare(const common::ObString& str1, const common::ObString& str2);

  private:
  uint64_t tenant_id_;
  common::ObNameCaseMode name_case_mode_;
  uint64_t database_id_;
};

class ObSchema {
  public:
  friend class ObLocality;
  friend class ObPrimaryZone;
  ObSchema();
  // explicit ObSchema(common::ObDataBuffer &buffer);
  explicit ObSchema(common::ObIAllocator* allocator);
  virtual ~ObSchema();
  virtual void reset();
  virtual bool is_valid() const
  {
    return common::OB_SUCCESS == error_ret_;
  }
  virtual int zone_array2str(
      const common::ObIArray<common::ObZone>& zone_list, char* str, const int64_t buf_size) const;
  virtual int string_array2str(
      const common::ObIArray<common::ObString>& string_array, char* buf, const int64_t buf_size) const;
  virtual int str2string_array(const char* str, common::ObIArray<common::ObString>& string_array) const;

  virtual int64_t get_convert_size() const
  {
    return 0;
  };
  template <typename DSTSCHEMA>
  static int set_charset_and_collation_options(
      common::ObCharsetType src_charset_type, common::ObCollationType src_collation_type, DSTSCHEMA& dst);
  static common::ObCollationType get_cs_type_with_cmp_mode(const common::ObNameCaseMode mode);

  ObSchema* get_buffer() const
  {
    return buffer_;
  }
  void set_buffer(ObSchema* buffer)
  {
    buffer_ = buffer;
  }
  common::ObIAllocator* get_allocator();
  void reset_allocator();
  int get_assign_ret()
  {
    return error_ret_;
  }
  inline int get_err_ret() const
  {
    return error_ret_;
  }

  protected:
  static const int64_t STRING_ARRAY_EXTEND_CNT = 7;
  void* alloc(const int64_t size);
  void free(void* ptr);
  int deep_copy_str(const char* src, common::ObString& dest);
  int deep_copy_str(const common::ObString& src, common::ObString& dest);
  int deep_copy_obj(const common::ObObj& src, common::ObObj& dest);
  int deep_copy_string_array(
      const common::ObIArray<common::ObString>& src, common::ObArrayHelper<common::ObString>& dst);
  int add_string_to_array(const common::ObString& str, common::ObArrayHelper<common::ObString>& str_array);
  int serialize_string_array(
      char* buf, const int64_t buf_len, int64_t& pos, const common::ObArrayHelper<common::ObString>& str_array) const;
  int deserialize_string_array(
      const char* buf, const int64_t data_len, int64_t& pos, common::ObArrayHelper<common::ObString>& str_array);
  int64_t get_string_array_serialize_size(const common::ObArrayHelper<common::ObString>& str_array) const;
  void reset_string(common::ObString& str);
  void reset_string_array(common::ObArrayHelper<common::ObString>& str_array);
  const char* extract_str(const common::ObString& str) const;
  // buffer is the memory used to store schema item, if not same with this pointer,
  // it means that this schema item has already been rewrote to buffer when rewriting
  // other schema manager, and when we want to rewrite this schema item in current schema
  // manager, we just set pointer of schema item in schema manager to buffer
  ObSchema* buffer_;
  int error_ret_;
  bool is_inner_allocator_;
  common::ObIAllocator* allocator_;
};

template <typename DSTSCHEMA>
int ObSchema::set_charset_and_collation_options(
    common::ObCharsetType src_charset_type, common::ObCollationType src_collation_type, DSTSCHEMA& dst)
{
  int ret = common::OB_SUCCESS;
  if (dst.get_charset_type() == common::CHARSET_INVALID && dst.get_collation_type() == common::CS_TYPE_INVALID) {
    // use upper layer schema's charset and collation type
    if (src_charset_type == common::CHARSET_INVALID || src_collation_type == common::CS_TYPE_INVALID) {
      ret = common::OB_ERR_UNEXPECTED;
      SHARE_SCHEMA_LOG(WARN, "charset type or collation type is invalid ", K(ret));
    } else {
      dst.set_charset_type(src_charset_type);
      dst.set_collation_type(src_collation_type);
    }
  } else {
    common::ObCharsetType charset_type = dst.get_charset_type();
    common::ObCollationType collation_type = dst.get_collation_type();
    if (OB_FAIL(common::ObCharset::check_and_fill_info(charset_type, collation_type))) {
      SHARE_SCHEMA_LOG(WARN, "fail to check charset collation", K(charset_type), K(collation_type), K(ret));
    } else {
      dst.set_charset_type(charset_type);
      dst.set_collation_type(collation_type);
    }
  }
  if (common::OB_SUCCESS == ret &&
      !common::ObCharset::is_valid_collation(dst.get_charset_type(), dst.get_collation_type())) {
    ret = common::OB_ERR_UNEXPECTED;
    SHARE_SCHEMA_LOG(WARN, "invalid collation!", K(dst.get_charset_type()), K(dst.get_collation_type()), K(ret));
  }
  return ret;
}

class ObLocality {
  OB_UNIS_VERSION(1);

  public:
  explicit ObLocality(ObSchema* schema) : schema_(schema)
  {}
  int assign(const ObLocality& other);
  int set_locality_str(const common::ObString& locality);
  int set_zone_replica_attr_array(const common::ObIArray<share::ObZoneReplicaAttrSet>& src);
  int set_zone_replica_attr_array(const common::ObIArray<share::SchemaZoneReplicaAttrSet>& src);
  int set_specific_replica_attr_array(
      share::SchemaReplicaAttrArray& schema_replica_set, const common::ObIArray<ReplicaAttr>& src);
  void reset_zone_replica_attr_array();
  int64_t get_convert_size() const;
  inline const common::ObString& get_locality_str() const
  {
    return locality_str_;
  }
  void reset();
  TO_STRING_KV(K_(locality_str), K_(zone_replica_attr_array));

  public:
  common::ObString locality_str_;
  ZoneLocalityArray zone_replica_attr_array_;
  ObSchema* schema_;
};

class ObPrimaryZone {
  OB_UNIS_VERSION(1);

  public:
  explicit ObPrimaryZone(ObSchema* schema) : schema_(schema)
  {}
  int assign(const ObPrimaryZone& other);
  inline const common::ObString& get_primary_zone() const
  {
    return primary_zone_str_;
  }
  inline const common::ObIArray<ObZoneScore>& get_primary_zone_array() const
  {
    return primary_zone_array_;
  }
  int set_primary_zone_array(const common::ObIArray<ObZoneScore>& primary_zone_array);
  int set_primary_zone(const common::ObString& zone);
  int64_t get_convert_size() const;
  void reset();
  TO_STRING_KV(K_(primary_zone_str), K_(primary_zone_array));

  public:
  common::ObString primary_zone_str_;
  common::ObSEArray<ObZoneScore, common::MAX_ZONE_NUM, common::ObNullAllocator> primary_zone_array_;
  ObSchema* schema_;
};

class ObSysVarSchema : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  ObSysVarSchema() : ObSchema()
  {
    reset();
  }
  ~ObSysVarSchema()
  {}
  explicit ObSysVarSchema(common::ObIAllocator* allocator);
  explicit ObSysVarSchema(const ObSysVarSchema& src_schema);
  ObSysVarSchema& operator=(const ObSysVarSchema& src_schema);
  int assign(const ObSysVarSchema& src_schema);
  virtual bool is_valid() const
  {
    return ObSchema::is_valid() && tenant_id_ != common::OB_INVALID_ID && !name_.empty();
  }
  void reset();
  int64_t get_convert_size() const;
  uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  void set_tenant_id(uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  const common::ObString& get_name() const
  {
    return name_;
  }
  int set_name(const common::ObString& name)
  {
    return deep_copy_str(name, name_);
  }
  common::ObObjType get_data_type() const
  {
    return data_type_;
  }
  void set_data_type(common::ObObjType data_type)
  {
    data_type_ = data_type;
  }
  const common::ObString& get_value() const
  {
    return value_;
  }
  int get_value(
      common::ObIAllocator* allocator, const common::ObDataTypeCastParams& dtc_params, common::ObObj& value) const;
  inline int get_value(
      common::ObIAllocator* allocator, const common::ObTimeZoneInfo* tz_info, common::ObObj& value) const
  {
    const common::ObDataTypeCastParams dtc_params(tz_info);
    return get_value(allocator, dtc_params, value);
  }
  int set_value(const common::ObString& value)
  {
    return deep_copy_str(value, value_);
  }
  const common::ObString& get_min_val() const
  {
    return min_val_;
  }
  int set_min_val(const common::ObString& min_val)
  {
    return deep_copy_str(min_val, min_val_);
  }
  const common::ObString& get_max_val() const
  {
    return max_val_;
  }
  int set_max_val(const common::ObString& max_val)
  {
    return deep_copy_str(max_val, max_val_);
  }
  int64_t get_schema_version() const
  {
    return schema_version_;
  }
  void set_schema_version(int64_t schema_version)
  {
    schema_version_ = schema_version;
  }
  int64_t get_flags() const
  {
    return flags_;
  }
  void set_flags(int64_t flags)
  {
    flags_ = flags;
  }
  int set_info(const common::ObString& info)
  {
    return deep_copy_str(info, info_);
  }
  const common::ObString& get_info() const
  {
    return info_;
  }
  int set_zone(const common::ObZone& zone)
  {
    return zone_.assign(zone);
  }
  int set_zone(const common::ObString& zone)
  {
    return zone_.assign(zone);
  }
  const common::ObZone& get_zone() const
  {
    return zone_;
  }
  bool is_invisible() const
  {
    return 0 != (flags_ & ObSysVarFlag::INVISIBLE);
  }
  bool is_global() const
  {
    return 0 != (flags_ & ObSysVarFlag::GLOBAL_SCOPE);
  }
  bool is_query_sensitive() const
  {
    return 0 != (flags_ & ObSysVarFlag::QUERY_SENSITIVE);
  }
  bool is_oracle_only() const
  {
    return 0 != (flags_ & ObSysVarFlag::ORACLE_ONLY);
  }
  bool is_mysql_only() const
  {
    return 0 != (flags_ & ObSysVarFlag::MYSQL_ONLY);
  }
  bool is_read_only() const
  {
    return 0 != (flags_ & ObSysVarFlag::READONLY);
  }
  TO_STRING_KV(K_(tenant_id), K_(name), K_(data_type), K_(value), K_(min_val), K_(max_val), K_(info), K_(zone),
      K_(schema_version), K_(flags));

  private:
  uint64_t tenant_id_;
  common::ObString name_;
  common::ObObjType data_type_;
  common::ObString value_;
  common::ObString min_val_;
  common::ObString max_val_;
  common::ObString info_;
  common::ObZone zone_;
  int64_t schema_version_;
  int64_t flags_;
};

class ObSysVariableSchema : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  // base methods
  ObSysVariableSchema();
  explicit ObSysVariableSchema(common::ObIAllocator* allocator);
  virtual ~ObSysVariableSchema();
  ObSysVariableSchema(const ObSysVariableSchema& src_schema);
  ObSysVariableSchema& operator=(const ObSysVariableSchema& src_schema);
  // set methods
  inline void set_tenant_id(const uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  inline void set_schema_version(const int64_t schema_version)
  {
    schema_version_ = schema_version;
  }
  // get methods
  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  // other methods
  virtual bool is_valid() const;
  virtual void reset();
  void reset_sysvars()
  {
    memset(sysvar_array_, 0, sizeof(sysvar_array_));
  }
  int64_t get_convert_size() const;
  int add_sysvar_schema(const share::schema::ObSysVarSchema& sysvar_schema);
  int load_default_system_variable(bool is_sys_tenant);
  int64_t get_sysvar_count() const
  {
    return ObSysVarFactory::ALL_SYS_VARS_COUNT;
  }
  int64_t get_real_sysvar_count() const;
  int get_sysvar_schema(const common::ObString& sysvar_name, const ObSysVarSchema*& sysvar_schema) const;
  int get_sysvar_schema(ObSysVarClassType var_type, const ObSysVarSchema*& sysvar_schema) const;
  const ObSysVarSchema* get_sysvar_schema(int64_t idx) const;
  ObSysVarSchema* get_sysvar_schema(int64_t idx);
  bool is_read_only() const
  {
    return read_only_;
  }
  common::ObNameCaseMode get_name_case_mode() const
  {
    return name_case_mode_;
  }
  void set_name_case_mode(const common::ObNameCaseMode mode)
  {
    name_case_mode_ = mode;
  }
  int get_oracle_mode(bool& is_oracle_mode) const;
  TO_STRING_KV(K_(tenant_id), K_(schema_version), "sysvars",
      common::ObArrayWrap<ObSysVarSchema*>(sysvar_array_, ObSysVarFactory::ALL_SYS_VARS_COUNT), K_(read_only),
      K_(name_case_mode));

  private:
  uint64_t tenant_id_;
  int64_t schema_version_;
  ObSysVarSchema* sysvar_array_[ObSysVarFactory::ALL_SYS_VARS_COUNT];
  bool read_only_;
  common::ObNameCaseMode name_case_mode_;
};

enum ObTenantStatus {
  TENANT_STATUS_NORMAL = 0,
  TENANT_STATUS_CREATING = 1,
  TENANT_STATUS_DROPPING = 2,
  TENANT_STATUS_RESTORE = 3,
  TENANT_STATUS_MAX
};

const char* ob_tenant_status_str(const ObTenantStatus);

int get_tenant_status(const common::ObString& str, ObTenantStatus& status);

class ObTenantSchema : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  // base methods
  ObTenantSchema();
  explicit ObTenantSchema(common::ObIAllocator* allocator);
  virtual ~ObTenantSchema();
  ObTenantSchema(const ObTenantSchema& src_schema);
  ObTenantSchema& operator=(const ObTenantSchema& src_schema);
  int assign(const ObTenantSchema& src_schema);
  // for sorted vector
  static bool cmp(const ObTenantSchema* lhs, const ObTenantSchema* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_tenant_id() < rhs->get_tenant_id() : false;
  }
  static bool equal(const ObTenantSchema* lhs, const ObTenantSchema* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_tenant_id() == rhs->get_tenant_id() : false;
  }
  static bool cmp_tenant_id(const ObTenantSchema* lhs, const uint64_t tenant_id)
  {
    return NULL != lhs ? lhs->get_tenant_id() < tenant_id : false;
  }
  static bool equal_tenant_id(const ObTenantSchema* lhs, const uint64_t tenant_id)
  {
    return NULL != lhs ? lhs->get_tenant_id() == tenant_id : false;
  }
  // set methods
  inline void set_tenant_id(const uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  inline void set_schema_version(const int64_t schema_version)
  {
    schema_version_ = schema_version;
  }
  inline int set_tenant_name(const char* tenant_name)
  {
    return deep_copy_str(tenant_name, tenant_name_);
  }
  inline int set_comment(const char* comment)
  {
    return deep_copy_str(comment, comment_);
  }
  inline int set_locality(const char* locality)
  {
    return deep_copy_str(locality, locality_str_);
  }
  inline int set_previous_locality(const char* previous_locality)
  {
    return deep_copy_str(previous_locality, previous_locality_str_);
  }
  inline int set_tenant_name(const common::ObString& tenant_name)
  {
    return deep_copy_str(tenant_name, tenant_name_);
  }
  inline int set_zone_list(const common::ObIArray<common::ObString>& zone_list);
  int set_zone_list(const common::ObIArray<common::ObZone>& zone_list);
  inline int set_primary_zone(const common::ObString& zone);
  int set_primary_zone_array(const common::ObIArray<ObZoneScore>& primary_zone_array);
  inline int add_zone(const common::ObString& zone);
  inline void set_locked(const bool locked)
  {
    locked_ = locked;
  }
  inline void set_read_only(const bool read_only)
  {
    read_only_ = read_only;
  }
  inline void set_rewrite_merge_version(const int64_t version)
  {
    rewrite_merge_version_ = version;
  }
  inline int set_comment(const common::ObString& comment)
  {
    return deep_copy_str(comment, comment_);
  }
  inline int set_locality(const common::ObString& locality)
  {
    return deep_copy_str(locality, locality_str_);
  }
  inline int set_previous_locality(const common::ObString& previous_locality)
  {
    return deep_copy_str(previous_locality, previous_locality_str_);
  }
  inline void set_charset_type(const common::ObCharsetType type)
  {
    charset_type_ = type;
  }
  inline void set_collation_type(const common::ObCollationType type)
  {
    collation_type_ = type;
  }
  inline void set_name_case_mode(const common::ObNameCaseMode mode)
  {
    name_case_mode_ = mode;
  }
  int set_zone_replica_attr_array(const common::ObIArray<share::ObZoneReplicaAttrSet>& src);
  int set_zone_replica_attr_array(const common::ObIArray<share::SchemaZoneReplicaAttrSet>& src);
  int set_specific_replica_attr_array(
      share::SchemaReplicaAttrArray& schema_replica_set, const common::ObIArray<ReplicaAttr>& src);
  void reset_zone_replica_attr_array();
  inline void set_storage_format_version(const int64_t storage_format_version);
  inline void set_storage_format_work_version(const int64_t storage_format_work_version);
  void set_default_tablegroup_id(const uint64_t tablegroup_id)
  {
    default_tablegroup_id_ = tablegroup_id;
  }
  int set_default_tablegroup_name(const common::ObString& tablegroup_name)
  {
    return deep_copy_str(tablegroup_name, default_tablegroup_name_);
  }
  inline void set_compatibility_mode(const common::ObCompatibilityMode compatibility_mode)
  {
    compatibility_mode_ = compatibility_mode;
  }

  // get methods
  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline const char* get_tenant_name() const
  {
    return extract_str(tenant_name_);
  }
  inline const char* get_comment() const
  {
    return extract_str(comment_);
  }
  inline const char* get_locality() const
  {
    return extract_str(locality_str_);
  }
  inline const char* get_previous_locality() const
  {
    return extract_str(previous_locality_str_);
  }
  inline const common::ObString& get_tenant_name_str() const
  {
    return tenant_name_;
  }
  inline int64_t get_logonly_replica_num() const
  {
    return logonly_replica_num_;
  }
  inline const common::ObString& get_primary_zone() const
  {
    return primary_zone_;
  }
  inline bool get_locked() const
  {
    return locked_;
  }
  inline bool is_read_only() const
  {
    return read_only_;
  }
  inline int64_t get_rewrite_merge_version() const
  {
    return rewrite_merge_version_;
  }
  inline const common::ObString& get_comment_str() const
  {
    return comment_;
  }
  inline const common::ObString& get_locality_str() const
  {
    return locality_str_;
  }
  inline const common::ObString& get_previous_locality_str() const
  {
    return previous_locality_str_;
  }
  inline common::ObCharsetType get_charset_type() const
  {
    return charset_type_;
  }
  inline common::ObCollationType get_collation_type() const
  {
    return collation_type_;
  }
  int get_raw_first_primary_zone(
      const rootserver::ObRandomZoneSelector& random_selector, common::ObZone& first_primary_zone) const;
  int get_first_primary_zone(const rootserver::ObRandomZoneSelector& random_selector,
      const common::ObIArray<rootserver::ObReplicaAddr>& replica_addrs, common::ObZone& first_primary_zone) const;
  int get_primary_zone_score(const common::ObZone& zone, int64_t& zone_score) const;
  inline const common::ObIArray<ObZoneScore>& get_primary_zone_array() const
  {
    return primary_zone_array_;
  }
  int get_primary_zone_inherit(
      share::schema::ObSchemaGetterGuard& schema_guard, share::schema::ObPrimaryZone& primary_zone) const;
  int get_zone_replica_attr_array(ZoneLocalityIArray& locality) const;
  int get_zone_replica_attr_array_inherit(ObSchemaGetterGuard& schema_guard, ZoneLocalityIArray& locality) const;
  int64_t get_full_replica_num() const;
  int get_paxos_replica_num(share::schema::ObSchemaGetterGuard& schema_guard, int64_t& num) const;
  int get_zone_list(common::ObIArray<common::ObZone>& zone_list) const;
  int get_zone_list(
      share::schema::ObSchemaGetterGuard& schema_guard, common::ObIArray<common::ObZone>& zone_list) const;
  inline int64_t get_storage_format_version() const
  {
    return storage_format_version_;
  }
  inline int64_t get_storage_format_work_version() const
  {
    return storage_format_work_version_;
  }
  inline uint64_t get_default_tablegroup_id() const
  {
    return default_tablegroup_id_;
  }
  inline const common::ObString& get_default_tablegroup_name() const
  {
    return default_tablegroup_name_;
  }
  inline common::ObCompatibilityMode get_compatibility_mode() const
  {
    return compatibility_mode_;
  }
  inline void set_drop_tenant_time(const int64_t drop_tenant_time)
  {
    drop_tenant_time_ = drop_tenant_time;
  }
  inline int64_t get_drop_tenant_time() const
  {
    return drop_tenant_time_;
  }
  inline bool is_dropping() const
  {
    return TENANT_STATUS_DROPPING == status_;
  }
  inline bool is_in_recyclebin() const
  {
    return in_recyclebin_;
  }
  inline void set_in_recyclebin(const bool in_recyclebin)
  {
    in_recyclebin_ = in_recyclebin;
  }
  inline bool is_creating() const
  {
    return TENANT_STATUS_CREATING == status_;
  }
  inline bool is_restore() const
  {
    return TENANT_STATUS_RESTORE == status_;
  }
  inline bool is_normal() const
  {
    return TENANT_STATUS_NORMAL == status_;
  }
  inline void set_status(const ObTenantStatus status)
  {
    status_ = status;
  }
  inline ObTenantStatus get_status() const
  {
    return status_;
  }
  // other methods
  virtual bool is_valid() const;
  virtual void reset();
  void reset_sysvars()
  {
    memset(sysvar_array_, 0, sizeof(sysvar_array_));
  }
  int64_t get_convert_size() const;
  TO_STRING_KV(K_(tenant_id), K_(schema_version), K_(tenant_name), K_(replica_num), K_(zone_list), K_(primary_zone),
      K_(charset_type), K_(locked), K_(comment), K_(name_case_mode), K_(read_only), K_(rewrite_merge_version),
      K_(locality_str), K_(logonly_replica_num), K_(zone_replica_attr_array), K_(primary_zone_array),
      K_(storage_format_version), K_(storage_format_work_version), K_(previous_locality_str), "sysvars",
      common::ObArrayWrap<ObSysVarSchema*>(sysvar_array_, ObSysVarFactory::ALL_SYS_VARS_COUNT),
      K_(default_tablegroup_id), K_(default_tablegroup_name), K_(compatibility_mode), K_(drop_tenant_time), K_(status),
      K_(in_recyclebin));

  private:
  int add_sysvar_schema(const share::schema::ObSysVarSchema& sysvar_schema);
  int64_t get_sysvar_count() const
  {
    return ObSysVarFactory::ALL_SYS_VARS_COUNT;
  }
  const ObSysVarSchema* get_sysvar_schema(int64_t idx) const;

  private:
  uint64_t tenant_id_;
  int64_t schema_version_;
  common::ObString tenant_name_;
  int64_t replica_num_;
  common::ObArrayHelper<common::ObString> zone_list_;
  common::ObString primary_zone_;
  bool locked_;
  bool read_only_;  // After the schema is split, the value of the system variable shall prevail
  int64_t rewrite_merge_version_;
  common::ObCharsetType charset_type_;
  common::ObCollationType collation_type_;
  common::ObNameCaseMode name_case_mode_;  // deprecated
  common::ObString comment_;
  common::ObString locality_str_;
  int64_t logonly_replica_num_;
  ZoneLocalityArray zone_replica_attr_array_;
  // primary_zone_ is primary zone list,
  // The following is the parsed array of a single zone, which has been sorted according to priority
  common::ObSEArray<ObZoneScore, common::MAX_ZONE_NUM, common::ObNullAllocator> primary_zone_array_;
  common::ObString previous_locality_str_;
  int64_t storage_format_version_;
  int64_t storage_format_work_version_;
  ObSysVarSchema* sysvar_array_[ObSysVarFactory::ALL_SYS_VARS_COUNT];  // deprecated
  uint64_t default_tablegroup_id_;
  common::ObString default_tablegroup_name_;
  common::ObCompatibilityMode compatibility_mode_;
  int64_t drop_tenant_time_;
  ObTenantStatus status_;
  bool in_recyclebin_;
};

inline int ObTenantSchema::set_zone_list(const common::ObIArray<common::ObString>& zone_list)
{
  return deep_copy_string_array(zone_list, zone_list_);
}

inline int ObTenantSchema::set_primary_zone(const common::ObString& zone)
{
  return deep_copy_str(zone, primary_zone_);
}

inline int ObTenantSchema::add_zone(const common::ObString& zone)
{
  return add_string_to_array(zone, zone_list_);
}

inline void ObTenantSchema::set_storage_format_version(const int64_t storage_format_version)
{
  storage_format_version_ = storage_format_version;
}

inline void ObTenantSchema::set_storage_format_work_version(const int64_t storage_format_work_version)
{
  storage_format_work_version_ = storage_format_work_version;
}

class ObDatabaseSchema : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  // base methods
  ObDatabaseSchema();
  explicit ObDatabaseSchema(common::ObIAllocator* allocator);
  virtual ~ObDatabaseSchema();
  ObDatabaseSchema(const ObDatabaseSchema& src_schema);
  ObDatabaseSchema& operator=(const ObDatabaseSchema& src_schema);
  int assign(const ObDatabaseSchema& src_schema);
  // set methods
  inline void set_tenant_id(const uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  inline void set_database_id(const uint64_t database_id)
  {
    database_id_ = database_id;
  }
  inline void set_schema_version(const int64_t schema_version)
  {
    schema_version_ = schema_version;
  }
  int set_database_name(const char* database_name)
  {
    return deep_copy_str(database_name, database_name_);
  }
  int set_database_name(const common::ObString& database_name)
  {
    return deep_copy_str(database_name, database_name_);
  }
  inline int set_zone_list(const common::ObIArray<common::ObString>& zone_list);
  int set_zone_list(const common::ObIArray<common::ObZone>& zone_list);
  inline int set_primary_zone(const common::ObString& zone);
  int set_primary_zone_array(const common::ObIArray<ObZoneScore>& primary_zone_array);
  inline int add_zone(const common::ObString& zone);
  int set_comment(const char* comment)
  {
    return deep_copy_str(comment, comment_);
  }
  int set_comment(const common::ObString& comment)
  {
    return deep_copy_str(comment, comment_);
  }
  inline void set_charset_type(const common::ObCharsetType type)
  {
    charset_type_ = type;
  }
  inline void set_collation_type(const common::ObCollationType type)
  {
    collation_type_ = type;
  }
  inline void set_name_case_mode(const common::ObNameCaseMode mode)
  {
    name_case_mode_ = mode;
  }
  inline void set_read_only(const bool read_only)
  {
    read_only_ = read_only;
  }
  void set_default_tablegroup_id(const uint64_t tablegroup_id)
  {
    default_tablegroup_id_ = tablegroup_id;
  }
  int set_default_tablegroup_name(const common::ObString& tablegroup_name)
  {
    return deep_copy_str(tablegroup_name, default_tablegroup_name_);
  }
  inline void set_in_recyclebin(const bool in_recyclebin)
  {
    in_recyclebin_ = in_recyclebin;
  }
  inline bool is_hidden() const
  {
    return common::OB_RECYCLEBIN_SCHEMA_ID == common::extract_pure_id(database_id_) ||
           common::OB_PUBLIC_SCHEMA_ID == common::extract_pure_id(database_id_);
  }

  // get methods
  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline const char* get_database_name() const
  {
    return extract_str(database_name_);
  }
  inline const common::ObString& get_database_name_str() const
  {
    return database_name_;
  }
  inline const common::ObString& get_primary_zone() const
  {
    return primary_zone_;
  }
  inline const char* get_comment() const
  {
    return extract_str(comment_);
  }
  inline const common::ObString& get_comment_str() const
  {
    return comment_;
  }
  inline common::ObCharsetType get_charset_type() const
  {
    return charset_type_;
  }
  inline common::ObCollationType get_collation_type() const
  {
    return collation_type_;
  }
  inline common::ObNameCaseMode get_name_case_mode() const
  {
    return name_case_mode_;
  }
  inline bool is_read_only() const
  {
    return read_only_;
  }
  inline uint64_t get_default_tablegroup_id() const
  {
    return default_tablegroup_id_;
  }
  inline const common::ObString& get_default_tablegroup_name() const
  {
    return default_tablegroup_name_;
  }
  inline bool is_in_recyclebin() const
  {
    return in_recyclebin_;
  }
  inline bool is_or_in_recyclebin() const
  {
    return in_recyclebin_ || database_id_ == common::combine_id(tenant_id_, common::OB_RECYCLEBIN_SCHEMA_ID);
  }
  inline const common::ObString& get_locality_str() const
  {
    static const common::ObString dummy;
    return dummy;
  }
  int get_raw_first_primary_zone(
      const rootserver::ObRandomZoneSelector& random_selector, common::ObZone& first_primary_zone) const;
  int get_first_primary_zone_inherit(share::schema::ObSchemaGetterGuard& schema_guard,
      const rootserver::ObRandomZoneSelector& random_selector,
      const common::ObIArray<rootserver::ObReplicaAddr>& replica_addrs, common::ObZone& first_primary_zone) const;
  int get_primary_zone_score(const common::ObZone& zone, int64_t& zone_score) const;
  inline const common::ObIArray<ObZoneScore>& get_primary_zone_array() const
  {
    return primary_zone_array_;
  }
  int get_primary_zone_inherit(
      share::schema::ObSchemaGetterGuard& schema_guard, share::schema::ObPrimaryZone& primary_zone) const;
  int get_paxos_replica_num(share::schema::ObSchemaGetterGuard& schema_guard, int64_t& num) const;
  int get_zone_replica_attr_array_inherit(
      share::schema::ObSchemaGetterGuard& schema_guard, ZoneLocalityIArray& locality) const;
  // In the current implementation, the zone_list of the Database is directly read from the corresponding tenant.
  int get_zone_list(
      share::schema::ObSchemaGetterGuard& schema_guard, common::ObIArray<common::ObZone>& zone_list) const;
  // other methods
  int64_t get_convert_size() const;
  virtual bool is_valid() const;
  virtual void reset();
  void set_drop_schema_version(const int64_t schema_version)
  {
    drop_schema_version_ = schema_version;
  }
  int64_t get_drop_schema_version() const
  {
    return drop_schema_version_;
  }
  bool is_dropped_schema() const
  {
    return drop_schema_version_ > 0;
  }
  TO_STRING_KV(K_(tenant_id), K_(database_id), K_(schema_version), K_(database_name), K_(replica_num), K_(zone_list),
      K_(primary_zone), K_(charset_type), K_(collation_type), K_(name_case_mode), K_(comment), K_(read_only),
      K_(default_tablegroup_id), K_(default_tablegroup_name), K_(in_recyclebin), K_(primary_zone_array),
      K_(drop_schema_version));

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  int64_t schema_version_;
  common::ObString database_name_;
  int64_t replica_num_;
  common::ObArrayHelper<common::ObString> zone_list_;
  common::ObString primary_zone_;
  common::ObCharsetType charset_type_;      // default:utf8mb4
  common::ObCollationType collation_type_;  // default:utf8mb4_general_ci
  common::ObNameCaseMode name_case_mode_;   // default:OB_NAME_CASE_INVALID
  common::ObString comment_;
  bool read_only_;
  uint64_t default_tablegroup_id_;
  common::ObString default_tablegroup_name_;
  bool in_recyclebin_;
  // primary_zone_ is primary zone list,
  // The following is the parsed array of a single zone, which has been sorted according to priority
  common::ObSEArray<ObZoneScore, common::MAX_ZONE_NUM, common::ObNullAllocator> primary_zone_array_;
  int64_t drop_schema_version_;
};

inline int ObDatabaseSchema::set_zone_list(const common::ObIArray<common::ObString>& zone_list)
{
  return deep_copy_string_array(zone_list, zone_list_);
}

inline int ObDatabaseSchema::set_primary_zone(const common::ObString& zone)
{
  return deep_copy_str(zone, primary_zone_);
}

inline int ObDatabaseSchema::add_zone(const common::ObString& zone)
{
  return add_string_to_array(zone, zone_list_);
}

class ObPartitionOption : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  ObPartitionOption();
  explicit ObPartitionOption(common::ObIAllocator* allocator);
  virtual ~ObPartitionOption();
  ObPartitionOption(const ObPartitionOption& expr);
  ObPartitionOption& operator=(const ObPartitionOption& expr);
  bool operator==(const ObPartitionOption& expr) const;
  bool operator!=(const ObPartitionOption& expr) const;

  inline bool is_range_part() const
  {
    return share::schema::is_range_part(part_func_type_);
  }
  inline bool is_hash_part() const
  {
    return share::schema::is_hash_part(part_func_type_);
  }
  inline bool is_hash_like_part() const
  {
    return share::schema::is_hash_like_part(part_func_type_);
  }
  inline bool is_key_part() const
  {
    return share::schema::is_key_part(part_func_type_);
  }
  inline bool is_list_part() const
  {
    return share::schema::is_list_part(part_func_type_);
  }
  inline bool is_auto_range_part() const
  {
    return auto_part_ && is_range_part();
  }

  // set methods
  int set_part_expr(const common::ObString& expr)
  {
    return deep_copy_str(expr, part_func_expr_);
  }
  inline void set_part_num(const int64_t part_num)
  {
    part_num_ = part_num;
  }
  inline void set_part_func_type(const ObPartitionFuncType func_type)
  {
    part_func_type_ = func_type;
  }
  inline void set_sub_part_func_type(const ObPartitionFuncType func_type)
  {
    part_func_type_ = func_type;
  }
  inline void set_max_used_part_id(const int64_t max_used_part_id)
  {
    max_used_part_id_ = max_used_part_id;
  }
  inline void set_partition_cnt_within_partition_table(const int64_t partition_cnt_within_partition_table)
  {
    partition_cnt_within_partition_table_ = partition_cnt_within_partition_table;
  }
  inline void set_auto_part(const bool auto_part)
  {
    auto_part_ = auto_part;
  }
  inline void set_auto_part_size(const int64_t auto_part_size)
  {
    auto_part_size_ = auto_part_size;
  }

  // get methods
  inline const common::ObString& get_part_func_expr_str() const
  {
    return part_func_expr_;
  }
  inline const char* get_part_func_expr() const
  {
    return extract_str(part_func_expr_);
  }
  inline int64_t get_part_num() const
  {
    return part_num_;
  }
  inline int64_t get_part_space() const
  {
    return part_space_;
  }
  inline ObPartitionFuncType get_part_func_type() const
  {
    return part_func_type_;
  }
  inline ObPartitionFuncType get_sub_part_func_type() const
  {
    return part_func_type_;
  }
  inline int64_t get_max_used_part_id() const
  {
    return max_used_part_id_;
  }
  inline int64_t get_partition_cnt_within_partition_table() const
  {
    return partition_cnt_within_partition_table_;
  }
  bool is_columns() const
  {
    return is_columns_;
  }
  const common::ObString& get_intervel_start_str() const
  {
    return interval_start_;
  }
  const common::ObString& get_part_intervel_str() const
  {
    return part_interval_;
  }
  inline int64_t get_auto_part_size() const
  {
    return auto_part_size_;
  }

  // other methods
  virtual void reset();
  int64_t assign(const ObPartitionOption& src_part);
  int64_t get_convert_size() const;
  virtual bool is_valid() const;
  TO_STRING_KV(K_(part_func_type), K_(part_func_expr), K_(part_num), K_(partition_cnt_within_partition_table),
      K_(max_used_part_id), K_(auto_part), K_(auto_part_size));

  private:
  ObPartitionFuncType part_func_type_;
  common::ObString part_func_expr_;
  int64_t part_num_;
  int32_t part_space_;               // Partition id space, see document for details
  bool is_columns_;                  // Whether it is the range columns/list columns partition
  common::ObString interval_start_;  // interval start value

  common::ObString part_interval_;  // interval partition step
  int64_t max_used_part_id_;
  int64_t partition_cnt_within_partition_table_;
  bool auto_part_;          // Whether it is automatic partition
  int64_t auto_part_size_;  // Automatic partition size, 0 is auto
};

// For any questions about the role of this structure, please contact @jiage
class ObSchemaAllocator : public common::ObIAllocator {
  public:
  ObSchemaAllocator() : allocator_(NULL)
  {}
  ObSchemaAllocator(common::ObIAllocator& allocator) : allocator_(&allocator)
  {}

  virtual void* alloc(const int64_t sz)
  {
    return alloc(sz, common::default_memattr);
  }

  virtual void* alloc(const int64_t sz, const common::ObMemAttr& attr)
  {
    void* ret = NULL;
    if (allocator_) {
      ret = allocator_->alloc(sz, attr);
    }
    return ret;
  }

  virtual ~ObSchemaAllocator(){};

  private:
  common::ObIAllocator* allocator_;
};

// May need to add a schema_version field, this mark when the table was created
// If it is at the table level, need not to add it, just use the table level.
// This level is added. Indicates that the partition level is considered.
// Then it is to modify the subpartition of a single primary partition without affecting other things
struct InnerPartListVectorCmp {
  public:
  InnerPartListVectorCmp() : ret_(common::OB_SUCCESS)
  {}

  public:
  bool operator()(const common::ObNewRow& left, const common::ObNewRow& right)
  {
    bool bool_ret = false;
    int cmp = 0;
    if (common::OB_SUCCESS != ret_) {
      // failed before
    } else if (common::OB_SUCCESS != (ret_ = common::ObRowUtil::compare_row(left, right, cmp))) {
      SHARE_SCHEMA_LOG(ERROR, "l or r is invalid", K(ret_));
    } else {
      bool_ret = (cmp < 0);
    }
    return bool_ret;
  }
  int get_ret() const
  {
    return ret_;
  }

  private:
  int ret_;
};

class ObPartitionUtils;
struct ObBasePartition : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  friend class ObPartitionUtils;
  friend class sql::ObPartitionExecutorUtils;
  ObBasePartition();
  explicit ObBasePartition(common::ObIAllocator* allocator);
  virtual void reset();
  void set_tenant_id(const uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }

  void set_table_id(const uint64_t table_id)
  {
    table_id_ = table_id;
  }
  uint64_t get_table_id() const
  {
    return table_id_;
  }

  void set_part_id(const int64_t part_id)
  {
    part_id_ = part_id;
  }
  int64_t get_part_id() const
  {
    return part_id_;
  }

  void set_part_idx(const int64_t part_idx)
  {
    part_idx_ = part_idx;
  }
  int64_t get_part_idx() const
  {
    return part_idx_;
  }

  void set_schema_version(int64_t schema_version)
  {
    schema_version_ = schema_version;
  }
  int64_t get_schema_version() const
  {
    return schema_version_;
  }

  int set_part_name(common::ObString& part_name)
  {
    return deep_copy_str(part_name, name_);
  }
  const common::ObString& get_part_name() const
  {
    return name_;
  }

  void set_tablespace_id(const int64_t tablespace_id)
  {
    tablespace_id_ = tablespace_id;
  }
  int64_t get_tablespace_id() const
  {
    return tablespace_id_;
  }

  int assign(const ObBasePartition& src_part);

  // This interface is not strictly semantically less than, please note
  static bool less_than(const ObBasePartition* lhs, const ObBasePartition* rhs);
  static bool list_part_func_layout(const ObBasePartition* lhs, const ObBasePartition* rhs);
  static bool range_like_func_less_than(const ObBasePartition* lhs, const ObBasePartition* rhs);
  static bool hash_like_func_less_than(const ObBasePartition* lhs, const ObBasePartition* rhs);
  int add_list_row(const common::ObNewRow& row)
  {
    return list_row_values_.push_back(row);
  }
  int set_high_bound_val(const common::ObRowkey& high_bound_val);
  int set_high_bound_val_with_hex_str(const common::ObString& high_bound_val_hex);
  int set_list_vector_values_with_hex_str(const common::ObString& list_vector_vals_hex);
  const common::ObRowkey& get_high_bound_val() const
  {
    return high_bound_val_;
  }
  virtual int64_t get_deep_copy_size() const;

  const common::ObIArray<common::ObNewRow>& get_list_row_values() const
  {
    return list_row_values_;
  }

  bool same_base_partition(const ObBasePartition& other) const
  {
    return part_id_ == other.part_id_ && high_bound_val_ == other.high_bound_val_ && status_ == other.status_;
  }
  bool allow_ddl_operator() const
  {
    bool ret = true;
    if (1 == source_part_ids_.count() && -1 != source_part_ids_.at(0)) {
      ret = false;
    }
    return ret;
  }
  ObPartitionStatus get_status() const
  {
    return status_;
  }
  const common::ObIArray<int64_t>& get_source_part_ids() const
  {
    return source_part_ids_;
  }
  common::ObIArray<int64_t>& get_source_part_ids()
  {
    return source_part_ids_;
  }
  int set_source_part_id(common::ObString& partition_str);
  VIRTUAL_TO_STRING_KV(K_(tenant_id), K_(table_id), K_(part_id), K_(name), K_(high_bound_val), K_(list_row_values),
      K_(part_idx), K_(is_empty_partition_name));
  int get_source_part_ids_str(char* str, const int64_t buf_len) const;
  void set_is_empty_partition_name(bool is_empty)
  {
    is_empty_partition_name_ = is_empty;
  }
  bool is_empty_partition_name() const
  {
    return is_empty_partition_name_;
  }

  protected:
  uint64_t tenant_id_;
  uint64_t table_id_;
  int64_t part_id_;
  int64_t schema_version_;
  common::ObString name_;
  common::ObRowkey high_bound_val_;
  ObSchemaAllocator schema_allocator_;
  common::ObSEArray<common::ObNewRow, 8> list_row_values_;
  enum ObPartitionStatus status_;
  int64_t spare1_;  // TODO Consider whether it is really useful
  int64_t spare2_;
  int64_t spare3_;
  /**
   * @warning: The projector can only be used by the less than interface for partition comparison calculations,
   *  and it is not allowed to be used in other places
   */
  int32_t* projector_;
  int64_t projector_size_;
  common::ObSEArray<int64_t, 2> source_part_ids_;
  int64_t part_idx_;  // Valid for hash partition
  // The partition management operation of tablegroup, because after adding pg,
  // the operation of tablegroup needs to be processed first
  // Under Oracle tenants, partition_name is allowed to be empty. There may be a partition name conflict
  // when filling the tablegroup first and directly copying it to the table. Therefore, add a variable
  // when copying to mark this as an empty partition name and do not copy the partition name.
  bool is_empty_partition_name_;
  int64_t tablespace_id_;
};

struct ObPartition : public ObBasePartition {
  OB_UNIS_VERSION(1);

  public:
  ObPartition();
  explicit ObPartition(common::ObIAllocator* allocator);
  int assign(const ObPartition& src_part);

  void reset();
  virtual int64_t get_convert_size() const;
  virtual int clone(common::ObIAllocator& allocator, ObPartition*& dst) const;

  void set_sub_part_num(const int64_t sub_part_num)
  {
    sub_part_num_ = sub_part_num;
  }
  int64_t get_sub_part_num() const
  {
    return sub_part_num_;
  }
  int32_t get_sub_part_space() const
  {
    return sub_part_space_;
  }
  void set_mapping_pg_part_id(const int64_t mapping_pg_part_id)
  {
    mapping_pg_part_id_ = mapping_pg_part_id;
  }
  int64_t get_mapping_pg_part_id() const
  {
    return mapping_pg_part_id_;
  }
  common::ObObj get_sub_interval_start() const
  {
    return sub_interval_start_;
  }
  common::ObObj get_sub_part_interval() const
  {
    return sub_part_interval_;
  }
  void set_drop_schema_version(const int64_t schema_version)
  {
    drop_schema_version_ = schema_version;
  }
  int64_t get_drop_schema_version() const
  {
    return drop_schema_version_;
  }
  bool is_dropped_partition() const
  {
    return drop_schema_version_ > 0;
  }
  void set_max_used_sub_part_id(const int64_t max_used_sub_part_id)
  {
    max_used_sub_part_id_ = max_used_sub_part_id;
  }
  int64_t get_max_used_sub_part_id() const
  {
    return max_used_sub_part_id_;
  }
  ObSubPartition** get_subpart_array() const
  {
    return subpartition_array_;
  }
  int64_t get_subpartition_num() const
  {
    return subpartition_num_;
  }
  ObSubPartition** get_sorted_part_id_subpartition_array() const
  {
    return sorted_part_id_subpartition_array_;
  }
  bool same_partition(const ObPartition& other) const
  {
    return same_base_partition(other) && sub_part_num_ == other.sub_part_num_ &&
           sub_part_space_ == other.sub_part_space_ && sub_interval_start_ == other.sub_interval_start_ &&
           sub_part_interval_ == other.sub_part_interval_;
  }
  int add_partition(const ObSubPartition& subpartition);
  int generate_mapping_pg_subpartition_array();
  ObSubPartition** get_dropped_subpart_array() const
  {
    return dropped_subpartition_array_;
  }
  int64_t get_dropped_subpartition_num() const
  {
    return dropped_subpartition_num_;
  }
  void reset_dropped_subpartition()
  {
    dropped_subpartition_num_ = 0;
    dropped_subpartition_array_ = NULL;
  }
  INHERIT_TO_STRING_KV("BasePartition", ObBasePartition, K_(mapping_pg_part_id), K_(source_part_ids),
      K_(drop_schema_version), K_(max_used_sub_part_id), "subpartition_array",
      common::ObArrayWrap<ObSubPartition*>(subpartition_array_, subpartition_num_), K_(subpartition_array_capacity),
      "dropped_subpartition_array",
      common::ObArrayWrap<ObSubPartition*>(dropped_subpartition_array_, dropped_subpartition_num_),
      K_(dropped_subpartition_array_capacity));

  private:
  int inner_add_partition(
      const ObSubPartition& part, ObSubPartition**& part_array, int64_t& part_array_capacity, int64_t& part_num);

  protected:
  static const int64_t DEFAULT_ARRAY_CAPACITY = 128;

  private:
  // The 14x branch gz_commmon cluster once supported ob_admin to increase the function of subpartition
  // However, this function does not modify sub_part_num, so it is not assumed that the sub_part_num column value
  // of __all_part_history of the templated subpartition table is correct, which is corrected when the schema is
  // refreshed
  int64_t sub_part_num_;
  int32_t sub_part_space_;
  common::ObObj sub_interval_start_;
  common::ObObj sub_part_interval_;
  int64_t mapping_pg_part_id_;
  int64_t drop_schema_version_;
  // The following new members are only valid for non-templated subpartitions
  // Ensure that sub_part_id is not reused when adding or deleting subpartitions
  int64_t max_used_sub_part_id_;
  // nontemplate equal sub_part_num_
  int64_t subpartition_num_;
  // The array size of subpartition_array is not necessarily equal to subpartition_num_
  int64_t subpartition_array_capacity_;
  ObSubPartition** subpartition_array_;
  // Generated when the schema is refreshed, only used by the table, used to quickly index pg_key, not serialized
  ObSubPartition** sorted_part_id_subpartition_array_;
  /* delay delete subpartition */
  int64_t dropped_subpartition_num_;
  int64_t dropped_subpartition_array_capacity_;
  ObSubPartition** dropped_subpartition_array_;
};

struct ObSubPartition : public ObBasePartition {
  OB_UNIS_VERSION(1);

  public:
  // For template, because it does not belong to any part, we set part_id to -1
  static const int64_t TEMPLATE_PART_ID = -1;

  public:
  ObSubPartition();
  explicit ObSubPartition(common::ObIAllocator* allocator);
  int assign(const ObSubPartition& src_part);
  virtual void reset();
  virtual int clone(common::ObIAllocator& allocator, ObSubPartition*& dst) const;

  void set_sub_part_id(const int64_t subpart_id)
  {
    subpart_id_ = subpart_id;
  }
  int64_t get_sub_part_id() const
  {
    return subpart_id_;
  }
  void set_sub_part_idx(const int64_t subpart_idx)
  {
    subpart_idx_ = subpart_idx;
  }
  int64_t get_sub_part_idx() const
  {
    return subpart_idx_;
  }
  void set_mapping_pg_sub_part_id(const int64_t mapping_pg_sub_part_id)
  {
    mapping_pg_sub_part_id_ = mapping_pg_sub_part_id;
  }
  int64_t get_mapping_pg_sub_part_id() const
  {
    return mapping_pg_sub_part_id_;
  }
  void set_drop_schema_version(const int64_t schema_version)
  {
    drop_schema_version_ = schema_version;
  }
  int64_t get_drop_schema_version() const
  {
    return drop_schema_version_;
  }
  bool is_dropped_partition() const
  {
    return drop_schema_version_ > 0;
  }

  // first compare part_idx,then compare high_bound_val
  static bool less_than(const ObSubPartition* lhs, const ObSubPartition* rhs);
  bool same_sub_partition(const ObSubPartition& other) const
  {
    return same_base_partition(other) && subpart_id_ == other.subpart_id_;
  }
  virtual int64_t get_convert_size() const;
  bool key_match(const ObSubPartition& other) const;
  static bool hash_like_func_less_than(const ObSubPartition* lhs, const ObSubPartition* rhs);
  INHERIT_TO_STRING_KV("BasePartition", ObBasePartition, K_(subpart_id), K_(subpart_idx), K_(mapping_pg_sub_part_id),
      K_(drop_schema_version));

  private:
  int64_t subpart_id_;
  int64_t subpart_idx_;             // Valid for hash partition;
  int64_t mapping_pg_sub_part_id_;  // nontemplate table, is partition_id of pg.
                                    // template table, is sub_part_id of pg of template
  int64_t drop_schema_version_;
};

class ObPartitionSchema : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  // base methods
  ObPartitionSchema();
  explicit ObPartitionSchema(common::ObIAllocator* allocator);
  virtual ~ObPartitionSchema();
  ObPartitionSchema(const ObPartitionSchema& src_schema);
  ObPartitionSchema& operator=(const ObPartitionSchema& src_schema);
  // partition related

  virtual const char* get_entity_name() const = 0;
  virtual uint64_t get_tenant_id() const = 0;
  virtual void set_tenant_id(const uint64_t tenant_id) = 0;
  virtual uint64_t get_table_id() const = 0;
  virtual void set_table_id(const uint64_t table_id) = 0;
  virtual int64_t get_schema_version() const = 0;
  virtual void set_schema_version(const int64_t schema_version) = 0;
  virtual bool is_user_partition_table() const = 0;
  virtual bool is_user_subpartition_table() const = 0;
  virtual ObPartitionLevel get_part_level() const
  {
    return part_level_;
  }
  virtual int64_t get_partition_cnt() const = 0;
  virtual bool has_self_partition() const = 0;
  virtual int get_primary_zone_inherit(ObSchemaGetterGuard& schema_guard, ObPrimaryZone& primary_zone) const = 0;
  virtual int get_zone_replica_attr_array_inherit(
      ObSchemaGetterGuard& schema_guard, ZoneLocalityIArray& locality) const = 0;
  virtual int get_zone_list(
      share::schema::ObSchemaGetterGuard& schema_guard, common::ObIArray<common::ObZone>& zone_list) const = 0;
  virtual int get_locality_str_inherit(
      share::schema::ObSchemaGetterGuard& guard, const common::ObString*& locality_str) const = 0;
  virtual int get_first_primary_zone_inherit(share::schema::ObSchemaGetterGuard& schema_guard,
      const rootserver::ObRandomZoneSelector& random_selector,
      const common::ObIArray<rootserver::ObReplicaAddr>& replica_addrs, common::ObZone& first_primary_zone) const = 0;
  virtual int check_is_duplicated(share::schema::ObSchemaGetterGuard& guard, bool& is_duplicated) const = 0;
  virtual uint64_t get_tablegroup_id() const = 0;
  virtual void set_tablegroup_id(const uint64_t tg_id) = 0;
  virtual const common::ObString& get_locality_str() const = 0;
  virtual common::ObString& get_locality_str() = 0;
  virtual const common::ObString& get_previous_locality_str() const = 0;
  virtual int get_paxos_replica_num(share::schema::ObSchemaGetterGuard& schema_guard, int64_t& num) const = 0;
  virtual share::ObDuplicateScope get_duplicate_scope() const = 0;
  virtual void set_duplicate_scope(const share::ObDuplicateScope duplicate_scope) = 0;
  virtual void set_duplicate_scope(const int64_t duplicate_scope) = 0;
  inline virtual int64_t get_part_func_expr_num() const
  {
    return 0;
  }
  inline virtual void set_part_func_expr_num(const int64_t part_func_expr_num)
  {
    UNUSED(part_func_expr_num);
  }
  inline virtual int64_t get_sub_part_func_expr_num() const
  {
    return 0;
  }
  inline virtual void set_sub_part_func_expr_num(const int64_t sub_part_func_expr_num)
  {
    UNUSED(sub_part_func_expr_num);
  }
  // Define the copy distribution method of the partition table, including:
  // 0. Disperse in any way
  // 1. Prioritize the first-partition division
  // 2. Prioritize the second-partition division
  int64_t distribute_by() const;

  inline void set_part_num(const int64_t part_num)
  {
    part_num_ = part_num;
    part_option_.set_part_num(part_num);
  }
  // Only the templated secondary partition is valid, pay attention!!
  inline void set_def_sub_part_num(const int64_t def_subpart_num)
  {
    def_subpart_num_ = def_subpart_num;
    sub_part_option_.set_part_num(def_subpart_num);
  }
  inline void set_part_level(const ObPartitionLevel part_level)
  {
    part_level_ = part_level;
  }
  virtual bool is_sub_part_template() const
  {
    return is_sub_part_template_;
  }
  void set_is_sub_part_template(bool is_sub_part_template)
  {
    is_sub_part_template_ = is_sub_part_template;
  }
  inline int64_t get_first_part_num() const
  {
    return part_option_.get_part_num();
  }
  // Only the templated secondary partition is valid, pay attention!!
  int64_t get_def_sub_part_num() const;
  int get_first_individual_sub_part_num(int64_t& sub_part_num) const;
  // SQL view, unable to see the delayed deleted partition
  int64_t get_all_part_num() const;
  int get_all_partition_num(bool check_dropped_partition, int64_t& part_num) const;

  int check_part_name(const ObPartition& partition);
  int check_part_id(const ObPartition& partition);
  int add_partition(const ObPartition& partition);
  int add_def_subpartition(const ObSubPartition& subpartition);

  inline bool is_hash_part() const
  {
    return part_option_.is_hash_part();
  }
  inline bool is_hash_subpart() const
  {
    return sub_part_option_.is_hash_part();
  }
  inline bool is_key_part() const
  {
    return part_option_.is_key_part();
  }
  inline bool is_key_subpart() const
  {
    return sub_part_option_.is_key_part();
  }
  inline bool is_range_part() const
  {
    return part_option_.is_range_part();
  }
  inline bool is_range_subpart() const
  {
    return sub_part_option_.is_range_part();
  }

  inline bool is_hash_like_part() const
  {
    return part_option_.is_hash_like_part();
  }
  inline bool is_hash_like_subpart() const
  {
    return sub_part_option_.is_hash_like_part();
  }
  inline bool is_list_part() const
  {
    return part_option_.is_list_part();
  }
  inline bool is_list_subpart() const
  {
    return sub_part_option_.is_list_part();
  }
  inline bool is_auto_partitioned_table() const
  {
    return part_option_.is_auto_range_part();
  }

  inline const ObPartitionOption& get_part_option() const
  {
    return part_option_;
  }
  inline ObPartitionOption& get_part_option()
  {
    return part_option_;
  }
  inline const ObPartitionOption& get_sub_part_option() const
  {
    return sub_part_option_;
  }
  inline ObPartitionOption& get_sub_part_option()
  {
    return sub_part_option_;
  }
  inline int64_t get_auto_part_size() const
  {
    return part_option_.get_auto_part_size();
  }

  int serialize_partitions(char* buf, const int64_t data_len, int64_t& pos) const;
  int serialize_dropped_partitions(char* buf, const int64_t data_len, int64_t& pos) const;
  int serialize_def_subpartitions(char* buf, const int64_t data_len, int64_t& pos) const;
  int deserialize_partitions(const char* buf, const int64_t data_len, int64_t& pos);
  int deserialize_def_subpartitions(const char* buf, const int64_t data_len, int64_t& pos);

  int get_partition_by_part_id(
      const int64_t part_id, const bool check_dropped_partition, const ObPartition*& partition) const;
  // both part_id and subpart_id is not OB_TWO_PART_MASK
  int get_subpartition(const int64_t part_id, const int64_t subpart_id, const ObSubPartition*& subpartition) const;

  /** generate part name of hash partition, for resolver only
   * @name_type: Type of generated hash partition name:
   *                                FIRST_PART generate partition name
   *                                TEMPLATE_SUB_PART generate subpartition name
   *                                INDIVIDUAL_SUB_PART generate subpartition name of nontemplate
   * @need_upper_case: Does the generated partition name need to be capitalized?
   * @partition: nantemplate table, the partition name needs to be spelled with the partition name,
   *    and partition indicates the partition where the current subpartition is located
   */
  int gen_hash_part_name(const int64_t part_id, const ObHashNameType name_type, const bool need_upper_case, char* buf,
      const int64_t buf_size, int64_t* pos, const ObPartition* partition = NULL) const;
  // Get the partition name corresponding to partition_id (non-partition/partition/subpartition)
  int get_partition_name(const int64_t partition_id, char* buf, const int64_t buf_size, int64_t* pos /* = NULL*/) const;
  // get partition name
  int get_part_name(const int64_t part_id, char* buf, const int64_t buf_size, int64_t* pos /* = NULL*/) const;
  // is_def_subpart refers to the generation of __all_def_sub_part or the part_name in the __all_sub_part table
  int get_subpart_name(const int64_t part_id, const int64_t subpart_id, const bool is_def_subpart, char* buf,
      const int64_t buf_size, int64_t* pos /* = NULL*/) const;

  inline ObPartition** get_part_array() const
  {
    return partition_array_;
  }
  inline int64_t get_partition_capacity() const
  {
    return partition_array_capacity_;
  }
  inline int64_t get_partition_num() const
  {
    return partition_num_;
  }
  // The following interfaces can only be used for templated subpartition tables
  inline ObSubPartition** get_def_subpart_array() const
  {
    return def_subpartition_array_;
  }
  inline int64_t get_def_subpartition_capacity() const
  {
    return def_subpartition_array_capacity_;
  }
  inline int64_t get_def_subpartition_num() const
  {
    return def_subpartition_num_;
  }
  /* ----------------------------------*/
  inline void set_partition_schema_version(const int64_t schema_version)
  {
    partition_schema_version_ = schema_version;
  }
  inline int64_t get_partition_schema_version() const
  {
    return partition_schema_version_;
  }
  // -----dropped partition related -----
  void set_drop_schema_version(const int64_t schema_version)
  {
    drop_schema_version_ = schema_version;
  }
  int64_t get_drop_schema_version() const
  {
    return drop_schema_version_;
  }
  bool is_dropped_schema() const
  {
    return drop_schema_version_ > 0;
  }
  int64_t get_dropped_partition_num() const
  {
    return dropped_partition_num_;
  }
  int clear_dropped_partition();
  void reset_dropped_partition()
  {
    dropped_partition_num_ = 0;
    dropped_partition_array_ = NULL;
  }
  // The partition information needs to be reorganized when truncate the subpartition
  void reset_partition_for_trun_subpart()
  {
    partition_array_capacity_ = 0;
    part_num_ = 0;
    partition_num_ = 0;
    partition_array_ = NULL;
  }
  // This interface is only for iterators, and the corresponding iterator should be used to access the deleted
  // partition, or the schema_guard/schema_service corresponding interface should be used
  ObPartition** get_dropped_part_array() const
  {
    return dropped_partition_array_;
  }
  // -------------------------------------
  int get_part_id_by_name(const common::ObString partition_name, int64_t& part_id) const;
  // FIXME:() Refresh the schema, do not assume that the partition_array is in order, and can be optimized later
  int find_partition_by_part_id(
      const int64_t part_id, const bool check_dropped_partition, const ObPartition*& partition) const;
  int get_subpart_info(
      const int64_t part_id, ObSubPartition**& subpart_array, int64_t& subpart_num, int64_t& subpartition_num) const;
  //-------index partition-------
  int get_part_id_by_idx(const int64_t part_idx, int64_t& part_id) const;
  int get_hash_subpart_id_by_idx(const int64_t part_id, const int64_t subpart_idx, int64_t& subpart_id) const;

  int get_hash_part_idx_by_id(const int64_t part_id, int64_t& part_idx) const;
  int get_hash_subpart_idx_by_id(const int64_t part_id, const int64_t subpart_id, int64_t& subpart_idx) const;

  int convert_partition_idx_to_id(const int64_t partition_idx, int64_t& partition_id) const;
  int convert_partition_id_to_idx(const int64_t partition_id, int64_t& partition_idx) const;
  //----------------------
  // Get the offset of the partition in partition_array, just take the offset of the partition,
  // not including the subpartition
  int get_partition_index_by_id(
      const int64_t part_id, const bool check_dropped_partition, int64_t& partition_index) const;
  // Binary search range partition, only applicable to the partition that has not been split
  int get_partition_index_binary_search(
      const int64_t part_id, const bool check_dropped_partition, int64_t& partition_index) const;
  // Iterate all the partitions to get the offset
  int get_partition_index_loop(
      const int64_t part_id, const bool check_dropped_partition, int64_t& partition_index) const;

  inline void set_partition_status(const ObPartitionStatus partition_status)
  {
    partition_status_ = partition_status;
  }
  inline ObPartitionStatus get_partition_status() const
  {
    return partition_status_;
  }
  bool is_in_splitting() const
  {
    return partition_status_ == PARTITION_STATUS_LOGICAL_SPLITTING ||
           partition_status_ == PARTITION_STATUS_PHYSICAL_SPLITTING;
  }
  bool is_in_logical_split() const
  {
    return partition_status_ == PARTITION_STATUS_LOGICAL_SPLITTING;
  }
  bool is_in_physical_split() const
  {
    return partition_status_ == PARTITION_STATUS_PHYSICAL_SPLITTING;
  }
  // other methods
  virtual void reset();
  virtual bool is_valid() const;
  virtual void set_min_partition_id(uint64_t partition_id)
  {
    UNUSED(partition_id);
  }
  virtual uint64_t get_min_partition_id() const
  {
    return 0;
  }
  virtual int get_split_source_partition_key(
      const common::ObPartitionKey& dst_part_key, common::ObPartitionKey& source_part_key) const;
  DECLARE_VIRTUAL_TO_STRING;
  int try_assign_part_array(const share::schema::ObPartitionSchema& that);
  int try_assign_def_subpart_array(const share::schema::ObPartitionSchema& that);

  protected:
  int inner_add_partition(const ObPartition& part);
  int inner_add_partition(const ObSubPartition& part);
  template <class T>
  int inner_add_partition(const T& part, T**& part_array, int64_t& part_array_capacity, int64_t& part_num);
  int get_subpart_name(const int64_t part_id, const int64_t subpart_id, char* buf, const int64_t buf_size,
      int64_t* pos /* = NULL*/) const;
  int get_def_subpart_name(const int64_t subpart_id, char* buf, const int64_t buf_size, int64_t* pos /* = NULL*/) const;

  protected:
  static const int64_t DEFAULT_ARRAY_CAPACITY = 128;

  protected:
  int64_t part_num_;
  // Redundant value, derived from sub_part_option_, valid when is_sub_part_template = true
  int64_t def_subpart_num_;
  ObPartitionLevel part_level_;
  ObPartitionOption part_option_;
  // The part_num_ is only valid when is_sub_part_template = true
  ObPartitionOption sub_part_option_;
  ObPartition** partition_array_;
  int64_t partition_array_capacity_;  // The array size of partition_array is not necessarily equal to partition_num;
  // Equal to part_num; historical reasons cause the two values to have the same meaning;
  // need to be modified together with part_num_
  int64_t partition_num_;
  /* template table, when is_sub_part_template = true, valid */
  ObSubPartition** def_subpartition_array_;
  // The array size of subpartition_array, not necessarily equal to subpartition_num
  int64_t def_subpartition_array_capacity_;
  int64_t def_subpartition_num_;  // equal subpart_num
  /* template subpartition define end*/
  // Record the split schema, initialized to 0, not cleared after splitting, the bottom layer needs to be used
  int64_t partition_schema_version_;
  ObPartitionStatus partition_status_;
  /* delay delete table/tablegroup/partition start*/
  int64_t drop_schema_version_;
  // delay delete partition, Not visible to SQL
  ObPartition** dropped_partition_array_;
  int64_t dropped_partition_array_capacity_;
  int64_t dropped_partition_num_;
  /* delay delete table/tablegroup/partition end*/
  // It is meaningful when the subpartition table is used to mark whether the subpartition is a templated definition,
  // and it is compatible with
  bool is_sub_part_template_;
};

class ObTablegroupSchema : public ObPartitionSchema {
  OB_UNIS_VERSION(1);

  public:
  // base methods
  ObTablegroupSchema();
  explicit ObTablegroupSchema(common::ObIAllocator* allocator);
  virtual ~ObTablegroupSchema();
  ObTablegroupSchema(const ObTablegroupSchema& src_schema);
  ObTablegroupSchema& operator=(const ObTablegroupSchema& src_schema);
  int assign(const ObTablegroupSchema& src_schema);
  // set methods
  inline void set_binding(const bool binding)
  {
    binding_ = binding;
  }
  inline void set_tenant_id(const uint64_t tenant_id) override
  {
    tenant_id_ = tenant_id;
  }
  inline void set_schema_version(const int64_t schema_version) override
  {
    schema_version_ = schema_version;
  }
  virtual void set_tablegroup_id(const uint64_t tablegroup_id) override
  {
    tablegroup_id_ = tablegroup_id;
  }
  inline int set_tablegroup_name(const char* name)
  {
    return deep_copy_str(name, tablegroup_name_);
  }
  inline int set_comment(const char* comment)
  {
    return deep_copy_str(comment, comment_);
  }
  inline int set_tablegroup_name(const common::ObString& name)
  {
    return deep_copy_str(name, tablegroup_name_);
  }
  inline int set_table_name(const common::ObString& name)
  {
    return deep_copy_str(name, tablegroup_name_);
  }
  inline int set_comment(const common::ObString& comment)
  {
    return deep_copy_str(comment, comment_);
  }
  inline int set_locality(const common::ObString& locality)
  {
    return deep_copy_str(locality, locality_info_.locality_str_);
  }
  inline int set_primary_zone(const common::ObString& primary_zone)
  {
    return deep_copy_str(primary_zone, primary_zone_info_.primary_zone_str_);
  }
  inline int set_previous_locality(const common::ObString& previous_locality)
  {
    return deep_copy_str(previous_locality, previous_locality_);
  }
  int set_primary_zone_array(const common::ObIArray<ObZoneScore>& primary_zone_array);

  int set_zone_replica_attr_array(const common::ObIArray<share::ObZoneReplicaAttrSet>& src);
  int set_zone_replica_attr_array(const common::ObIArray<share::SchemaZoneReplicaAttrSet>& src);
  inline int set_split_partition(const common::ObString& split_partition)
  {
    return deep_copy_str(split_partition, split_partition_name_);
  }
  inline int set_split_rowkey(const common::ObRowkey& rowkey)
  {
    return rowkey.deep_copy(split_high_bound_val_, *get_allocator());
  }
  inline int set_split_list_value(common::ObRowkey& list_values)
  {
    return list_values.deep_copy(split_list_row_values_, *get_allocator());
  }
  // get methods
  inline bool get_binding() const
  {
    return binding_;
  }
  inline uint64_t get_tenant_id() const override
  {
    return tenant_id_;
  }
  virtual inline int64_t get_schema_version() const override
  {
    return schema_version_;
  }
  virtual uint64_t get_tablegroup_id() const override
  {
    return tablegroup_id_;
  }
  inline const char* get_tablegroup_name_str() const
  {
    return extract_str(tablegroup_name_);
  }
  inline const char* get_comment() const
  {
    return extract_str(comment_);
  }
  inline const common::ObString& get_tablegroup_name() const
  {
    return tablegroup_name_;
  }
  inline const common::ObString& get_table_name() const
  {
    return tablegroup_name_;
  }
  virtual const char* get_entity_name() const override
  {
    return extract_str(tablegroup_name_);
  }
  inline const common::ObString& get_comment_str() const
  {
    return comment_;
  }
  inline const ObLocality& get_locality_info() const
  {
    return locality_info_;
  }
  virtual common::ObString& get_locality_str() override
  {
    return locality_info_.locality_str_;
  }
  virtual const common::ObString& get_locality_str() const override
  {
    return locality_info_.locality_str_;
  }
  inline const char* get_locality() const
  {
    return extract_str(locality_info_.locality_str_);
  }
  inline const char* get_previous_locality() const
  {
    return extract_str(previous_locality_);
  }
  virtual const common::ObString& get_previous_locality_str() const override
  {
    return previous_locality_;
  }
  inline const ObPrimaryZone& get_primary_zone_info() const
  {
    return primary_zone_info_;
  }
  inline const common::ObString& get_primary_zone() const
  {
    return primary_zone_info_.primary_zone_str_;
  }
  int set_zone_list(const common::ObIArray<common::ObZone>& zone_list)
  {
    UNUSED(zone_list);
    return common::OB_SUCCESS;
  }
  inline const common::ObString& get_split_partition_name() const
  {
    return split_partition_name_;
  }
  inline const common::ObRowkey& get_split_rowkey() const
  {
    return split_high_bound_val_;
  }
  inline const common::ObRowkey& get_split_list_row_values() const
  {
    return split_list_row_values_;
  }
  void reset_locality_options();
  // In the current implementation, if the locality of the zone_list of the tablegroup is empty,
  // it will be read from the tenant, otherwise it will be parsed from the locality
  virtual int get_zone_list(
      share::schema::ObSchemaGetterGuard& schema_guard, common::ObIArray<common::ObZone>& zone_list) const override;
  virtual int get_zone_replica_attr_array(ZoneLocalityIArray& locality) const;
  virtual int get_zone_replica_attr_array_inherit(
      ObSchemaGetterGuard& schema_guard, ZoneLocalityIArray& locality) const override;
  virtual int get_locality_str_inherit(
      ObSchemaGetterGuard& schema_guard, const common::ObString*& locality_str) const override;
  virtual int get_first_primary_zone_inherit(share::schema::ObSchemaGetterGuard& schema_guard,
      const rootserver::ObRandomZoneSelector& random_selector,
      const common::ObIArray<rootserver::ObReplicaAddr>& replica_addrs,
      common::ObZone& first_primary_zone) const override;
  virtual int check_is_duplicated(share::schema::ObSchemaGetterGuard& guard, bool& is_duplicated) const override;
  int get_primary_zone_score(const common::ObZone& zone, int64_t& zone_score) const;
  inline const common::ObIArray<ObZoneScore>& get_primary_zone_array() const
  {
    return primary_zone_info_.primary_zone_array_;
  }
  virtual int get_primary_zone_inherit(
      share::schema::ObSchemaGetterGuard& schema_guard, share::schema::ObPrimaryZone& primary_zone) const override;
  int fill_additional_options();
  int check_in_locality_modification(
      share::schema::ObSchemaGetterGuard& schema_guard, bool& in_locality_modification) const;
  int check_is_readonly_at_all(share::schema::ObSchemaGetterGuard& guard, const common::ObZone& zone,
      const common::ObRegion& region, bool& readonly_at_all) const;
  int get_full_replica_num(share::schema::ObSchemaGetterGuard& schema_guard, int64_t& num) const;
  virtual int get_paxos_replica_num(share::schema::ObSchemaGetterGuard& schema_guard, int64_t& num) const override;
  int get_all_replica_num(share::schema::ObSchemaGetterGuard& schema_guard, int64_t& num) const;
  // partition related
  virtual share::ObDuplicateScope get_duplicate_scope() const override
  {
    return share::ObDuplicateScope::DUPLICATE_SCOPE_NONE;
  }
  virtual void set_duplicate_scope(const share::ObDuplicateScope duplicate_scope) override
  {
    UNUSED(duplicate_scope);
  }
  virtual void set_duplicate_scope(const int64_t duplicate_scope) override
  {
    UNUSED(duplicate_scope);
  }
  inline virtual bool is_user_partition_table() const override
  {
    return PARTITION_LEVEL_ONE == get_part_level() || PARTITION_LEVEL_TWO == get_part_level();
  }
  inline virtual bool is_user_subpartition_table() const override
  {
    return PARTITION_LEVEL_TWO == get_part_level();
  }
G
gm 已提交
3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215
  inline virtual uint64_t get_table_id() const override { return tablegroup_id_; } // for partition schema used
  inline virtual uint64_t get_database_id() const { return 0; }
  inline virtual void set_database_id(const uint64_t database_id) { UNUSED(database_id); }
  inline virtual void set_table_id(const uint64_t tablegroup_id) override { tablegroup_id_ = tablegroup_id; }
  inline int64_t get_part_func_expr_num() const override { return part_func_expr_num_; }
  inline void set_part_func_expr_num(const int64_t part_func_expr_num) override { part_func_expr_num_ = part_func_expr_num; }
  inline int64_t get_sub_part_func_expr_num() const override { return sub_part_func_expr_num_; }
  inline void set_sub_part_func_expr_num(const int64_t sub_part_func_expr_num) override { sub_part_func_expr_num_ = sub_part_func_expr_num; }
  virtual int64_t get_partition_cnt() const override { return 0; }
  virtual int calc_part_func_expr_num(int64_t &part_func_expr_num) const;
  virtual int calc_subpart_func_expr_num(int64_t &subpart_func_expr_num) const;
  //other methods
  virtual void reset() override;
  int64_t get_convert_size() const override;
  virtual bool has_self_partition() const override { return get_binding(); }
  virtual bool is_valid() const override;
  bool is_mock_global_index_invalid() const { return is_mock_global_index_invalid_; }
  bool is_global_index_table() const { return false; }
  void set_mock_global_index_invalid(const bool is_invalid) {is_mock_global_index_invalid_ = is_invalid; }
  bool can_read_index() const { return true; }
O
oceanbase-admin 已提交
3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877

  DECLARE_VIRTUAL_TO_STRING;

  private:
  uint64_t tenant_id_;
  uint64_t tablegroup_id_;
  int64_t schema_version_;
  common::ObString tablegroup_name_;
  common::ObString comment_;
  // 2.0 add
  ObLocality locality_info_;
  ObPrimaryZone primary_zone_info_;
  int64_t part_func_expr_num_;
  int64_t sub_part_func_expr_num_;
  common::ObString previous_locality_;
  common::ObString split_partition_name_;
  common::ObRowkey split_high_bound_val_;
  common::ObRowkey split_list_row_values_;
  // Indicates whether the tablegroup has physical physical partitions
  // true: With physical physical partition
  // false: Without physical physical partition
  bool binding_;
  bool is_mock_global_index_invalid_;  // Standalone cluster use; no serialization required
};

class ObPartitionUtils {
  public:
  /// Get part ids through range of partition_column

  // Get hash(FUNC_HASH/FUNC_KEY) part type ids
  static int get_hash_part_ids(const ObTableSchema& table_schema, const common::ObNewRange& range,
      const int64_t part_num, common::ObIArray<int64_t>& part_ids);
  // @param: get_part_index Indicates whether this function is called to get whether it is part_index or part_id
  // - true  Indicates that part_index is to be obtained, and part_index indicates the position of partition
  //  in the partition array.
  // - false Indicates that the part to be obtained is part_id, and part_id indicates the logical id of the primary
  // partition
  static int get_hash_part_ids(const ObTableSchema& table_schema, const common::ObNewRow& row, int64_t part_num,
      common::ObIArray<int64_t>& part_ids, bool get_part_index = false);
  static int get_hash_subpart_ids(const ObTableSchema& table_schema, const int64_t part_id,
      const common::ObNewRange& range, const int64_t subpart_num, common::ObIArray<int64_t>& subpart_ids);
  // @param: get_subpart_index  Indicates whether this function is called to get whether it is subpart_index or
  // subpart_id
  // - true  Indicates that subpart_index is to be obtained, and subpart_index indicates the position of subpartition
  //  in the subpartition array.
  // - false Indicates that the subpart to be obtained is subpart_id, and subpart_id indicates the logical id of
  //  the primary subpartition
  static int get_hash_subpart_ids(const ObTableSchema& table_schema, const int64_t part_id, const common::ObNewRow& row,
      int64_t subpart_num, common::ObIArray<int64_t>& subpart_ids, bool get_subpart_index = false);

  // Get level-one range part_ids
  static int get_range_part_ids(const common::ObNewRange& range, const bool reverse,
      ObPartition* const* partition_array, const int64_t partition_num, common::ObIArray<int64_t>& part_ids);
  // The meaning of get_part_index can refer to get_hash_part_ids()
  static int get_range_part_ids(const common::ObNewRow& row, ObPartition* const* partition_array,
      const int64_t partition_num, common::ObIArray<int64_t>& part_ids, bool get_part_index = false);

  // Get level-one range part_ids
  static int get_list_part_ids(const common::ObNewRange& range, const bool reverse, ObPartition* const* partition_array,
      const int64_t partition_num, common::ObIArray<int64_t>& part_ids);

  // The meaning of get_part_index can refer to get_hash_part_ids()
  static int get_list_part_ids(const common::ObNewRow& row, ObPartition* const* partition_array,
      const int64_t partition_num, common::ObIArray<int64_t>& part_ids, bool get_part_index = false);

  // Get level-two range part_ids
  static int get_range_part_ids(const int64_t part_id, const common::ObNewRange& range, const bool reverse,
      ObSubPartition* const* partition_array, const int64_t partition_num, common::ObIArray<int64_t>& part_ids);
  // The meaning of get_subpart_index can refer to get_hash_subpart_ids()
  static int get_range_part_ids(const int64_t part_id, const common::ObNewRow& row,
      ObSubPartition* const* partition_array, const int64_t partition_num, common::ObIArray<int64_t>& part_ids,
      bool get_subpart_index = false);

  // Get level-two range part_ids
  static int get_list_part_ids(const int64_t part_id, const common::ObNewRange& range, const bool reverse,
      ObSubPartition* const* partition_array, const int64_t partition_num, common::ObIArray<int64_t>& part_ids);

  // The meaning of get_subpart_index can refer to get_hash_subpart_ids()
  static int get_list_part_ids(const int64_t part_id, const common::ObNewRow& row,
      ObSubPartition* const* partition_array, const int64_t partition_num, common::ObIArray<int64_t>& part_ids,
      bool get_subpart_index = false);

  // According to the given hash value val and partition number part_num,
  // distinguish between oracle and mysql modes to calculate which partition this fold falls on
  // This interface is called at get_hash_part_idxs, get_hash_subpart_ids, etc.
  static int calc_hash_part_idx(const uint64_t val, const int64_t part_num, int64_t& partition_idx);
  template <typename T>
  static int get_range_part_idx(
      const common::ObObj& obj, T* const* part_array, const int64_t part_num, int64_t& part_idx);

  template <typename T>
  static int get_range_part_bounds(T* const* part_array, const int64_t part_num, const int64_t part_idx,
      common::ObObj& lower_bound, common::ObObj& upper_bound);

  // Get all part idxs of part num
  static int get_all_part(const ObTableSchema& table_schema, int64_t part_num, common::ObIArray<int64_t>& part_ids);

  // Convert rowkey to sql literal for show
  static int convert_rowkey_to_sql_literal(const common::ObRowkey& rowkey, char* buf, const int64_t buf_len,
      int64_t& pos, bool print_collation, const common::ObTimeZoneInfo* tz_info);
  // Used to display the defined value of the LIST partition
  static int convert_rows_to_sql_literal(const common::ObIArray<common::ObNewRow>& rows, char* buf,
      const int64_t buf_len, int64_t& pos, bool print_collation, const common::ObTimeZoneInfo* tz_info);
  static int print_oracle_datetime_literal(const common::ObObj& tmp_obj, char* buf, const int64_t buf_len, int64_t& pos,
      const common::ObTimeZoneInfo* tz_info);

  // Convert rowkey's serialize buff to hex.For record all rowkey info.
  static int convert_rowkey_to_hex(const common::ObRowkey& rowkey, char* buf, const int64_t buf_len, int64_t& pos);
  static int convert_rows_to_hex(
      const common::ObIArray<common::ObNewRow>& rows, char* buf, const int64_t buf_len, int64_t& pos);

  // Get partition start with start_part rowkey, return start_pos
  template <typename T>
  static int get_start(
      const T* const* partition_array, const int64_t partition_num, const T& start_part, int64_t& start_pos);

  // Get partition end with end_part rowkey, return end_pos
  template <typename T>
  static int get_end(const T* const* partition_array, const int64_t partition_num,
      const common::ObBorderFlag& border_flag, const T& end_part, int64_t& end_pos);

  // check if partition value equal
  template <typename PARTITION>
  static int check_partition_value(
      const PARTITION& l_part, const PARTITION& r_part, const ObPartitionFuncType part_type, bool& is_equal);

  static bool is_types_equal_for_partition_check(const common::ObObjType& typ1, const common::ObObjType& type2);

  private:
  // Get level-one range part_ids
  // The meaning of get_part_index can refer to get_hash_part_ids()
  static int get_range_part_ids(ObPartition& start, ObPartition& end, const common::ObBorderFlag& border_flag,
      const bool reverse, ObPartition* const* partition_array, const int64_t partition_num,
      common::ObIArray<int64_t>& part_ids, bool get_part_index = false);
  // Get level-two range part_ids
  // The meaning of get_subpart_index can refer to get_hash_subpart_ids()
  static int get_range_part_ids(ObSubPartition& start_bound, ObSubPartition& end_bound,
      const common::ObBorderFlag& border_flag, const bool reverse, ObSubPartition* const* partition_array,
      const int64_t partition_num, common::ObIArray<int64_t>& part_ids, bool get_subpart_index = false);
};

template <typename T>
int ObPartitionUtils::get_range_part_idx(
    const common::ObObj& obj, T* const* part_array, const int64_t part_num, int64_t& part_idx)
{
  int ret = common::OB_SUCCESS;
  if (obj.is_null()) {
    part_idx = 0;
  } else {
    common::ObObj buf_obj = obj;
    common::ObRowkey row_key(&buf_obj, 1);
    T end_key;
    end_key.high_bound_val_ = row_key;
    common::ObBorderFlag border_flag;
    border_flag.set_inclusive_start();
    border_flag.set_inclusive_end();
    if (part_num < 1) {
      ret = common::OB_ERR_UNEXPECTED;
      SHARE_SCHEMA_LOG(WARN, "Unexpected partition num", K(part_num), K(ret));
    } else if (OB_FAIL(get_end(part_array, part_num, border_flag, end_key, part_idx))) {
      SHARE_SCHEMA_LOG(WARN, "Failed to get end partition idx", K(end_key), K(ret));
    }
  }
  return ret;
}

template <typename T>
int ObPartitionUtils::get_range_part_bounds(T* const* part_array, const int64_t part_num, const int64_t part_idx,
    common::ObObj& lower_bound, common::ObObj& upper_bound)
{
  int ret = common::OB_SUCCESS;
  if (OB_UNLIKELY(!(0 <= part_idx && part_idx < part_num))) {
    ret = common::OB_ERR_UNEXPECTED;
    SHARE_SCHEMA_LOG(WARN, "invalid part_num or part_idx", K(part_num), K(part_idx), K(ret));
  } else if (OB_ISNULL(part_array[part_idx])) {
    ret = common::OB_ERR_UNEXPECTED;
    SHARE_SCHEMA_LOG(WARN, "part_array[part_idx] is null", K(part_idx), K(ret));
  } else if (part_array[part_idx]->get_high_bound_val().get_obj_cnt() > 1) {
    ret = common::OB_NOT_IMPLEMENT;
    SHARE_SCHEMA_LOG(WARN, "range columns count should be 1 now", K(ret));
  } else {
    if (part_idx > 0) {
      if (OB_ISNULL(part_array[part_idx - 1])) {
        ret = common::OB_ERR_UNEXPECTED;
        SHARE_SCHEMA_LOG(WARN, "part_array[part_idx - 1] is null", K(part_idx - 1), K(ret));
      } else {
        lower_bound = part_array[part_idx - 1]->get_high_bound_val().get_obj_ptr()[0];
      }
    } else {
      lower_bound.set_min_value();
    }
    if (part_idx < part_num - 1) {
      upper_bound = part_array[part_idx]->get_high_bound_val().get_obj_ptr()[0];
    } else {
      upper_bound.set_max_value();
    }
  }
  return ret;
}

template <typename T>
int ObPartitionUtils::get_start(
    const T* const* partition_array, const int64_t partition_num, const T& start_part, int64_t& start_pos)
{
  int ret = common::OB_SUCCESS;
  if (OB_ISNULL(partition_array)) {
    ret = common::OB_ERR_UNEXPECTED;
    SHARE_SCHEMA_LOG(WARN, "Partition array should not be NULL", K(ret));
  } else {
    const T* const* result =
        std::upper_bound(partition_array, partition_array + partition_num, &start_part, T::less_than);
    start_pos = result - partition_array;
    if (start_pos < 0) {
      ret = common::OB_ERR_UNEXPECTED;
      SHARE_SCHEMA_LOG(WARN, "Start pos error", K(partition_num), K(ret));
    }
  }
  return ret;
}

template <typename T>
int ObPartitionUtils::get_end(const T* const* partition_array, const int64_t partition_num,
    const common::ObBorderFlag& border_flag, const T& end_part, int64_t& end_pos)
{
  int ret = common::OB_SUCCESS;
  if (OB_ISNULL(partition_array)) {
    ret = common::OB_ERR_UNEXPECTED;
    SHARE_SCHEMA_LOG(WARN, "Input partition array should not be NULL", K(ret));
  } else {
    const T* const* result =
        std::lower_bound(partition_array, partition_array + partition_num, &end_part, T::less_than);
    int64_t pos = result - partition_array;
    if (pos >= partition_num) {
      end_pos = partition_num - 1;
    } else if (OB_ISNULL(result) || OB_ISNULL(*result)) {
      ret = common::OB_ERR_UNEXPECTED;
      SHARE_SCHEMA_LOG(WARN, "result should not be NULL", K(ret), K(result));
    } else {
      common::ObNewRow lrow;
      lrow.cells_ = const_cast<common::ObObj*>((*result)->high_bound_val_.get_obj_ptr());
      lrow.count_ = (*result)->high_bound_val_.get_obj_cnt();
      lrow.projector_ = (*result)->projector_;
      lrow.projector_size_ = (*result)->projector_size_;
      common::ObNewRow rrow;
      rrow.cells_ = const_cast<common::ObObj*>(end_part.high_bound_val_.get_obj_ptr());
      rrow.count_ = end_part.high_bound_val_.get_obj_cnt();
      rrow.projector_ = end_part.projector_;
      rrow.projector_size_ = end_part.projector_size_;
      int cmp = 0;
      if (common::OB_SUCCESS != common::ObRowUtil::compare_row(lrow, rrow, cmp)) {
        SHARE_SCHEMA_LOG(ERROR, "lhs or rhs is invalid");
      }
      if (0 == cmp) {
        if (pos == partition_num - 1) {
          end_pos = partition_num - 1;
        } else {
          if (border_flag.inclusive_end()) {
            end_pos = pos + 1;
          } else {
            end_pos = pos;
          }
        }
      } else {
        end_pos = pos;
      }
    }
  }
  return ret;
}

// TODO Put the partition description information together
// struct ObPartitionDesc
//{
//  OB_UNIS_VERSION(1);
//  int get_part(const common::ObNewRange &range,
//               bool reverse,
//               common::ObIArray<int64_t> &part_ids);
//
//  int get_sub_part(uint64_t table_id,
//                   int64_t part_id,
//                   const common::ObNewRange &range,
//                   bool reverse,
//                   common::ObIArray<int64_t> &part_ids);
//  //first partition
//  ObPartition **partition_array_;
//  int64_t partition_array_capacity_;
//  int64_t partition_num_;
//  //second partition
//  ObSubPartition **subpartition_array_;
//  int64_t subpartition_array_capacity_;
//  int64_t subpartition_num_;
//};

class ObViewSchema : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  ObViewSchema();
  explicit ObViewSchema(common::ObIAllocator* allocator);
  virtual ~ObViewSchema();
  ObViewSchema(const ObViewSchema& src_schema);
  ObViewSchema& operator=(const ObViewSchema& src_schema);
  bool operator==(const ObViewSchema& other) const;
  bool operator!=(const ObViewSchema& other) const;

  inline int set_view_definition(const char* view_definition)
  {
    return deep_copy_str(view_definition, view_definition_);
  }
  inline int set_view_definition(const common::ObString& view_definition)
  {
    return deep_copy_str(view_definition, view_definition_);
  }
  inline void set_view_check_option(const ViewCheckOption option)
  {
    view_check_option_ = option;
  }
  inline void set_view_is_updatable(const bool is_updatable)
  {
    view_is_updatable_ = is_updatable;
  }
  inline void set_materialized(const bool materialized)
  {
    materialized_ = materialized;
  }
  inline void set_character_set_client(const common::ObCharsetType character_set_client)
  {
    character_set_client_ = character_set_client;
  }
  inline void set_collation_connection(const common::ObCollationType collation_connection)
  {
    collation_connection_ = collation_connection;
  }

  // view_definition_ is defined using utf8, for sql resolve please use
  // ObSQLUtils::generate_view_definition_for_resolve
  inline const common::ObString& get_view_definition_str() const
  {
    return view_definition_;
  }
  inline const char* get_view_definition() const
  {
    return extract_str(view_definition_);
  }
  inline ViewCheckOption get_view_check_option() const
  {
    return view_check_option_;
  }
  inline bool get_view_is_updatable() const
  {
    return view_is_updatable_;
  }
  inline bool get_materialized() const
  {
    return materialized_;
  }
  inline common::ObCharsetType get_character_set_client() const
  {
    return character_set_client_;
  }
  inline common::ObCollationType get_collation_connection() const
  {
    return collation_connection_;
  }

  int64_t get_convert_size() const;
  virtual bool is_valid() const;
  virtual void reset();

  TO_STRING_KV(N_VIEW_DEFINITION, view_definition_, N_CHECK_OPTION, ob_view_check_option_str(view_check_option_),
      N_IS_UPDATABLE, STR_BOOL(view_is_updatable_), N_IS_MATERIALIZED, STR_BOOL(materialized_),
      K_(character_set_client), K_(collation_connection));

  private:
  common::ObString view_definition_;
  ViewCheckOption view_check_option_;
  bool view_is_updatable_;
  bool materialized_;
  common::ObCharsetType character_set_client_;
  common::ObCollationType collation_connection_;
};

class ObColumnSchemaHashWrapper {
  public:
  ObColumnSchemaHashWrapper()
  {}
  explicit ObColumnSchemaHashWrapper(const common::ObString& str) : column_name_(str)
  {}
  ~ObColumnSchemaHashWrapper()
  {}
  void set_name(const common::ObString& str)
  {
    column_name_ = str;
  }
  inline bool operator==(const ObColumnSchemaHashWrapper& other) const
  {
    ObCompareNameWithTenantID name_cmp;
    return (0 == name_cmp.compare(column_name_, other.column_name_));
  }
  inline uint64_t hash() const;
  common::ObString column_name_;
};
class ObColumnSchemaWrapper {
  public:
  ObColumnSchemaWrapper() : column_name_(), prefix_len_(0)
  {}
  explicit ObColumnSchemaWrapper(const common::ObString& str, int32_t prefix_len)
      : column_name_(str), prefix_len_(prefix_len)
  {}
  ~ObColumnSchemaWrapper()
  {}
  void set_name(const common::ObString& str)
  {
    column_name_ = str;
  }
  inline bool name_equal(const ObColumnSchemaWrapper& other) const
  {
    ObCompareNameWithTenantID name_cmp;
    return (0 == name_cmp.compare(column_name_, other.column_name_));
  }
  inline bool all_equal(const ObColumnSchemaWrapper& other) const
  {
    ObCompareNameWithTenantID name_cmp;
    return (0 == name_cmp.compare(column_name_, other.column_name_)) && prefix_len_ == other.prefix_len_;
  }
  TO_STRING_KV(K_(column_name), K_(prefix_len));

  common::ObString column_name_;
  int32_t prefix_len_;
};
typedef ObColumnSchemaHashWrapper ObColumnNameHashWrapper;
typedef ObColumnSchemaHashWrapper ObIndexNameHashWrapper;
typedef ObColumnSchemaHashWrapper ObPartitionNameHashWrapper;
typedef ObColumnSchemaHashWrapper ObForeignKeyNameHashWrapper;
typedef ObColumnSchemaWrapper ObColumnNameWrapper;

inline uint64_t ObColumnSchemaHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  // case insensitive
  hash_ret = common::ObCharset::hash(common::CS_TYPE_UTF8MB4_GENERAL_CI, column_name_, hash_ret);
  return hash_ret;
}
class ObIndexSchemaHashWrapper {
  public:
  ObIndexSchemaHashWrapper() : tenant_id_(common::OB_INVALID_ID), database_id_(common::OB_INVALID_ID)
  {}
  ObIndexSchemaHashWrapper(uint64_t tenant_id, const uint64_t database_id, const common::ObString& index_name)
      : tenant_id_(tenant_id), database_id_(database_id), index_name_(index_name)
  {}
  ~ObIndexSchemaHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObIndexSchemaHashWrapper& rv) const;

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline const common::ObString& get_index_name() const
  {
    return index_name_;
  }

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  common::ObString index_name_;
};

inline uint64_t ObIndexSchemaHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
  // case insensitive
  hash_ret = common::ObCharset::hash(common::CS_TYPE_UTF8MB4_GENERAL_CI, index_name_, hash_ret);
  return hash_ret;
}

inline bool ObIndexSchemaHashWrapper::operator==(const ObIndexSchemaHashWrapper& rv) const
{
  // mysql case insensitive
  // oracle case sensitive
  ObCompareNameWithTenantID name_cmp(tenant_id_);
  return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_) &&
         (0 == name_cmp.compare(index_name_, rv.index_name_));
}

class ObTableSchemaHashWrapper {
  public:
  ObTableSchemaHashWrapper()
      : tenant_id_(common::OB_INVALID_ID),
        database_id_(common::OB_INVALID_ID),
        session_id_(common::OB_INVALID_ID),
        name_case_mode_(common::OB_NAME_CASE_INVALID)
  {}
  ObTableSchemaHashWrapper(const uint64_t tenant_id, const uint64_t database_id, const uint64_t session_id,
      const common::ObNameCaseMode mode, const common::ObString& table_name)
      : tenant_id_(tenant_id),
        database_id_(database_id),
        session_id_(session_id),
        name_case_mode_(mode),
        table_name_(table_name)
  {}
  ~ObTableSchemaHashWrapper()
  {}
  inline uint64_t hash() const;
  bool operator==(const ObTableSchemaHashWrapper& rv) const;

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline uint64_t get_session_id() const
  {
    return session_id_;
  }
  inline const common::ObString& get_table_name() const
  {
    return table_name_;
  }

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  uint64_t session_id_;
  common::ObNameCaseMode name_case_mode_;
  common::ObString table_name_;
};

inline uint64_t ObTableSchemaHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
  common::ObCollationType cs_type = ObSchema::get_cs_type_with_cmp_mode(name_case_mode_);
  hash_ret = common::ObCharset::hash(cs_type, table_name_, hash_ret);
  return hash_ret;
}

// See ObSchemaMgr::get_table_schema comment for session visibility judgment
inline bool ObTableSchemaHashWrapper::operator==(const ObTableSchemaHashWrapper& rv) const
{
  ObCompareNameWithTenantID name_cmp(tenant_id_, name_case_mode_, database_id_);
  return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_) &&
         (name_case_mode_ == rv.name_case_mode_) &&
         (session_id_ == rv.session_id_ || common::OB_INVALID_ID == rv.session_id_) &&
         (0 == name_cmp.compare(table_name_, rv.table_name_));
}

class ObDatabaseSchemaHashWrapper {
  public:
  ObDatabaseSchemaHashWrapper() : tenant_id_(common::OB_INVALID_ID), name_case_mode_(common::OB_NAME_CASE_INVALID)
  {}
  ObDatabaseSchemaHashWrapper(
      const uint64_t tenant_id, const common::ObNameCaseMode mode, const common::ObString& database_name)
      : tenant_id_(tenant_id), name_case_mode_(mode), database_name_(database_name)
  {}
  ~ObDatabaseSchemaHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObDatabaseSchemaHashWrapper& rv) const;

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline common::ObNameCaseMode get_name_case_mode() const
  {
    return name_case_mode_;
  }
  inline const common::ObString& get_database_name() const
  {
    return database_name_;
  }

  private:
  uint64_t tenant_id_;
  common::ObNameCaseMode name_case_mode_;
  common::ObString database_name_;
};

inline uint64_t ObDatabaseSchemaHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  common::ObCollationType cs_type = ObSchema::get_cs_type_with_cmp_mode(name_case_mode_);
  hash_ret = common::ObCharset::hash(cs_type, database_name_, hash_ret);
  return hash_ret;
}

inline bool ObDatabaseSchemaHashWrapper::operator==(const ObDatabaseSchemaHashWrapper& rv) const
{
  ObCompareNameWithTenantID name_cmp(tenant_id_, name_case_mode_);
  return (tenant_id_ == rv.tenant_id_) && (name_case_mode_ == rv.name_case_mode_) &&
         (0 == name_cmp.compare(database_name_, rv.database_name_));
}

class ObTablegroupSchemaHashWrapper {
  public:
  ObTablegroupSchemaHashWrapper() : tenant_id_(common::OB_INVALID_ID)
  {}
  ObTablegroupSchemaHashWrapper(uint64_t tenant_id, const common::ObString& tablegroup_name)
      : tenant_id_(tenant_id), tablegroup_name_(tablegroup_name)
  {}
  ~ObTablegroupSchemaHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObTablegroupSchemaHashWrapper& rv) const;

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline const common::ObString& get_tablegroup_name() const
  {
    return tablegroup_name_;
  }

  private:
  uint64_t tenant_id_;
  common::ObString tablegroup_name_;
};

class ObForeignKeyInfoHashWrapper {
  public:
  ObForeignKeyInfoHashWrapper()
  {
    tenant_id_ = common::OB_INVALID_ID;
    database_id_ = common::OB_INVALID_ID;
    foreign_key_name_.assign_ptr("", 0);
  }
  ObForeignKeyInfoHashWrapper(uint64_t tenant_id, const uint64_t database_id, const common::ObString& foreign_key_name)
      : tenant_id_(tenant_id), database_id_(database_id), foreign_key_name_(foreign_key_name)
  {}
  ~ObForeignKeyInfoHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObForeignKeyInfoHashWrapper& rv) const;
  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline const common::ObString& get_foreign_key_name() const
  {
    return foreign_key_name_;
  }

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  common::ObString foreign_key_name_;
};

inline uint64_t ObForeignKeyInfoHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
  // case insensitive
  hash_ret = common::ObCharset::hash(common::CS_TYPE_UTF8MB4_GENERAL_CI, foreign_key_name_, hash_ret);
  return hash_ret;
}

inline bool ObForeignKeyInfoHashWrapper::operator==(const ObForeignKeyInfoHashWrapper& rv) const
{
  // mysql case insensitive
  // oracle case sensitive
  ObCompareNameWithTenantID name_cmp(tenant_id_);
  return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_) &&
         (0 == name_cmp.compare(foreign_key_name_, rv.foreign_key_name_));
}

class ObConstraintInfoHashWrapper {
  public:
  ObConstraintInfoHashWrapper()
  {
    tenant_id_ = common::OB_INVALID_ID;
    database_id_ = common::OB_INVALID_ID;
    constraint_name_.assign_ptr("", 0);
  }
  ObConstraintInfoHashWrapper(uint64_t tenant_id, const uint64_t database_id, const common::ObString& constraint_name)
      : tenant_id_(tenant_id), database_id_(database_id), constraint_name_(constraint_name)
  {}
  ~ObConstraintInfoHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObConstraintInfoHashWrapper& rv) const;
  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline const common::ObString& get_constraint_name() const
  {
    return constraint_name_;
  }

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  common::ObString constraint_name_;
};

inline uint64_t ObConstraintInfoHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
  // case insensitive
  hash_ret = common::ObCharset::hash(common::CS_TYPE_UTF8MB4_GENERAL_CI, constraint_name_, hash_ret);
  return hash_ret;
}

inline bool ObConstraintInfoHashWrapper::operator==(const ObConstraintInfoHashWrapper& rv) const
{
  // mysql case insensitive
  // oracle case sensitive
  ObCompareNameWithTenantID name_cmp(tenant_id_);
  return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_) &&
         (0 == name_cmp.compare(constraint_name_, rv.constraint_name_));
}

inline uint64_t ObTablegroupSchemaHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(tablegroup_name_.ptr(), tablegroup_name_.length(), hash_ret);
  return hash_ret;
}

inline bool ObTablegroupSchemaHashWrapper::operator==(const ObTablegroupSchemaHashWrapper& rv) const
{
  return (tenant_id_ == rv.tenant_id_) && (tablegroup_name_ == rv.tablegroup_name_);
}

struct ObTenantPlanBaselineId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantPlanBaselineId() : tenant_id_(common::OB_INVALID_ID), plan_baseline_id_(common::OB_INVALID_ID)
  {}
  ObTenantPlanBaselineId(const uint64_t tenant_id, const uint64_t plan_baseline_id)
      : tenant_id_(tenant_id), plan_baseline_id_(plan_baseline_id)
  {}
  bool operator==(const ObTenantPlanBaselineId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (plan_baseline_id_ == rhs.plan_baseline_id_);
  }
  bool operator!=(const ObTenantPlanBaselineId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantPlanBaselineId& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (tenant_id_ == rhs.tenant_id_) {
      bret = plan_baseline_id_ < rhs.plan_baseline_id_;
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&plan_baseline_id_, sizeof(plan_baseline_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (plan_baseline_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(plan_baseline_id));
  uint64_t tenant_id_;
  uint64_t plan_baseline_id_;
};

struct ObTenantOutlineId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantOutlineId() : tenant_id_(common::OB_INVALID_ID), outline_id_(common::OB_INVALID_ID)
  {}
  ObTenantOutlineId(const uint64_t tenant_id, const uint64_t outline_id)
      : tenant_id_(tenant_id), outline_id_(outline_id)
  {}
  bool operator==(const ObTenantOutlineId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (outline_id_ == rhs.outline_id_);
  }
  bool operator!=(const ObTenantOutlineId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantOutlineId& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (tenant_id_ == rhs.tenant_id_) {
      bret = outline_id_ < rhs.outline_id_;
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&outline_id_, sizeof(outline_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (outline_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(outline_id));
  uint64_t tenant_id_;
  uint64_t outline_id_;
};

// For managing privilege
struct ObTenantUserId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantUserId() : tenant_id_(common::OB_INVALID_ID), user_id_(common::OB_INVALID_ID)
  {}
  ObTenantUserId(const uint64_t tenant_id, const uint64_t user_id) : tenant_id_(tenant_id), user_id_(user_id)
  {}
  bool operator==(const ObTenantUserId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (user_id_ == rhs.user_id_);
  }
  bool operator!=(const ObTenantUserId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantUserId& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (tenant_id_ == rhs.tenant_id_) {
      bret = user_id_ < rhs.user_id_;
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&user_id_, sizeof(user_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (user_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(user_id));
  uint64_t tenant_id_;
  uint64_t user_id_;
};

// For managing privilege
struct ObTenantUrObjId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantUrObjId()
      : tenant_id_(common::OB_INVALID_ID),
        grantee_id_(common::OB_INVALID_ID),
        obj_id_(common::OB_INVALID_ID),
        obj_type_(common::OB_INVALID_ID),
        col_id_(common::OB_INVALID_ID)
  {}
  ObTenantUrObjId(const uint64_t tenant_id, const uint64_t grantee_id, const uint64_t obj_id, const uint64_t obj_type,
      const uint64_t col_id)
      : tenant_id_(tenant_id), grantee_id_(grantee_id), obj_id_(obj_id), obj_type_(obj_type), col_id_(col_id)
  {}
  bool operator==(const ObTenantUrObjId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (grantee_id_ == rhs.grantee_id_) && (obj_id_ == rhs.obj_id_) &&
           (obj_type_ == rhs.obj_type_) && (col_id_ == rhs.col_id_);
  }
  bool operator!=(const ObTenantUrObjId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantUrObjId& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (tenant_id_ == rhs.tenant_id_) {
      bret = grantee_id_ < rhs.grantee_id_;
      if (false == bret && grantee_id_ == rhs.grantee_id_) {
        bret = obj_id_ < rhs.obj_id_;
        if (false == bret && obj_id_ == rhs.obj_id_) {
          bret = obj_type_ < rhs.obj_type_;
          if (false == bret && obj_type_ == rhs.obj_type_) {
            bret = col_id_ < rhs.col_id_;
          }
        }
      }
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&grantee_id_, sizeof(grantee_id_), hash_ret);
    hash_ret = common::murmurhash(&obj_id_, sizeof(obj_id_), hash_ret);
    hash_ret = common::murmurhash(&obj_type_, sizeof(obj_type_), hash_ret);
    hash_ret = common::murmurhash(&col_id_, sizeof(col_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (grantee_id_ != common::OB_INVALID_ID) &&
           (obj_id_ != common::OB_INVALID_ID) && (obj_type_ != common::OB_INVALID_ID) &&
           (col_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(grantee_id), K_(obj_id), K_(obj_type), K_(col_id));
  uint64_t tenant_id_;
  uint64_t grantee_id_;
  uint64_t obj_id_;
  uint64_t obj_type_;
  uint64_t col_id_;
};

class ObPrintPrivSet {
  public:
  explicit ObPrintPrivSet(ObPrivSet priv_set) : priv_set_(priv_set)
  {}

  DECLARE_TO_STRING;

  private:
  ObPrivSet priv_set_;
};

class ObPrintPackedPrivArray {
  public:
  explicit ObPrintPackedPrivArray(const ObPackedPrivArray& packed_priv_array) : packed_priv_array_(packed_priv_array)
  {}

  DECLARE_TO_STRING;

  private:
  const ObPackedPrivArray& packed_priv_array_;
};

class ObPriv {
  OB_UNIS_VERSION_V(1);

  public:
  ObPriv()
      : tenant_id_(common::OB_INVALID_ID),
        user_id_(common::OB_INVALID_ID),
        schema_version_(1),
        priv_set_(0),
        priv_array_()
  {}
  ObPriv(common::ObIAllocator* allocator)
      : tenant_id_(common::OB_INVALID_ID),
        user_id_(common::OB_INVALID_ID),
        schema_version_(1),
        priv_set_(0),
        priv_array_(common::OB_MALLOC_NORMAL_BLOCK_SIZE, common::ModulePageAllocator(*allocator))
  {}
  ObPriv(const uint64_t tenant_id, const uint64_t user_id, const int64_t schema_version, const ObPrivSet priv_set)
      : tenant_id_(tenant_id), user_id_(user_id), schema_version_(schema_version), priv_set_(priv_set), priv_array_()
  {}

  virtual ~ObPriv()
  {}
  ObPriv& operator=(const ObPriv& other);
  static bool cmp_tenant_user_id(const ObPriv* lhs, const ObTenantUserId& tenant_user_id)
  {
    return (lhs->get_tenant_user_id() < tenant_user_id);
  }
  static bool equal_tenant_user_id(const ObPriv* lhs, const ObTenantUserId& tenant_user_id)
  {
    return (lhs->get_tenant_user_id() == tenant_user_id);
  }
  static bool cmp_tenant_id(const ObPriv* lhs, const uint64_t tenant_id)
  {
    return (lhs->get_tenant_id() < tenant_id);
  }
  ObTenantUserId get_tenant_user_id() const
  {
    return ObTenantUserId(tenant_id_, user_id_);
  }

  inline void set_tenant_id(const uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  inline void set_user_id(const uint64_t user_id)
  {
    user_id_ = user_id;
  }
  inline void set_schema_version(const uint64_t schema_version)
  {
    schema_version_ = schema_version;
  }
  inline void set_priv(const ObPrivType priv)
  {
    priv_set_ |= priv;
  }
  inline void set_priv_set(const ObPrivSet priv_set)
  {
    priv_set_ = priv_set;
  }
  inline void reset_priv_set()
  {
    priv_set_ = 0;
  }
  inline void set_obj_privs(const ObPackedObjPriv obj_privs)
  {
    priv_set_ = obj_privs;
  }
  int set_priv_array(const ObPackedPrivArray& other)
  {
    return priv_array_.assign(other);
  }

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  };
  inline uint64_t get_user_id() const
  {
    return user_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline ObPrivSet get_priv_set() const
  {
    return priv_set_;
  }
  inline ObPrivType get_priv(const ObPrivType priv) const
  {
    return priv_set_ & priv;
  }
  inline const ObPackedPrivArray& get_priv_array() const
  {
    return priv_array_;
  }
  inline ObPackedObjPriv get_obj_privs() const
  {
    return priv_set_;
  }
  virtual void reset();
  int64_t get_convert_size() const;
  virtual bool is_valid() const
  {
    return common::OB_INVALID_ID != tenant_id_ && common::OB_INVALID_ID != user_id_ && schema_version_ > 0;
  }

  TO_STRING_KV(K_(tenant_id), K_(user_id), K_(schema_version), "privileges", ObPrintPrivSet(priv_set_));

  protected:
  uint64_t tenant_id_;
  uint64_t user_id_;
  int64_t schema_version_;
  ObPrivSet priv_set_;
  // ObPrivSet ora_sys_priv_set_;
  ObPackedPrivArray priv_array_;
};

// Not used now
class ObUserInfoHashWrapper {
  public:
  ObUserInfoHashWrapper() : tenant_id_(common::OB_INVALID_ID)
  {}
  ObUserInfoHashWrapper(uint64_t tenant_id, const common::ObString& user_name)
      : tenant_id_(tenant_id), user_name_(user_name)
  {}
  ~ObUserInfoHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObUserInfoHashWrapper& rv) const;

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline const common::ObString& get_user_name() const
  {
    return user_name_;
  }

  private:
  uint64_t tenant_id_;
  common::ObString user_name_;
};

inline uint64_t ObUserInfoHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(user_name_.ptr(), user_name_.length(), hash_ret);
  return hash_ret;
}

inline bool ObUserInfoHashWrapper::operator==(const ObUserInfoHashWrapper& other) const
{
  return (tenant_id_ == other.tenant_id_) && (user_name_ == other.user_name_);
}

enum class ObSSLType : int {
  SSL_TYPE_NOT_SPECIFIED = 0,
  SSL_TYPE_NONE,
  SSL_TYPE_ANY,
  SSL_TYPE_X509,
  SSL_TYPE_SPECIFIED,
  SSL_TYPE_MAX
};

common::ObString get_ssl_type_string(const ObSSLType ssl_type);
ObSSLType get_ssl_type_from_string(const common::ObString& ssl_type_str);

enum class ObSSLSpecifiedType : int {
  SSL_SPEC_TYPE_CIPHER = 0,
  SSL_SPEC_TYPE_ISSUER,
  SSL_SPEC_TYPE_SUBJECT,
  SSL_SPEC_TYPE_MAX
};

const char* get_ssl_spec_type_str(const ObSSLSpecifiedType ssl_spec_type);

enum ObUserType {
  OB_USER = 0,
  OB_ROLE,
  OB_TYPE_MAX,
};

#define ADMIN_OPTION_SHIFT 0
#define DISABLE_FLAG_SHIFT 1

class ObUserInfo : public ObSchema, public ObPriv {
  OB_UNIS_VERSION(1);

  public:
  ObUserInfo()
      : ObSchema(),
        ObPriv(),
        user_name_(),
        host_name_(),
        passwd_(),
        info_(),
        locked_(false),
        ssl_type_(ObSSLType::SSL_TYPE_NOT_SPECIFIED),
        ssl_cipher_(),
        x509_issuer_(),
        x509_subject_(),
        type_(OB_USER),
        grantee_id_array_(),
        role_id_array_(),
        profile_id_(common::OB_INVALID_ID),
        password_last_changed_timestamp_(common::OB_INVALID_TIMESTAMP),
        role_id_option_array_()
  {}
  explicit ObUserInfo(common::ObIAllocator* allocator);
  virtual ~ObUserInfo();
  ObUserInfo(const ObUserInfo& other);
  ObUserInfo& operator=(const ObUserInfo& other);
  static bool cmp(const ObUserInfo* lhs, const ObUserInfo* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_tenant_user_id() < rhs->get_tenant_user_id() : false;
  }
  static bool equal(const ObUserInfo* lhs, const ObUserInfo* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_tenant_user_id() == rhs->get_tenant_user_id() : false;
  }

  // set methods
  inline int set_user_name(const char* user_name)
  {
    return deep_copy_str(user_name, user_name_);
  }
  inline int set_user_name(const common::ObString& user_name)
  {
    return deep_copy_str(user_name, user_name_);
  }
  inline int set_host(const char* host_name)
  {
    return deep_copy_str(host_name, host_name_);
  }
  inline int set_host(const common::ObString& host_name)
  {
    return deep_copy_str(host_name, host_name_);
  }
  inline int set_passwd(const char* passwd)
  {
    return deep_copy_str(passwd, passwd_);
  }
  inline int set_passwd(const common::ObString& passwd)
  {
    return deep_copy_str(passwd, passwd_);
  }
  inline int set_info(const char* info)
  {
    return deep_copy_str(info, info_);
  }
  inline int set_info(const common::ObString& info)
  {
    return deep_copy_str(info, info_);
  }
  inline void set_is_locked(const bool locked)
  {
    locked_ = locked;
  }
  inline void set_ssl_type(const ObSSLType ssl_type)
  {
    ssl_type_ = ssl_type;
  }
  inline int set_ssl_cipher(const char* ssl_cipher)
  {
    return deep_copy_str(ssl_cipher, ssl_cipher_);
  }
  inline int set_ssl_cipher(const common::ObString& ssl_cipher)
  {
    return deep_copy_str(ssl_cipher, ssl_cipher_);
  }
  inline int set_x509_issuer(const char* x509_issuer)
  {
    return deep_copy_str(x509_issuer, x509_issuer_);
  }
  inline int set_x509_issuer(const common::ObString& x509_issuer)
  {
    return deep_copy_str(x509_issuer, x509_issuer_);
  }
  inline int set_x509_subject(const char* x509_subject)
  {
    return deep_copy_str(x509_subject, x509_subject_);
  }
  inline int set_x509_subject(const common::ObString& x509_subject)
  {
    return deep_copy_str(x509_subject, x509_subject_);
  }
  inline void set_type(const uint64_t type)
  {
    type_ = type;
  }
  inline void set_profile_id(const uint64_t profile_id)
  {
    profile_id_ = profile_id;
  }
  inline void set_password_last_changed(int64_t ts)
  {
    password_last_changed_timestamp_ = ts;
  }
  // get methods
  inline const char* get_user_name() const
  {
    return extract_str(user_name_);
  }
  inline const common::ObString& get_user_name_str() const
  {
    return user_name_;
  }
  inline const char* get_host_name() const
  {
    return extract_str(host_name_);
  }
  inline const common::ObString& get_host_name_str() const
  {
    return host_name_;
  }
  inline const char* get_passwd() const
  {
    return extract_str(passwd_);
  }
  inline const common::ObString& get_passwd_str() const
  {
    return passwd_;
  }
  inline const char* get_info() const
  {
    return extract_str(info_);
  }
  inline const common::ObString& get_info_str() const
  {
    return info_;
  }
  inline bool get_is_locked() const
  {
    return locked_;
  }
  inline ObSSLType get_ssl_type() const
  {
    return ssl_type_;
  }
  inline const common::ObString get_ssl_type_str() const
  {
    return get_ssl_type_string(ssl_type_);
  }
  inline const char* get_ssl_cipher() const
  {
    return extract_str(ssl_cipher_);
  }
  inline const common::ObString& get_ssl_cipher_str() const
  {
    return ssl_cipher_;
  }
  inline const char* get_x509_issuer() const
  {
    return extract_str(x509_issuer_);
  }
  inline const common::ObString& get_x509_issuer_str() const
  {
    return x509_issuer_;
  }
  inline const char* get_x509_subject() const
  {
    return extract_str(x509_subject_);
  }
  inline const common::ObString& get_x509_subject_str() const
  {
    return x509_subject_;
  }
  inline uint64_t get_profile_id() const
  {
    return profile_id_;
  }
  inline int64_t get_password_last_changed() const
  {
    return password_last_changed_timestamp_;
  }
  // role
  inline bool is_role() const
  {
    return OB_ROLE == type_;
  }
  inline int get_grantee_count() const
  {
    return grantee_id_array_.count();
  }
  inline int get_role_count() const
  {
    return role_id_array_.count();
  }
  const common::ObSEArray<uint64_t, 8>& get_grantee_id_array() const
  {
    return grantee_id_array_;
  }
  const common::ObSEArray<uint64_t, 8>& get_role_id_array() const
  {
    return role_id_array_;
  }
  const common::ObSEArray<uint64_t, 8>& get_role_id_option_array() const
  {
    return role_id_option_array_;
  }
  int add_grantee_id(const uint64_t id)
  {
    return grantee_id_array_.push_back(id);
  }
  int add_role_id(const uint64_t id, const uint64_t admin_option = NO_OPTION, const uint64_t disable_flag = 0);
  void set_admin_option(uint64_t& option, const uint64_t admin_option)
  {
    option |= (admin_option << ADMIN_OPTION_SHIFT);
  }
  void set_disable_flag(uint64_t& option, const uint64_t disable_flag)
  {
    option |= (disable_flag << DISABLE_FLAG_SHIFT);
  }
  int get_nth_role_option(uint64_t nth, uint64_t& option) const;
  uint64_t get_admin_option(uint64_t option) const
  {
    return 1 & (option >> ADMIN_OPTION_SHIFT);
  }
  uint64_t get_disable_option(uint64_t option) const
  {
    return 1 & (option >> DISABLE_FLAG_SHIFT);
  }

  // other methods
  virtual bool is_valid() const;
  virtual void reset();
  int64_t get_convert_size() const;
  TO_STRING_KV(K_(tenant_id), K_(user_id), K_(user_name), K_(host_name), "privileges", ObPrintPrivSet(priv_set_),
      K_(info), K_(locked), K_(ssl_type), K_(ssl_cipher), K_(x509_issuer), K_(x509_subject), K_(type),
      K_(grantee_id_array), K_(role_id_array), K_(profile_id));
  bool role_exists(const uint64_t role_id, const uint64_t option) const;
  int get_seq_by_role_id(uint64_t role_id, uint64_t& seq) const;

  private:
  common::ObString user_name_;
  common::ObString host_name_;
  common::ObString passwd_;
  common::ObString info_;
  bool locked_;
  ObSSLType ssl_type_;
  common::ObString ssl_cipher_;
  common::ObString x509_issuer_;
  common::ObString x509_subject_;

  int type_;
  common::ObSEArray<uint64_t, 8> grantee_id_array_;  // Record role granted to user
  common::ObSEArray<uint64_t, 8> role_id_array_;     // Record which roles the user/role has
  uint64_t profile_id_;
  int64_t password_last_changed_timestamp_;
  common::ObSEArray<uint64_t, 8> role_id_option_array_;  // Record which roles the user/role has
};

struct ObDBPrivSortKey {
  ObDBPrivSortKey() : tenant_id_(common::OB_INVALID_ID), user_id_(common::OB_INVALID_ID), sort_(0)
  {}
  ObDBPrivSortKey(const uint64_t tenant_id, const uint64_t user_id, const uint64_t sort_value)
      : tenant_id_(tenant_id), user_id_(user_id), sort_(sort_value)
  {}
  bool operator==(const ObDBPrivSortKey& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (user_id_ == rhs.user_id_) && (sort_ == rhs.sort_);
  }
  bool operator!=(const ObDBPrivSortKey& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObDBPrivSortKey& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (false == bret && tenant_id_ == rhs.tenant_id_) {
      bret = user_id_ < rhs.user_id_;
      if (false == bret && user_id_ == rhs.user_id_) {
        bret = sort_ > rhs.sort_;  // sort values of 'sort_' from big to small
      }
    }
    return bret;
  }

  TO_STRING_KV(K_(tenant_id), K_(user_id), K(sort_));

  uint64_t tenant_id_;
  uint64_t user_id_;
  uint64_t sort_;
};

struct ObOriginalDBKey {
  ObOriginalDBKey() : tenant_id_(common::OB_INVALID_ID), user_id_(common::OB_INVALID_ID)
  {}
  ObOriginalDBKey(const uint64_t tenant_id, const uint64_t user_id, const common::ObString& db)
      : tenant_id_(tenant_id), user_id_(user_id), db_(db)
  {}
  bool operator==(const ObOriginalDBKey& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (user_id_ == rhs.user_id_) && (db_ == rhs.db_);
  }
  bool operator!=(const ObOriginalDBKey& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObOriginalDBKey& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (false == bret && tenant_id_ == rhs.tenant_id_) {
      bret = user_id_ < rhs.user_id_;
    }
    return bret;
  }
  // Not used yet.
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&user_id_, sizeof(user_id_), hash_ret);
    hash_ret = common::murmurhash(db_.ptr(), db_.length(), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (user_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(user_id), K_(db));
  uint64_t tenant_id_;
  uint64_t user_id_;
  common::ObString db_;
};

struct ObSysPrivKey {
  ObSysPrivKey() : tenant_id_(common::OB_INVALID_ID), grantee_id_(common::OB_INVALID_ID)
  {}
  ObSysPrivKey(const uint64_t tenant_id, const uint64_t user_id) : tenant_id_(tenant_id), grantee_id_(user_id)
  {}
  bool operator==(const ObSysPrivKey& rhs) const
  {
    return ((tenant_id_ == rhs.tenant_id_) && (grantee_id_ == rhs.grantee_id_));
  }
  bool operator!=(const ObSysPrivKey& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObSysPrivKey& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (false == bret && tenant_id_ == rhs.tenant_id_) {
      bret = grantee_id_ < rhs.grantee_id_;
    }
    return bret;
  }
  // Not used yet.
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&grantee_id_, sizeof(grantee_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (grantee_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(grantee_id));
  uint64_t tenant_id_;
  uint64_t grantee_id_;
};

class ObDBPriv : public ObSchema, public ObPriv {
  OB_UNIS_VERSION(1);

  public:
  ObDBPriv() : ObPriv(), db_(), sort_(0)
  {}
  explicit ObDBPriv(common::ObIAllocator* allocator) : ObSchema(allocator), ObPriv(allocator), db_(), sort_(0)
  {}
  virtual ~ObDBPriv()
  {}
  ObDBPriv(const ObDBPriv& other) : ObSchema(), ObPriv()
  {
    *this = other;
  }
  ObDBPriv& operator=(const ObDBPriv& other);

  static bool cmp(const ObDBPriv* lhs, const ObDBPriv* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? (lhs->get_sort_key() < rhs->get_sort_key()) : false;
  }
  static bool cmp_sort_key(const ObDBPriv* lhs, const ObDBPrivSortKey& sort_key)
  {
    return NULL != lhs ? lhs->get_sort_key() < sort_key : false;
  }
  ObDBPrivSortKey get_sort_key() const
  {
    return ObDBPrivSortKey(tenant_id_, user_id_, sort_);
  }
  static bool equal(const ObDBPriv* lhs, const ObDBPriv* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_sort_key() == rhs->get_sort_key() : false;
  }  // point check
  ObOriginalDBKey get_original_key() const
  {
    return ObOriginalDBKey(tenant_id_, user_id_, db_);
  }

  // set methods
  inline int set_database_name(const char* db)
  {
    return deep_copy_str(db, db_);
  }
  inline int set_database_name(const common::ObString& db)
  {
    return deep_copy_str(db, db_);
  }
  inline void set_sort(const uint64_t sort)
  {
    sort_ = sort;
  }

  // get methods
  inline const char* get_database_name() const
  {
    return extract_str(db_);
  }
  inline const common::ObString& get_database_name_str() const
  {
    return db_;
  }
  inline uint64_t get_sort() const
  {
    return sort_;
  }
  // other methods
  virtual bool is_valid() const;
  virtual void reset();
  int64_t get_convert_size() const;
  TO_STRING_KV(K_(tenant_id), K_(user_id), K_(db), "privileges", ObPrintPrivSet(priv_set_));

  private:
  common::ObString db_;
  uint64_t sort_;
};

// In order to find in table_privs_ whether a table is authorized under a certain db
struct ObTablePrivDBKey {
  ObTablePrivDBKey() : tenant_id_(common::OB_INVALID_ID), user_id_(common::OB_INVALID_ID)
  {}
  ObTablePrivDBKey(const uint64_t tenant_id, const uint64_t user_id, const common::ObString& db)
      : tenant_id_(tenant_id), user_id_(user_id), db_(db)
  {}
  bool operator==(const ObTablePrivDBKey& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (user_id_ == rhs.user_id_) && (db_ == rhs.db_);
  }
  bool operator!=(const ObTablePrivDBKey& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTablePrivDBKey& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (false == bret && tenant_id_ == rhs.tenant_id_) {
      bret = user_id_ < rhs.user_id_;
      if (false == bret && user_id_ == rhs.user_id_) {
        bret = db_ < rhs.db_;
      }
    }
    return bret;
  }
  uint64_t tenant_id_;
  uint64_t user_id_;
  common::ObString db_;
};

struct ObTablePrivSortKey {
  ObTablePrivSortKey() : tenant_id_(common::OB_INVALID_ID), user_id_(common::OB_INVALID_ID)
  {}
  ObTablePrivSortKey(
      const uint64_t tenant_id, const uint64_t user_id, const common::ObString& db, const common::ObString& table)
      : tenant_id_(tenant_id), user_id_(user_id), db_(db), table_(table)
  {}
  bool operator==(const ObTablePrivSortKey& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (user_id_ == rhs.user_id_) && (db_ == rhs.db_) && (table_ == rhs.table_);
  }
  bool operator!=(const ObTablePrivSortKey& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTablePrivSortKey& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (false == bret && tenant_id_ == rhs.tenant_id_) {
      bret = user_id_ < rhs.user_id_;
      if (false == bret && user_id_ == rhs.user_id_) {
        bret = db_ < rhs.db_;
        if (false == bret && db_ == rhs.db_) {
          bret = table_ < rhs.table_;
        }
      }
    }
    return bret;
  }
  // Not used yet.
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&user_id_, sizeof(user_id_), hash_ret);
    hash_ret = common::murmurhash(db_.ptr(), db_.length(), hash_ret);
    hash_ret = common::murmurhash(table_.ptr(), table_.length(), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (user_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(user_id), K_(db), K_(table));
  uint64_t tenant_id_;
  uint64_t user_id_;
  common::ObString db_;
  common::ObString table_;
};

struct ObObjPrivSortKey {
  ObObjPrivSortKey()
      : tenant_id_(common::OB_INVALID_ID),
        obj_id_(common::OB_INVALID_ID),
        obj_type_(common::OB_INVALID_ID),
        col_id_(common::OB_INVALID_ID),
        grantor_id_(common::OB_INVALID_ID),
        grantee_id_(common::OB_INVALID_ID)
  {}
  ObObjPrivSortKey(const uint64_t tenant_id, const uint64_t obj_id, const uint64_t obj_type, const uint64_t col_id,
      const uint64_t grantor_id, const uint64_t grantee_id)
      : tenant_id_(tenant_id),
        obj_id_(obj_id),
        obj_type_(obj_type),
        col_id_(col_id),
        grantor_id_(grantor_id),
        grantee_id_(grantee_id)
  {}
  bool operator==(const ObObjPrivSortKey& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (obj_id_ == rhs.obj_id_) && (obj_type_ == rhs.obj_type_) &&
           (col_id_ == rhs.col_id_) && (grantor_id_ == rhs.grantor_id_) && (grantee_id_ == rhs.grantee_id_);
  }
  bool operator!=(const ObObjPrivSortKey& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObObjPrivSortKey& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (false == bret && tenant_id_ == rhs.tenant_id_) {
      bret = grantee_id_ < rhs.grantee_id_;
      if (false == bret && grantee_id_ == rhs.grantee_id_) {
        bret = obj_id_ < rhs.obj_id_;
        if (false == bret && obj_id_ == rhs.obj_id_) {
          bret = obj_type_ < rhs.obj_type_;
          if (false == bret && obj_type_ == rhs.obj_type_) {
            bret = col_id_ < rhs.col_id_;
            if (false == bret && col_id_ == rhs.col_id_) {
              bret = grantor_id_ < rhs.grantor_id_;
            }
          }
        }
      }
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&grantee_id_, sizeof(grantee_id_), hash_ret);
    hash_ret = common::murmurhash(&obj_id_, sizeof(obj_id_), hash_ret);
    hash_ret = common::murmurhash(&obj_type_, sizeof(obj_type_), hash_ret);
    hash_ret = common::murmurhash(&col_id_, sizeof(col_id_), hash_ret);
    hash_ret = common::murmurhash(&grantor_id_, sizeof(grantor_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (obj_id_ != common::OB_INVALID_ID) &&
           (obj_type_ != common::OB_INVALID_ID) && (grantor_id_ != common::OB_INVALID_ID) &&
           (grantee_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(obj_id), K_(obj_type), K_(col_id), K_(grantor_id), K_(grantee_id));
  uint64_t tenant_id_;
  uint64_t obj_id_;
  uint64_t obj_type_;
  uint64_t col_id_;
  uint64_t grantor_id_;
  uint64_t grantee_id_;
};

typedef common::ObSEArray<share::schema::ObObjPrivSortKey, 4> ObObjPrivSortKeyArray;

class ObTablePriv : public ObSchema, public ObPriv {
  OB_UNIS_VERSION(1);

  public:
  // constructor and destructor
  ObTablePriv() : ObSchema(), ObPriv()
  {}
  explicit ObTablePriv(common::ObIAllocator* allocator) : ObSchema(allocator), ObPriv(allocator)
  {}
  ObTablePriv(const ObTablePriv& other) : ObSchema(), ObPriv()
  {
    *this = other;
  }
  virtual ~ObTablePriv()
  {}

  // operator=
  ObTablePriv& operator=(const ObTablePriv& other);

  // for sort
  ObTablePrivSortKey get_sort_key() const
  {
    return ObTablePrivSortKey(tenant_id_, user_id_, db_, table_);
  }
  static bool cmp(const ObTablePriv* lhs, const ObTablePriv* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_sort_key() < rhs->get_sort_key() : false;
  }
  static bool cmp_sort_key(const ObTablePriv* lhs, const ObTablePrivSortKey& sort_key)
  {
    return NULL != lhs ? lhs->get_sort_key() < sort_key : false;
  }
  static bool equal(const ObTablePriv* lhs, const ObTablePriv* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_sort_key() == rhs->get_sort_key() : false;
  }
  static bool equal_sort_key(const ObTablePriv* lhs, const ObTablePrivSortKey& sort_key)
  {
    return NULL != lhs ? lhs->get_sort_key() == sort_key : false;
  }

  ObTablePrivDBKey get_db_key() const
  {
    return ObTablePrivDBKey(tenant_id_, user_id_, db_);
  }
  static bool cmp_db_key(const ObTablePriv* lhs, const ObTablePrivDBKey& db_key)
  {
    return lhs->get_db_key() < db_key;
  }

  // set methods
  inline int set_database_name(const char* db)
  {
    return deep_copy_str(db, db_);
  }
  inline int set_database_name(const common::ObString& db)
  {
    return deep_copy_str(db, db_);
  }
  inline int set_table_name(const char* table)
  {
    return deep_copy_str(table, table_);
  }
  inline int set_table_name(const common::ObString& table)
  {
    return deep_copy_str(table, table_);
  }

  // get methods
  inline const char* get_database_name() const
  {
    return extract_str(db_);
  }
  inline const common::ObString& get_database_name_str() const
  {
    return db_;
  }
  inline const char* get_table_name() const
  {
    return extract_str(table_);
  }
  inline const common::ObString& get_table_name_str() const
  {
    return table_;
  }

  TO_STRING_KV(K_(tenant_id), K_(user_id), K_(db), K_(table), "privileges", ObPrintPrivSet(priv_set_));
  // other methods
  virtual bool is_valid() const;
  virtual void reset();
  int64_t get_convert_size() const;

  private:
  common::ObString db_;
  common::ObString table_;
};

class ObObjPriv : public ObSchema, public ObPriv {
  OB_UNIS_VERSION(1);

  public:
  // constructor and destructor
  ObObjPriv() : ObSchema(), ObPriv()
  {}
  explicit ObObjPriv(common::ObIAllocator* allocator) : ObSchema(allocator), ObPriv()
  {}
  ObObjPriv(const ObObjPriv& other) : ObSchema(), ObPriv()
  {
    *this = other;
  }
  virtual ~ObObjPriv()
  {}

  // operator=
  ObObjPriv& operator=(const ObObjPriv& other);

  // for sort
  ObObjPrivSortKey get_sort_key() const
  {
    return ObObjPrivSortKey(tenant_id_, obj_id_, obj_type_, col_id_, grantor_id_, grantee_id_);
  }

  ObTenantUrObjId get_tenant_ur_obj_id() const
  {
    return ObTenantUrObjId(tenant_id_, grantee_id_, obj_id_, obj_type_, col_id_);
  }

  static bool cmp_tenant_ur_obj_id(const ObObjPriv* lhs, const ObTenantUrObjId& rhs)
  {
    return (lhs->get_tenant_ur_obj_id() < rhs);
  }
  static bool cmp(const ObObjPriv* lhs, const ObObjPriv* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_sort_key() < rhs->get_sort_key() : false;
  }
  static bool cmp_sort_key(const ObObjPriv* lhs, const ObObjPrivSortKey& sort_key)
  {
    return NULL != lhs ? lhs->get_sort_key() < sort_key : false;
  }
  static bool equal(const ObObjPriv* lhs, const ObObjPriv* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_sort_key() == rhs->get_sort_key() : false;
  }
  static bool equal_sort_key(const ObObjPriv* lhs, const ObObjPrivSortKey& sort_key)
  {
    return NULL != lhs ? lhs->get_sort_key() == sort_key : false;
  }

  // ObTablePrivDBKey get_db_key() const
  // { return ObTablePrivDBKey(tenant_id_, user_id_, db_); }
  // static bool cmp_db_key(const ObTablePriv *lhs, const ObTablePrivDBKey &db_key)
  // { return lhs->get_db_key() < db_key; }

  // set methods
  inline void set_obj_id(const uint64_t obj_id)
  {
    obj_id_ = obj_id;
  }
  inline void set_col_id(const uint64_t col_id)
  {
    col_id_ = col_id;
  }
  inline void set_grantor_id(const uint64_t grantor_id)
  {
    grantor_id_ = grantor_id;
  }
  inline void set_grantee_id(const uint64_t grantee_id)
  {
    grantee_id_ = grantee_id;
  }
  inline void set_objtype(const uint64_t objtype)
  {
    obj_type_ = objtype;
  }
  // get methods
  inline uint64_t get_objtype() const
  {
    return obj_type_;
  }
  inline uint64_t get_obj_id() const
  {
    return obj_id_;
  }
  inline uint64_t get_col_id() const
  {
    return col_id_;
  }
  inline uint64_t get_grantee_id() const
  {
    return grantee_id_;
  }
  inline uint64_t get_grantor_id() const
  {
    return grantor_id_;
  }

  TO_STRING_KV(K_(tenant_id), K_(user_id), K_(obj_id), K_(obj_type), K_(col_id), "privileges",
      ObPrintPrivSet(priv_set_), K_(grantor_id), K_(grantee_id));
  // other methods
  virtual bool is_valid() const;
  virtual void reset();
  int64_t get_convert_size() const;

  private:
  uint64_t obj_id_;
  uint64_t obj_type_;
  uint64_t col_id_;
  uint64_t grantor_id_;
  uint64_t grantee_id_;
};

enum ObPrivLevel {
  OB_PRIV_INVALID_LEVEL,
  OB_PRIV_USER_LEVEL,
  OB_PRIV_DB_LEVEL,
  OB_PRIV_TABLE_LEVEL,
  OB_PRIV_DB_ACCESS_LEVEL,
  OB_PRIV_SYS_ORACLE_LEVEL, /* oracle-mode system privilege */
  OB_PRIV_OBJ_ORACLE_LEVEL, /* oracle-mode object privilege */
  OB_PRIV_MAX_LEVEL,
};

const char* ob_priv_level_str(const ObPrivLevel grant_level);

struct ObNeedPriv {
  ObNeedPriv(const common::ObString& db, const common::ObString& table, ObPrivLevel priv_level, ObPrivSet priv_set,
      const bool is_sys_table)
      : db_(db), table_(table), priv_level_(priv_level), priv_set_(priv_set), is_sys_table_(is_sys_table)
  {}
  ObNeedPriv() : db_(), table_(), priv_level_(OB_PRIV_INVALID_LEVEL), priv_set_(0), is_sys_table_(false)
  {}
  int deep_copy(const ObNeedPriv& other, common::ObIAllocator& allocator);
  common::ObString db_;
  common::ObString table_;
  ObPrivLevel priv_level_;
  ObPrivSet priv_set_;
  bool is_sys_table_;  // May be used to represent the table of schema metadata
  TO_STRING_KV(K_(db), K_(table), K_(priv_set), K_(priv_level), K_(is_sys_table));
};

struct ObStmtNeedPrivs {
  typedef common::ObFixedArray<ObNeedPriv, common::ObIAllocator> NeedPrivs;
  explicit ObStmtNeedPrivs(common::ObIAllocator& alloc) : need_privs_(alloc)
  {}
  ObStmtNeedPrivs() : need_privs_()
  {}
  ~ObStmtNeedPrivs()
  {
    reset();
  }
  void reset()
  {
    need_privs_.reset();
  }
  int deep_copy(const ObStmtNeedPrivs& other, common::ObIAllocator& allocator);
  NeedPrivs need_privs_;
  TO_STRING_KV(K_(need_privs));
};

#define CHECK_FLAG_NORMAL 0X0
#define CHECK_FLAG_DIRECT 0X1
#define CHECK_FLAG_WITH_GRANT_OPTION 0x2
/* flag Can proceed or */

// Define the permissions required in oracle mode.
// Record a set of system permissions, or an object permission
struct ObOraNeedPriv {
  ObOraNeedPriv()
      : db_name_(),
        grantee_id_(common::OB_INVALID_ID),
        obj_id_(common::OB_INVALID_ID),
        col_id_(common::OB_INVALID_ID),
        obj_type_(common::OB_INVALID_ID),
        check_flag_(false),
        obj_privs_(0),
        owner_id_(common::OB_INVALID_ID)
  {}
  ObOraNeedPriv(const common::ObString& db_name, uint64_t grantee_id, uint64_t obj_id, uint64_t col_id,
      uint64_t obj_type, uint32_t check_flag, ObPackedObjPriv obj_privs, uint64_t owner_id)
      : db_name_(db_name),
        grantee_id_(grantee_id),
        obj_id_(obj_id),
        col_id_(col_id),
        obj_type_(obj_type),
        check_flag_(check_flag),
        obj_privs_(obj_privs),
        owner_id_(owner_id)
  {}
  ~ObOraNeedPriv()
  {}
  int deep_copy(const ObOraNeedPriv& other, common::ObIAllocator& allocator);
  bool same_obj(const ObOraNeedPriv& other);
  // ObOraNeedPriv& operator=(const ObOraNeedPriv &other);
  common::ObString db_name_;
  uint64_t grantee_id_;
  uint64_t obj_id_;
  uint64_t col_id_;
  uint64_t obj_type_;
  uint64_t check_flag_;
  ObPackedObjPriv obj_privs_;
  uint64_t owner_id_;
  TO_STRING_KV(
      K_(db_name), K_(grantee_id), K_(obj_id), K_(col_id), K_(obj_type), K_(check_flag), K_(obj_privs), K_(owner_id));
};

// Define the permissions required for a statement in oracle mode. Use an array to record,
// the system permissions and multiple object permissions are recorded in the array
struct ObStmtOraNeedPrivs {
  typedef common::ObFixedArray<ObOraNeedPriv, common::ObIAllocator> OraNeedPrivs;
  explicit ObStmtOraNeedPrivs(common::ObIAllocator& alloc) : need_privs_(alloc)
  {}
  ObStmtOraNeedPrivs() : need_privs_()
  {}
  ~ObStmtOraNeedPrivs()
  {
    reset();
  }
  void reset()
  {
    need_privs_.reset();
  }
  int deep_copy(const ObStmtOraNeedPrivs& other, common::ObIAllocator& allocator);
  OraNeedPrivs need_privs_;
  TO_STRING_KV(K_(need_privs));
};

struct ObSessionPrivInfo {
  ObSessionPrivInfo()
      : tenant_id_(common::OB_INVALID_ID),
        user_id_(common::OB_INVALID_ID),
        user_name_(),
        host_name_(),
        db_(),
        user_priv_set_(0),
        db_priv_set_(0),
        effective_tenant_id_(common::OB_INVALID_ID),
        enable_role_id_array_()
  {}
  ObSessionPrivInfo(const uint64_t tenant_id, const uint64_t effective_tenant_id, const uint64_t user_id,
      const common::ObString& db, const ObPrivSet user_priv_set, const ObPrivSet db_priv_set)
      : tenant_id_(tenant_id),
        user_id_(user_id),
        user_name_(),
        host_name_(),
        db_(db),
        user_priv_set_(user_priv_set),
        db_priv_set_(db_priv_set),
        effective_tenant_id_(effective_tenant_id),
        enable_role_id_array_()
  {}

  virtual ~ObSessionPrivInfo()
  {}

  void reset()
  {
    tenant_id_ = common::OB_INVALID_ID;
    effective_tenant_id_ = common::OB_INVALID_ID;
    user_id_ = common::OB_INVALID_ID;
    user_name_.reset();
    host_name_.reset();
    db_.reset();
    user_priv_set_ = 0;
    db_priv_set_ = 0;
    enable_role_id_array_.reset();
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (user_id_ != common::OB_INVALID_ID);
  }
  bool is_tenant_changed() const
  {
    return common::OB_INVALID_ID != effective_tenant_id_ && tenant_id_ != effective_tenant_id_;
  }
  void set_effective_tenant_id(uint64_t effective_tenant_id)
  {
    effective_tenant_id_ = effective_tenant_id;
  }
  uint64_t get_effective_tenant_id()
  {
    return effective_tenant_id_;
  }
  virtual TO_STRING_KV(K_(tenant_id), K_(effective_tenant_id), K_(user_id), K_(user_name), K_(host_name), K_(db),
      K_(user_priv_set), K_(db_priv_set));

  uint64_t tenant_id_;  // for privilege.Current login tenant. if normal tenant access
                        // sys tenant's object should use other method for priv checking.
  uint64_t user_id_;
  common::ObString user_name_;
  common::ObString host_name_;
  common::ObString db_;  // db name in current session
  ObPrivSet user_priv_set_;
  ObPrivSet db_priv_set_;  // user's db_priv_set of db
  // Only used for privilege check to determine whether there are currently tenants, otherwise the value is illegal
  uint64_t effective_tenant_id_;
  common::ObSEArray<uint64_t, 8> enable_role_id_array_;
};

struct ObUserLoginInfo {
  ObUserLoginInfo()
  {}
  ObUserLoginInfo(const common::ObString& tenant_name, const common::ObString& user_name,
      const common::ObString& client_ip, const common::ObString& passwd, const common::ObString& db)
      : tenant_name_(tenant_name),
        user_name_(user_name),
        client_ip_(client_ip),
        passwd_(passwd),
        db_(db),
        scramble_str_()
  {}

  ObUserLoginInfo(const common::ObString& tenant_name, const common::ObString& user_name,
      const common::ObString& client_ip, const common::ObString& passwd, const common::ObString& db,
      const common::ObString& scramble_str)
      : tenant_name_(tenant_name),
        user_name_(user_name),
        client_ip_(client_ip),
        passwd_(passwd),
        db_(db),
        scramble_str_(scramble_str)
  {}

  TO_STRING_KV(K_(tenant_name), K_(user_name), K_(client_ip), K_(db), K_(scramble_str));
  common::ObString tenant_name_;
  common::ObString user_name_;
  common::ObString client_ip_;  // client ip for current user
  common::ObString passwd_;
  common::ObString db_;
  common::ObString scramble_str_;
};

// oracle compatible: define u/r system permissions
class ObSysPriv : public ObSchema, public ObPriv {
  OB_UNIS_VERSION(1);

  public:
  ObSysPriv() : ObPriv(), grantee_id_(common::OB_INVALID_ID)
  {}
  explicit ObSysPriv(common::ObIAllocator* allocator) : ObSchema(allocator), ObPriv(allocator)
  {}
  virtual ~ObSysPriv()
  {}
  ObSysPriv(const ObSysPriv& other) : ObSchema(), ObPriv(), grantee_id_(common::OB_INVALID_ID)
  {
    *this = other;
  }
  ObSysPriv& operator=(const ObSysPriv& other);

  static bool cmp_tenant_grantee_id(const ObSysPriv* lhs, const ObTenantUserId& tenant_grantee_id)
  {
    return (lhs->get_tenant_grantee_id() < tenant_grantee_id);
  }
  static bool equal_tenant_grantee_id(const ObSysPriv* lhs, const ObTenantUserId& tenant_grantee_id)
  {
    return (lhs->get_tenant_grantee_id() == tenant_grantee_id);
  }
  static bool cmp_tenant_id(const ObPriv* lhs, const uint64_t tenant_id)
  {
    return (lhs->get_tenant_id() < tenant_id);
  }
  ObTenantUserId get_tenant_grantee_id() const
  {
    return ObTenantUserId(tenant_id_, grantee_id_);
  }
  void set_grantee_id(uint64_t grantee_id)
  {
    grantee_id_ = grantee_id;
  }
  uint64_t get_grantee_id() const
  {
    return grantee_id_;
  }
  void set_revoke()
  {
    user_id_ = 234;
  }
  bool is_revoke()
  {
    return user_id_ == 234;
  }

  static bool cmp(const ObSysPriv* lhs, const ObSysPriv* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? (lhs->get_key() < rhs->get_key()) : false;
  }
  static bool cmp_key(const ObSysPriv* lhs, const ObSysPrivKey& key)
  {
    return NULL != lhs ? lhs->get_key() < key : false;
  }
  ObSysPrivKey get_key() const
  {
    return ObSysPrivKey(tenant_id_, grantee_id_);
  }
  static bool equal(const ObSysPriv* lhs, const ObSysPriv* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_key() == rhs->get_key() : false;
  }  // point check
  // ObSysPrivKey get_original_key() const
  //{ return ObSysPrivKey(tenant_id_, user_id_); }

  // other methods
  virtual bool is_valid() const;
  virtual void reset();
  int64_t get_convert_size() const;
  TO_STRING_KV(K_(tenant_id), K_(user_id), K_(grantee_id), "privileges", ObPrintPrivSet(priv_set_), "packedprivarray",
      ObPrintPackedPrivArray(priv_array_));

  private:
  uint64_t grantee_id_;
};

int get_int_value(const common::ObString& str, int64_t& value);

class ObHostnameStuct {
  public:
  ObHostnameStuct()
  {}
  ~ObHostnameStuct()
  {}
  static const uint32_t FAKE_PORT = 0;
  static const int MAX_IP_BITS = 128;
  static int get_int_value(const common::ObString& str, int64_t& value);
  static bool calc_ip(const common::ObString& host_ip, common::ObAddr& addr);
  static bool calc_ip_mask(const common::ObString& host_ip_mask, common::ObAddr& mask);
  static bool is_ip_match(const common::ObString& client_ip, common::ObString host_name);
  static bool is_wild_match(const common::ObString& client_ip, const common::ObString& host_name);
  static bool is_in_white_list(const common::ObString& client_ip, common::ObString& ip_white_list);
};

enum ObHintFormat {
  HINT_NORMAL,
  HINT_LOCAL,
};

class ObFixedParam {
  public:
  ObFixedParam() : offset_(common::OB_INVALID_INDEX), value_()
  {}
  virtual ~ObFixedParam()
  {}
  bool has_equal_value(const common::ObObj& other_value) const;
  bool is_equal(const ObFixedParam& other_param) const;
  VIRTUAL_TO_STRING_KV(K(offset_), K(value_));
  int64_t offset_;
  common::ObObj value_;
};

class ObMaxConcurrentParam {
  OB_UNIS_VERSION(1);

  public:
  static const int64_t UNLIMITED = -1;
  typedef common::ObArray<ObFixedParam, common::ObWrapperAllocator> FixParamStore;
  explicit ObMaxConcurrentParam(common::ObIAllocator* allocator, const common::ObMemAttr& attr = common::ObMemAttr());
  virtual ~ObMaxConcurrentParam();
  int destroy();
  int64_t get_convert_size() const;
  int assign(const ObMaxConcurrentParam& max_concurrent_param);
  int64_t get_concurrent_num() const
  {
    return concurrent_num_;
  }
  int match_fixed_param(const ParamStore& const_param_store, bool& is_match) const;
  bool is_concurrent_limit_param() const
  {
    return concurrent_num_ != UNLIMITED;
  }
  bool is_outline_content_param() const
  {
    return !outline_content_.empty();
  }
  int get_fixed_param_with_offset(int64_t offset, ObFixedParam& fixed_param, bool& is_found) const;
  int same_param_as(const ObMaxConcurrentParam& other, bool& is_same) const;
  void set_mem_attr(const common::ObMemAttr& attr)
  {
    mem_attr_ = attr;
  }
  VIRTUAL_TO_STRING_KV(K_(concurrent_num), K_(outline_content), K_(fixed_param_store));

  private:
  int deep_copy_outline_content(const common::ObString& src);
  int deep_copy_param_value(const common::ObObj& src, common::ObObj& dest);

  public:
  common::ObIAllocator* allocator_;
  int64_t concurrent_num_;
  common::ObString outline_content_;
  common::ObMemAttr mem_attr_;
  FixParamStore fixed_param_store_;

  private:
  DISALLOW_COPY_AND_ASSIGN(ObMaxConcurrentParam);
};

// used for outline manager
class ObOutlineParamsWrapper {
  typedef common::ObArray<ObMaxConcurrentParam*, common::ObWrapperAllocator> OutlineParamsArray;
  OB_UNIS_VERSION(1);

  public:
  ObOutlineParamsWrapper();
  explicit ObOutlineParamsWrapper(common::ObIAllocator* allocator);
  ~ObOutlineParamsWrapper();
  int destroy();
  int assign(const ObOutlineParamsWrapper& src);
  int set_allocator(common::ObIAllocator* allocator, const common::ObMemAttr& attr = common::ObMemAttr());
  OutlineParamsArray& get_outline_params()
  {
    return outline_params_;
  }
  const OutlineParamsArray& get_outline_params() const
  {
    return outline_params_;
  }
  ObMaxConcurrentParam* get_outline_param(int64_t index) const;
  int64_t get_convert_size() const;
  bool is_empty() const
  {
    return 0 == outline_params_.count();
  }
  int add_param(const ObMaxConcurrentParam& param);
  int has_param(const ObMaxConcurrentParam& param, bool& has_param) const;
  int has_concurrent_limit_param(bool& has) const;
  int64_t get_param_count() const
  {
    return outline_params_.count();
  }
  void reset_allocator()
  {
    allocator_ = NULL;
    mem_attr_ = common::ObMemAttr();
  }
  void set_mem_attr(const common::ObMemAttr& attr)
  {
    mem_attr_ = attr;
  };
  TO_STRING_KV(K_(outline_params));

  private:
  common::ObIAllocator* allocator_;
  OutlineParamsArray outline_params_;
  common::ObMemAttr mem_attr_;

  private:
  DISALLOW_COPY_AND_ASSIGN(ObOutlineParamsWrapper);
};

struct BaselineKey {
  OB_UNIS_VERSION(1);

  public:
  BaselineKey() : tenant_id_(common::OB_INVALID_ID), db_id_(common::OB_INVALID_ID)
  {}

  TO_STRING_KV(K_(tenant_id), K_(db_id), K_(constructed_sql), K_(params_info_str));

  inline uint64_t hash(uint64_t seed = 0) const
  {
    uint64_t hash_val = seed;
    hash_val = common::murmurhash(&tenant_id_, sizeof(tenant_id_), hash_val);
    hash_val = common::murmurhash(&db_id_, sizeof(db_id_), hash_val);
    hash_val = constructed_sql_.hash(hash_val);
    hash_val = params_info_str_.hash(hash_val);
    return hash_val;
  }

  inline bool operator==(const BaselineKey& other_key) const
  {
    return tenant_id_ == other_key.tenant_id_ && db_id_ == other_key.db_id_ &&
           constructed_sql_ == other_key.constructed_sql_ && params_info_str_ == other_key.params_info_str_;
  }

  void reset()
  {
    tenant_id_ = common::OB_INVALID_ID;
    db_id_ = common::OB_INVALID_ID;
    constructed_sql_.reset();
    params_info_str_.reset();
  }

  uint64_t tenant_id_;                // tenant id  -- ob sql layer obtain
  uint64_t db_id_;                    // database id -- ob sql layer obtain
  common::ObString constructed_sql_;  // Parameterized text string
  common::ObString params_info_str_;  // ObPlanSet obtain
};

class ObPlanBaselineInfo : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  ObPlanBaselineInfo();
  explicit ObPlanBaselineInfo(common::ObIAllocator* allocator);
  virtual ~ObPlanBaselineInfo();

  ObPlanBaselineInfo(const ObPlanBaselineInfo& src_schema);
  ObPlanBaselineInfo& operator=(const ObPlanBaselineInfo& src_schema);
  void reset();
  int64_t get_convert_size() const;
  static bool cmp(const ObPlanBaselineInfo* lhs, const ObPlanBaselineInfo* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_plan_baseline_id() < rhs->get_plan_baseline_id() : false;
  }
  static bool equal(const ObPlanBaselineInfo* lhs, const ObPlanBaselineInfo* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_plan_baseline_id() == rhs->get_plan_baseline_id() : false;
  }

  inline uint64_t get_tenant_id() const
  {
    return key_.tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return key_.db_id_;
  }
  inline uint64_t get_plan_baseline_id() const
  {
    return plan_baseline_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline uint64_t get_plan_hash_value() const
  {
    return plan_hash_value_;
  }
  inline bool get_fixed() const
  {
    return fixed_;
  }
  inline bool get_enabled() const
  {
    return enabled_;
  }
  inline bool get_executions() const
  {
    return executions_;
  }
  inline bool get_cpu_time() const
  {
    return cpu_time_;
  }
  inline bool get_hints_all_worked() const
  {
    return hints_all_worked_;
  }

  inline void set_tenant_id(const uint64_t id)
  {
    key_.tenant_id_ = id;
  }
  inline void set_database_id(const uint64_t id)
  {
    key_.db_id_ = id;
  }
  inline void set_plan_baseline_id(uint64_t id)
  {
    plan_baseline_id_ = id;
  }
  inline void set_schema_version(int64_t version)
  {
    schema_version_ = version;
  }
  inline void set_plan_hash_value(uint64_t v)
  {
    plan_hash_value_ = v;
  }
  inline void set_fixed(bool v)
  {
    fixed_ = v;
  }
  inline void set_enabled(bool v)
  {
    enabled_ = v;
  }
  inline void set_executions(bool v)
  {
    executions_ = v;
  }
  inline void set_cpu_time(bool v)
  {
    cpu_time_ = v;
  }
  inline void set_hints_all_worked(bool hints_all_worked)
  {
    hints_all_worked_ = hints_all_worked;
  }

  // int set_plan_hash_value(const common::number::ObNumber &num);

  int set_sql_id(const char* sql_id)
  {
    return deep_copy_str(sql_id, sql_id_);
  }
  int set_sql_id(const common::ObString& sql_id)
  {
    return deep_copy_str(sql_id, sql_id_);
  }

  inline const char* get_sql_id() const
  {
    return extract_str(sql_id_);
  }
  inline const common::ObString& get_sql_id_str() const
  {
    return sql_id_;
  }

  int set_hints_info(const char* hints_info)
  {
    return deep_copy_str(hints_info, hints_info_);
  }
  int set_hints_info(const common::ObString& hints_info)
  {
    return deep_copy_str(hints_info, hints_info_);
  }

  inline const char* get_hints_info() const
  {
    return extract_str(hints_info_);
  }
  inline const common::ObString& get_hints_info_str() const
  {
    return hints_info_;
  }

  int set_outline_data(const char* outline_data)
  {
    return deep_copy_str(outline_data, outline_data_);
  }
  int set_outline_data(const common::ObString& outline_data)
  {
    return deep_copy_str(outline_data, outline_data_);
  }

  inline const char* get_outline_data() const
  {
    return extract_str(outline_data_);
  }
  inline const common::ObString& get_outline_data_str() const
  {
    return outline_data_;
  }

  int set_sql_text(const char* constructed_sql)
  {
    return deep_copy_str(constructed_sql, key_.constructed_sql_);
  }
  int set_sql_text(const common::ObString& constructed_sql)
  {
    return deep_copy_str(constructed_sql, key_.constructed_sql_);
  }

  inline const char* get_sql_text() const
  {
    return extract_str(key_.constructed_sql_);
  }
  inline const common::ObString& get_sql_text_str() const
  {
    return key_.constructed_sql_;
  }

  int set_params_info(const char* params_info)
  {
    return deep_copy_str(params_info, key_.params_info_str_);
  }
  int set_params_info(const common::ObString& params_info)
  {
    return deep_copy_str(params_info, key_.params_info_str_);
  }

  inline const char* get_params_info() const
  {
    return extract_str(key_.params_info_str_);
  }
  inline const common::ObString& get_params_info_str() const
  {
    return key_.params_info_str_;
  }

  VIRTUAL_TO_STRING_KV(K_(key), K_(plan_baseline_id), K_(schema_version), K_(outline_data), K_(plan_hash_value),
      K_(fixed), K_(enabled), K_(executions), K_(cpu_time), K_(hints_info), K_(hints_all_worked));

  public:
  BaselineKey key_;
  uint64_t plan_baseline_id_;
  int64_t schema_version_;         // the last modify timestamp of this version
  common::ObString outline_data_;  // Hint collection of fixed plan
  common::ObString sql_id_;        // sql id //The last byte stores'\0'
  uint64_t plan_hash_value_;
  bool fixed_;
  bool enabled_;
  int64_t executions_;  // The total number of executions in the evolution process
  int64_t cpu_time_;    // The total CPU time consumed during the evolution process
  common::ObString hints_info_;
  bool hints_all_worked_;
};

class ObOutlineInfo : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  ObOutlineInfo();
  explicit ObOutlineInfo(common::ObIAllocator* allocator);
  virtual ~ObOutlineInfo();
  ObOutlineInfo(const ObOutlineInfo& src_schema);
  ObOutlineInfo& operator=(const ObOutlineInfo& src_schema);
  void reset();
  bool is_valid() const;
  bool is_valid_for_replace() const;
  int64_t get_convert_size() const;
  static bool cmp(const ObOutlineInfo* lhs, const ObOutlineInfo* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_outline_id() < rhs->get_outline_id() : false;
  }
  static bool equal(const ObOutlineInfo* lhs, const ObOutlineInfo* rhs)
  {
    return (NULL != lhs && NULL != rhs) ? lhs->get_outline_id() == rhs->get_outline_id() : false;
  }

  inline void set_tenant_id(const uint64_t id)
  {
    tenant_id_ = id;
  }
  inline void set_database_id(const uint64_t id)
  {
    database_id_ = id;
  }
  inline void set_outline_id(uint64_t id)
  {
    outline_id_ = id;
  }
  inline void set_schema_version(int64_t version)
  {
    schema_version_ = version;
  }
  int set_name(const char* name)
  {
    return deep_copy_str(name, name_);
  }
  int set_name(const common::ObString& name)
  {
    return deep_copy_str(name, name_);
  }
  int set_signature(const char* sig)
  {
    return deep_copy_str(sig, signature_);
  }
  int set_signature(const common::ObString& sig)
  {
    return deep_copy_str(sig, signature_);
  }
  int set_sql_id(const char* sql_id)
  {
    return deep_copy_str(sql_id, sql_id_);
  }
  int set_sql_id(const common::ObString& sql_id)
  {
    return deep_copy_str(sql_id, sql_id_);
  }
  int set_outline_params(const common::ObString& outline_params_str);
  int set_outline_content(const char* content)
  {
    return deep_copy_str(content, outline_content_);
  }
  int set_outline_content(const common::ObString& content)
  {
    return deep_copy_str(content, outline_content_);
  }
  int set_sql_text(const char* sql)
  {
    return deep_copy_str(sql, sql_text_);
  }
  int set_sql_text(const common::ObString& sql)
  {
    return deep_copy_str(sql, sql_text_);
  }
  int set_outline_target(const char* target)
  {
    return deep_copy_str(target, outline_target_);
  }
  int set_outline_target(const common::ObString& target)
  {
    return deep_copy_str(target, outline_target_);
  }
  int set_owner(const char* owner)
  {
    return deep_copy_str(owner, owner_);
  }
  int set_owner(const common::ObString& owner)
  {
    return deep_copy_str(owner, owner_);
  }
  void set_owner_id(const uint64_t owner_id)
  {
    owner_id_ = owner_id;
  }
  void set_used(const bool used)
  {
    used_ = used;
  }
  int set_version(const char* version)
  {
    return deep_copy_str(version, version_);
  }
  int set_version(const common::ObString& version)
  {
    return deep_copy_str(version, version_);
  }
  void set_compatible(const bool compatible)
  {
    compatible_ = compatible;
  }
  void set_enabled(const bool enabled)
  {
    enabled_ = enabled;
  }
  void set_format(const ObHintFormat hint_format)
  {
    format_ = hint_format;
  }

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_owner_id() const
  {
    return owner_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline uint64_t get_outline_id() const
  {
    return outline_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline bool is_used() const
  {
    return used_;
  }
  inline bool is_enabled() const
  {
    return enabled_;
  }
  inline bool is_compatible() const
  {
    return compatible_;
  }
  inline ObHintFormat get_hint_format() const
  {
    return format_;
  }
  inline const char* get_name() const
  {
    return extract_str(name_);
  }
  inline const common::ObString& get_name_str() const
  {
    return name_;
  }
  inline const char* get_signature() const
  {
    return extract_str(signature_);
  }
  inline const char* get_sql_id() const
  {
    return extract_str(sql_id_);
  }
  inline const common::ObString& get_sql_id_str() const
  {
    return sql_id_;
  }
  inline const common::ObString& get_signature_str() const
  {
    return signature_;
  }
  inline const char* get_outline_content() const
  {
    return extract_str(outline_content_);
  }
  inline const common::ObString& get_outline_content_str() const
  {
    return outline_content_;
  }
  inline const char* get_sql_text() const
  {
    return extract_str(sql_text_);
  }
  inline const common::ObString& get_sql_text_str() const
  {
    return sql_text_;
  }
  inline common::ObString& get_sql_text_str()
  {
    return sql_text_;
  }
  inline const char* get_outline_target() const
  {
    return extract_str(outline_target_);
  }
  inline const common::ObString& get_outline_target_str() const
  {
    return outline_target_;
  }
  inline common::ObString& get_outline_target_str()
  {
    return outline_target_;
  }
  inline const char* get_owner() const
  {
    return extract_str(owner_);
  }
  inline const common::ObString& get_owner_str() const
  {
    return owner_;
  }
  inline const char* get_version() const
  {
    return extract_str(version_);
  }
  inline const common::ObString& get_version_str() const
  {
    return version_;
  }
  int get_visible_signature(common::ObString& visiable_signature) const;
  int get_outline_sql(
      common::ObIAllocator& allocator, const sql::ObSQLSessionInfo& session, common::ObString& outline_sql) const;
  int get_hex_str_from_outline_params(common::ObString& hex_str, common::ObIAllocator& allocator) const;
  const ObOutlineParamsWrapper& get_outline_params_wrapper() const
  {
    return outline_params_wrapper_;
  }
  ObOutlineParamsWrapper& get_outline_params_wrapper()
  {
    return outline_params_wrapper_;
  }
  bool has_outline_params() const
  {
    return outline_params_wrapper_.get_outline_params().count() > 0;
  }
  int has_concurrent_limit_param(bool& has) const;
  int gen_valid_allocator();
  int add_param(const ObMaxConcurrentParam& src_param);
  static int gen_limit_sql(const common::ObString& visible_signature, const ObMaxConcurrentParam* param,
      const sql::ObSQLSessionInfo& session, common::ObIAllocator& allocator, common::ObString& limit_sql);
  VIRTUAL_TO_STRING_KV(K_(tenant_id), K_(database_id), K_(outline_id), K_(schema_version), K_(name), K_(signature),
      K_(sql_id), K_(outline_content), K_(sql_text), K_(owner_id), K_(owner), K_(used), K_(compatible), K_(enabled),
      K_(format), K_(outline_params_wrapper), K_(outline_target));
  static bool is_sql_id_valid(const common::ObString& sql_id);

  private:
  static int replace_question_mark(const common::ObString& not_param_sql, const ObMaxConcurrentParam& concurrent_param,
      int64_t start_pos, int64_t cur_pos, int64_t& question_mark_offset, common::ObSqlString& string_helper);
  static int replace_not_param(const common::ObString& not_param_sql, const ParseNode& node, int64_t start_pos,
      int64_t cur_pos, common::ObSqlString& string_helper);

  protected:
  uint64_t tenant_id_;
  uint64_t database_id_;
  uint64_t outline_id_;
  int64_t schema_version_;      // the last modify timestamp of this version
  common::ObString name_;       // outline name
  common::ObString signature_;  // SQL after constant parameterization
  common::ObString sql_id_;     // Used to directly determine sql_id
  common::ObString outline_content_;
  common::ObString sql_text_;
  common::ObString outline_target_;
  common::ObString owner_;
  bool used_;
  common::ObString version_;
  bool compatible_;
  bool enabled_;
  ObHintFormat format_;
  uint64_t owner_id_;
  ObOutlineParamsWrapper outline_params_wrapper_;
};

class ObDbLinkBaseInfo : public ObSchema {
  public:
  ObDbLinkBaseInfo() : ObSchema()
  {
    reset();
  }
  explicit ObDbLinkBaseInfo(common::ObIAllocator* allocator) : ObSchema(allocator)
  {
    reset();
  }
  virtual ~ObDbLinkBaseInfo()
  {}

  inline void set_tenant_id(const uint64_t id)
  {
    tenant_id_ = id;
  }
  inline void set_owner_id(const uint64_t id)
  {
    owner_id_ = id;
  }
  inline void set_dblink_id(const uint64_t id)
  {
    dblink_id_ = id;
  }
  inline void set_schema_version(const int64_t version)
  {
    schema_version_ = version;
  }
  inline int set_dblink_name(const common::ObString& name)
  {
    return deep_copy_str(name, dblink_name_);
  }
  inline int set_cluster_name(const common::ObString& name)
  {
    return deep_copy_str(name, cluster_name_);
  }
  inline int set_tenant_name(const common::ObString& name)
  {
    return deep_copy_str(name, tenant_name_);
  }
  inline int set_user_name(const common::ObString& name)
  {
    return deep_copy_str(name, user_name_);
  }
  inline int set_password(const common::ObString& password)
  {
    return deep_copy_str(password, password_);
  }
  inline void set_host_addr(const common::ObAddr& addr)
  {
    host_addr_ = addr;
  }
  inline int set_host_ip(const common::ObString& host_ip)
  {
    host_addr_.set_ip_addr(host_ip, 0);
    return common::OB_SUCCESS;
  }
  inline void set_host_port(const int32_t host_port)
  {
    host_addr_.set_port(host_port);
  }

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_owner_id() const
  {
    return owner_id_;
  }
  inline uint64_t get_dblink_id() const
  {
    return dblink_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline const common::ObString& get_dblink_name() const
  {
    return dblink_name_;
  }
  inline const common::ObString& get_cluster_name() const
  {
    return cluster_name_;
  }
  inline const common::ObString& get_tenant_name() const
  {
    return tenant_name_;
  }
  inline const common::ObString& get_user_name() const
  {
    return user_name_;
  }
  inline const common::ObString& get_password() const
  {
    return password_;
  }
  inline const common::ObAddr& get_host_addr() const
  {
    return host_addr_;
  }
  inline uint32_t get_host_ip() const
  {
    return host_addr_.get_ipv4();
  }
  inline int32_t get_host_port() const
  {
    return host_addr_.get_port();
  }

  void reset();
  virtual bool is_valid() const;
  VIRTUAL_TO_STRING_KV(K_(tenant_id), K_(owner_id), K_(dblink_id), K_(dblink_name), K_(cluster_name), K_(tenant_name),
      K_(user_name), K_(host_addr));

  protected:
  uint64_t tenant_id_;
  uint64_t owner_id_;
  uint64_t dblink_id_;
  int64_t schema_version_;
  common::ObString dblink_name_;
  common::ObString cluster_name_;
  common::ObString tenant_name_;
  common::ObString user_name_;
  common::ObString password_;  // only encrypt when write to sys table.
  common::ObAddr host_addr_;
};

struct ObTenantDbLinkId {
  public:
  ObTenantDbLinkId() : tenant_id_(common::OB_INVALID_ID), dblink_id_(common::OB_INVALID_ID)
  {}
  ObTenantDbLinkId(uint64_t tenant_id, uint64_t dblink_id) : tenant_id_(tenant_id), dblink_id_(dblink_id)
  {}
  ObTenantDbLinkId(const ObTenantDbLinkId& other) : tenant_id_(other.tenant_id_), dblink_id_(other.dblink_id_)
  {}
  ObTenantDbLinkId& operator=(const ObTenantDbLinkId& other)
  {
    tenant_id_ = other.tenant_id_;
    dblink_id_ = other.dblink_id_;
    return *this;
  }
  bool operator==(const ObTenantDbLinkId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (dblink_id_ == rhs.dblink_id_);
  }
  bool operator!=(const ObTenantDbLinkId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantDbLinkId& rhs) const
  {
    return (tenant_id_ < rhs.tenant_id_) || (tenant_id_ == rhs.tenant_id_ && dblink_id_ < rhs.dblink_id_);
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), hash_ret);
    hash_ret = common::murmurhash(&dblink_id_, sizeof(dblink_id_), hash_ret);
    return hash_ret;
  }
  inline bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (dblink_id_ != common::OB_INVALID_ID);
  }
  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_dblink_id() const
  {
    return dblink_id_;
  }
  TO_STRING_KV(K_(tenant_id), K_(dblink_id));

  private:
  uint64_t tenant_id_;
  uint64_t dblink_id_;
};

class ObDbLinkInfo : public ObDbLinkBaseInfo {
  OB_UNIS_VERSION(1);

  public:
  ObDbLinkInfo() : ObDbLinkBaseInfo()
  {}
  explicit ObDbLinkInfo(common::ObIAllocator* allocator) : ObDbLinkBaseInfo(allocator)
  {}
  virtual ~ObDbLinkInfo()
  {}
};

class ObDbLinkSchema : public ObDbLinkBaseInfo {
  public:
  ObDbLinkSchema() : ObDbLinkBaseInfo()
  {}
  explicit ObDbLinkSchema(common::ObIAllocator* allocator) : ObDbLinkBaseInfo(allocator)
  {}
  ObDbLinkSchema(const ObDbLinkSchema& src_schema);
  virtual ~ObDbLinkSchema()
  {}
  ObDbLinkSchema& operator=(const ObDbLinkSchema& other);
  bool operator==(const ObDbLinkSchema& other) const;

  inline ObTenantDbLinkId get_tenant_dblink_id() const
  {
    return ObTenantDbLinkId(tenant_id_, dblink_id_);
  }
  inline int64_t get_convert_size() const
  {
    return sizeof(ObDbLinkSchema) + dblink_name_.length() + 1 + cluster_name_.length() + 1 + tenant_name_.length() + 1 +
           user_name_.length() + 1 + password_.length() + 1;
  }
};

class ObSynonymInfo : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  ObSynonymInfo();
  explicit ObSynonymInfo(common::ObIAllocator* allocator);
  VIRTUAL_TO_STRING_KV(K_(tenant_id), K_(database_id), K_(synonym_id), K_(schema_version));
  virtual ~ObSynonymInfo();
  ObSynonymInfo& operator=(const ObSynonymInfo& src_schema);
  ObSynonymInfo(const ObSynonymInfo& src_schema);
  inline void set_tenant_id(const uint64_t id)
  {
    tenant_id_ = id;
  }
  inline void set_database_id(const uint64_t id)
  {
    database_id_ = id;
  }
  inline void set_object_database_id(const uint64_t id)
  {
    object_db_id_ = id;
  }
  inline void set_synonym_id(uint64_t id)
  {
    synonym_id_ = id;
  }
  inline void set_schema_version(int64_t version)
  {
    schema_version_ = version;
  }
  int64_t get_convert_size() const;
  int set_synonym_name(const char* name)
  {
    return deep_copy_str(name, name_);
  }
  int set_synonym_name(const common::ObString& name)
  {
    return deep_copy_str(name, name_);
  }
  int set_object_name(const char* name)
  {
    return deep_copy_str(name, object_name_);
  }
  int set_object_name(const common::ObString& name)
  {
    return deep_copy_str(name, object_name_);
  }
  int set_version(const char* version)
  {
    return deep_copy_str(version, version_);
  }
  int set_version(const common::ObString& version)
  {
    return deep_copy_str(version, version_);
  }
  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline uint64_t get_synonym_id() const
  {
    return synonym_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline const char* get_synonym_name() const
  {
    return extract_str(name_);
  }
  inline const common::ObString& get_synonym_name_str() const
  {
    return name_;
  }
  inline const char* get_object_name() const
  {
    return extract_str(object_name_);
  }
  inline const common::ObString& get_object_name_str() const
  {
    return object_name_;
  }
  inline const char* get_version() const
  {
    return extract_str(version_);
  }
  inline const common::ObString& get_version_str() const
  {
    return version_;
  }
  inline uint64_t get_object_database_id() const
  {
    return object_db_id_;
  }
  void reset();

  private:
  // void *alloc(int64_t size);
  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  uint64_t synonym_id_;
  int64_t schema_version_;  // the last modify timestamp of this version
  common::ObString name_;   // synonym name
  common::ObString version_;
  common::ObString object_name_;
  uint64_t object_db_id_;
  // common::ObArenaAllocator allocator_;
};

struct ObTenantUDFId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantUDFId() : tenant_id_(common::OB_INVALID_ID), udf_name_()
  {}
  ObTenantUDFId(const uint64_t tenant_id, const common::ObString& name) : tenant_id_(tenant_id), udf_name_(name)
  {}
  bool operator==(const ObTenantUDFId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (udf_name_ == rhs.udf_name_);
  }
  bool operator!=(const ObTenantUDFId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantUDFId& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (tenant_id_ == rhs.tenant_id_) {
      bret = udf_name_ < rhs.udf_name_;
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(udf_name_.ptr(), udf_name_.length(), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (udf_name_.length() != 0);
  }
  TO_STRING_KV(K_(tenant_id), K_(udf_name));
  uint64_t tenant_id_;
  common::ObString udf_name_;
};

struct ObTenantSynonymId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantSynonymId() : tenant_id_(common::OB_INVALID_ID), synonym_id_(common::OB_INVALID_ID)
  {}
  ObTenantSynonymId(const uint64_t tenant_id, const uint64_t synonym_id)
      : tenant_id_(tenant_id), synonym_id_(synonym_id)
  {}
  bool operator==(const ObTenantSynonymId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (synonym_id_ == rhs.synonym_id_);
  }
  bool operator!=(const ObTenantSynonymId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantSynonymId& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (tenant_id_ == rhs.tenant_id_) {
      bret = synonym_id_ < rhs.synonym_id_;
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&synonym_id_, sizeof(synonym_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (synonym_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(synonym_id));
  uint64_t tenant_id_;
  uint64_t synonym_id_;
};

struct ObTenantSequenceId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantSequenceId() : tenant_id_(common::OB_INVALID_ID), sequence_id_(common::OB_INVALID_ID)
  {}
  ObTenantSequenceId(const uint64_t tenant_id, const uint64_t sequence_id)
      : tenant_id_(tenant_id), sequence_id_(sequence_id)
  {}
  bool operator==(const ObTenantSequenceId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (sequence_id_ == rhs.sequence_id_);
  }
  bool operator!=(const ObTenantSequenceId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantSequenceId& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (tenant_id_ == rhs.tenant_id_) {
      bret = sequence_id_ < rhs.sequence_id_;
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&sequence_id_, sizeof(sequence_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_ID) && (sequence_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(sequence_id));
  uint64_t tenant_id_;
  uint64_t sequence_id_;
};

class ObAlterOutlineInfo : public ObOutlineInfo {
  OB_UNIS_VERSION(1);

  public:
  ObAlterOutlineInfo() : ObOutlineInfo(), alter_option_bitset_()
  {}
  virtual ~ObAlterOutlineInfo()
  {}
  void reset()
  {
    ObOutlineInfo::reset();
    alter_option_bitset_.reset();
  }
  const common::ObBitSet<>& get_alter_option_bitset() const
  {
    return alter_option_bitset_;
  }
  common::ObBitSet<>& get_alter_option_bitset()
  {
    return alter_option_bitset_;
  }
  INHERIT_TO_STRING_KV("ObOutlineInfo", ObOutlineInfo, K_(alter_option_bitset));

  private:
  common::ObBitSet<> alter_option_bitset_;
};

class ObOutlineNameHashWrapper {
  public:
  ObOutlineNameHashWrapper() : tenant_id_(common::OB_INVALID_ID), database_id_(common::OB_INVALID_ID), name_()
  {}
  ObOutlineNameHashWrapper(const uint64_t tenant_id, const uint64_t database_id, const common::ObString& name_)
      : tenant_id_(tenant_id), database_id_(database_id), name_(name_)
  {}
  ~ObOutlineNameHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObOutlineNameHashWrapper& rv) const;
  inline void set_tenant_id(uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  inline void set_database_id(uint64_t database_id)
  {
    database_id_ = database_id;
  }
  inline void set_name(const common::ObString& name)
  {
    name_ = name;
  }

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline const common::ObString& get_name() const
  {
    return name_;
  }

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  common::ObString name_;
};

inline uint64_t ObOutlineNameHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
  hash_ret = common::murmurhash(name_.ptr(), name_.length(), hash_ret);
  return hash_ret;
}

inline bool ObOutlineNameHashWrapper::operator==(const ObOutlineNameHashWrapper& rv) const
{
  return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_) && (name_ == rv.name_);
}

class ObOutlineSignatureHashWrapper {
  public:
  ObOutlineSignatureHashWrapper() : tenant_id_(common::OB_INVALID_ID), database_id_(common::OB_INVALID_ID), signature_()
  {}
  ObOutlineSignatureHashWrapper(const uint64_t tenant_id, const uint64_t database_id, const common::ObString& signature)
      : tenant_id_(tenant_id), database_id_(database_id), signature_(signature)
  {}
  ~ObOutlineSignatureHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObOutlineSignatureHashWrapper& rv) const;
  inline void set_tenant_id(uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  inline void set_database_id(uint64_t database_id)
  {
    database_id_ = database_id;
  }
  inline void set_signature(const common::ObString& signature)
  {
    signature_ = signature;
  }

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline const common::ObString& get_signature() const
  {
    return signature_;
  }

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  common::ObString signature_;
};

class ObOutlineSqlIdHashWrapper {
  public:
  ObOutlineSqlIdHashWrapper() : tenant_id_(common::OB_INVALID_ID), database_id_(common::OB_INVALID_ID), sql_id_()
  {}
  ObOutlineSqlIdHashWrapper(const uint64_t tenant_id, const uint64_t database_id, const common::ObString& sql_id)
      : tenant_id_(tenant_id), database_id_(database_id), sql_id_(sql_id)
  {}
  ~ObOutlineSqlIdHashWrapper()
  {}
  inline uint64_t hash() const;
  inline bool operator==(const ObOutlineSqlIdHashWrapper& rv) const;
  inline void set_tenant_id(uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  inline void set_database_id(uint64_t database_id)
  {
    database_id_ = database_id;
  }
  inline void set_sql_id(const common::ObString& sql_id)
  {
    sql_id_ = sql_id;
  }

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline const common::ObString& get_sql_id() const
  {
    return sql_id_;
  }

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  common::ObString sql_id_;
};

inline uint64_t ObOutlineSqlIdHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
  hash_ret = common::murmurhash(sql_id_.ptr(), sql_id_.length(), hash_ret);
  return hash_ret;
}

inline bool ObOutlineSqlIdHashWrapper::operator==(const ObOutlineSqlIdHashWrapper& rv) const
{
  return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_) && (sql_id_ == rv.sql_id_);
}

inline uint64_t ObOutlineSignatureHashWrapper::hash() const
{
  uint64_t hash_ret = 0;
  hash_ret = common::murmurhash(&tenant_id_, sizeof(uint64_t), 0);
  hash_ret = common::murmurhash(&database_id_, sizeof(uint64_t), hash_ret);
  hash_ret = common::murmurhash(signature_.ptr(), signature_.length(), hash_ret);
  return hash_ret;
}

inline bool ObOutlineSignatureHashWrapper::operator==(const ObOutlineSignatureHashWrapper& rv) const
{
  return (tenant_id_ == rv.tenant_id_) && (database_id_ == rv.database_id_) && (signature_ == rv.signature_);
}

class ObSysTableChecker {
  private:
  ObSysTableChecker();
  ~ObSysTableChecker();

  int init_tenant_space_table_id_map();
  int init_sys_table_name_map();
  int check_tenant_space_table_id(const uint64_t table_id, bool& is_tenant_space_table);
  int check_sys_table_name(const uint64_t database_id, const common::ObString& table_name, bool& is_tenant_space_table);
  int ob_write_string(const common::ObString& src, common::ObString& dst);

  public:
  static ObSysTableChecker& instance();
  int init();
  int destroy();

  int64_t get_tenant_space_sys_table_num()
  {
    return tenant_space_sys_table_num_;
  }

  static int is_tenant_space_table_id(const uint64_t table_id, bool& is_tenant_space_table);
  static int is_sys_table_name(
      const uint64_t database_id, const common::ObString& table_name, bool& is_tenant_space_table);
  static bool is_tenant_table_in_version_2200(const uint64_t table_id);
  static bool is_cluster_private_tenant_table(const uint64_t table_id);
  static bool is_backup_private_tenant_table(const uint64_t table_id);
  static int is_tenant_table_need_weak_read(const uint64_t table_id, bool& need_weak_read);
  static bool is_rs_restart_related_table_id(const uint64_t table_id);
  static bool is_rs_restart_related_partition(const uint64_t table_id, const int64_t partition_id);

  public:
  class TableNameWrapper {
    public:
    TableNameWrapper()
        : database_id_(common::OB_INVALID_ID), name_case_mode_(common::OB_NAME_CASE_INVALID), table_name_()
    {}
    TableNameWrapper(const uint64_t database_id, const common::ObNameCaseMode mode, const common::ObString& table_name)
        : database_id_(database_id), name_case_mode_(mode), table_name_(table_name)
    {}
    ~TableNameWrapper()
    {}
    inline uint64_t hash() const;
    bool operator==(const TableNameWrapper& rv) const;
    TO_STRING_KV(K_(database_id), K_(name_case_mode), K_(table_name));

    private:
    uint64_t database_id_;  // pure_database_id
    common::ObNameCaseMode name_case_mode_;
    common::ObString table_name_;
  };
  typedef common::ObSEArray<TableNameWrapper, 2> TableNameWrapperArray;

  private:
  static const int64_t TABLE_BUCKET_NUM = 300;

  private:
  common::hash::ObHashSet<uint64_t, common::hash::NoPthreadDefendMode> tenant_space_table_id_map_;
  common::hash::ObHashMap<uint64_t, TableNameWrapperArray*, common::hash::NoPthreadDefendMode> sys_table_name_map_;
  int64_t tenant_space_sys_table_num_;  // Number of tenant-level system tables (including system table indexes)
  common::ObArenaAllocator allocator_;
  bool is_inited_;
  DISALLOW_COPY_AND_ASSIGN(ObSysTableChecker);
};

class ObTableSchema;
class ObRecycleObject : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  enum RecycleObjType {
    INVALID = 0,
    TABLE,
    INDEX,
    VIEW,
    DATABASE,
    RESERVED_OBJ_TYPE,
    TRIGGER,
    TENANT,
  };
  ObRecycleObject(common::ObIAllocator* allocator);
  ObRecycleObject()
      : ObSchema(),
        tenant_id_(common::OB_INVALID_ID),
        database_id_(common::OB_INVALID_ID),
        table_id_(common::OB_INVALID_ID),
        tablegroup_id_(common::OB_INVALID_ID),
        object_name_(),
        original_name_(),
        type_(INVALID),
        tablegroup_name_(),
        database_name_()
  {}
  ObRecycleObject(const ObRecycleObject& recycle_obj);
  ObRecycleObject& operator=(const ObRecycleObject& recycle_obj);
  virtual ~ObRecycleObject()
  {}
  inline bool is_valid() const;
  virtual void reset();

  uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  uint64_t get_database_id() const
  {
    return database_id_;
  }
  uint64_t get_table_id() const
  {
    return table_id_;
  }
  uint64_t get_tablegroup_id() const
  {
    return tablegroup_id_;
  }
  const common::ObString& get_object_name() const
  {
    return object_name_;
  }
  const common::ObString& get_original_name() const
  {
    return original_name_;
  }
  RecycleObjType get_type() const
  {
    return type_;
  }
  void set_tenant_id(const uint64_t tenant_id)
  {
    tenant_id_ = tenant_id;
  }
  void set_database_id(const uint64_t db_id)
  {
    database_id_ = db_id;
  }
  void set_table_id(const uint64_t table_id)
  {
    table_id_ = table_id;
  }
  void set_tablegroup_id(const uint64_t tablegroup_id)
  {
    tablegroup_id_ = tablegroup_id;
  }
  int set_object_name(const common::ObString& object_name)
  {
    return deep_copy_str(object_name, object_name_);
  }
  int set_original_name(const common::ObString& original_name)
  {
    return deep_copy_str(original_name, original_name_);
  }
  void set_type(const RecycleObjType type)
  {
    type_ = type;
  }
  int set_type_by_table_schema(const ObSimpleTableSchemaV2& table_schema);
  static RecycleObjType get_type_by_table_schema(const ObSimpleTableSchemaV2& table_schema);
  // for backup
  int set_tablegroup_name(const common::ObString& tablegroup_name)
  {
    return deep_copy_str(tablegroup_name, tablegroup_name_);
  }
  const common::ObString& get_tablegroup_name() const
  {
    return tablegroup_name_;
  }
  int set_database_name(const common::ObString& database_name)
  {
    return deep_copy_str(database_name, database_name_);
  }
  const common::ObString& get_database_name() const
  {
    return database_name_;
  }
  TO_STRING_KV(K_(tenant_id), K_(database_id), K_(table_id), K_(tablegroup_id), K_(object_name), K_(original_name),
      K_(type), K_(tablegroup_name), K_(database_name));

  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  uint64_t table_id_;
  uint64_t tablegroup_id_;
  common::ObString object_name_;
  common::ObString original_name_;
  RecycleObjType type_;
  // for backup
  common::ObString tablegroup_name_;
  common::ObString database_name_;
};

inline bool ObRecycleObject::is_valid() const
{
  return INVALID != type_ && !object_name_.empty() && !original_name_.empty();
}

typedef common::hash::ObPlacementHashSet<uint64_t, common::OB_MAX_TABLE_NUM_PER_STMT> DropTableIdHashSet;
// Used to count vertical partition columns
typedef common::hash::ObPlacementHashSet<common::ObString, common::OB_MAX_USER_DEFINED_COLUMNS_COUNT>
    VPColumnNameHashSet;

struct ObBasedSchemaObjectInfo {
  OB_UNIS_VERSION(1);

  public:
  ObBasedSchemaObjectInfo()
      : schema_id_(common::OB_INVALID_ID), schema_type_(OB_MAX_SCHEMA), schema_version_(common::OB_INVALID_VERSION)
  {}
  ObBasedSchemaObjectInfo(const uint64_t schema_id, const ObSchemaType schema_type, const int64_t schema_version)
      : schema_id_(schema_id), schema_type_(schema_type), schema_version_(schema_version)
  {}
  bool operator==(const ObBasedSchemaObjectInfo& other) const
  {
    return (schema_id_ == other.schema_id_ && schema_type_ == other.schema_type_ &&
            schema_version_ == other.schema_version_);
  }
  int64_t get_convert_size() const
  {
    int64_t convert_size = sizeof(*this);
    return convert_size;
  }
  TO_STRING_KV(K_(schema_id), K_(schema_type), K_(schema_version));
  uint64_t schema_id_;
  ObSchemaType schema_type_;
  int64_t schema_version_;
};

struct ObAuxTableMetaInfo {
  OB_UNIS_VERSION(1);

  public:
  ObAuxTableMetaInfo()
      : table_id_(common::OB_INVALID_ID), table_type_(MAX_TABLE_TYPE), drop_schema_version_(common::OB_INVALID_VERSION)
  {}
  ObAuxTableMetaInfo(const uint64_t table_id, const ObTableType table_type, const int64_t drop_schema_version)
      : table_id_(table_id), table_type_(table_type), drop_schema_version_(drop_schema_version)
  {}
  bool operator==(const ObAuxTableMetaInfo& other) const
  {
    return (table_id_ == other.table_id_ && table_type_ == other.table_type_ &&
            drop_schema_version_ == other.drop_schema_version_);
  }
  int64_t get_convert_size() const
  {
    int64_t convert_size = sizeof(*this);
    return convert_size;
  }
  bool is_dropped_schema() const
  {
    return drop_schema_version_ > 0;
  }
  TO_STRING_KV(K_(table_id), K_(table_type), K_(drop_schema_version));
  uint64_t table_id_;
  ObTableType table_type_;
  int64_t drop_schema_version_;
};

enum ObConstraintType {
  CONSTRAINT_TYPE_INVALID = 0,
  CONSTRAINT_TYPE_PRIMARY_KEY = 1,
  CONSTRAINT_TYPE_UNIQUE_KEY = 2,
  CONSTRAINT_TYPE_CHECK = 3,
  CONSTRAINT_TYPE_MAX,
};

enum ObReferenceAction {
  ACTION_INVALID = 0,
  ACTION_RESTRICT,
  ACTION_CASCADE,
  ACTION_SET_NULL,
  ACTION_NO_ACTION,
  ACTION_SET_DEFAULT,  // no use now
  ACTION_CHECK_EXIST,  // not a valid option, just used for construct dml stmt.
  ACTION_MAX
};

class ObForeignKeyInfo {
  OB_UNIS_VERSION(1);

  public:
  ObForeignKeyInfo()
      : table_id_(common::OB_INVALID_ID),
        foreign_key_id_(common::OB_INVALID_ID),
        child_table_id_(common::OB_INVALID_ID),
        parent_table_id_(common::OB_INVALID_ID),
        child_column_ids_(),
        parent_column_ids_(),
        update_action_(ACTION_INVALID),
        delete_action_(ACTION_INVALID),
        foreign_key_name_(),
        enable_flag_(true),
        is_modify_enable_flag_(false),
        validate_flag_(true),
        is_modify_validate_flag_(false),
        rely_flag_(false),
        is_modify_rely_flag_(false),
        is_modify_fk_state_(false),
        ref_cst_type_(CONSTRAINT_TYPE_INVALID),
        ref_cst_id_(common::OB_INVALID_ID)
  {}
  ObForeignKeyInfo(common::ObIAllocator* allocator);
  virtual ~ObForeignKeyInfo()
  {}

  public:
  inline void set_table_id(uint64_t table_id)
  {
    table_id_ = table_id;
  }
  inline void set_foreign_key_id(uint64_t foreign_key_id)
  {
    foreign_key_id_ = foreign_key_id;
  }
  inline void set_child_table_id(uint64_t child_table_id)
  {
    child_table_id_ = child_table_id;
  }
  inline void set_parent_table_id(uint64_t parent_table_id)
  {
    parent_table_id_ = parent_table_id;
  }
  inline void set_update_action(uint64_t update_action)
  {
    update_action_ = static_cast<ObReferenceAction>(update_action);
  }
  inline void set_delete_action(uint64_t delete_action)
  {
    delete_action_ = static_cast<ObReferenceAction>(delete_action);
  }
  inline int set_foreign_key_name(const common::ObString& foreign_key_name)
  {
    foreign_key_name_ = foreign_key_name;
    return common::OB_SUCCESS;
  }
  inline void set_enable_flag(const bool enable_flag)
  {
    enable_flag_ = enable_flag;
  }
  inline void set_is_modify_enable_flag(const bool is_modify_enable_flag)
  {
    is_modify_enable_flag_ = is_modify_enable_flag;
  }
  inline void set_validate_flag(const bool validate_flag)
  {
    validate_flag_ = validate_flag;
  }
  inline void set_is_modify_validate_flag(const bool is_modify_validate_flag)
  {
    is_modify_validate_flag_ = is_modify_validate_flag;
  }
  inline void set_rely_flag(const bool rely_flag)
  {
    rely_flag_ = rely_flag;
  }
  inline void set_is_modify_rely_flag(const bool is_modify_rely_flag)
  {
    is_modify_rely_flag_ = is_modify_rely_flag;
  }
  inline void set_is_modify_fk_state(const bool is_modify_fk_state)
  {
    is_modify_fk_state_ = is_modify_fk_state;
  }
  inline void set_ref_cst_type(ObConstraintType ref_cst_type)
  {
    ref_cst_type_ = ref_cst_type;
  }
  inline void set_ref_cst_id(uint64_t ref_cst_id)
  {
    ref_cst_id_ = ref_cst_id;
  }
  inline const char* get_update_action_str() const
  {
    return get_action_str(update_action_);
  }
  inline const char* get_delete_action_str() const
  {
    return get_action_str(delete_action_);
  }
  inline const char* get_action_str(ObReferenceAction action) const
  {
    const char* ret = NULL;
    if (ACTION_RESTRICT <= action && action <= ACTION_SET_DEFAULT) {
      ret = reference_action_str_[action];
    }
    return ret;
  }
  inline void reset()
  {
    table_id_ = common::OB_INVALID_ID;
    foreign_key_id_ = common::OB_INVALID_ID;
    child_table_id_ = common::OB_INVALID_ID;
    parent_table_id_ = common::OB_INVALID_ID;
    child_column_ids_.reset();
    parent_column_ids_.reset();
    update_action_ = ACTION_INVALID;
    delete_action_ = ACTION_INVALID;
    foreign_key_name_.reset();
    enable_flag_ = true;
    is_modify_enable_flag_ = false;
    validate_flag_ = true;
    is_modify_validate_flag_ = false;
    rely_flag_ = false;
    is_modify_rely_flag_ = false;
    is_modify_fk_state_ = false;
    ref_cst_type_ = CONSTRAINT_TYPE_INVALID;
    ref_cst_id_ = common::OB_INVALID_ID;
  }
  int assign(const ObForeignKeyInfo& other);
  inline int64_t get_convert_size() const
  {
    int64_t convert_size = sizeof(*this);
    convert_size += child_column_ids_.get_data_size();
    convert_size += parent_column_ids_.get_data_size();
    convert_size += foreign_key_name_.length() + 1;
    return convert_size;
  }
  TO_STRING_KV(K_(table_id), K_(foreign_key_id), K_(child_table_id), K_(parent_table_id), K_(child_column_ids),
      K_(parent_column_ids), K_(update_action), K_(delete_action), K_(foreign_key_name), K_(enable_flag),
      K_(is_modify_enable_flag), K_(validate_flag), K_(is_modify_validate_flag), K_(rely_flag), K_(is_modify_rely_flag),
      K_(is_modify_fk_state), K_(ref_cst_type), K_(ref_cst_id));

  public:
  uint64_t table_id_;  // table_id is not in __all_foreign_key.
  uint64_t foreign_key_id_;
  uint64_t child_table_id_;
  uint64_t parent_table_id_;
  common::ObSEArray<uint64_t, 8> child_column_ids_;
  common::ObSEArray<uint64_t, 8> parent_column_ids_;
  ObReferenceAction update_action_;
  ObReferenceAction delete_action_;
  common::ObString foreign_key_name_;
  bool enable_flag_;
  bool is_modify_enable_flag_;
  bool validate_flag_;
  bool is_modify_validate_flag_;
  bool rely_flag_;
  bool is_modify_rely_flag_;
  bool is_modify_fk_state_;
  ObConstraintType ref_cst_type_;
  uint64_t ref_cst_id_;

  private:
  static const char* reference_action_str_[ACTION_MAX + 1];
};

struct ObSimpleForeignKeyInfo {
  OB_UNIS_VERSION(1);

  public:
  ObSimpleForeignKeyInfo()
  {
    tenant_id_ = common::OB_INVALID_ID;
    database_id_ = common::OB_INVALID_ID;
    table_id_ = common::OB_INVALID_ID;
    foreign_key_name_.assign_ptr("", 0);
    foreign_key_id_ = common::OB_INVALID_ID;
  }
  ObSimpleForeignKeyInfo(const uint64_t tenant_id, const uint64_t database_id, const uint64_t table_id,
      const common::ObString& foreign_key_name, const uint64_t foreign_key_id)
      : tenant_id_(tenant_id),
        database_id_(database_id),
        table_id_(table_id),
        foreign_key_name_(foreign_key_name),
        foreign_key_id_(foreign_key_id)
  {}
  bool operator==(const ObSimpleForeignKeyInfo& other) const
  {
    return (tenant_id_ == other.tenant_id_ && database_id_ == other.database_id_ && table_id_ == other.table_id_ &&
            foreign_key_name_ == other.foreign_key_name_ && foreign_key_id_ == other.foreign_key_id_);
  }
  int64_t get_convert_size() const
  {
    int64_t convert_size = sizeof(*this);
    convert_size += foreign_key_name_.length() + 1;
    return convert_size;
  }
  void reset()
  {
    tenant_id_ = common::OB_INVALID_ID;
    database_id_ = common::OB_INVALID_ID;
    table_id_ = common::OB_INVALID_ID;
    foreign_key_name_.assign_ptr("", 0);
    foreign_key_id_ = common::OB_INVALID_ID;
  }
  TO_STRING_KV(K_(tenant_id), K_(database_id), K_(table_id), K_(foreign_key_name), K_(foreign_key_id));

  uint64_t tenant_id_;
  uint64_t database_id_;
  uint64_t table_id_;
  common::ObString foreign_key_name_;
  uint64_t foreign_key_id_;
};

struct ObSimpleConstraintInfo {
  OB_UNIS_VERSION(1);

  public:
  ObSimpleConstraintInfo()
  {
    tenant_id_ = common::OB_INVALID_ID;
    database_id_ = common::OB_INVALID_ID;
    table_id_ = common::OB_INVALID_ID;
    constraint_name_.assign_ptr("", 0);
    constraint_id_ = common::OB_INVALID_ID;
  }
  ObSimpleConstraintInfo(const uint64_t tenant_id, const uint64_t database_id, const uint64_t table_id,
      const common::ObString& constraint_name, const uint64_t constraint_id)
      : tenant_id_(tenant_id),
        database_id_(database_id),
        table_id_(table_id),
        constraint_name_(constraint_name),
        constraint_id_(constraint_id)
  {}
  bool operator==(const ObSimpleConstraintInfo& other) const
  {
    return (tenant_id_ == other.tenant_id_ && database_id_ == other.database_id_ && table_id_ == other.table_id_ &&
            constraint_name_ == other.constraint_name_ && constraint_id_ == other.constraint_id_);
  }
  int64_t get_convert_size() const
  {
    int64_t convert_size = sizeof(*this);
    convert_size += constraint_name_.length() + 1;
    return convert_size;
  }
  void reset()
  {
    tenant_id_ = common::OB_INVALID_ID;
    database_id_ = common::OB_INVALID_ID;
    table_id_ = common::OB_INVALID_ID;
    constraint_name_.assign_ptr("", 0);
    constraint_id_ = common::OB_INVALID_ID;
  }
  TO_STRING_KV(K_(tenant_id), K_(database_id), K_(table_id), K_(constraint_name), K_(constraint_id));

  uint64_t tenant_id_;
  uint64_t database_id_;
  uint64_t table_id_;
  common::ObString constraint_name_;
  uint64_t constraint_id_;
};

template <typename PARTITION>
int ObPartitionUtils::check_partition_value(
    const PARTITION& l_part, const PARTITION& r_part, const ObPartitionFuncType part_type, bool& is_equal)
{
  int ret = common::OB_SUCCESS;
  is_equal = true;
  if (is_hash_like_part(part_type)) {
    is_equal = true;
  } else if (is_range_part(part_type)) {
    if (l_part.get_high_bound_val().get_obj_cnt() != r_part.get_high_bound_val().get_obj_cnt()) {
      is_equal = false;
      SHARE_SCHEMA_LOG(DEBUG,
          "fail to check partition value, value count not equal",
          "left",
          l_part.get_high_bound_val(),
          "right",
          r_part.get_high_bound_val());
    } else {
      for (int64_t i = 0; i < l_part.get_high_bound_val().get_obj_cnt() && is_equal; i++) {
        const common::ObObjMeta meta1 = l_part.get_high_bound_val().get_obj_ptr()[i].get_meta();
        const common::ObObjMeta meta2 = r_part.get_high_bound_val().get_obj_ptr()[i].get_meta();
        if (meta1.get_collation_level() == meta2.get_collation_level() &&
            meta1.get_collation_type() == meta2.get_collation_type()) {
          is_equal = is_types_equal_for_partition_check(meta1.get_type(), meta2.get_type());
        } else {
          is_equal = false;
        }
        if (false == is_equal) {
          SHARE_SCHEMA_LOG(DEBUG,
              "fail to check partition values, value meta not equal",
              "left",
              l_part.get_high_bound_val().get_obj_ptr()[i],
              "right",
              r_part.get_high_bound_val().get_obj_ptr()[i],
              K(lib::is_oracle_mode()));
        } else if (0 !=
                   l_part.get_high_bound_val().get_obj_ptr()[i].compare(r_part.get_high_bound_val().get_obj_ptr()[i],
                       r_part.get_high_bound_val().get_obj_ptr()[i].get_collation_type())) {
          is_equal = false;
          SHARE_SCHEMA_LOG(DEBUG,
              "fail to check partition values, value not equal",
              "left",
              l_part.get_high_bound_val().get_obj_ptr()[i],
              "right",
              r_part.get_high_bound_val().get_obj_ptr()[i]);
        }
      }
    }
  } else if (is_list_part(part_type)) {
    const common::ObIArray<common::ObNewRow>& l_list_values = l_part.get_list_row_values();
    const common::ObIArray<common::ObNewRow>& r_list_values = r_part.get_list_row_values();
    if (l_list_values.count() != r_list_values.count()) {
      is_equal = false;
    } else {
      for (int64_t i = 0; i < l_list_values.count() && is_equal; i++) {
        const common::ObNewRow& l_rowkey = l_list_values.at(i);
        bool find_equal_item = false;
        for (int64_t j = 0; j < r_list_values.count() && !find_equal_item && is_equal; j++) {
          const common::ObNewRow& r_rowkey = r_list_values.at(j);
          // First check that the count and meta information are consistent;
          if (l_rowkey.get_count() != r_rowkey.get_count()) {
            is_equal = false;
            SHARE_SCHEMA_LOG(
                DEBUG, "fail to check partition value, value count not equal", "left", l_rowkey, "right", r_rowkey);
          } else {
            for (int64_t z = 0; z < l_rowkey.get_count() && is_equal; z++) {
              const common::ObObjMeta meta1 = l_rowkey.get_cell(z).get_meta();
              const common::ObObjMeta meta2 = r_rowkey.get_cell(z).get_meta();
              if (meta1.get_collation_level() == meta2.get_collation_level() &&
                  meta1.get_collation_type() == meta2.get_collation_type()) {
                is_equal = is_types_equal_for_partition_check(meta1.get_type(), meta2.get_type());
              } else {
                is_equal = false;
              }
              if (false == is_equal) {
                SHARE_SCHEMA_LOG(DEBUG,
                    "fail to check partition values, value meta not equal",
                    "left",
                    l_rowkey.get_cell(z),
                    "right",
                    r_rowkey.get_cell(z));
              }
            }
          }
          // Check whether the value of rowkey is the same;
          if (OB_SUCC(ret) && is_equal && l_rowkey == r_rowkey) {
            find_equal_item = true;
          }
        }  // end for (int64_t j = 0
        if (!find_equal_item) {
          is_equal = false;
        }
      }  // end for (int64_t i = 0;
    }
  } else {
    ret = common::OB_INVALID_ARGUMENT;
    SHARE_SCHEMA_LOG(WARN, "invalid part_type", K(ret), K(part_type));
  }
  return ret;
}

class ObSequenceSchema : public ObSchema {
  OB_UNIS_VERSION(1);

  public:
  ObSequenceSchema();
  explicit ObSequenceSchema(common::ObIAllocator* allocator);
  virtual ~ObSequenceSchema();
  ObSequenceSchema& operator=(const ObSequenceSchema& src_schema);
  int assign(const ObSequenceSchema& src_schema);
  ObSequenceSchema(const ObSequenceSchema& src_schema);
  int64_t get_convert_size() const;

  inline void set_tenant_id(const uint64_t id)
  {
    tenant_id_ = id;
  }
  inline void set_database_id(const uint64_t id)
  {
    database_id_ = id;
  }
  inline void set_sequence_id(uint64_t id)
  {
    sequence_id_ = id;
  }
  inline void set_schema_version(int64_t version)
  {
    schema_version_ = version;
  }
  inline int set_sequence_name(const char* name)
  {
    return deep_copy_str(name, name_);
  }
  inline int set_sequence_name(const common::ObString& name)
  {
    return deep_copy_str(name, name_);
  }
  inline int set_name(const common::ObString& name)
  {
    return set_sequence_name(name);
  }
  // inline void set_max_value(int64_t val) { option_.set_max_value(val); }
  // inline void set_min_value(int64_t val) { option_.set_min_value(val); }
  // inline void set_increment_by(int64_t val) { option_.set_increment_by(val); }
  // inline void set_start_with(int64_t val) { option_.set_start_with(val); }
  // inline void set_cache_size(int64_t val) { option_.set_cache_size(val); }
  inline void set_cycle_flag(bool cycle)
  {
    option_.set_cycle_flag(cycle);
  }
  inline void set_order_flag(bool order)
  {
    option_.set_order_flag(order);
  }

  // Temporary compatibility code, in order to support max_value etc. as Number type
  // int set_max_value(const common::ObString &str);
  // int set_min_value(const common::ObString &str);
  // int set_increment_by(const common::ObString &str);
  // int set_start_with(const common::ObString &str);
  // int set_cache_size(const common::ObString &str);

  int set_max_value(const common::number::ObNumber& num)
  {
    return option_.set_max_value(num);
  }
  int set_min_value(const common::number::ObNumber& num)
  {
    return option_.set_min_value(num);
  }
  int set_increment_by(const common::number::ObNumber& num)
  {
    return option_.set_increment_by(num);
  }
  int set_start_with(const common::number::ObNumber& num)
  {
    return option_.set_start_with(num);
  }
  int set_cache_size(const common::number::ObNumber& num)
  {
    return option_.set_cache_size(num);
  }

  inline const common::number::ObNumber& get_min_value() const
  {
    return option_.get_min_value();
  }
  inline const common::number::ObNumber& get_max_value() const
  {
    return option_.get_max_value();
  }
  inline const common::number::ObNumber& get_increment_by() const
  {
    return option_.get_increment_by();
  }
  inline const common::number::ObNumber& get_start_with() const
  {
    return option_.get_start_with();
  }
  inline const common::number::ObNumber& get_cache_size() const
  {
    return option_.get_cache_size();
  }

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_database_id() const
  {
    return database_id_;
  }
  inline uint64_t get_sequence_id() const
  {
    return sequence_id_;
  }
  // inline int64_t get_min_value() const { return option_.get_min_value(); }
  // inline int64_t get_max_value() const { return option_.get_max_value(); }
  // inline int64_t get_increment_by() const { return option_.get_increment_by(); }
  // inline int64_t get_start_with() const { return option_.get_start_with(); }
  // inline int64_t get_cache_size() const { return option_.get_cache_size(); }
  inline bool get_cycle_flag() const
  {
    return option_.get_cycle_flag();
  }
  inline bool get_order_flag() const
  {
    return option_.get_order_flag();
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline const common::ObString& get_sequence_name() const
  {
    return name_;
  }
  inline const char* get_sequence_name_str() const
  {
    return extract_str(name_);
  }
  inline share::ObSequenceOption& get_sequence_option()
  {
    return option_;
  }
  inline const share::ObSequenceOption& get_sequence_option() const
  {
    return option_;
  }
  inline ObTenantSequenceId get_tenant_sequence_id() const
  {
    return ObTenantSequenceId(tenant_id_, sequence_id_);
  }

  void reset();

  VIRTUAL_TO_STRING_KV(K_(name), K_(tenant_id), K_(database_id), K_(sequence_id), K_(schema_version), K_(option));

  private:
  // void *alloc(int64_t size);
  // int get_value(const common::ObString &str, int64_t &val);
  // int get_value(const common::number::ObNumber &num, int64_t &val);
  private:
  uint64_t tenant_id_;
  uint64_t database_id_;
  uint64_t sequence_id_;
  int64_t schema_version_;  // the last modify timestamp of this version
  common::ObString name_;   // sequence name
  share::ObSequenceOption option_;
  // common::ObArenaAllocator allocator_;
};

typedef ObSequenceSchema ObSequenceInfo;

class ObTenantCommonSchemaId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantCommonSchemaId() : tenant_id_(common::OB_INVALID_TENANT_ID), schema_id_(common::OB_INVALID_ID)
  {}
  ObTenantCommonSchemaId(const uint64_t tenant_id, const uint64_t schema_id)
      : tenant_id_(tenant_id), schema_id_(schema_id)
  {}
  bool operator==(const ObTenantCommonSchemaId& rhs) const
  {
    return (tenant_id_ == rhs.tenant_id_) && (schema_id_ == rhs.schema_id_);
  }
  bool operator!=(const ObTenantCommonSchemaId& rhs) const
  {
    return !(*this == rhs);
  }
  bool operator<(const ObTenantCommonSchemaId& rhs) const
  {
    bool bret = tenant_id_ < rhs.tenant_id_;
    if (tenant_id_ == rhs.tenant_id_) {
      bret = schema_id_ < rhs.schema_id_;
    }
    return bret;
  }
  inline uint64_t hash() const
  {
    uint64_t hash_ret = 0;
    hash_ret = common::murmurhash(&tenant_id_, sizeof(tenant_id_), 0);
    hash_ret = common::murmurhash(&schema_id_, sizeof(schema_id_), hash_ret);
    return hash_ret;
  }
  bool is_valid() const
  {
    return (tenant_id_ != common::OB_INVALID_TENANT_ID) && (schema_id_ != common::OB_INVALID_ID);
  }
  TO_STRING_KV(K_(tenant_id), K_(schema_id));
  uint64_t tenant_id_;
  uint64_t schema_id_;
};

class ObTenantProfileId : public ObTenantCommonSchemaId {
  OB_UNIS_VERSION(1);

  public:
  ObTenantProfileId() : ObTenantCommonSchemaId()
  {}
  ObTenantProfileId(const uint64_t tenant_id, const uint64_t profile_id) : ObTenantCommonSchemaId(tenant_id, profile_id)
  {}
};

class ObProfileSchema : public ObSchema {  // simple schema
  OB_UNIS_VERSION(1);

  public:
  static const int64_t INVALID_VALUE = -1;

  enum PARAM_TYPES {
    FAILED_LOGIN_ATTEMPTS = 0,
    PASSWORD_LOCK_TIME,
    PASSWORD_VERIFY_FUNCTION,
    PASSWORD_LIFE_TIME,
    PASSWORD_GRACE_TIME,
    /*
    PASSWORD_REUSE_TIME,
    PASSWORD_REUSE_MAX,
    SESSIONS_PER_USER,
    CPU_PER_SESSION,
    CPU_PER_CALL,
    CONNECT_TIME,
    IDLE_TIME,
    LOGICAL_READS_PER_SESSION,
    LOGICAL_READS_PER_CALL,
    PRIVATE_SGA,
    */
    MAX_PARAMS
  };

  static const int64_t DEFAULT_PARAM_VALUES[MAX_PARAMS];
  static const int64_t INVALID_PARAM_VALUES[MAX_PARAMS];
  static const char* PARAM_VALUE_NAMES[MAX_PARAMS];

  ObProfileSchema();
  explicit ObProfileSchema(common::ObIAllocator* allocator);
  virtual ~ObProfileSchema();

  TO_STRING_KV(K_(tenant_id), K_(profile_id), K_(schema_version), K_(profile_name), K_(failed_login_attempts),
      K_(password_lock_time), K_(password_life_time), K_(password_grace_time));

  bool is_valid() const;
  void reset();
  int64_t get_convert_size() const;

  ObProfileSchema& operator=(const ObProfileSchema& src_schema);
  ObProfileSchema(const ObProfileSchema& src_schema);

  inline void set_tenant_id(const uint64_t id)
  {
    tenant_id_ = id;
  }
  inline void set_profile_id(uint64_t id)
  {
    profile_id_ = id;
  }
  inline void set_schema_version(int64_t version)
  {
    schema_version_ = version;
  }
  inline int set_profile_name(const char* name)
  {
    return deep_copy_str(name, profile_name_);
  }
  inline int set_profile_name(const common::ObString& name)
  {
    return deep_copy_str(name, profile_name_);
  }
  inline void set_failed_login_attempts(const int64_t value)
  {
    failed_login_attempts_ = value;
  }
  inline void set_password_lock_time(const int64_t value)
  {
    password_lock_time_ = value;
  }
  inline void set_password_life_time(const int64_t value)
  {
    password_life_time_ = value;
  }
  inline void set_password_grace_time(const int64_t value)
  {
    password_grace_time_ = value;
  }

  inline uint64_t get_tenant_id() const
  {
    return tenant_id_;
  }
  inline uint64_t get_profile_id() const
  {
    return profile_id_;
  }
  inline int64_t get_schema_version() const
  {
    return schema_version_;
  }
  inline const char* get_profile_name() const
  {
    return extract_str(profile_name_);
  }
  inline const common::ObString& get_profile_name_str() const
  {
    return profile_name_;
  }
  inline int64_t get_failed_login_attempts() const
  {
    return failed_login_attempts_;
  }
  inline int64_t get_password_lock_time() const
  {
    return password_lock_time_;
  }
  inline int64_t get_password_life_time() const
  {
    return password_life_time_;
  }
  inline int64_t get_password_grace_time() const
  {
    return password_grace_time_;
  }

  inline ObTenantProfileId get_tenant_profile_id() const
  {
    return ObTenantProfileId(tenant_id_, profile_id_);
  }

  int set_value(const int64_t type, const int64_t value);
  int set_default_value(const int64_t type);
  int set_default_values();
  int set_invalid_values();
  static int get_default_value(const int64_t type, int64_t& value);

  inline const char* get_password_verify_function() const
  {
    return extract_str(password_verify_function_);
  }
  inline const common::ObString& get_password_verify_function_str() const
  {
    return password_verify_function_;
  }
  inline int set_password_verify_function(const char* name)
  {
    return deep_copy_str(name, password_verify_function_);
  }
  inline int set_password_verify_function(const common::ObString& name)
  {
    return deep_copy_str(name, password_verify_function_);
  }

  private:
  uint64_t tenant_id_;
  uint64_t profile_id_;
  int64_t schema_version_;
  common::ObString profile_name_;
  int64_t failed_login_attempts_;
  int64_t password_lock_time_;
  common::ObString password_verify_function_;
  int64_t password_life_time_;
  int64_t password_grace_time_;
};

common::ObIAllocator*& schema_stack_allocator();

struct ObObjectStruct {
  ObObjectStruct() : type_(ObObjectType::INVALID), id_(common::OB_INVALID_ID){};
  ObObjectStruct(const ObObjectType type, const uint64_t id) : type_(type), id_(id){};
  ~ObObjectStruct(){};

  TO_STRING_KV(K_(type), K_(id));

  ObObjectType type_;
  uint64_t id_;
};

//
class IObErrorInfo {
  public:
  IObErrorInfo()
  {}
  virtual ~IObErrorInfo() = 0;
  virtual uint64_t get_object_id() const = 0;
  virtual uint64_t get_tenant_id() const = 0;
  virtual uint64_t get_database_id() const = 0;
  virtual int64_t get_schema_version() const = 0;
  virtual ObObjectType get_object_type() const = 0;
  static constexpr uint64_t TYPE_MASK = (0x7) << (sizeof(uint64_t) - 3);
  static constexpr uint64_t VAL_MASK = (-1) >> 3;
  void inline gen_mask(uint64_t type, uint64_t& id)
  {
    id = (TYPE_MASK & type) | (VAL_MASK & id);
  }
};

}  // namespace schema
}  // namespace share
}  // namespace oceanbase

#endif /* _OB_OCEANBASE_SCHEMA_SCHEMA_STRUCT_H */