summaryrefslogtreecommitdiff
path: root/storage/spider/spd_param.cc
blob: 0a5d881749c116b4441b84d7b99698c2e96c6a17 (plain)
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
/* Copyright (C) 2008-2018 Kentoku Shiba

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */

#define MYSQL_SERVER 1
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#include "sql_priv.h"
#include "probes_mysql.h"
#include "sql_class.h"
#include "sql_partition.h"
#include <my_getopt.h>
#include "spd_err.h"
#include "spd_db_include.h"
#include "spd_include.h"
#include "ha_spider.h"
#include "spd_table.h"
#include "spd_trx.h"

extern struct st_mysql_plugin spider_i_s_alloc_mem;
extern struct st_mysql_plugin spider_i_s_wrapper_protocols;
extern struct st_maria_plugin spider_i_s_alloc_mem_maria;
extern struct st_maria_plugin spider_i_s_wrapper_protocols_maria;

extern volatile ulonglong spider_mon_table_cache_version;
extern volatile ulonglong spider_mon_table_cache_version_req;

static int spider_direct_update(THD *thd, SHOW_VAR *var, char *buff)
{
  int error_num = 0;
  SPIDER_TRX *trx;
  DBUG_ENTER("spider_direct_update");
  var->type = SHOW_LONGLONG;
  if ((trx = spider_get_trx(thd, TRUE, &error_num)))
    var->value = (char *) &trx->direct_update_count;
  DBUG_RETURN(error_num);
}

static int spider_direct_delete(THD *thd, SHOW_VAR *var, char *buff)
{
  int error_num = 0;
  SPIDER_TRX *trx;
  DBUG_ENTER("spider_direct_delete");
  var->type = SHOW_LONGLONG;
  if ((trx = spider_get_trx(thd, TRUE, &error_num)))
    var->value = (char *) &trx->direct_delete_count;
  DBUG_RETURN(error_num);
}

static int spider_direct_order_limit(THD *thd, SHOW_VAR *var, char *buff)
{
  int error_num = 0;
  SPIDER_TRX *trx;
  DBUG_ENTER("spider_direct_order_limit");
  var->type = SHOW_LONGLONG;
  if ((trx = spider_get_trx(thd, TRUE, &error_num)))
    var->value = (char *) &trx->direct_order_limit_count;
  DBUG_RETURN(error_num);
}

static int spider_direct_aggregate(THD *thd, SHOW_VAR *var, char *buff)
{
  int error_num = 0;
  SPIDER_TRX *trx;
  DBUG_ENTER("spider_direct_aggregate");
  var->type = SHOW_LONGLONG;
  if ((trx = spider_get_trx(thd, TRUE, &error_num)))
    var->value = (char *) &trx->direct_aggregate_count;
  DBUG_RETURN(error_num);
}

static int spider_parallel_search(THD *thd, SHOW_VAR *var, char *buff)
{
  int error_num = 0;
  SPIDER_TRX *trx;
  DBUG_ENTER("spider_parallel_search");
  var->type = SHOW_LONGLONG;
  if ((trx = spider_get_trx(thd, TRUE, &error_num)))
    var->value = (char *) &trx->parallel_search_count;
  DBUG_RETURN(error_num);
}

struct st_mysql_show_var spider_status_variables[] =
{
  {"Spider_mon_table_cache_version",
    (char *) &spider_mon_table_cache_version, SHOW_LONGLONG},
  {"Spider_mon_table_cache_version_req",
    (char *) &spider_mon_table_cache_version_req, SHOW_LONGLONG},
#ifdef SPIDER_HAS_SHOW_SIMPLE_FUNC
  {"Spider_direct_update", (char *) &spider_direct_update, SHOW_SIMPLE_FUNC},
  {"Spider_direct_delete", (char *) &spider_direct_delete, SHOW_SIMPLE_FUNC},
#else
  {"Spider_direct_update", (char *) &spider_direct_update, SHOW_FUNC},
  {"Spider_direct_delete", (char *) &spider_direct_delete, SHOW_FUNC},
#endif
#ifdef SPIDER_HAS_SHOW_SIMPLE_FUNC
  {"Spider_direct_order_limit",
    (char *) &spider_direct_order_limit, SHOW_SIMPLE_FUNC},
  {"Spider_direct_aggregate",
    (char *) &spider_direct_aggregate, SHOW_SIMPLE_FUNC},
  {"Spider_parallel_search",
    (char *) &spider_parallel_search, SHOW_SIMPLE_FUNC},
#else
  {"Spider_direct_order_limit",
    (char *) &spider_direct_order_limit, SHOW_FUNC},
  {"Spider_direct_aggregate",
    (char *) &spider_direct_aggregate, SHOW_FUNC},
  {"Spider_parallel_search",
    (char *) &spider_parallel_search, SHOW_FUNC},
#endif
  {NullS, NullS, SHOW_LONG}
};

typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int);
extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed,
  bool is_unsignd, longlong v);

static my_bool spider_support_xa;
static MYSQL_SYSVAR_BOOL(
  support_xa,
  spider_support_xa,
  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
  "XA support",
  NULL,
  NULL,
  TRUE
);

static void spider_var_deprecated_int(THD *thd, st_mysql_sys_var *,
                                      void *var_ptr, const void *save)
{
  int val= *static_cast<const int *>(save);
  *static_cast<int *>(var_ptr)= val;
  if (val == -1)
  {
    push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
                        HA_ERR_UNSUPPORTED,
                        "The option value -1 (use table value) is deprecated "
                        "and will be removed in a future release");
  }
}

static void spider_var_deprecated_longlong(THD *thd, st_mysql_sys_var *,
                                           void *var_ptr, const void *save)
{
  longlong val= *static_cast<const longlong *>(save);
  *static_cast<longlong *>(var_ptr)= val;
  if (val == -1)
  {
    push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
                        HA_ERR_UNSUPPORTED,
                        "The option value -1 (use table value) is deprecated "
                        "and will be removed in a future release");
  }
}

my_bool spider_param_support_xa()
{
  DBUG_ENTER("spider_param_support_xa");
  DBUG_RETURN(spider_support_xa);
}

static my_bool spider_connect_mutex;
static MYSQL_SYSVAR_BOOL(
  connect_mutex,
  spider_connect_mutex,
  PLUGIN_VAR_OPCMDARG,
  "Use mutex at connecting",
  NULL,
  NULL,
  FALSE
);

my_bool spider_param_connect_mutex()
{
  DBUG_ENTER("spider_param_connect_mutex");
  DBUG_RETURN(spider_connect_mutex);
}

static uint spider_connect_error_interval;
/*
  0-: interval
 */
static MYSQL_SYSVAR_UINT(
  connect_error_interval,
  spider_connect_error_interval,
  PLUGIN_VAR_RQCMDARG,
  "Return same error code until interval passes if connection is failed",
  NULL,
  NULL,
  1,
  0,
  4294967295U,
  0
);

uint spider_param_connect_error_interval()
{
  DBUG_ENTER("spider_param_connect_error_interval");
  DBUG_RETURN(spider_connect_error_interval);
}

static uint spider_table_init_error_interval;
/*
  0-: interval
 */
static MYSQL_SYSVAR_UINT(
  table_init_error_interval,
  spider_table_init_error_interval,
  PLUGIN_VAR_RQCMDARG,
  "Return same error code until interval passes if table init is failed",
  NULL,
  NULL,
  1,
  0,
  4294967295U,
  0
);

uint spider_param_table_init_error_interval()
{
  DBUG_ENTER("spider_param_table_init_error_interval");
  DBUG_RETURN(spider_table_init_error_interval);
}

static int spider_use_table_charset;
/*
 -1 :use table parameter
  0 :use utf8
  1 :use table charset
 */
static MYSQL_SYSVAR_INT(
  use_table_charset,
  spider_use_table_charset,
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  "Use table charset for remote access",
  NULL,
  spider_var_deprecated_int,
  1,
  -1,
  1,
  0
);

int spider_param_use_table_charset(
  int use_table_charset
) {
  DBUG_ENTER("spider_param_use_table_charset");
  DBUG_RETURN(spider_use_table_charset == -1 ?
    use_table_charset : spider_use_table_charset);
}

/*
  0: no recycle
  1: recycle in instance
  2: recycle in thread
 */
static MYSQL_THDVAR_UINT(
  conn_recycle_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Connection recycle mode", /* comment */
  NULL, /* check */
  NULL, /* update */
  0, /* def */
  0, /* min */
  2, /* max */
  0 /* blk */
);

uint spider_param_conn_recycle_mode(
  THD *thd
) {
  DBUG_ENTER("spider_param_conn_recycle_mode");
  DBUG_RETURN(THDVAR(thd, conn_recycle_mode));
}

/*
  0: weak
  1: strict
 */
static MYSQL_THDVAR_UINT(
  conn_recycle_strict, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Strict connection recycle", /* comment */
  NULL, /* check */
  NULL, /* update */
  0, /* def */
  0, /* min */
  1, /* max */
  0 /* blk */
);

uint spider_param_conn_recycle_strict(
  THD *thd
) {
  DBUG_ENTER("spider_param_conn_recycle_strict");
  DBUG_RETURN(THDVAR(thd, conn_recycle_strict));
}

/*
  FALSE: no sync
  TRUE:  sync
 */
static MYSQL_THDVAR_BOOL(
  sync_trx_isolation, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Sync transaction isolation level", /* comment */
  NULL, /* check */
  NULL, /* update */
  TRUE /* def */
);

bool spider_param_sync_trx_isolation(
  THD *thd
) {
  DBUG_ENTER("spider_param_sync_trx_isolation");
  DBUG_RETURN(THDVAR(thd, sync_trx_isolation));
}

/*
  FALSE: no use
  TRUE:  use
 */
static MYSQL_THDVAR_BOOL(
  use_consistent_snapshot, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Use start transaction with consistent snapshot", /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

bool spider_param_use_consistent_snapshot(
  THD *thd
) {
  DBUG_ENTER("spider_param_use_consistent_snapshot");
  DBUG_RETURN(THDVAR(thd, use_consistent_snapshot));
}

/*
  FALSE: off
  TRUE:  on
 */
static MYSQL_THDVAR_BOOL(
  internal_xa, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Use inner xa transaction", /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

bool spider_param_internal_xa(
  THD *thd
) {
  DBUG_ENTER("spider_param_internal_xa");
  DBUG_RETURN(THDVAR(thd, internal_xa));
}

/*
  0 :err when use a spider table
  1 :err when start trx
  2 :start trx with snapshot on remote server(not use xa)
  3 :start xa on remote server(not use trx with snapshot)
 */
static MYSQL_THDVAR_UINT(
  internal_xa_snapshot, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Action of inner xa and snapshot both using", /* comment */
  NULL, /* check */
  NULL, /* update */
  0, /* def */
  0, /* min */
  3, /* max */
  0 /* blk */
);

uint spider_param_internal_xa_snapshot(
  THD *thd
) {
  DBUG_ENTER("spider_param_internal_xa_snapshot");
  DBUG_RETURN(THDVAR(thd, internal_xa_snapshot));
}

/*
  0 :off
  1 :continue prepare, commit, rollback if xid not found return
  2 :continue prepare, commit, rollback if all error return
 */
static MYSQL_THDVAR_UINT(
  force_commit, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Force prepare, commit, rollback mode", /* comment */
  NULL, /* check */
  NULL, /* update */
  1, /* def */
  0, /* min */
  2, /* max */
  0 /* blk */
);

uint spider_param_force_commit(
  THD *thd
) {
  DBUG_ENTER("spider_param_force_commit");
  DBUG_RETURN(THDVAR(thd, force_commit));
}

/*
  0: register all XA transaction
  1: register only write XA transaction
 */
static MYSQL_THDVAR_UINT(
  xa_register_mode, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Mode of XA transaction register into system table", /* comment */
  NULL, /* check */
  NULL, /* update */
  1, /* def */
  0, /* min */
  1, /* max */
  0 /* blk */
);

uint spider_param_xa_register_mode(
  THD *thd
) {
  DBUG_ENTER("spider_param_xa_register_mode");
  DBUG_RETURN(THDVAR(thd, xa_register_mode));
}

/*
 -1 :use table parameter
  0-:offset
 */
static MYSQL_THDVAR_LONGLONG(
  internal_offset, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Internal offset", /* comment */
  NULL, /* check */
  spider_var_deprecated_longlong, /* update */
  0, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_internal_offset(
  THD *thd,
  longlong internal_offset
) {
  DBUG_ENTER("spider_param_internal_offset");
  DBUG_RETURN(THDVAR(thd, internal_offset) < 0 ?
    internal_offset : THDVAR(thd, internal_offset));
}

/*
 -1 :use table parameter
  0-:limit
 */
static MYSQL_THDVAR_LONGLONG(
  internal_limit, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Internal limit", /* comment */
  NULL, /* check */
  spider_var_deprecated_longlong, /* update */
  9223372036854775807LL, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_internal_limit(
  THD *thd,
  longlong internal_limit
) {
  DBUG_ENTER("spider_param_internal_limit");
  DBUG_RETURN(THDVAR(thd, internal_limit) < 0 ?
    internal_limit : THDVAR(thd, internal_limit));
}

/*
 -1 :use table parameter
  0-:number of rows at a select
 */
static MYSQL_THDVAR_LONGLONG(
  split_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Number of rows at a select", /* comment */
  NULL, /* check */
  spider_var_deprecated_longlong, /* update */
  9223372036854775807LL, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_split_read(
  THD *thd,
  longlong split_read
) {
  DBUG_ENTER("spider_param_split_read");
  DBUG_RETURN(THDVAR(thd, split_read) < 0 ?
    split_read : THDVAR(thd, split_read));
}

/*
  -1 :use table parameter
   0 :doesn't use "offset" and "limit" for "split_read"
   1-:magnification
 */
static MYSQL_THDVAR_INT(
  semi_split_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Use offset and limit parameter in SQL for split_read parameter.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  2, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

double spider_param_semi_split_read(
  THD *thd,
  double semi_split_read
) {
  DBUG_ENTER("spider_param_semi_split_read");
  DBUG_RETURN(THDVAR(thd, semi_split_read) < 0 ?
    semi_split_read : THDVAR(thd, semi_split_read));
}

/*
 -1 :use table parameter
  0-:the limit value
 */
static MYSQL_THDVAR_LONGLONG(
  semi_split_read_limit, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "The limit value for semi_split_read", /* comment */
  NULL, /* check */
  spider_var_deprecated_longlong, /* update */
  9223372036854775807LL, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_semi_split_read_limit(
  THD *thd,
  longlong semi_split_read_limit
) {
  DBUG_ENTER("spider_param_semi_split_read_limit");
  DBUG_RETURN(THDVAR(thd, semi_split_read_limit) < 0 ?
    semi_split_read_limit : THDVAR(thd, semi_split_read_limit));
}

/*
 -1 :use table parameter
  0 :no alloc
  1-:alloc size
 */
static MYSQL_THDVAR_INT(
  init_sql_alloc_size, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Initial sql string alloc size", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1024, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_init_sql_alloc_size(
  THD *thd,
  int init_sql_alloc_size
) {
  DBUG_ENTER("spider_param_init_sql_alloc_size");
  DBUG_RETURN(THDVAR(thd, init_sql_alloc_size) < 0 ?
    init_sql_alloc_size : THDVAR(thd, init_sql_alloc_size));
}

/*
 -1 :use table parameter
  0 :off
  1 :on
 */
static MYSQL_THDVAR_INT(
  reset_sql_alloc, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Reset sql string alloc after execute", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_reset_sql_alloc(
  THD *thd,
  int reset_sql_alloc
) {
  DBUG_ENTER("spider_param_reset_sql_alloc");
  DBUG_RETURN(THDVAR(thd, reset_sql_alloc) < 0 ?
    reset_sql_alloc : THDVAR(thd, reset_sql_alloc));
}

/*
 -1 :use table parameter
  0 :off
  1 :on
 */
static MYSQL_THDVAR_INT(
  multi_split_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Sprit read mode for multi range", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  100, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_multi_split_read(
  THD *thd,
  int multi_split_read
) {
  DBUG_ENTER("spider_param_multi_split_read");
  DBUG_RETURN(THDVAR(thd, multi_split_read) < 0 ?
    multi_split_read : THDVAR(thd, multi_split_read));
}

/*
 -1 :use table parameter
  0-:max order columns
 */
static MYSQL_THDVAR_INT(
  max_order, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Max columns for order by", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  32767, /* def */
  -1, /* min */
  32767, /* max */
  0 /* blk */
);

int spider_param_max_order(
  THD *thd,
  int max_order
) {
  DBUG_ENTER("spider_param_max_order");
  DBUG_RETURN(THDVAR(thd, max_order) < 0 ?
    max_order : THDVAR(thd, max_order));
}

/*
 -1 :off
  0 :read uncommitted
  1 :read committed
  2 :repeatable read
  3 :serializable
 */
static MYSQL_THDVAR_INT(
  semi_trx_isolation, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Transaction isolation level during execute a sql", /* comment */
  NULL, /* check */
  NULL, /* update */
  -1, /* def */
  -1, /* min */
  3, /* max */
  0 /* blk */
);

int spider_param_semi_trx_isolation(
  THD *thd
) {
  DBUG_ENTER("spider_param_semi_trx_isolation");
  DBUG_RETURN(THDVAR(thd, semi_trx_isolation));
}

static int spider_param_semi_table_lock_check(
  MYSQL_THD thd,
  struct st_mysql_sys_var *var,
  void *save,
  struct st_mysql_value *value
) {
  int error_num;
  SPIDER_TRX *trx;
  my_bool fixed;
  long long tmp;
  struct my_option options;
  DBUG_ENTER("spider_param_semi_table_lock_check");
  if (!(trx = spider_get_trx((THD *) thd, TRUE, &error_num)))
    DBUG_RETURN(error_num);
  if (trx->locked_connections)
  {
    my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
      ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
    DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM);
  }
  value->val_int(value, &tmp);
  options.sub_size = 0;
  options.var_type = GET_INT;
  options.def_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->def_val;
  options.min_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->min_val;
  options.max_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->max_val;
  options.block_size =
    (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz;
  options.arg_type = REQUIRED_ARG;
  *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed);
  DBUG_RETURN(throw_bounds_warning(thd,
    ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE,
    (longlong) tmp));
}

/*
  0 :off
  1 :on
 */
static MYSQL_THDVAR_INT(
  semi_table_lock, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Table lock during execute a sql", /* comment */
  &spider_param_semi_table_lock_check, /* check */
  NULL, /* update */
  0, /* def */
  0, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_semi_table_lock(
  THD *thd,
  int semi_table_lock
) {
  DBUG_ENTER("spider_param_semi_table_lock");
  DBUG_RETURN((semi_table_lock & THDVAR(thd, semi_table_lock)));
}

static int spider_param_semi_table_lock_connection_check(
  MYSQL_THD thd,
  struct st_mysql_sys_var *var,
  void *save,
  struct st_mysql_value *value
) {
  int error_num;
  SPIDER_TRX *trx;
  my_bool fixed;
  long long tmp;
  struct my_option options;
  DBUG_ENTER("spider_param_semi_table_lock_connection_check");
  if (!(trx = spider_get_trx((THD *) thd, TRUE, &error_num)))
    DBUG_RETURN(error_num);
  if (trx->locked_connections)
  {
    my_message(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM,
      ER_SPIDER_ALTER_BEFORE_UNLOCK_STR, MYF(0));
    DBUG_RETURN(ER_SPIDER_ALTER_BEFORE_UNLOCK_NUM);
  }
  value->val_int(value, &tmp);
  options.sub_size = 0;
  options.var_type = GET_INT;
  options.def_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->def_val;
  options.min_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->min_val;
  options.max_value = ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->max_val;
  options.block_size =
    (long) ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->blk_sz;
  options.arg_type = REQUIRED_ARG;
  *((int *) save) = (int) getopt_ll_limit_value(tmp, &options, &fixed);
  DBUG_RETURN(throw_bounds_warning(thd,
    ((MYSQL_SYSVAR_NAME(thdvar_int_t) *) var)->name, fixed, FALSE,
    (longlong) tmp));
}

/*
 -1 :off
  0 :use same connection
  1 :use different connection
 */
static MYSQL_THDVAR_INT(
  semi_table_lock_connection, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Use different connection if semi_table_lock is enabled", /* comment */
  &spider_param_semi_table_lock_connection_check, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_semi_table_lock_connection(
  THD *thd,
  int semi_table_lock_connection
) {
  DBUG_ENTER("spider_param_semi_table_lock_connection");
  DBUG_RETURN(THDVAR(thd, semi_table_lock_connection) == -1 ?
    semi_table_lock_connection : THDVAR(thd, semi_table_lock_connection));
}

/*
  0-:block_size
 */
static MYSQL_THDVAR_UINT(
  block_size, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Index block size", /* comment */
  NULL, /* check */
  NULL, /* update */
  16384, /* def */
  0, /* min */
  4294967295U, /* max */
  0 /* blk */
);

uint spider_param_block_size(
  THD *thd
) {
  DBUG_ENTER("spider_param_block_size");
  DBUG_RETURN(THDVAR(thd, block_size));
}

/*
 -1 :use table parameter
  0 :off
  1 :lock in share mode
  2 :for update
 */
static MYSQL_THDVAR_INT(
  selupd_lock_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Lock for select with update", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_selupd_lock_mode(
  THD *thd,
  int selupd_lock_mode
) {
  DBUG_ENTER("spider_param_selupd_lock_mode");
  DBUG_RETURN(THDVAR(thd, selupd_lock_mode) == -1 ?
    selupd_lock_mode : THDVAR(thd, selupd_lock_mode));
}

/*
  FALSE: no sync
  TRUE:  sync
 */
static MYSQL_THDVAR_BOOL(
  sync_autocommit, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Sync autocommit", /* comment */
  NULL, /* check */
  NULL, /* update */
  TRUE /* def */
);

bool spider_param_sync_autocommit(
  THD *thd
) {
  DBUG_ENTER("spider_param_sync_autocommit");
  DBUG_RETURN(THDVAR(thd, sync_autocommit));
}

/*
  FALSE: not use
  TRUE:  use
 */
static MYSQL_THDVAR_BOOL(
  use_default_database, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Use default database", /* comment */
  NULL, /* check */
  NULL, /* update */
  TRUE /* def */
);

bool spider_param_use_default_database(
  THD *thd
) {
  DBUG_ENTER("spider_param_use_default_database");
  DBUG_RETURN(THDVAR(thd, use_default_database));
}

/*
-1 :don't know or does not matter; don't send 'SET SQL_LOG_OFF' statement
 0 :do send 'SET SQL_LOG_OFF 0' statement to data nodes
 1 :do send 'SET SQL_LOG_OFF 1' statement to data nodes
*/
static MYSQL_THDVAR_INT(
  internal_sql_log_off,                                  /* name */
  PLUGIN_VAR_RQCMDARG,                                   /* opt */
  "Manage SQL_LOG_OFF mode statement to the data nodes", /* comment */
  NULL,                                                  /* check */
  NULL,                                                  /* update */
  -1,                                                    /* default */
  -1,                                                    /* min */
  1,                                                     /* max */
  0                                                      /* blk */
);

int spider_param_internal_sql_log_off(
  THD *thd
) {
  DBUG_ENTER("spider_param_internal_sql_log_off");
  DBUG_RETURN(THDVAR(thd, internal_sql_log_off));
}

/*
 -1 :use table parameter
  0-:bulk insert size
 */
static MYSQL_THDVAR_INT(
  bulk_size, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Bulk insert size", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  16000, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_bulk_size(
  THD *thd,
  int bulk_size
) {
  DBUG_ENTER("spider_param_bulk_size");
  DBUG_RETURN(THDVAR(thd, bulk_size) < 0 ?
    bulk_size : THDVAR(thd, bulk_size));
}

/*
 -1 :use table parameter
  0 : Send "update" and "delete" statements one by one.
  1 : Send collected multiple "update" and "delete" statements.
      (Collected statements are sent one by one)
  2 : Send collected multiple "update" and "delete" statements.
      (Collected statements are sent together)
 */
static MYSQL_THDVAR_INT(
  bulk_update_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "The mode of bulk updating and deleting", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_bulk_update_mode(
  THD *thd,
  int bulk_update_mode
) {
  DBUG_ENTER("spider_param_bulk_update_mode");
  DBUG_RETURN(THDVAR(thd, bulk_update_mode) == -1 ?
    bulk_update_mode : THDVAR(thd, bulk_update_mode));
}

/*
 -1 :use table parameter
  0-:bulk update size
 */
static MYSQL_THDVAR_INT(
  bulk_update_size, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Bulk update size", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  16000, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_bulk_update_size(
  THD *thd,
  int bulk_update_size
) {
  DBUG_ENTER("spider_param_bulk_update_size");
  DBUG_RETURN(THDVAR(thd, bulk_update_size) == -1 ?
    bulk_update_size : THDVAR(thd, bulk_update_size));
}

/*
 -1 :use table parameter
  0-:buffer size
 */
static MYSQL_THDVAR_INT(
  buffer_size, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Buffer size", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  16000, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_buffer_size(
  THD *thd,
  int buffer_size
) {
  DBUG_ENTER("spider_param_buffer_size");
  DBUG_RETURN(THDVAR(thd, buffer_size) == -1 ?
    buffer_size : THDVAR(thd, buffer_size));
}

/*
 -1 :use table parameter
  0 :off
  1 :on
 */
static MYSQL_THDVAR_INT(
  internal_optimize, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Execute optimize to remote server", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_internal_optimize(
  THD *thd,
  int internal_optimize
) {
  DBUG_ENTER("spider_param_internal_optimize");
  DBUG_RETURN(THDVAR(thd, internal_optimize) == -1 ?
    internal_optimize : THDVAR(thd, internal_optimize));
}

/*
 -1 :use table parameter
  0 :off
  1 :on
 */
static MYSQL_THDVAR_INT(
  internal_optimize_local, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Execute optimize to remote server with local", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_internal_optimize_local(
  THD *thd,
  int internal_optimize_local
) {
  DBUG_ENTER("spider_param_internal_optimize_local");
  DBUG_RETURN(THDVAR(thd, internal_optimize_local) == -1 ?
    internal_optimize_local : THDVAR(thd, internal_optimize_local));
}

/*
  FALSE: off
  TRUE:  on
 */
static MYSQL_THDVAR_BOOL(
  use_flash_logs, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Execute flush logs to remote server", /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

bool spider_param_use_flash_logs(
  THD *thd
) {
  DBUG_ENTER("spider_param_use_flash_logs");
  DBUG_RETURN(THDVAR(thd, use_flash_logs));
}

/*
  0 :off
  1 :flush tables with read lock
  2 :flush tables another connection
 */
static MYSQL_THDVAR_INT(
  use_snapshot_with_flush_tables, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Execute optimize to remote server with local", /* comment */
  NULL, /* check */
  NULL, /* update */
  0, /* def */
  0, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_use_snapshot_with_flush_tables(
  THD *thd
) {
  DBUG_ENTER("spider_param_use_snapshot_with_flush_tables");
  DBUG_RETURN(THDVAR(thd, use_snapshot_with_flush_tables));
}

/*
  FALSE: off
  TRUE:  on
 */
static MYSQL_THDVAR_BOOL(
  use_all_conns_snapshot, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "When start trx with snapshot, it send to all connections", /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

bool spider_param_use_all_conns_snapshot(
  THD *thd
) {
  DBUG_ENTER("spider_param_use_all_conns_snapshot");
  DBUG_RETURN(THDVAR(thd, use_all_conns_snapshot));
}

/*
  FALSE: off
  TRUE:  on
 */
static MYSQL_THDVAR_BOOL(
  lock_exchange, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Exchange select lock to lock tables", /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

bool spider_param_lock_exchange(
  THD *thd
) {
  DBUG_ENTER("spider_param_lock_exchange");
  DBUG_RETURN(THDVAR(thd, lock_exchange));
}

/*
  FALSE: off
  TRUE:  on
 */
static MYSQL_THDVAR_BOOL(
  internal_unlock, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Unlock tables for using connections in sql", /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

bool spider_param_internal_unlock(
  THD *thd
) {
  DBUG_ENTER("spider_param_internal_unlock");
  DBUG_RETURN(THDVAR(thd, internal_unlock));
}

/*
  FALSE: off
  TRUE:  on
 */
static MYSQL_THDVAR_BOOL(
  semi_trx, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Take a transaction during execute a sql", /* comment */
  NULL, /* check */
  NULL, /* update */
  TRUE /* def */
);

bool spider_param_semi_trx(
  THD *thd
) {
  DBUG_ENTER("spider_param_semi_trx");
  DBUG_RETURN(THDVAR(thd, semi_trx));
}

/*
 -1 :use table parameter
  0-:seconds of timeout
 */
static MYSQL_THDVAR_INT(
  connect_timeout, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Wait timeout of connecting to remote server", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  6, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_connect_timeout(
  THD *thd,
  int connect_timeout
) {
  DBUG_ENTER("spider_param_connect_timeout");
  if (thd)
    DBUG_RETURN(THDVAR(thd, connect_timeout) == -1 ?
      connect_timeout : THDVAR(thd, connect_timeout));
  DBUG_RETURN(connect_timeout);
}

/*
 -1 :use table parameter
  0-:seconds of timeout
 */
static MYSQL_THDVAR_INT(
  net_read_timeout, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Wait timeout of receiving data from remote server", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  600, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_net_read_timeout(
  THD *thd,
  int net_read_timeout
) {
  DBUG_ENTER("spider_param_net_read_timeout");
  if (thd)
    DBUG_RETURN(THDVAR(thd, net_read_timeout) == -1 ?
      net_read_timeout : THDVAR(thd, net_read_timeout));
  DBUG_RETURN(net_read_timeout);
}

/*
 -1 :use table parameter
  0-:seconds of timeout
 */
static MYSQL_THDVAR_INT(
  net_write_timeout, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Wait timeout of sending data to remote server", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  600, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_net_write_timeout(
  THD *thd,
  int net_write_timeout
) {
  DBUG_ENTER("spider_param_net_write_timeout");
  if (thd)
    DBUG_RETURN(THDVAR(thd, net_write_timeout) == -1 ?
      net_write_timeout : THDVAR(thd, net_write_timeout));
  DBUG_RETURN(net_write_timeout);
}

/*
 -1 :use table parameter
  0 :It acquires it collectively.
  1 :Acquisition one by one.If it discontinues once, and it will need
     it later, it retrieves it again when there is interrupt on the way.
  2 :Acquisition one by one.Interrupt is waited for until end of getting
     result when there is interrupt on the way.
 */
static MYSQL_THDVAR_INT(
  quick_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "The retrieval result from a remote server is acquired by acquisition one by one", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  3, /* def */
  -1, /* min */
  3, /* max */
  0 /* blk */
);

int spider_param_quick_mode(
  THD *thd,
  int quick_mode
) {
  DBUG_ENTER("spider_param_quick_mode");
  DBUG_RETURN(THDVAR(thd, quick_mode) < 0 ?
    quick_mode : THDVAR(thd, quick_mode));
}

/*
 -1 :use table parameter
  0-:number of records
 */
static MYSQL_THDVAR_LONGLONG(
  quick_page_size, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Number of records in a page when acquisition one by one", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1024, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_quick_page_size(
  THD *thd,
  longlong quick_page_size
) {
  DBUG_ENTER("spider_param_quick_page_size");
  DBUG_RETURN(THDVAR(thd, quick_page_size) < 0 ?
    quick_page_size : THDVAR(thd, quick_page_size));
}

/*
 -1 :use table parameter
  0-:the limitation of memory size
 */
static MYSQL_THDVAR_LONGLONG(
  quick_page_byte, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "The limitation of memory size in a page when acquisition one by one", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  10485760, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_quick_page_byte(
  THD *thd,
  longlong quick_page_byte
) {
  DBUG_ENTER("spider_param_quick_page_byte");
  DBUG_RETURN(THDVAR(thd, quick_page_byte) < 0 ?
    quick_page_byte : THDVAR(thd, quick_page_byte));
}

/*
 -1 :use table parameter
  0 :It doesn't use low memory mode.
  1 :It uses low memory mode.
 */
static MYSQL_THDVAR_INT(
  low_mem_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Use low memory mode when SQL(SELECT) internally issued to a remote server is executed and get a result list", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_low_mem_read(
  THD *thd,
  int low_mem_read
) {
  DBUG_ENTER("spider_param_low_mem_read");
  DBUG_RETURN(THDVAR(thd, low_mem_read) < 0 ?
    low_mem_read : THDVAR(thd, low_mem_read));
}

/*
 -1 :use table parameter
  0 :Use index columns if select statement can solve by using index,
     otherwise use all columns.
  1 :Use columns that are judged necessary.
 */
static MYSQL_THDVAR_INT(
  select_column_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "The mode of using columns at select clause", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_select_column_mode(
  THD *thd,
  int select_column_mode
) {
  DBUG_ENTER("spider_param_select_column_mode");
  DBUG_RETURN(THDVAR(thd, select_column_mode) == -1 ?
    select_column_mode : THDVAR(thd, select_column_mode));
}

/*
 -1 :use table parameter
  0 :background search is disabled
  1 :background search is used if search with no lock
  2 :background search is used if search with no lock or shared lock
  3 :background search is used regardless of the lock
 */
static MYSQL_THDVAR_INT(
  bgs_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Mode of background search", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  3, /* max */
  0 /* blk */
);

int spider_param_bgs_mode(
  THD *thd,
  int bgs_mode
) {
  DBUG_ENTER("spider_param_bgs_mode");
  DBUG_RETURN(THDVAR(thd, bgs_mode) < 0 ?
    bgs_mode : THDVAR(thd, bgs_mode));
}

/*
 -1 :use table parameter
  0 :records is gotten usually
  1-:number of records
 */
static MYSQL_THDVAR_LONGLONG(
  bgs_first_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Number of first read records when background search is used", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  2, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_bgs_first_read(
  THD *thd,
  longlong bgs_first_read
) {
  DBUG_ENTER("spider_param_bgs_first_read");
  DBUG_RETURN(THDVAR(thd, bgs_first_read) < 0 ?
    bgs_first_read : THDVAR(thd, bgs_first_read));
}

/*
 -1 :use table parameter
  0 :records is gotten usually
  1-:number of records
 */
static MYSQL_THDVAR_LONGLONG(
  bgs_second_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Number of second read records when background search is used", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  100, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_bgs_second_read(
  THD *thd,
  longlong bgs_second_read
) {
  DBUG_ENTER("spider_param_bgs_second_read");
  DBUG_RETURN(THDVAR(thd, bgs_second_read) < 0 ?
    bgs_second_read : THDVAR(thd, bgs_second_read));
}

/*
 -1 :use table parameter
  0 :records is gotten usually
  1-:number of records
 */
static MYSQL_THDVAR_LONGLONG(
  first_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Number of first read records", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_first_read(
  THD *thd,
  longlong first_read
) {
  DBUG_ENTER("spider_param_first_read");
  DBUG_RETURN(THDVAR(thd, first_read) < 0 ?
    first_read : THDVAR(thd, first_read));
}

/*
 -1 :use table parameter
  0 :records is gotten usually
  1-:number of records
 */
static MYSQL_THDVAR_LONGLONG(
  second_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Number of second read records", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_second_read(
  THD *thd,
  longlong second_read
) {
  DBUG_ENTER("spider_param_second_read");
  DBUG_RETURN(THDVAR(thd, second_read) < 0 ?
    second_read : THDVAR(thd, second_read));
}

/*
 -1 :use table parameter
  0 :always get the newest information
  1-:interval
 */
static MYSQL_THDVAR_INT(
  crd_interval, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Interval of cardinality confirmation.(second)", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  51, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

double spider_param_crd_interval(
  THD *thd,
  double crd_interval
) {
  DBUG_ENTER("spider_param_crd_interval");
  DBUG_RETURN(THDVAR(thd, crd_interval) == -1 ?
    crd_interval : THDVAR(thd, crd_interval));
}

/*
 -1 :use table parameter
  0 :use table parameter
  1 :use show command
  2 :use information schema
  3 :use explain
 */
static MYSQL_THDVAR_INT(
  crd_mode, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Mode of cardinality confirmation.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  3, /* max */
  0 /* blk */
);

int spider_param_crd_mode(
  THD *thd,
  int crd_mode
) {
  DBUG_ENTER("spider_param_crd_mode");
  DBUG_RETURN(THDVAR(thd, crd_mode) <= 0 ?
    crd_mode : THDVAR(thd, crd_mode));
}

/*
 -1 :use table parameter
  0 :No synchronization.
  1 :Cardinality is synchronized when opening a table.
     Then no synchronization.
  2 :Synchronization.
 */
static MYSQL_THDVAR_INT(
  crd_sync, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Cardinality synchronization in partitioned table.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_crd_sync(
  THD *thd,
  int crd_sync
) {
  DBUG_ENTER("spider_param_crd_sync");
  DBUG_RETURN(THDVAR(thd, crd_sync) == -1 ?
    crd_sync : THDVAR(thd, crd_sync));
}

/*
 -1 :use table parameter
  0 :The crd_weight is used as a fixed value.
  1 :The crd_weight is used as an addition value.
  2 :The crd_weight is used as a multiplication value.
 */
static MYSQL_THDVAR_INT(
  crd_type, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Type of cardinality calculation.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  2, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_crd_type(
  THD *thd,
  int crd_type
) {
  DBUG_ENTER("spider_param_crd_type");
  DBUG_RETURN(THDVAR(thd, crd_type) == -1 ?
    crd_type : THDVAR(thd, crd_type));
}

/*
 -1 :use table parameter
  0-:weight
 */
static MYSQL_THDVAR_INT(
  crd_weight, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Weight coefficient to calculate effectiveness of index from cardinality of column.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  2, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

double spider_param_crd_weight(
  THD *thd,
  double crd_weight
) {
  DBUG_ENTER("spider_param_crd_weight");
  DBUG_RETURN(THDVAR(thd, crd_weight) == -1 ?
    crd_weight : THDVAR(thd, crd_weight));
}

/*
 -1 :use table parameter
  0 :Background confirmation is disabled
  1 :Background confirmation is enabled (create thread per table/partition)
  2 :Background confirmation is enabled (use static threads)
 */
static MYSQL_THDVAR_INT(
  crd_bg_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Mode of cardinality confirmation at background.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  2, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_crd_bg_mode(
  THD *thd,
  int crd_bg_mode
) {
  DBUG_ENTER("spider_param_crd_bg_mode");
  DBUG_RETURN(THDVAR(thd, crd_bg_mode) == -1 ?
    crd_bg_mode : THDVAR(thd, crd_bg_mode));
}

/*
 -1 :use table parameter
  0 :always get the newest information
  1-:interval
 */
static MYSQL_THDVAR_INT(
  sts_interval, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Interval of table state confirmation.(second)", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  10, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

double spider_param_sts_interval(
  THD *thd,
  double sts_interval
) {
  DBUG_ENTER("spider_param_sts_interval");
  DBUG_RETURN(THDVAR(thd, sts_interval) == -1 ?
    sts_interval : THDVAR(thd, sts_interval));
}

/*
 -1 :use table parameter
  0 :use table parameter
  1 :use show command
  2 :use information schema
 */
static MYSQL_THDVAR_INT(
  sts_mode, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "Mode of table state confirmation.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_sts_mode(
  THD *thd,
  int sts_mode
) {
  DBUG_ENTER("spider_param_sts_mode");
  DBUG_RETURN(THDVAR(thd, sts_mode) <= 0 ?
    sts_mode : THDVAR(thd, sts_mode));
}

/*
 -1 :use table parameter
  0 :No synchronization.
  1 :Table state is synchronized when opening a table.
     Then no synchronization.
  2 :Synchronization.
 */
static MYSQL_THDVAR_INT(
  sts_sync, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Table state synchronization in partitioned table.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_sts_sync(
  THD *thd,
  int sts_sync
) {
  DBUG_ENTER("spider_param_sts_sync");
  DBUG_RETURN(THDVAR(thd, sts_sync) == -1 ?
    sts_sync : THDVAR(thd, sts_sync));
}

/*
 -1 :use table parameter
  0 :Background confirmation is disabled
  1 :Background confirmation is enabled (create thread per table/partition)
  2 :Background confirmation is enabled (use static threads)
 */
static MYSQL_THDVAR_INT(
  sts_bg_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Mode of table state confirmation at background.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  2, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_sts_bg_mode(
  THD *thd,
  int sts_bg_mode
) {
  DBUG_ENTER("spider_param_sts_bg_mode");
  DBUG_RETURN(THDVAR(thd, sts_bg_mode) == -1 ?
    sts_bg_mode : THDVAR(thd, sts_bg_mode));
}

/*
  0 :always ping
  1-:interval
 */
static MYSQL_THDVAR_INT(
  ping_interval_at_trx_start, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Ping interval at transaction start", /* comment */
  NULL, /* check */
  NULL, /* update */
  3600, /* def */
  0, /* min */
  2147483647, /* max */
  0 /* blk */
);

double spider_param_ping_interval_at_trx_start(
  THD *thd
) {
  DBUG_ENTER("spider_param_ping_interval_at_trx_start");
  DBUG_RETURN(THDVAR(thd, ping_interval_at_trx_start));
}

/*
 -1 :use table parameter
  0 :normal mode
  1 :quick mode
  2 :set 0 value
 */
static MYSQL_THDVAR_INT(
  auto_increment_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Mode of auto increment.", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  3, /* max */
  0 /* blk */
);

int spider_param_auto_increment_mode(
  THD *thd,
  int auto_increment_mode
) {
  DBUG_ENTER("spider_param_auto_increment_mode");
  DBUG_RETURN(THDVAR(thd, auto_increment_mode) == -1 ?
    auto_increment_mode : THDVAR(thd, auto_increment_mode));
}

/*
  FALSE: off
  TRUE:  on
 */
static MYSQL_THDVAR_BOOL(
  same_server_link, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Permit one to link same server's table", /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

bool spider_param_same_server_link(
  THD *thd
) {
  DBUG_ENTER("spider_param_same_server_link");
  DBUG_RETURN(THDVAR(thd, same_server_link));
}

/*
  FALSE: transmits
  TRUE:  don't transmit
 */
static MYSQL_THDVAR_BOOL(
  local_lock_table, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Remote server transmission when lock tables is executed at local",
    /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

bool spider_param_local_lock_table(
  THD *thd
) {
  DBUG_ENTER("spider_param_local_lock_table");
  DBUG_RETURN(THDVAR(thd, local_lock_table));
}

/*
 -1 :use table parameter
  0 :don't transmit
  1 :transmits
 */
static MYSQL_THDVAR_INT(
  use_pushdown_udf, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Remote server transmission existence when UDF is used at condition and \"engine_condition_pushdown=1\"", /* comment */
  NULL, /* check */
  NULL, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_use_pushdown_udf(
  THD *thd,
  int use_pushdown_udf
) {
  DBUG_ENTER("spider_param_use_pushdown_udf");
  DBUG_RETURN(THDVAR(thd, use_pushdown_udf) == -1 ?
    use_pushdown_udf : THDVAR(thd, use_pushdown_udf));
}

/*
 -1 :use table parameter
  0 :duplicate check on local server
  1 :avoid duplicate check on local server
 */
static MYSQL_THDVAR_INT(
  direct_dup_insert, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Execute \"REPLACE\" and \"INSERT IGNORE\" on remote server and avoid duplicate check on local server", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_direct_dup_insert(
  THD *thd,
  int direct_dup_insert
) {
  DBUG_ENTER("spider_param_direct_dup_insert");
  DBUG_RETURN(THDVAR(thd, direct_dup_insert) < 0 ?
    direct_dup_insert : THDVAR(thd, direct_dup_insert));
}

static char *spider_remote_access_charset;
/*
 */
static MYSQL_SYSVAR_STR(
  remote_access_charset,
  spider_remote_access_charset,
  PLUGIN_VAR_MEMALLOC |
  PLUGIN_VAR_RQCMDARG,
  "Set remote access charset at connecting for improvement performance of connection if you know",
  NULL,
  NULL,
  NULL
);

char *spider_param_remote_access_charset()
{
  DBUG_ENTER("spider_param_remote_access_charset");
  DBUG_RETURN(spider_remote_access_charset);
}

static int spider_remote_autocommit;
/*
 -1 :don't set
  0 :autocommit = 0
  1 :autocommit = 1
 */
static MYSQL_SYSVAR_INT(
  remote_autocommit,
  spider_remote_autocommit,
  PLUGIN_VAR_RQCMDARG,
  "Set autocommit mode at connecting for improvement performance of connection if you know",
  NULL,
  NULL,
  -1,
  -1,
  1,
  0
);

int spider_param_remote_autocommit()
{
  DBUG_ENTER("spider_param_remote_autocommit");
  DBUG_RETURN(spider_remote_autocommit);
}

static char *spider_remote_time_zone;
/*
 */
static MYSQL_SYSVAR_STR(
  remote_time_zone,
  spider_remote_time_zone,
  PLUGIN_VAR_MEMALLOC |
  PLUGIN_VAR_RQCMDARG,
  "Set remote time_zone at connecting for improvement performance of connection if you know",
  NULL,
  NULL,
  NULL
);

char *spider_param_remote_time_zone()
{
  DBUG_ENTER("spider_param_remote_time_zone");
  DBUG_RETURN(spider_remote_time_zone);
}

static int spider_remote_sql_log_off;
/*
 -1 :don't know the value on all data nodes, or does not matter
  0 :sql_log_off = 0 on all data nodes
  1 :sql_log_off = 1 on all data nodes
 */
static MYSQL_SYSVAR_INT(
  remote_sql_log_off,
  spider_remote_sql_log_off,
  PLUGIN_VAR_RQCMDARG,
  "Set SQL_LOG_OFF mode on connecting for improved performance of connection, if you know",
  NULL,
  NULL,
  -1,
  -1,
  1,
  0
);

int spider_param_remote_sql_log_off()
{
  DBUG_ENTER("spider_param_remote_sql_log_off");
  DBUG_RETURN(spider_remote_sql_log_off);
}

static int spider_remote_trx_isolation;
/*
 -1 :don't set
  0 :READ UNCOMMITTED
  1 :READ COMMITTED
  2 :REPEATABLE READ
  3 :SERIALIZABLE
 */
static MYSQL_SYSVAR_INT(
  remote_trx_isolation,
  spider_remote_trx_isolation,
  PLUGIN_VAR_RQCMDARG,
  "Set transaction isolation level at connecting for improvement performance of connection if you know",
  NULL,
  NULL,
  -1,
  -1,
  3,
  0
);

int spider_param_remote_trx_isolation()
{
  DBUG_ENTER("spider_param_remote_trx_isolation");
  DBUG_RETURN(spider_remote_trx_isolation);
}

static char *spider_remote_default_database;
/*
 */
static MYSQL_SYSVAR_STR(
  remote_default_database,
  spider_remote_default_database,
  PLUGIN_VAR_MEMALLOC |
  PLUGIN_VAR_RQCMDARG,
  "Set remote database at connecting for improvement performance of connection if you know",
  NULL,
  NULL,
  NULL
);

char *spider_param_remote_default_database()
{
  DBUG_ENTER("spider_param_remote_default_database");
  DBUG_RETURN(spider_remote_default_database);
}

/*
  0-:connect retry interval (micro second)
 */
static MYSQL_THDVAR_LONGLONG(
  connect_retry_interval, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Connect retry interval", /* comment */
  NULL, /* check */
  NULL, /* update */
  1000, /* def */
  0, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_connect_retry_interval(
  THD *thd
) {
  DBUG_ENTER("spider_param_connect_retry_interval");
  if (thd)
    DBUG_RETURN(THDVAR(thd, connect_retry_interval));
  DBUG_RETURN(0);
}

/*
  0-:connect retry count
 */
static MYSQL_THDVAR_INT(
  connect_retry_count, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Connect retry count", /* comment */
  NULL, /* check */
  NULL, /* update */
  1000, /* def */
  0, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_connect_retry_count(
  THD *thd
) {
  DBUG_ENTER("spider_param_connect_retry_count");
  if (thd)
    DBUG_RETURN(THDVAR(thd, connect_retry_count));
  DBUG_RETURN(0);
}

/*
 */
static MYSQL_THDVAR_STR(
  bka_engine, /* name */
  PLUGIN_VAR_MEMALLOC |
  PLUGIN_VAR_RQCMDARG,
  "Temporary table's engine for BKA", /* comment */
  NULL, /* check */
  NULL, /* update */
  NULL /* def */
);

char *spider_param_bka_engine(
  THD *thd,
  char *bka_engine
) {
  DBUG_ENTER("spider_param_bka_engine");
  DBUG_RETURN(THDVAR(thd, bka_engine) ?
    THDVAR(thd, bka_engine) : bka_engine);
}

/*
 -1 :use table parameter
  0 :use union all
  1 :use temporary table
 */
static MYSQL_THDVAR_INT(
  bka_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Mode of BKA for Spider", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  2, /* max */
  0 /* blk */
);

int spider_param_bka_mode(
  THD *thd,
  int bka_mode
) {
  DBUG_ENTER("spider_param_bka_mode");
  DBUG_RETURN(THDVAR(thd, bka_mode) == -1 ?
    bka_mode : THDVAR(thd, bka_mode));
}

/*
 -1 :use table parameter
  0 :return error if error
  1 :return 0 record if error
 */
static MYSQL_THDVAR_INT(
  error_read_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Read error mode if error", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_error_read_mode(
  THD *thd,
  int error_read_mode
) {
  DBUG_ENTER("spider_param_error_read_mode");
  DBUG_RETURN(THDVAR(thd, error_read_mode) == -1 ?
    error_read_mode : THDVAR(thd, error_read_mode));
}

/*
 -1 :use table parameter
  0 :return error if error
  1 :return 0 record if error
 */
static MYSQL_THDVAR_INT(
  error_write_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Write error mode if error", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_error_write_mode(
  THD *thd,
  int error_write_mode
) {
  DBUG_ENTER("spider_param_error_write_mode");
  DBUG_RETURN(THDVAR(thd, error_write_mode) == -1 ?
    error_write_mode : THDVAR(thd, error_write_mode));
}

/*
 -1 :use table parameter
  0 :not skip
  1 :skip
 */
static MYSQL_THDVAR_INT(
  skip_default_condition, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Skip generating internal default condition", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_skip_default_condition(
  THD *thd,
  int skip_default_condition
) {
  DBUG_ENTER("spider_param_skip_default_condition");
  DBUG_RETURN(THDVAR(thd, skip_default_condition) == -1 ?
    skip_default_condition : THDVAR(thd, skip_default_condition));
}

/*
 -1 :use table parameter
  0 :not skip
  1 :skip parallel search if query is not SELECT statement
  2 :skip parallel search if query has SQL_NO_CACHE
  3 :1+2
 */
static MYSQL_THDVAR_INT(
  skip_parallel_search, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Skip parallel search by specific conditions", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  3, /* max */
  0 /* blk */
);

int spider_param_skip_parallel_search(
  THD *thd,
  int skip_parallel_search
) {
  DBUG_ENTER("spider_param_skip_parallel_search");
  DBUG_RETURN(THDVAR(thd, skip_parallel_search) == -1 ?
    skip_parallel_search : THDVAR(thd, skip_parallel_search));
}

/*
 -1 :use table parameter
  0 :not send directly
  1-:send directly
 */
static MYSQL_THDVAR_LONGLONG(
  direct_order_limit, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Send 'ORDER BY' and 'LIMIT' to remote server directly", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  9223372036854775807LL, /* def */
  -1, /* min */
  9223372036854775807LL, /* max */
  0 /* blk */
);

longlong spider_param_direct_order_limit(
  THD *thd,
  longlong direct_order_limit
) {
  DBUG_ENTER("spider_param_direct_order_limit");
  DBUG_RETURN(THDVAR(thd, direct_order_limit) == -1 ?
    direct_order_limit : THDVAR(thd, direct_order_limit));
}

/*
 -1 :use table parameter
  0 :writable
  1 :read only
 */
static MYSQL_THDVAR_INT(
  read_only_mode, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Read only", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_read_only_mode(
  THD *thd,
  int read_only_mode
) {
  DBUG_ENTER("spider_param_read_only_mode");
  DBUG_RETURN(THDVAR(thd, read_only_mode) == -1 ?
    read_only_mode : THDVAR(thd, read_only_mode));
}

static my_bool spider_general_log;
static MYSQL_SYSVAR_BOOL(
  general_log,
  spider_general_log,
  PLUGIN_VAR_OPCMDARG,
  "Log query to remote server in general log",
  NULL,
  NULL,
  FALSE
);

my_bool spider_param_general_log()
{
  DBUG_ENTER("spider_param_general_log");
  DBUG_RETURN(spider_general_log);
}

/*
  FALSE: no pushdown hints
  TRUE:  pushdown hints
 */
static MYSQL_THDVAR_BOOL(
  index_hint_pushdown, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "switch to control if push down index hint, like force_index", /* comment */
  NULL, /* check */
  NULL, /* update */
  FALSE /* def */
);

my_bool spider_param_index_hint_pushdown(
  THD *thd
) {
  DBUG_ENTER("spider_param_index_hint_pushdown");
  DBUG_RETURN(THDVAR(thd, index_hint_pushdown));
}

static uint spider_max_connections;
static MYSQL_SYSVAR_UINT(
  max_connections,
  spider_max_connections,
  PLUGIN_VAR_RQCMDARG,
  "the values, as the max conncetion from spider to remote mysql. Default 0, mean unlimit the connections",
  NULL,
  NULL,
  0, /* def */
  0, /* min */
  99999, /* max */
  0 /* blk */
);

uint spider_param_max_connections()
{
  DBUG_ENTER("spider_param_max_connections");
  DBUG_RETURN(spider_max_connections);
}

static uint spider_conn_wait_timeout;
static MYSQL_SYSVAR_UINT(
  conn_wait_timeout,
  spider_conn_wait_timeout,
  PLUGIN_VAR_RQCMDARG,
  "the values, as the max waiting time when spider get a remote conn",
  NULL,
  NULL,
  10, /* def */
  0, /* min */
  1000, /* max */
  0 /* blk */
);

uint spider_param_conn_wait_timeout()
{
  DBUG_ENTER("spider_param_conn_wait_timeout");
  DBUG_RETURN(spider_conn_wait_timeout);
}

static uint spider_log_result_errors;
/*
  0: no log
  1: log error
  2: log warning summary
  3: log warning
  4: log info
 */
static MYSQL_SYSVAR_UINT(
  log_result_errors,
  spider_log_result_errors,
  PLUGIN_VAR_RQCMDARG,
  "Log error from remote server in error log",
  NULL,
  NULL,
  0,
  0,
  4,
  0
);

uint spider_param_log_result_errors()
{
  DBUG_ENTER("spider_param_log_result_errors");
  DBUG_RETURN(spider_log_result_errors);
}

static uint spider_log_result_error_with_sql;
/*
  0: no log
  1: log spider sql at logging result errors
  2: log user sql at logging result errors
  3: log both sql at logging result errors
 */
static MYSQL_SYSVAR_UINT(
  log_result_error_with_sql,
  spider_log_result_error_with_sql,
  PLUGIN_VAR_RQCMDARG,
  "Log sql at logging result errors",
  NULL,
  NULL,
  0,
  0,
  3,
  0
);

uint spider_param_log_result_error_with_sql()
{
  DBUG_ENTER("spider_param_log_result_error_with_sql");
  DBUG_RETURN(spider_log_result_error_with_sql);
}

/*
  0: server_id + thread_id
  1: server_id + thread_id + query_id
 */
static MYSQL_THDVAR_UINT(
  internal_xa_id_type, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "The type of internal_xa id", /* comment */
  NULL, /* check */
  NULL, /* update */
  0, /* def */
  0, /* min */
  1, /* max */
  0 /* blk */
);

uint spider_param_internal_xa_id_type(
  THD *thd
) {
  DBUG_ENTER("spider_param_internal_xa_id_type");
  DBUG_RETURN(THDVAR(thd, internal_xa_id_type));
}

/*
 -1 :use table parameter
  0 :OFF
  1 :automatic channel
  2-63 :use custom channel
 */
static MYSQL_THDVAR_INT(
  casual_read, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Read casually if it is possible", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  63, /* max */
  0 /* blk */
);

int spider_param_casual_read(
  THD *thd,
  int casual_read
) {
  DBUG_ENTER("spider_param_casual_read");
  DBUG_RETURN(THDVAR(thd, casual_read) == -1 ?
    casual_read : THDVAR(thd, casual_read));
}

static my_bool spider_dry_access;
static MYSQL_SYSVAR_BOOL(
  dry_access,
  spider_dry_access,
  PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
  "dry access",
  NULL,
  NULL,
  FALSE
);

my_bool spider_param_dry_access()
{
  DBUG_ENTER("spider_param_dry_access");
  DBUG_RETURN(spider_dry_access);
}

/*
 -1 :use table parameter
  0 :fast
  1 :correct delete row number
 */
static MYSQL_THDVAR_INT(
  delete_all_rows_type, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "The type of delete_all_rows", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_delete_all_rows_type(
  THD *thd,
  int delete_all_rows_type
) {
  DBUG_ENTER("spider_param_delete_all_rows_type");
  DBUG_RETURN(THDVAR(thd, delete_all_rows_type) == -1 ?
    delete_all_rows_type : THDVAR(thd, delete_all_rows_type));
}

/*
 -1 :use table parameter
  0 :compact
  1 :add original table name
 */
static MYSQL_THDVAR_INT(
  bka_table_name_type, /* name */
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, /* opt */
  "The type of temporary table name for bka", /* comment */
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  0, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_bka_table_name_type(
  THD *thd,
  int bka_table_name_type
) {
  DBUG_ENTER("spider_param_bka_table_name_type");
  DBUG_RETURN(THDVAR(thd, bka_table_name_type) == -1 ?
    bka_table_name_type : THDVAR(thd, bka_table_name_type));
}

/*
 -1 :use table parameter
  0 :off
  1 :on
 */
static MYSQL_THDVAR_INT(
  use_cond_other_than_pk_for_update, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Use all conditions even if condition has pk", /* comment */
  NULL, /* check */
  NULL, /* update */
  1, /* def */
  0, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_use_cond_other_than_pk_for_update(
  THD *thd
) {
  DBUG_ENTER("spider_param_reset_sql_alloc");
  DBUG_RETURN(THDVAR(thd, use_cond_other_than_pk_for_update));
}

static int spider_store_last_sts;
/*
 -1 : use table parameter
  0 : do not store
  1 : do store
 */
static MYSQL_SYSVAR_INT(
  store_last_sts,
  spider_store_last_sts,
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
  "Store last sts result into system table",
  NULL,
  spider_var_deprecated_int,
  1,
  -1,
  1,
  0
);

int spider_param_store_last_sts(
  int store_last_sts
) {
  DBUG_ENTER("spider_param_store_last_sts");
  DBUG_RETURN(spider_store_last_sts == -1 ?
    store_last_sts : spider_store_last_sts);
}

static int spider_store_last_crd;
/*
 -1 : use table parameter
  0 : do not store
  1 : do store
 */
static MYSQL_SYSVAR_INT(
  store_last_crd,
  spider_store_last_crd,
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
  "Store last crd result into system table",
  NULL,
  spider_var_deprecated_int,
  1,
  -1,
  1,
  0
);

int spider_param_store_last_crd(
  int store_last_crd
) {
  DBUG_ENTER("spider_param_store_last_crd");
  DBUG_RETURN(spider_store_last_crd == -1 ?
    store_last_crd : spider_store_last_crd);
}

static int spider_load_sts_at_startup;
/*
 -1 : use table parameter
  0 : do not load
  1 : do load
 */
static MYSQL_SYSVAR_INT(
  load_sts_at_startup,
  spider_load_sts_at_startup,
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
  "Load sts from system table at startup",
  NULL,
  spider_var_deprecated_int,
  1,
  -1,
  1,
  0
);

int spider_param_load_sts_at_startup(
  int load_sts_at_startup
) {
  DBUG_ENTER("spider_param_load_sts_at_startup");
  DBUG_RETURN(spider_load_sts_at_startup == -1 ?
    load_sts_at_startup : spider_load_sts_at_startup);
}

static int spider_load_crd_at_startup;
/*
 -1 : use table parameter
  0 : do not load
  1 : do load
 */
static MYSQL_SYSVAR_INT(
  load_crd_at_startup,
  spider_load_crd_at_startup,
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED,
  "Load crd from system table at startup",
  NULL,
  spider_var_deprecated_int,
  1,
  -1,
  1,
  0
);

int spider_param_load_crd_at_startup(
  int load_crd_at_startup
) {
  DBUG_ENTER("spider_param_load_crd_at_startup");
  DBUG_RETURN(spider_load_crd_at_startup == -1 ?
    load_crd_at_startup : spider_load_crd_at_startup);
}

static uint spider_table_sts_thread_count;
/*
  1-: thread count
 */
static MYSQL_SYSVAR_UINT(
  table_sts_thread_count,
  spider_table_sts_thread_count,
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  "Static thread count of table sts",
  NULL,
  NULL,
  10,
  1,
  4294967295U,
  0
);

uint spider_param_table_sts_thread_count()
{
  DBUG_ENTER("spider_param_table_sts_thread_count");
  DBUG_RETURN(spider_table_sts_thread_count);
}

static uint spider_table_crd_thread_count;
/*
  1-: thread count
 */
static MYSQL_SYSVAR_UINT(
  table_crd_thread_count,
  spider_table_crd_thread_count,
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
  "Static thread count of table crd",
  NULL,
  NULL,
  10,
  1,
  4294967295U,
  0
);

uint spider_param_table_crd_thread_count()
{
  DBUG_ENTER("spider_param_table_crd_thread_count");
  DBUG_RETURN(spider_table_crd_thread_count);
}

static int spider_slave_trx_isolation;
/*
 -1 :off
  0 :read uncommitted
  1 :read committed
  2 :repeatable read
  3 :serializable
 */
static MYSQL_SYSVAR_INT(
  slave_trx_isolation,
  spider_slave_trx_isolation,
  PLUGIN_VAR_RQCMDARG,
  "Transaction isolation level when Spider table is used by slave SQL thread",
  NULL, /* check */
  NULL, /* update */
  -1, /* def */
  -1, /* min */
  3, /* max */
  0 /* blk */
);

int spider_param_slave_trx_isolation()
{
  DBUG_ENTER("spider_param_slave_trx_isolation");
  DBUG_RETURN(spider_slave_trx_isolation);
}

/*
 -1 :not set
  0-:seconds of timeout
 */
static MYSQL_THDVAR_INT(
  remote_wait_timeout, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Wait timeout on remote server", /* comment */
  NULL, /* check */
  NULL, /* update */
  -1, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_remote_wait_timeout(
  THD *thd
) {
  DBUG_ENTER("spider_param_remote_wait_timeout");
  if (likely(thd))
    DBUG_RETURN(THDVAR(thd, remote_wait_timeout));
  DBUG_RETURN(-1);
}

/*
 -1 :not set
  0-:seconds of timeout
 */
static MYSQL_THDVAR_INT(
  wait_timeout, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Wait timeout of setting to remote server", /* comment */
  NULL, /* check */
  NULL, /* update */
  604800, /* def */
  -1, /* min */
  2147483647, /* max */
  0 /* blk */
);

int spider_param_wait_timeout(
  THD *thd
) {
  DBUG_ENTER("spider_param_wait_timeout");
  if (likely(thd))
    DBUG_RETURN(THDVAR(thd, wait_timeout));
  DBUG_RETURN(604800);
}

/*
  FALSE: no sync
  TRUE:  sync
 */
static MYSQL_THDVAR_BOOL(
  sync_sql_mode, /* name */
  PLUGIN_VAR_OPCMDARG, /* opt */
  "Sync sql_mode", /* comment */
  NULL, /* check */
  NULL, /* update */
  TRUE /* def */
);

bool spider_param_sync_sql_mode(
  THD *thd
) {
  DBUG_ENTER("spider_param_sync_sql_mode");
  DBUG_RETURN(THDVAR(thd, sync_sql_mode));
}

/*
 -1 : use table parameter
  0 : do not strict
  1 : do strict
 */
static MYSQL_THDVAR_INT(
  strict_group_by, /* name */
  PLUGIN_VAR_RQCMDARG, /* opt */
  "Use columns in select clause strictly for group by clause",
  NULL, /* check */
  spider_var_deprecated_int, /* update */
  1, /* def */
  -1, /* min */
  1, /* max */
  0 /* blk */
);

int spider_param_strict_group_by(
  THD *thd,
  int strict_group_by
) {
  DBUG_ENTER("spider_param_strict_group_by");
  DBUG_RETURN(THDVAR(thd, strict_group_by) == -1 ?
    strict_group_by : THDVAR(thd, strict_group_by));
}

static struct st_mysql_storage_engine spider_storage_engine =
{ MYSQL_HANDLERTON_INTERFACE_VERSION };

static struct st_mysql_sys_var* spider_system_variables[] = {
  MYSQL_SYSVAR(support_xa),
  MYSQL_SYSVAR(table_init_error_interval),
  MYSQL_SYSVAR(use_table_charset),
  MYSQL_SYSVAR(conn_recycle_mode),
  MYSQL_SYSVAR(conn_recycle_strict),
  MYSQL_SYSVAR(sync_trx_isolation),
  MYSQL_SYSVAR(use_consistent_snapshot),
  MYSQL_SYSVAR(internal_xa),
  MYSQL_SYSVAR(internal_xa_snapshot),
  MYSQL_SYSVAR(force_commit),
  MYSQL_SYSVAR(xa_register_mode),
  MYSQL_SYSVAR(internal_offset),
  MYSQL_SYSVAR(internal_limit),
  MYSQL_SYSVAR(split_read),
  MYSQL_SYSVAR(semi_split_read),
  MYSQL_SYSVAR(semi_split_read_limit),
  MYSQL_SYSVAR(init_sql_alloc_size),
  MYSQL_SYSVAR(reset_sql_alloc),
  MYSQL_SYSVAR(multi_split_read),
  MYSQL_SYSVAR(max_order),
  MYSQL_SYSVAR(semi_trx_isolation),
  MYSQL_SYSVAR(semi_table_lock),
  MYSQL_SYSVAR(semi_table_lock_connection),
  MYSQL_SYSVAR(block_size),
  MYSQL_SYSVAR(selupd_lock_mode),
  MYSQL_SYSVAR(sync_autocommit),
  MYSQL_SYSVAR(use_default_database),
  MYSQL_SYSVAR(internal_sql_log_off),
  MYSQL_SYSVAR(bulk_size),
  MYSQL_SYSVAR(bulk_update_mode),
  MYSQL_SYSVAR(bulk_update_size),
  MYSQL_SYSVAR(buffer_size),
  MYSQL_SYSVAR(internal_optimize),
  MYSQL_SYSVAR(internal_optimize_local),
  MYSQL_SYSVAR(use_flash_logs),
  MYSQL_SYSVAR(use_snapshot_with_flush_tables),
  MYSQL_SYSVAR(use_all_conns_snapshot),
  MYSQL_SYSVAR(lock_exchange),
  MYSQL_SYSVAR(internal_unlock),
  MYSQL_SYSVAR(semi_trx),
  MYSQL_SYSVAR(connect_timeout),
  MYSQL_SYSVAR(net_read_timeout),
  MYSQL_SYSVAR(net_write_timeout),
  MYSQL_SYSVAR(quick_mode),
  MYSQL_SYSVAR(quick_page_size),
  MYSQL_SYSVAR(quick_page_byte),
  MYSQL_SYSVAR(low_mem_read),
  MYSQL_SYSVAR(select_column_mode),
  MYSQL_SYSVAR(bgs_mode),
  MYSQL_SYSVAR(bgs_first_read),
  MYSQL_SYSVAR(bgs_second_read),
  MYSQL_SYSVAR(first_read),
  MYSQL_SYSVAR(second_read),
  MYSQL_SYSVAR(crd_interval),
  MYSQL_SYSVAR(crd_mode),
  MYSQL_SYSVAR(crd_sync),
  MYSQL_SYSVAR(store_last_crd),
  MYSQL_SYSVAR(load_crd_at_startup),
  MYSQL_SYSVAR(crd_type),
  MYSQL_SYSVAR(crd_weight),
  MYSQL_SYSVAR(crd_bg_mode),
  MYSQL_SYSVAR(sts_interval),
  MYSQL_SYSVAR(sts_mode),
  MYSQL_SYSVAR(sts_sync),
  MYSQL_SYSVAR(store_last_sts),
  MYSQL_SYSVAR(load_sts_at_startup),
  MYSQL_SYSVAR(sts_bg_mode),
  MYSQL_SYSVAR(ping_interval_at_trx_start),
  MYSQL_SYSVAR(auto_increment_mode),
  MYSQL_SYSVAR(same_server_link),
  MYSQL_SYSVAR(local_lock_table),
  MYSQL_SYSVAR(use_pushdown_udf),
  MYSQL_SYSVAR(direct_dup_insert),
  MYSQL_SYSVAR(remote_access_charset),
  MYSQL_SYSVAR(remote_autocommit),
  MYSQL_SYSVAR(remote_time_zone),
  MYSQL_SYSVAR(remote_sql_log_off),
  MYSQL_SYSVAR(remote_trx_isolation),
  MYSQL_SYSVAR(remote_default_database),
  MYSQL_SYSVAR(connect_retry_interval),
  MYSQL_SYSVAR(connect_retry_count),
  MYSQL_SYSVAR(connect_mutex),
  MYSQL_SYSVAR(bka_engine),
  MYSQL_SYSVAR(bka_mode),
  MYSQL_SYSVAR(error_read_mode),
  MYSQL_SYSVAR(error_write_mode),
  MYSQL_SYSVAR(skip_default_condition),
  MYSQL_SYSVAR(skip_parallel_search),
  MYSQL_SYSVAR(direct_order_limit),
  MYSQL_SYSVAR(read_only_mode),
  MYSQL_SYSVAR(general_log),
  MYSQL_SYSVAR(index_hint_pushdown),
  MYSQL_SYSVAR(max_connections),
  MYSQL_SYSVAR(conn_wait_timeout),
  MYSQL_SYSVAR(log_result_errors),
  MYSQL_SYSVAR(log_result_error_with_sql),
  MYSQL_SYSVAR(internal_xa_id_type),
  MYSQL_SYSVAR(casual_read),
  MYSQL_SYSVAR(dry_access),
  MYSQL_SYSVAR(delete_all_rows_type),
  MYSQL_SYSVAR(bka_table_name_type),
  MYSQL_SYSVAR(use_cond_other_than_pk_for_update),
  MYSQL_SYSVAR(connect_error_interval),
  MYSQL_SYSVAR(table_sts_thread_count),
  MYSQL_SYSVAR(table_crd_thread_count),
  MYSQL_SYSVAR(slave_trx_isolation),
  MYSQL_SYSVAR(remote_wait_timeout),
  MYSQL_SYSVAR(wait_timeout),
  MYSQL_SYSVAR(sync_sql_mode),
  MYSQL_SYSVAR(strict_group_by),
  NULL
};

mysql_declare_plugin(spider)
{
  MYSQL_STORAGE_ENGINE_PLUGIN,
  &spider_storage_engine,
  "SPIDER",
  "Kentoku Shiba",
  "Spider storage engine",
  PLUGIN_LICENSE_GPL,
  spider_db_init,
  spider_db_done,
  SPIDER_HEX_VERSION,
  spider_status_variables,
  spider_system_variables,
  NULL,
  0,
},
spider_i_s_alloc_mem,
spider_i_s_wrapper_protocols
mysql_declare_plugin_end;

maria_declare_plugin(spider)
{
  MYSQL_STORAGE_ENGINE_PLUGIN,
  &spider_storage_engine,
  "SPIDER",
  "Kentoku Shiba",
  "Spider storage engine",
  PLUGIN_LICENSE_GPL,
  spider_db_init,
  spider_db_done,
  SPIDER_HEX_VERSION,
  spider_status_variables,
  spider_system_variables,
  SPIDER_DETAIL_VERSION,
  MariaDB_PLUGIN_MATURITY_STABLE
},
spider_i_s_alloc_mem_maria,
spider_i_s_wrapper_protocols_maria
maria_declare_plugin_end;