1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
|
/*-------------------------------------------------------------------------
*
* utility.c
* Contains functions which control the execution of the POSTGRES utility
* commands. At one time acted as an interface between the Lisp and C
* systems.
*
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/backend/tcop/utility.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_inherits.h"
#include "catalog/toasting.h"
#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/collationcmds.h"
#include "commands/comment.h"
#include "commands/conversioncmds.h"
#include "commands/copy.h"
#include "commands/createas.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/discard.h"
#include "commands/event_trigger.h"
#include "commands/explain.h"
#include "commands/extension.h"
#include "commands/lockcmds.h"
#include "commands/matview.h"
#include "commands/policy.h"
#include "commands/portalcmds.h"
#include "commands/prepare.h"
#include "commands/proclang.h"
#include "commands/publicationcmds.h"
#include "commands/schemacmds.h"
#include "commands/seclabel.h"
#include "commands/sequence.h"
#include "commands/subscriptioncmds.h"
#include "commands/tablecmds.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "commands/typecmds.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/view.h"
#include "miscadmin.h"
#include "parser/parse_utilcmd.h"
#include "postmaster/bgwriter.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteRemove.h"
#include "storage/fd.h"
#include "tcop/pquery.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
/* Hook for plugins to get control in ProcessUtility() */
ProcessUtility_hook_type ProcessUtility_hook = NULL;
/* local function declarations */
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree);
static void ProcessUtilitySlow(ParseState *pstate,
PlannedStmt *pstmt,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo params,
QueryEnvironment *queryEnv,
DestReceiver *dest,
QueryCompletion *qc);
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel);
/*
* CommandIsReadOnly: is an executable query read-only?
*
* This is a much stricter test than we apply for XactReadOnly mode;
* the query must be *in truth* read-only, because the caller wishes
* not to do CommandCounterIncrement for it.
*
* Note: currently no need to support raw or analyzed queries here
*/
bool
CommandIsReadOnly(PlannedStmt *pstmt)
{
Assert(IsA(pstmt, PlannedStmt));
switch (pstmt->commandType)
{
case CMD_SELECT:
if (pstmt->rowMarks != NIL)
return false; /* SELECT FOR [KEY] UPDATE/SHARE */
else if (pstmt->hasModifyingCTE)
return false; /* data-modifying CTE */
else
return true;
case CMD_UPDATE:
case CMD_INSERT:
case CMD_DELETE:
return false;
case CMD_UTILITY:
/* For now, treat all utility commands as read/write */
return false;
default:
elog(WARNING, "unrecognized commandType: %d",
(int) pstmt->commandType);
break;
}
return false;
}
/*
* Determine the degree to which a utility command is read only.
*
* Note the definitions of the relevant flags in src/include/utility/tcop.h.
*/
static int
ClassifyUtilityCommandAsReadOnly(Node *parsetree)
{
switch (nodeTag(parsetree))
{
case T_AlterCollationStmt:
case T_AlterDatabaseSetStmt:
case T_AlterDatabaseStmt:
case T_AlterDefaultPrivilegesStmt:
case T_AlterDomainStmt:
case T_AlterEnumStmt:
case T_AlterEventTrigStmt:
case T_AlterExtensionContentsStmt:
case T_AlterExtensionStmt:
case T_AlterFdwStmt:
case T_AlterForeignServerStmt:
case T_AlterFunctionStmt:
case T_AlterObjectDependsStmt:
case T_AlterObjectSchemaStmt:
case T_AlterOpFamilyStmt:
case T_AlterOperatorStmt:
case T_AlterOwnerStmt:
case T_AlterPolicyStmt:
case T_AlterPublicationStmt:
case T_AlterRoleSetStmt:
case T_AlterRoleStmt:
case T_AlterSeqStmt:
case T_AlterStatsStmt:
case T_AlterSubscriptionStmt:
case T_AlterTSConfigurationStmt:
case T_AlterTSDictionaryStmt:
case T_AlterTableMoveAllStmt:
case T_AlterTableSpaceOptionsStmt:
case T_AlterTableStmt:
case T_AlterTypeStmt:
case T_AlterUserMappingStmt:
case T_CommentStmt:
case T_CompositeTypeStmt:
case T_CreateAmStmt:
case T_CreateCastStmt:
case T_CreateConversionStmt:
case T_CreateDomainStmt:
case T_CreateEnumStmt:
case T_CreateEventTrigStmt:
case T_CreateExtensionStmt:
case T_CreateFdwStmt:
case T_CreateForeignServerStmt:
case T_CreateForeignTableStmt:
case T_CreateFunctionStmt:
case T_CreateOpClassStmt:
case T_CreateOpFamilyStmt:
case T_CreatePLangStmt:
case T_CreatePolicyStmt:
case T_CreatePublicationStmt:
case T_CreateRangeStmt:
case T_CreateRoleStmt:
case T_CreateSchemaStmt:
case T_CreateSeqStmt:
case T_CreateStatsStmt:
case T_CreateStmt:
case T_CreateSubscriptionStmt:
case T_CreateTableAsStmt:
case T_CreateTableSpaceStmt:
case T_CreateTransformStmt:
case T_CreateTrigStmt:
case T_CreateUserMappingStmt:
case T_CreatedbStmt:
case T_DefineStmt:
case T_DropOwnedStmt:
case T_DropRoleStmt:
case T_DropStmt:
case T_DropSubscriptionStmt:
case T_DropTableSpaceStmt:
case T_DropUserMappingStmt:
case T_DropdbStmt:
case T_GrantRoleStmt:
case T_GrantStmt:
case T_ImportForeignSchemaStmt:
case T_IndexStmt:
case T_ReassignOwnedStmt:
case T_RefreshMatViewStmt:
case T_RenameStmt:
case T_RuleStmt:
case T_SecLabelStmt:
case T_TruncateStmt:
case T_ViewStmt:
{
/* DDL is not read-only, and neither is TRUNCATE. */
return COMMAND_IS_NOT_READ_ONLY;
}
case T_AlterSystemStmt:
{
/*
* Surprisingly, ALTER SYSTEM meets all our definitions of
* read-only: it changes nothing that affects the output of
* pg_dump, it doesn't write WAL or imperil the application of
* future WAL, and it doesn't depend on any state that needs
* to be synchronized with parallel workers.
*
* So, despite the fact that it writes to a file, it's read
* only!
*/
return COMMAND_IS_STRICTLY_READ_ONLY;
}
case T_CallStmt:
case T_DoStmt:
{
/*
* Commands inside the DO block or the called procedure might
* not be read only, but they'll be checked separately when we
* try to execute them. Here we only need to worry about the
* DO or CALL command itself.
*/
return COMMAND_IS_STRICTLY_READ_ONLY;
}
case T_CheckPointStmt:
{
/*
* You might think that this should not be permitted in
* recovery, but we interpret a CHECKPOINT command during
* recovery as a request for a restartpoint instead. We allow
* this since it can be a useful way of reducing switchover
* time when using various forms of replication.
*/
return COMMAND_IS_STRICTLY_READ_ONLY;
}
case T_ClosePortalStmt:
case T_ConstraintsSetStmt:
case T_DeallocateStmt:
case T_DeclareCursorStmt:
case T_DiscardStmt:
case T_ExecuteStmt:
case T_FetchStmt:
case T_LoadStmt:
case T_PrepareStmt:
case T_UnlistenStmt:
case T_VariableSetStmt:
{
/*
* These modify only backend-local state, so they're OK to run
* in a read-only transaction or on a standby. However, they
* are disallowed in parallel mode, because they either rely
* upon or modify backend-local state that might not be
* synchronized among cooperating backends.
*/
return COMMAND_OK_IN_RECOVERY | COMMAND_OK_IN_READ_ONLY_TXN;
}
case T_ClusterStmt:
case T_ReindexStmt:
case T_VacuumStmt:
{
/*
* These commands write WAL, so they're not strictly
* read-only, and running them in parallel workers isn't
* supported.
*
* However, they don't change the database state in a way that
* would affect pg_dump output, so it's fine to run them in a
* read-only transaction. (CLUSTER might change the order of
* rows on disk, which could affect the ordering of pg_dump
* output, but that's not semantically significant.)
*/
return COMMAND_OK_IN_READ_ONLY_TXN;
}
case T_CopyStmt:
{
CopyStmt *stmt = (CopyStmt *) parsetree;
/*
* You might think that COPY FROM is not at all read only, but
* it's OK to copy into a temporary table, because that
* wouldn't change the output of pg_dump. If the target table
* turns out to be non-temporary, DoCopy itself will call
* PreventCommandIfReadOnly.
*/
if (stmt->is_from)
return COMMAND_OK_IN_READ_ONLY_TXN;
else
return COMMAND_IS_STRICTLY_READ_ONLY;
}
case T_ExplainStmt:
case T_VariableShowStmt:
{
/*
* These commands don't modify any data and are safe to run in
* a parallel worker.
*/
return COMMAND_IS_STRICTLY_READ_ONLY;
}
case T_ListenStmt:
case T_NotifyStmt:
{
/*
* NOTIFY requires an XID assignment, so it can't be permitted
* on a standby. Perhaps LISTEN could, since without NOTIFY it
* would be OK to just do nothing, at least until promotion,
* but we currently prohibit it lest the user get the wrong
* idea.
*
* (We do allow T_UnlistenStmt on a standby, though, because
* it's a no-op.)
*/
return COMMAND_OK_IN_READ_ONLY_TXN;
}
case T_LockStmt:
{
LockStmt *stmt = (LockStmt *) parsetree;
/*
* Only weaker locker modes are allowed during recovery. The
* restrictions here must match those in
* LockAcquireExtended().
*/
if (stmt->mode > RowExclusiveLock)
return COMMAND_OK_IN_READ_ONLY_TXN;
else
return COMMAND_IS_STRICTLY_READ_ONLY;
}
case T_TransactionStmt:
{
TransactionStmt *stmt = (TransactionStmt *) parsetree;
/*
* PREPARE, COMMIT PREPARED, and ROLLBACK PREPARED all write
* WAL, so they're not read-only in the strict sense; but the
* first and third do not change pg_dump output, so they're OK
* in a read-only transactions.
*
* We also consider COMMIT PREPARED to be OK in a read-only
* transaction environment, by way of exception.
*/
switch (stmt->kind)
{
case TRANS_STMT_BEGIN:
case TRANS_STMT_START:
case TRANS_STMT_COMMIT:
case TRANS_STMT_ROLLBACK:
case TRANS_STMT_SAVEPOINT:
case TRANS_STMT_RELEASE:
case TRANS_STMT_ROLLBACK_TO:
return COMMAND_IS_STRICTLY_READ_ONLY;
case TRANS_STMT_PREPARE:
case TRANS_STMT_COMMIT_PREPARED:
case TRANS_STMT_ROLLBACK_PREPARED:
return COMMAND_OK_IN_READ_ONLY_TXN;
}
elog(ERROR, "unrecognized TransactionStmtKind: %d",
(int) stmt->kind);
return 0; /* silence stupider compilers */
}
default:
elog(ERROR, "unrecognized node type: %d",
(int) nodeTag(parsetree));
return 0; /* silence stupider compilers */
}
}
/*
* PreventCommandIfReadOnly: throw error if XactReadOnly
*
* This is useful partly to ensure consistency of the error message wording;
* some callers have checked XactReadOnly for themselves.
*/
void
PreventCommandIfReadOnly(const char *cmdname)
{
if (XactReadOnly)
ereport(ERROR,
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
/* translator: %s is name of a SQL command, eg CREATE */
errmsg("cannot execute %s in a read-only transaction",
cmdname)));
}
/*
* PreventCommandIfParallelMode: throw error if current (sub)transaction is
* in parallel mode.
*
* This is useful partly to ensure consistency of the error message wording;
* some callers have checked IsInParallelMode() for themselves.
*/
void
PreventCommandIfParallelMode(const char *cmdname)
{
if (IsInParallelMode())
ereport(ERROR,
(errcode(ERRCODE_INVALID_TRANSACTION_STATE),
/* translator: %s is name of a SQL command, eg CREATE */
errmsg("cannot execute %s during a parallel operation",
cmdname)));
}
/*
* PreventCommandDuringRecovery: throw error if RecoveryInProgress
*
* The majority of operations that are unsafe in a Hot Standby
* will be rejected by XactReadOnly tests. However there are a few
* commands that are allowed in "read-only" xacts but cannot be allowed
* in Hot Standby mode. Those commands should call this function.
*/
void
PreventCommandDuringRecovery(const char *cmdname)
{
if (RecoveryInProgress())
ereport(ERROR,
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
/* translator: %s is name of a SQL command, eg CREATE */
errmsg("cannot execute %s during recovery",
cmdname)));
}
/*
* CheckRestrictedOperation: throw error for hazardous command if we're
* inside a security restriction context.
*
* This is needed to protect session-local state for which there is not any
* better-defined protection mechanism, such as ownership.
*/
static void
CheckRestrictedOperation(const char *cmdname)
{
if (InSecurityRestrictedOperation())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
/* translator: %s is name of a SQL command, eg PREPARE */
errmsg("cannot execute %s within security-restricted operation",
cmdname)));
}
/*
* ProcessUtility
* general utility function invoker
*
* pstmt: PlannedStmt wrapper for the utility statement
* queryString: original source text of command
* context: identifies source of statement (toplevel client command,
* non-toplevel client command, subcommand of a larger utility command)
* params: parameters to use during execution
* queryEnv: environment for parse through execution (e.g., ephemeral named
* tables like trigger transition tables). May be NULL.
* dest: where to send results
* qc: where to store command completion status data. May be NULL,
* but if not, then caller must have initialized it.
*
* Caller MUST supply a queryString; it is not allowed (anymore) to pass NULL.
* If you really don't have source text, you can pass a constant string,
* perhaps "(query not available)".
*
* Note for users of ProcessUtility_hook: the same queryString may be passed
* to multiple invocations of ProcessUtility when processing a query string
* containing multiple semicolon-separated statements. One should use
* pstmt->stmt_location and pstmt->stmt_len to identify the substring
* containing the current statement. Keep in mind also that some utility
* statements (e.g., CREATE SCHEMA) will recurse to ProcessUtility to process
* sub-statements, often passing down the same queryString, stmt_location,
* and stmt_len that were given for the whole statement.
*/
void
ProcessUtility(PlannedStmt *pstmt,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo params,
QueryEnvironment *queryEnv,
DestReceiver *dest,
QueryCompletion *qc)
{
Assert(IsA(pstmt, PlannedStmt));
Assert(pstmt->commandType == CMD_UTILITY);
Assert(queryString != NULL); /* required as of 8.4 */
Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
/*
* We provide a function hook variable that lets loadable plugins get
* control when ProcessUtility is called. Such a plugin would normally
* call standard_ProcessUtility().
*/
if (ProcessUtility_hook)
(*ProcessUtility_hook) (pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
standard_ProcessUtility(pstmt, queryString,
context, params, queryEnv,
dest, qc);
}
/*
* standard_ProcessUtility itself deals only with utility commands for
* which we do not provide event trigger support. Commands that do have
* such support are passed down to ProcessUtilitySlow, which contains the
* necessary infrastructure for such triggers.
*
* This division is not just for performance: it's critical that the
* event trigger code not be invoked when doing START TRANSACTION for
* example, because we might need to refresh the event trigger cache,
* which requires being in a valid transaction.
*/
void
standard_ProcessUtility(PlannedStmt *pstmt,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo params,
QueryEnvironment *queryEnv,
DestReceiver *dest,
QueryCompletion *qc)
{
Node *parsetree = pstmt->utilityStmt;
bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
ParseState *pstate;
int readonly_flags;
/* This can recurse, so check for excessive recursion */
check_stack_depth();
/* Prohibit read/write commands in read-only states. */
readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
(XactReadOnly || IsInParallelMode()))
{
CommandTag commandtag = CreateCommandTag(parsetree);
if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
PreventCommandIfReadOnly(GetCommandTagName(commandtag));
if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
PreventCommandIfParallelMode(GetCommandTagName(commandtag));
if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
PreventCommandDuringRecovery(GetCommandTagName(commandtag));
}
pstate = make_parsestate(NULL);
pstate->p_sourcetext = queryString;
pstate->p_queryEnv = queryEnv;
switch (nodeTag(parsetree))
{
/*
* ******************** transactions ********************
*/
case T_TransactionStmt:
{
TransactionStmt *stmt = (TransactionStmt *) parsetree;
switch (stmt->kind)
{
/*
* START TRANSACTION, as defined by SQL99: Identical
* to BEGIN. Same code for both.
*/
case TRANS_STMT_BEGIN:
case TRANS_STMT_START:
{
ListCell *lc;
BeginTransactionBlock();
foreach(lc, stmt->options)
{
DefElem *item = (DefElem *) lfirst(lc);
if (strcmp(item->defname, "transaction_isolation") == 0)
SetPGVariable("transaction_isolation",
list_make1(item->arg),
true);
else if (strcmp(item->defname, "transaction_read_only") == 0)
SetPGVariable("transaction_read_only",
list_make1(item->arg),
true);
else if (strcmp(item->defname, "transaction_deferrable") == 0)
SetPGVariable("transaction_deferrable",
list_make1(item->arg),
true);
}
}
break;
case TRANS_STMT_COMMIT:
if (!EndTransactionBlock(stmt->chain))
{
/* report unsuccessful commit in qc */
if (qc)
SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
}
break;
case TRANS_STMT_PREPARE:
if (!PrepareTransactionBlock(stmt->gid))
{
/* report unsuccessful commit in qc */
if (qc)
SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
}
break;
case TRANS_STMT_COMMIT_PREPARED:
PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
FinishPreparedTransaction(stmt->gid, true);
break;
case TRANS_STMT_ROLLBACK_PREPARED:
PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
FinishPreparedTransaction(stmt->gid, false);
break;
case TRANS_STMT_ROLLBACK:
UserAbortTransactionBlock(stmt->chain);
break;
case TRANS_STMT_SAVEPOINT:
RequireTransactionBlock(isTopLevel, "SAVEPOINT");
DefineSavepoint(stmt->savepoint_name);
break;
case TRANS_STMT_RELEASE:
RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
ReleaseSavepoint(stmt->savepoint_name);
break;
case TRANS_STMT_ROLLBACK_TO:
RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
RollbackToSavepoint(stmt->savepoint_name);
/*
* CommitTransactionCommand is in charge of
* re-defining the savepoint again
*/
break;
}
}
break;
/*
* Portal (cursor) manipulation
*/
case T_DeclareCursorStmt:
PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
isTopLevel);
break;
case T_ClosePortalStmt:
{
ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
CheckRestrictedOperation("CLOSE");
PerformPortalClose(stmt->portalname);
}
break;
case T_FetchStmt:
PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
break;
case T_DoStmt:
ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
break;
case T_CreateTableSpaceStmt:
/* no event triggers for global objects */
PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
CreateTableSpace((CreateTableSpaceStmt *) parsetree);
break;
case T_DropTableSpaceStmt:
/* no event triggers for global objects */
PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
DropTableSpace((DropTableSpaceStmt *) parsetree);
break;
case T_AlterTableSpaceOptionsStmt:
/* no event triggers for global objects */
AlterTableSpaceOptions((AlterTableSpaceOptionsStmt *) parsetree);
break;
case T_TruncateStmt:
ExecuteTruncate((TruncateStmt *) parsetree);
break;
case T_CopyStmt:
{
uint64 processed;
DoCopy(pstate, (CopyStmt *) parsetree,
pstmt->stmt_location, pstmt->stmt_len,
&processed);
if (qc)
SetQueryCompletion(qc, CMDTAG_COPY, processed);
}
break;
case T_PrepareStmt:
CheckRestrictedOperation("PREPARE");
PrepareQuery(pstate, (PrepareStmt *) parsetree,
pstmt->stmt_location, pstmt->stmt_len);
break;
case T_ExecuteStmt:
ExecuteQuery(pstate,
(ExecuteStmt *) parsetree, NULL,
params,
dest, qc);
break;
case T_DeallocateStmt:
CheckRestrictedOperation("DEALLOCATE");
DeallocateQuery((DeallocateStmt *) parsetree);
break;
case T_GrantRoleStmt:
/* no event triggers for global objects */
GrantRole((GrantRoleStmt *) parsetree);
break;
case T_CreatedbStmt:
/* no event triggers for global objects */
PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
createdb(pstate, (CreatedbStmt *) parsetree);
break;
case T_AlterDatabaseStmt:
/* no event triggers for global objects */
AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
break;
case T_AlterDatabaseSetStmt:
/* no event triggers for global objects */
AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
break;
case T_DropdbStmt:
/* no event triggers for global objects */
PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
DropDatabase(pstate, (DropdbStmt *) parsetree);
break;
/* Query-level asynchronous notification */
case T_NotifyStmt:
{
NotifyStmt *stmt = (NotifyStmt *) parsetree;
Async_Notify(stmt->conditionname, stmt->payload);
}
break;
case T_ListenStmt:
{
ListenStmt *stmt = (ListenStmt *) parsetree;
CheckRestrictedOperation("LISTEN");
Async_Listen(stmt->conditionname);
}
break;
case T_UnlistenStmt:
{
UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
CheckRestrictedOperation("UNLISTEN");
if (stmt->conditionname)
Async_Unlisten(stmt->conditionname);
else
Async_UnlistenAll();
}
break;
case T_LoadStmt:
{
LoadStmt *stmt = (LoadStmt *) parsetree;
closeAllVfds(); /* probably not necessary... */
/* Allowed names are restricted if you're not superuser */
load_file(stmt->filename, !superuser());
}
break;
case T_CallStmt:
ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
break;
case T_ClusterStmt:
cluster((ClusterStmt *) parsetree, isTopLevel);
break;
case T_VacuumStmt:
ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
break;
case T_ExplainStmt:
ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
break;
case T_AlterSystemStmt:
PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
AlterSystemSetConfigFile((AlterSystemStmt *) parsetree);
break;
case T_VariableSetStmt:
ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
break;
case T_VariableShowStmt:
{
VariableShowStmt *n = (VariableShowStmt *) parsetree;
GetPGVariable(n->name, dest);
}
break;
case T_DiscardStmt:
/* should we allow DISCARD PLANS? */
CheckRestrictedOperation("DISCARD");
DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
break;
case T_CreateEventTrigStmt:
/* no event triggers on event triggers */
CreateEventTrigger((CreateEventTrigStmt *) parsetree);
break;
case T_AlterEventTrigStmt:
/* no event triggers on event triggers */
AlterEventTrigger((AlterEventTrigStmt *) parsetree);
break;
/*
* ******************************** ROLE statements ****
*/
case T_CreateRoleStmt:
/* no event triggers for global objects */
CreateRole(pstate, (CreateRoleStmt *) parsetree);
break;
case T_AlterRoleStmt:
/* no event triggers for global objects */
AlterRole((AlterRoleStmt *) parsetree);
break;
case T_AlterRoleSetStmt:
/* no event triggers for global objects */
AlterRoleSet((AlterRoleSetStmt *) parsetree);
break;
case T_DropRoleStmt:
/* no event triggers for global objects */
DropRole((DropRoleStmt *) parsetree);
break;
case T_ReassignOwnedStmt:
/* no event triggers for global objects */
ReassignOwnedObjects((ReassignOwnedStmt *) parsetree);
break;
case T_LockStmt:
/*
* Since the lock would just get dropped immediately, LOCK TABLE
* outside a transaction block is presumed to be user error.
*/
RequireTransactionBlock(isTopLevel, "LOCK TABLE");
LockTableCommand((LockStmt *) parsetree);
break;
case T_ConstraintsSetStmt:
WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
AfterTriggerSetState((ConstraintsSetStmt *) parsetree);
break;
case T_CheckPointStmt:
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to do CHECKPOINT")));
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT |
(RecoveryInProgress() ? 0 : CHECKPOINT_FORCE));
break;
case T_ReindexStmt:
{
ReindexStmt *stmt = (ReindexStmt *) parsetree;
if (stmt->concurrent)
PreventInTransactionBlock(isTopLevel,
"REINDEX CONCURRENTLY");
switch (stmt->kind)
{
case REINDEX_OBJECT_INDEX:
ReindexIndex(stmt->relation, stmt->options, stmt->concurrent);
break;
case REINDEX_OBJECT_TABLE:
ReindexTable(stmt->relation, stmt->options, stmt->concurrent);
break;
case REINDEX_OBJECT_SCHEMA:
case REINDEX_OBJECT_SYSTEM:
case REINDEX_OBJECT_DATABASE:
/*
* This cannot run inside a user transaction block; if
* we were inside a transaction, then its commit- and
* start-transaction-command calls would not have the
* intended effect!
*/
PreventInTransactionBlock(isTopLevel,
(stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
(stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
"REINDEX DATABASE");
ReindexMultipleTables(stmt->name, stmt->kind, stmt->options, stmt->concurrent);
break;
default:
elog(ERROR, "unrecognized object type: %d",
(int) stmt->kind);
break;
}
}
break;
/*
* The following statements are supported by Event Triggers only
* in some cases, so we "fast path" them in the other cases.
*/
case T_GrantStmt:
{
GrantStmt *stmt = (GrantStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->objtype))
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
ExecuteGrantStmt(stmt);
}
break;
case T_DropStmt:
{
DropStmt *stmt = (DropStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->removeType))
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
ExecDropStmt(stmt, isTopLevel);
}
break;
case T_RenameStmt:
{
RenameStmt *stmt = (RenameStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->renameType))
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
ExecRenameStmt(stmt);
}
break;
case T_AlterObjectDependsStmt:
{
AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->objectType))
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
ExecAlterObjectDependsStmt(stmt, NULL);
}
break;
case T_AlterObjectSchemaStmt:
{
AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->objectType))
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
ExecAlterObjectSchemaStmt(stmt, NULL);
}
break;
case T_AlterOwnerStmt:
{
AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->objectType))
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
ExecAlterOwnerStmt(stmt);
}
break;
case T_CommentStmt:
{
CommentStmt *stmt = (CommentStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->objtype))
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
CommentObject(stmt);
break;
}
case T_SecLabelStmt:
{
SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
if (EventTriggerSupportsObjectType(stmt->objtype))
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
else
ExecSecLabelStmt(stmt);
break;
}
default:
/* All other statement types have event trigger support */
ProcessUtilitySlow(pstate, pstmt, queryString,
context, params, queryEnv,
dest, qc);
break;
}
free_parsestate(pstate);
/*
* Make effects of commands visible, for instance so that
* PreCommit_on_commit_actions() can see them (see for example bug
* #15631).
*/
CommandCounterIncrement();
}
/*
* The "Slow" variant of ProcessUtility should only receive statements
* supported by the event triggers facility. Therefore, we always
* perform the trigger support calls if the context allows it.
*/
static void
ProcessUtilitySlow(ParseState *pstate,
PlannedStmt *pstmt,
const char *queryString,
ProcessUtilityContext context,
ParamListInfo params,
QueryEnvironment *queryEnv,
DestReceiver *dest,
QueryCompletion *qc)
{
Node *parsetree = pstmt->utilityStmt;
bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
bool isCompleteQuery = (context != PROCESS_UTILITY_SUBCOMMAND);
bool needCleanup;
bool commandCollected = false;
ObjectAddress address;
ObjectAddress secondaryObject = InvalidObjectAddress;
/* All event trigger calls are done only when isCompleteQuery is true */
needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
/* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
PG_TRY();
{
if (isCompleteQuery)
EventTriggerDDLCommandStart(parsetree);
switch (nodeTag(parsetree))
{
/*
* relation and attribute manipulation
*/
case T_CreateSchemaStmt:
CreateSchemaCommand((CreateSchemaStmt *) parsetree,
queryString,
pstmt->stmt_location,
pstmt->stmt_len);
/*
* EventTriggerCollectSimpleCommand called by
* CreateSchemaCommand
*/
commandCollected = true;
break;
case T_CreateStmt:
case T_CreateForeignTableStmt:
{
List *stmts;
RangeVar *table_rv = NULL;
/* Run parse analysis ... */
stmts = transformCreateStmt((CreateStmt *) parsetree,
queryString);
/*
* ... and do it. We can't use foreach() because we may
* modify the list midway through, so pick off the
* elements one at a time, the hard way.
*/
while (stmts != NIL)
{
Node *stmt = (Node *) linitial(stmts);
stmts = list_delete_first(stmts);
if (IsA(stmt, CreateStmt))
{
CreateStmt *cstmt = (CreateStmt *) stmt;
Datum toast_options;
static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
/* Remember transformed RangeVar for LIKE */
table_rv = cstmt->relation;
/* Create the table itself */
address = DefineRelation(cstmt,
RELKIND_RELATION,
InvalidOid, NULL,
queryString);
EventTriggerCollectSimpleCommand(address,
secondaryObject,
stmt);
/*
* Let NewRelationCreateToastTable decide if this
* one needs a secondary relation too.
*/
CommandCounterIncrement();
/*
* parse and validate reloptions for the toast
* table
*/
toast_options = transformRelOptions((Datum) 0,
cstmt->options,
"toast",
validnsps,
true,
false);
(void) heap_reloptions(RELKIND_TOASTVALUE,
toast_options,
true);
NewRelationCreateToastTable(address.objectId,
toast_options);
}
else if (IsA(stmt, CreateForeignTableStmt))
{
CreateForeignTableStmt *cstmt = (CreateForeignTableStmt *) stmt;
/* Remember transformed RangeVar for LIKE */
table_rv = cstmt->base.relation;
/* Create the table itself */
address = DefineRelation(&cstmt->base,
RELKIND_FOREIGN_TABLE,
InvalidOid, NULL,
queryString);
CreateForeignTable(cstmt,
address.objectId);
EventTriggerCollectSimpleCommand(address,
secondaryObject,
stmt);
}
else if (IsA(stmt, TableLikeClause))
{
/*
* Do delayed processing of LIKE options. This
* will result in additional sub-statements for us
* to process. Those should get done before any
* remaining actions, so prepend them to "stmts".
*/
TableLikeClause *like = (TableLikeClause *) stmt;
List *morestmts;
Assert(table_rv != NULL);
morestmts = expandTableLikeClause(table_rv, like);
stmts = list_concat(morestmts, stmts);
}
else
{
/*
* Recurse for anything else. Note the recursive
* call will stash the objects so created into our
* event trigger context.
*/
PlannedStmt *wrapper;
wrapper = makeNode(PlannedStmt);
wrapper->commandType = CMD_UTILITY;
wrapper->canSetTag = false;
wrapper->utilityStmt = stmt;
wrapper->stmt_location = pstmt->stmt_location;
wrapper->stmt_len = pstmt->stmt_len;
ProcessUtility(wrapper,
queryString,
PROCESS_UTILITY_SUBCOMMAND,
params,
NULL,
None_Receiver,
NULL);
}
/* Need CCI between commands */
if (stmts != NIL)
CommandCounterIncrement();
}
/*
* The multiple commands generated here are stashed
* individually, so disable collection below.
*/
commandCollected = true;
}
break;
case T_AlterTableStmt:
{
AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
Oid relid;
LOCKMODE lockmode;
/*
* Figure out lock mode, and acquire lock. This also does
* basic permissions checks, so that we won't wait for a
* lock on (for example) a relation on which we have no
* permissions.
*/
lockmode = AlterTableGetLockLevel(atstmt->cmds);
relid = AlterTableLookupRelation(atstmt, lockmode);
if (OidIsValid(relid))
{
AlterTableUtilityContext atcontext;
/* Set up info needed for recursive callbacks ... */
atcontext.pstmt = pstmt;
atcontext.queryString = queryString;
atcontext.relid = relid;
atcontext.params = params;
atcontext.queryEnv = queryEnv;
/* ... ensure we have an event trigger context ... */
EventTriggerAlterTableStart(parsetree);
EventTriggerAlterTableRelid(relid);
/* ... and do it */
AlterTable(atstmt, lockmode, &atcontext);
/* done */
EventTriggerAlterTableEnd();
}
else
ereport(NOTICE,
(errmsg("relation \"%s\" does not exist, skipping",
atstmt->relation->relname)));
}
/* ALTER TABLE stashes commands internally */
commandCollected = true;
break;
case T_AlterDomainStmt:
{
AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
/*
* Some or all of these functions are recursive to cover
* inherited things, so permission checks are done there.
*/
switch (stmt->subtype)
{
case 'T': /* ALTER DOMAIN DEFAULT */
/*
* Recursively alter column default for table and,
* if requested, for descendants
*/
address =
AlterDomainDefault(stmt->typeName,
stmt->def);
break;
case 'N': /* ALTER DOMAIN DROP NOT NULL */
address =
AlterDomainNotNull(stmt->typeName,
false);
break;
case 'O': /* ALTER DOMAIN SET NOT NULL */
address =
AlterDomainNotNull(stmt->typeName,
true);
break;
case 'C': /* ADD CONSTRAINT */
address =
AlterDomainAddConstraint(stmt->typeName,
stmt->def,
&secondaryObject);
break;
case 'X': /* DROP CONSTRAINT */
address =
AlterDomainDropConstraint(stmt->typeName,
stmt->name,
stmt->behavior,
stmt->missing_ok);
break;
case 'V': /* VALIDATE CONSTRAINT */
address =
AlterDomainValidateConstraint(stmt->typeName,
stmt->name);
break;
default: /* oops */
elog(ERROR, "unrecognized alter domain type: %d",
(int) stmt->subtype);
break;
}
}
break;
/*
* ************* object creation / destruction **************
*/
case T_DefineStmt:
{
DefineStmt *stmt = (DefineStmt *) parsetree;
switch (stmt->kind)
{
case OBJECT_AGGREGATE:
address =
DefineAggregate(pstate, stmt->defnames, stmt->args,
stmt->oldstyle,
stmt->definition,
stmt->replace);
break;
case OBJECT_OPERATOR:
Assert(stmt->args == NIL);
address = DefineOperator(stmt->defnames,
stmt->definition);
break;
case OBJECT_TYPE:
Assert(stmt->args == NIL);
address = DefineType(pstate,
stmt->defnames,
stmt->definition);
break;
case OBJECT_TSPARSER:
Assert(stmt->args == NIL);
address = DefineTSParser(stmt->defnames,
stmt->definition);
break;
case OBJECT_TSDICTIONARY:
Assert(stmt->args == NIL);
address = DefineTSDictionary(stmt->defnames,
stmt->definition);
break;
case OBJECT_TSTEMPLATE:
Assert(stmt->args == NIL);
address = DefineTSTemplate(stmt->defnames,
stmt->definition);
break;
case OBJECT_TSCONFIGURATION:
Assert(stmt->args == NIL);
address = DefineTSConfiguration(stmt->defnames,
stmt->definition,
&secondaryObject);
break;
case OBJECT_COLLATION:
Assert(stmt->args == NIL);
address = DefineCollation(pstate,
stmt->defnames,
stmt->definition,
stmt->if_not_exists);
break;
default:
elog(ERROR, "unrecognized define stmt type: %d",
(int) stmt->kind);
break;
}
}
break;
case T_IndexStmt: /* CREATE INDEX */
{
IndexStmt *stmt = (IndexStmt *) parsetree;
Oid relid;
LOCKMODE lockmode;
bool is_alter_table;
if (stmt->concurrent)
PreventInTransactionBlock(isTopLevel,
"CREATE INDEX CONCURRENTLY");
/*
* Look up the relation OID just once, right here at the
* beginning, so that we don't end up repeating the name
* lookup later and latching onto a different relation
* partway through. To avoid lock upgrade hazards, it's
* important that we take the strongest lock that will
* eventually be needed here, so the lockmode calculation
* needs to match what DefineIndex() does.
*/
lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
: ShareLock;
relid =
RangeVarGetRelidExtended(stmt->relation, lockmode,
0,
RangeVarCallbackOwnsRelation,
NULL);
/*
* CREATE INDEX on partitioned tables (but not regular
* inherited tables) recurses to partitions, so we must
* acquire locks early to avoid deadlocks.
*
* We also take the opportunity to verify that all
* partitions are something we can put an index on, to
* avoid building some indexes only to fail later.
*/
if (stmt->relation->inh &&
get_rel_relkind(relid) == RELKIND_PARTITIONED_TABLE)
{
ListCell *lc;
List *inheritors = NIL;
inheritors = find_all_inheritors(relid, lockmode, NULL);
foreach(lc, inheritors)
{
char relkind = get_rel_relkind(lfirst_oid(lc));
if (relkind != RELKIND_RELATION &&
relkind != RELKIND_MATVIEW &&
relkind != RELKIND_PARTITIONED_TABLE &&
relkind != RELKIND_FOREIGN_TABLE)
elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"",
relkind, stmt->relation->relname);
if (relkind == RELKIND_FOREIGN_TABLE &&
(stmt->unique || stmt->primary))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot create unique index on partitioned table \"%s\"",
stmt->relation->relname),
errdetail("Table \"%s\" contains partitions that are foreign tables.",
stmt->relation->relname)));
}
list_free(inheritors);
}
/*
* If the IndexStmt is already transformed, it must have
* come from generateClonedIndexStmt, which in current
* usage means it came from expandTableLikeClause rather
* than from original parse analysis. And that means we
* must treat it like ALTER TABLE ADD INDEX, not CREATE.
* (This is a bit grotty, but currently it doesn't seem
* worth adding a separate bool field for the purpose.)
*/
is_alter_table = stmt->transformed;
/* Run parse analysis ... */
stmt = transformIndexStmt(relid, stmt, queryString);
/* ... and do it */
EventTriggerAlterTableStart(parsetree);
address =
DefineIndex(relid, /* OID of heap relation */
stmt,
InvalidOid, /* no predefined OID */
InvalidOid, /* no parent index */
InvalidOid, /* no parent constraint */
is_alter_table,
true, /* check_rights */
true, /* check_not_in_use */
false, /* skip_build */
false); /* quiet */
/*
* Add the CREATE INDEX node itself to stash right away;
* if there were any commands stashed in the ALTER TABLE
* code, we need them to appear after this one.
*/
EventTriggerCollectSimpleCommand(address, secondaryObject,
parsetree);
commandCollected = true;
EventTriggerAlterTableEnd();
}
break;
case T_CreateExtensionStmt:
address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
break;
case T_AlterExtensionStmt:
address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
break;
case T_AlterExtensionContentsStmt:
address = ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree,
&secondaryObject);
break;
case T_CreateFdwStmt:
address = CreateForeignDataWrapper((CreateFdwStmt *) parsetree);
break;
case T_AlterFdwStmt:
address = AlterForeignDataWrapper((AlterFdwStmt *) parsetree);
break;
case T_CreateForeignServerStmt:
address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
break;
case T_AlterForeignServerStmt:
address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
break;
case T_CreateUserMappingStmt:
address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
break;
case T_AlterUserMappingStmt:
address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
break;
case T_DropUserMappingStmt:
RemoveUserMapping((DropUserMappingStmt *) parsetree);
/* no commands stashed for DROP */
commandCollected = true;
break;
case T_ImportForeignSchemaStmt:
ImportForeignSchema((ImportForeignSchemaStmt *) parsetree);
/* commands are stashed inside ImportForeignSchema */
commandCollected = true;
break;
case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
{
CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
address = DefineCompositeType(stmt->typevar,
stmt->coldeflist);
}
break;
case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
address = DefineEnum((CreateEnumStmt *) parsetree);
break;
case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
address = DefineRange((CreateRangeStmt *) parsetree);
break;
case T_AlterEnumStmt: /* ALTER TYPE (enum) */
address = AlterEnum((AlterEnumStmt *) parsetree);
break;
case T_ViewStmt: /* CREATE VIEW */
EventTriggerAlterTableStart(parsetree);
address = DefineView((ViewStmt *) parsetree, queryString,
pstmt->stmt_location, pstmt->stmt_len);
EventTriggerCollectSimpleCommand(address, secondaryObject,
parsetree);
/* stashed internally */
commandCollected = true;
EventTriggerAlterTableEnd();
break;
case T_CreateFunctionStmt: /* CREATE FUNCTION */
address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
break;
case T_AlterFunctionStmt: /* ALTER FUNCTION */
address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
break;
case T_RuleStmt: /* CREATE RULE */
address = DefineRule((RuleStmt *) parsetree, queryString);
break;
case T_CreateSeqStmt:
address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
break;
case T_AlterSeqStmt:
address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
break;
case T_CreateTableAsStmt:
address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
params, queryEnv, qc);
break;
case T_RefreshMatViewStmt:
/*
* REFRESH CONCURRENTLY executes some DDL commands internally.
* Inhibit DDL command collection here to avoid those commands
* from showing up in the deparsed command queue. The refresh
* command itself is queued, which is enough.
*/
EventTriggerInhibitCommandCollection();
PG_TRY();
{
address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
queryString, params, qc);
}
PG_FINALLY();
{
EventTriggerUndoInhibitCommandCollection();
}
PG_END_TRY();
break;
case T_CreateTrigStmt:
address = CreateTrigger((CreateTrigStmt *) parsetree,
queryString, InvalidOid, InvalidOid,
InvalidOid, InvalidOid, InvalidOid,
InvalidOid, NULL, false, false);
break;
case T_CreatePLangStmt:
address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
break;
case T_CreateDomainStmt:
address = DefineDomain((CreateDomainStmt *) parsetree);
break;
case T_CreateConversionStmt:
address = CreateConversionCommand((CreateConversionStmt *) parsetree);
break;
case T_CreateCastStmt:
address = CreateCast((CreateCastStmt *) parsetree);
break;
case T_CreateOpClassStmt:
DefineOpClass((CreateOpClassStmt *) parsetree);
/* command is stashed in DefineOpClass */
commandCollected = true;
break;
case T_CreateOpFamilyStmt:
address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
break;
case T_CreateTransformStmt:
address = CreateTransform((CreateTransformStmt *) parsetree);
break;
case T_AlterOpFamilyStmt:
AlterOpFamily((AlterOpFamilyStmt *) parsetree);
/* commands are stashed in AlterOpFamily */
commandCollected = true;
break;
case T_AlterTSDictionaryStmt:
address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
break;
case T_AlterTSConfigurationStmt:
AlterTSConfiguration((AlterTSConfigurationStmt *) parsetree);
/*
* Commands are stashed in MakeConfigurationMapping and
* DropConfigurationMapping, which are called from
* AlterTSConfiguration
*/
commandCollected = true;
break;
case T_AlterTableMoveAllStmt:
AlterTableMoveAll((AlterTableMoveAllStmt *) parsetree);
/* commands are stashed in AlterTableMoveAll */
commandCollected = true;
break;
case T_DropStmt:
ExecDropStmt((DropStmt *) parsetree, isTopLevel);
/* no commands stashed for DROP */
commandCollected = true;
break;
case T_RenameStmt:
address = ExecRenameStmt((RenameStmt *) parsetree);
break;
case T_AlterObjectDependsStmt:
address =
ExecAlterObjectDependsStmt((AlterObjectDependsStmt *) parsetree,
&secondaryObject);
break;
case T_AlterObjectSchemaStmt:
address =
ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree,
&secondaryObject);
break;
case T_AlterOwnerStmt:
address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
break;
case T_AlterOperatorStmt:
address = AlterOperator((AlterOperatorStmt *) parsetree);
break;
case T_AlterTypeStmt:
address = AlterType((AlterTypeStmt *) parsetree);
break;
case T_CommentStmt:
address = CommentObject((CommentStmt *) parsetree);
break;
case T_GrantStmt:
ExecuteGrantStmt((GrantStmt *) parsetree);
/* commands are stashed in ExecGrantStmt_oids */
commandCollected = true;
break;
case T_DropOwnedStmt:
DropOwnedObjects((DropOwnedStmt *) parsetree);
/* no commands stashed for DROP */
commandCollected = true;
break;
case T_AlterDefaultPrivilegesStmt:
ExecAlterDefaultPrivilegesStmt(pstate, (AlterDefaultPrivilegesStmt *) parsetree);
EventTriggerCollectAlterDefPrivs((AlterDefaultPrivilegesStmt *) parsetree);
commandCollected = true;
break;
case T_CreatePolicyStmt: /* CREATE POLICY */
address = CreatePolicy((CreatePolicyStmt *) parsetree);
break;
case T_AlterPolicyStmt: /* ALTER POLICY */
address = AlterPolicy((AlterPolicyStmt *) parsetree);
break;
case T_SecLabelStmt:
address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
break;
case T_CreateAmStmt:
address = CreateAccessMethod((CreateAmStmt *) parsetree);
break;
case T_CreatePublicationStmt:
address = CreatePublication((CreatePublicationStmt *) parsetree);
break;
case T_AlterPublicationStmt:
AlterPublication((AlterPublicationStmt *) parsetree);
/*
* AlterPublication calls EventTriggerCollectSimpleCommand
* directly
*/
commandCollected = true;
break;
case T_CreateSubscriptionStmt:
address = CreateSubscription((CreateSubscriptionStmt *) parsetree,
isTopLevel);
break;
case T_AlterSubscriptionStmt:
address = AlterSubscription((AlterSubscriptionStmt *) parsetree);
break;
case T_DropSubscriptionStmt:
DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
/* no commands stashed for DROP */
commandCollected = true;
break;
case T_CreateStatsStmt:
address = CreateStatistics((CreateStatsStmt *) parsetree);
break;
case T_AlterStatsStmt:
address = AlterStatistics((AlterStatsStmt *) parsetree);
break;
case T_AlterCollationStmt:
address = AlterCollation((AlterCollationStmt *) parsetree);
break;
default:
elog(ERROR, "unrecognized node type: %d",
(int) nodeTag(parsetree));
break;
}
/*
* Remember the object so that ddl_command_end event triggers have
* access to it.
*/
if (!commandCollected)
EventTriggerCollectSimpleCommand(address, secondaryObject,
parsetree);
if (isCompleteQuery)
{
EventTriggerSQLDrop(parsetree);
EventTriggerDDLCommandEnd(parsetree);
}
}
PG_FINALLY();
{
if (needCleanup)
EventTriggerEndCompleteQuery();
}
PG_END_TRY();
}
/*
* ProcessUtilityForAlterTable
* Recursive entry from ALTER TABLE
*
* ALTER TABLE sometimes generates subcommands such as CREATE INDEX.
* It calls this, not the main entry point ProcessUtility, to execute
* such subcommands.
*
* stmt: the utility command to execute
* context: opaque passthrough struct with the info we need
*
* It's caller's responsibility to do CommandCounterIncrement after
* calling this, if needed.
*/
void
ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
{
PlannedStmt *wrapper;
/*
* For event triggers, we must "close" the current complex-command set,
* and start a new one afterwards; this is needed to ensure the ordering
* of command events is consistent with the way they were executed.
*/
EventTriggerAlterTableEnd();
/* Create a suitable wrapper */
wrapper = makeNode(PlannedStmt);
wrapper->commandType = CMD_UTILITY;
wrapper->canSetTag = false;
wrapper->utilityStmt = stmt;
wrapper->stmt_location = context->pstmt->stmt_location;
wrapper->stmt_len = context->pstmt->stmt_len;
ProcessUtility(wrapper,
context->queryString,
PROCESS_UTILITY_SUBCOMMAND,
context->params,
context->queryEnv,
None_Receiver,
NULL);
EventTriggerAlterTableStart(context->pstmt->utilityStmt);
EventTriggerAlterTableRelid(context->relid);
}
/*
* Dispatch function for DropStmt
*/
static void
ExecDropStmt(DropStmt *stmt, bool isTopLevel)
{
switch (stmt->removeType)
{
case OBJECT_INDEX:
if (stmt->concurrent)
PreventInTransactionBlock(isTopLevel,
"DROP INDEX CONCURRENTLY");
/* fall through */
case OBJECT_TABLE:
case OBJECT_SEQUENCE:
case OBJECT_VIEW:
case OBJECT_MATVIEW:
case OBJECT_FOREIGN_TABLE:
RemoveRelations(stmt);
break;
default:
RemoveObjects(stmt);
break;
}
}
/*
* UtilityReturnsTuples
* Return "true" if this utility statement will send output to the
* destination.
*
* Generally, there should be a case here for each case in ProcessUtility
* where "dest" is passed on.
*/
bool
UtilityReturnsTuples(Node *parsetree)
{
switch (nodeTag(parsetree))
{
case T_CallStmt:
{
CallStmt *stmt = (CallStmt *) parsetree;
return (stmt->funcexpr->funcresulttype == RECORDOID);
}
case T_FetchStmt:
{
FetchStmt *stmt = (FetchStmt *) parsetree;
Portal portal;
if (stmt->ismove)
return false;
portal = GetPortalByName(stmt->portalname);
if (!PortalIsValid(portal))
return false; /* not our business to raise error */
return portal->tupDesc ? true : false;
}
case T_ExecuteStmt:
{
ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
PreparedStatement *entry;
entry = FetchPreparedStatement(stmt->name, false);
if (!entry)
return false; /* not our business to raise error */
if (entry->plansource->resultDesc)
return true;
return false;
}
case T_ExplainStmt:
return true;
case T_VariableShowStmt:
return true;
default:
return false;
}
}
/*
* UtilityTupleDescriptor
* Fetch the actual output tuple descriptor for a utility statement
* for which UtilityReturnsTuples() previously returned "true".
*
* The returned descriptor is created in (or copied into) the current memory
* context.
*/
TupleDesc
UtilityTupleDescriptor(Node *parsetree)
{
switch (nodeTag(parsetree))
{
case T_CallStmt:
return CallStmtResultDesc((CallStmt *) parsetree);
case T_FetchStmt:
{
FetchStmt *stmt = (FetchStmt *) parsetree;
Portal portal;
if (stmt->ismove)
return NULL;
portal = GetPortalByName(stmt->portalname);
if (!PortalIsValid(portal))
return NULL; /* not our business to raise error */
return CreateTupleDescCopy(portal->tupDesc);
}
case T_ExecuteStmt:
{
ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
PreparedStatement *entry;
entry = FetchPreparedStatement(stmt->name, false);
if (!entry)
return NULL; /* not our business to raise error */
return FetchPreparedStatementResultDesc(entry);
}
case T_ExplainStmt:
return ExplainResultDesc((ExplainStmt *) parsetree);
case T_VariableShowStmt:
{
VariableShowStmt *n = (VariableShowStmt *) parsetree;
return GetPGVariableResultDesc(n->name);
}
default:
return NULL;
}
}
/*
* QueryReturnsTuples
* Return "true" if this Query will send output to the destination.
*/
#ifdef NOT_USED
bool
QueryReturnsTuples(Query *parsetree)
{
switch (parsetree->commandType)
{
case CMD_SELECT:
/* returns tuples */
return true;
case CMD_INSERT:
case CMD_UPDATE:
case CMD_DELETE:
/* the forms with RETURNING return tuples */
if (parsetree->returningList)
return true;
break;
case CMD_UTILITY:
return UtilityReturnsTuples(parsetree->utilityStmt);
case CMD_UNKNOWN:
case CMD_NOTHING:
/* probably shouldn't get here */
break;
}
return false; /* default */
}
#endif
/*
* UtilityContainsQuery
* Return the contained Query, or NULL if there is none
*
* Certain utility statements, such as EXPLAIN, contain a plannable Query.
* This function encapsulates knowledge of exactly which ones do.
* We assume it is invoked only on already-parse-analyzed statements
* (else the contained parsetree isn't a Query yet).
*
* In some cases (currently, only EXPLAIN of CREATE TABLE AS/SELECT INTO and
* CREATE MATERIALIZED VIEW), potentially Query-containing utility statements
* can be nested. This function will drill down to a non-utility Query, or
* return NULL if none.
*/
Query *
UtilityContainsQuery(Node *parsetree)
{
Query *qry;
switch (nodeTag(parsetree))
{
case T_DeclareCursorStmt:
qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt);
return qry;
case T_ExplainStmt:
qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt);
return qry;
case T_CreateTableAsStmt:
qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt);
return qry;
default:
return NULL;
}
}
/*
* AlterObjectTypeCommandTag
* helper function for CreateCommandTag
*
* This covers most cases where ALTER is used with an ObjectType enum.
*/
static CommandTag
AlterObjectTypeCommandTag(ObjectType objtype)
{
CommandTag tag;
switch (objtype)
{
case OBJECT_AGGREGATE:
tag = CMDTAG_ALTER_AGGREGATE;
break;
case OBJECT_ATTRIBUTE:
tag = CMDTAG_ALTER_TYPE;
break;
case OBJECT_CAST:
tag = CMDTAG_ALTER_CAST;
break;
case OBJECT_COLLATION:
tag = CMDTAG_ALTER_COLLATION;
break;
case OBJECT_COLUMN:
tag = CMDTAG_ALTER_TABLE;
break;
case OBJECT_CONVERSION:
tag = CMDTAG_ALTER_CONVERSION;
break;
case OBJECT_DATABASE:
tag = CMDTAG_ALTER_DATABASE;
break;
case OBJECT_DOMAIN:
case OBJECT_DOMCONSTRAINT:
tag = CMDTAG_ALTER_DOMAIN;
break;
case OBJECT_EXTENSION:
tag = CMDTAG_ALTER_EXTENSION;
break;
case OBJECT_FDW:
tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
break;
case OBJECT_FOREIGN_SERVER:
tag = CMDTAG_ALTER_SERVER;
break;
case OBJECT_FOREIGN_TABLE:
tag = CMDTAG_ALTER_FOREIGN_TABLE;
break;
case OBJECT_FUNCTION:
tag = CMDTAG_ALTER_FUNCTION;
break;
case OBJECT_INDEX:
tag = CMDTAG_ALTER_INDEX;
break;
case OBJECT_LANGUAGE:
tag = CMDTAG_ALTER_LANGUAGE;
break;
case OBJECT_LARGEOBJECT:
tag = CMDTAG_ALTER_LARGE_OBJECT;
break;
case OBJECT_OPCLASS:
tag = CMDTAG_ALTER_OPERATOR_CLASS;
break;
case OBJECT_OPERATOR:
tag = CMDTAG_ALTER_OPERATOR;
break;
case OBJECT_OPFAMILY:
tag = CMDTAG_ALTER_OPERATOR_FAMILY;
break;
case OBJECT_POLICY:
tag = CMDTAG_ALTER_POLICY;
break;
case OBJECT_PROCEDURE:
tag = CMDTAG_ALTER_PROCEDURE;
break;
case OBJECT_ROLE:
tag = CMDTAG_ALTER_ROLE;
break;
case OBJECT_ROUTINE:
tag = CMDTAG_ALTER_ROUTINE;
break;
case OBJECT_RULE:
tag = CMDTAG_ALTER_RULE;
break;
case OBJECT_SCHEMA:
tag = CMDTAG_ALTER_SCHEMA;
break;
case OBJECT_SEQUENCE:
tag = CMDTAG_ALTER_SEQUENCE;
break;
case OBJECT_TABLE:
case OBJECT_TABCONSTRAINT:
tag = CMDTAG_ALTER_TABLE;
break;
case OBJECT_TABLESPACE:
tag = CMDTAG_ALTER_TABLESPACE;
break;
case OBJECT_TRIGGER:
tag = CMDTAG_ALTER_TRIGGER;
break;
case OBJECT_EVENT_TRIGGER:
tag = CMDTAG_ALTER_EVENT_TRIGGER;
break;
case OBJECT_TSCONFIGURATION:
tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
break;
case OBJECT_TSDICTIONARY:
tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
break;
case OBJECT_TSPARSER:
tag = CMDTAG_ALTER_TEXT_SEARCH_PARSER;
break;
case OBJECT_TSTEMPLATE:
tag = CMDTAG_ALTER_TEXT_SEARCH_TEMPLATE;
break;
case OBJECT_TYPE:
tag = CMDTAG_ALTER_TYPE;
break;
case OBJECT_VIEW:
tag = CMDTAG_ALTER_VIEW;
break;
case OBJECT_MATVIEW:
tag = CMDTAG_ALTER_MATERIALIZED_VIEW;
break;
case OBJECT_PUBLICATION:
tag = CMDTAG_ALTER_PUBLICATION;
break;
case OBJECT_SUBSCRIPTION:
tag = CMDTAG_ALTER_SUBSCRIPTION;
break;
case OBJECT_STATISTIC_EXT:
tag = CMDTAG_ALTER_STATISTICS;
break;
default:
tag = CMDTAG_UNKNOWN;
break;
}
return tag;
}
/*
* CreateCommandTag
* utility to get a CommandTag for the command operation,
* given either a raw (un-analyzed) parsetree, an analyzed Query,
* or a PlannedStmt.
*
* This must handle all command types, but since the vast majority
* of 'em are utility commands, it seems sensible to keep it here.
*/
CommandTag
CreateCommandTag(Node *parsetree)
{
CommandTag tag;
switch (nodeTag(parsetree))
{
/* recurse if we're given a RawStmt */
case T_RawStmt:
tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
break;
/* raw plannable queries */
case T_InsertStmt:
tag = CMDTAG_INSERT;
break;
case T_DeleteStmt:
tag = CMDTAG_DELETE;
break;
case T_UpdateStmt:
tag = CMDTAG_UPDATE;
break;
case T_SelectStmt:
tag = CMDTAG_SELECT;
break;
/* utility statements --- same whether raw or cooked */
case T_TransactionStmt:
{
TransactionStmt *stmt = (TransactionStmt *) parsetree;
switch (stmt->kind)
{
case TRANS_STMT_BEGIN:
tag = CMDTAG_BEGIN;
break;
case TRANS_STMT_START:
tag = CMDTAG_START_TRANSACTION;
break;
case TRANS_STMT_COMMIT:
tag = CMDTAG_COMMIT;
break;
case TRANS_STMT_ROLLBACK:
case TRANS_STMT_ROLLBACK_TO:
tag = CMDTAG_ROLLBACK;
break;
case TRANS_STMT_SAVEPOINT:
tag = CMDTAG_SAVEPOINT;
break;
case TRANS_STMT_RELEASE:
tag = CMDTAG_RELEASE;
break;
case TRANS_STMT_PREPARE:
tag = CMDTAG_PREPARE_TRANSACTION;
break;
case TRANS_STMT_COMMIT_PREPARED:
tag = CMDTAG_COMMIT_PREPARED;
break;
case TRANS_STMT_ROLLBACK_PREPARED:
tag = CMDTAG_ROLLBACK_PREPARED;
break;
default:
tag = CMDTAG_UNKNOWN;
break;
}
}
break;
case T_DeclareCursorStmt:
tag = CMDTAG_DECLARE_CURSOR;
break;
case T_ClosePortalStmt:
{
ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
if (stmt->portalname == NULL)
tag = CMDTAG_CLOSE_CURSOR_ALL;
else
tag = CMDTAG_CLOSE_CURSOR;
}
break;
case T_FetchStmt:
{
FetchStmt *stmt = (FetchStmt *) parsetree;
tag = (stmt->ismove) ? CMDTAG_MOVE : CMDTAG_FETCH;
}
break;
case T_CreateDomainStmt:
tag = CMDTAG_CREATE_DOMAIN;
break;
case T_CreateSchemaStmt:
tag = CMDTAG_CREATE_SCHEMA;
break;
case T_CreateStmt:
tag = CMDTAG_CREATE_TABLE;
break;
case T_CreateTableSpaceStmt:
tag = CMDTAG_CREATE_TABLESPACE;
break;
case T_DropTableSpaceStmt:
tag = CMDTAG_DROP_TABLESPACE;
break;
case T_AlterTableSpaceOptionsStmt:
tag = CMDTAG_ALTER_TABLESPACE;
break;
case T_CreateExtensionStmt:
tag = CMDTAG_CREATE_EXTENSION;
break;
case T_AlterExtensionStmt:
tag = CMDTAG_ALTER_EXTENSION;
break;
case T_AlterExtensionContentsStmt:
tag = CMDTAG_ALTER_EXTENSION;
break;
case T_CreateFdwStmt:
tag = CMDTAG_CREATE_FOREIGN_DATA_WRAPPER;
break;
case T_AlterFdwStmt:
tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
break;
case T_CreateForeignServerStmt:
tag = CMDTAG_CREATE_SERVER;
break;
case T_AlterForeignServerStmt:
tag = CMDTAG_ALTER_SERVER;
break;
case T_CreateUserMappingStmt:
tag = CMDTAG_CREATE_USER_MAPPING;
break;
case T_AlterUserMappingStmt:
tag = CMDTAG_ALTER_USER_MAPPING;
break;
case T_DropUserMappingStmt:
tag = CMDTAG_DROP_USER_MAPPING;
break;
case T_CreateForeignTableStmt:
tag = CMDTAG_CREATE_FOREIGN_TABLE;
break;
case T_ImportForeignSchemaStmt:
tag = CMDTAG_IMPORT_FOREIGN_SCHEMA;
break;
case T_DropStmt:
switch (((DropStmt *) parsetree)->removeType)
{
case OBJECT_TABLE:
tag = CMDTAG_DROP_TABLE;
break;
case OBJECT_SEQUENCE:
tag = CMDTAG_DROP_SEQUENCE;
break;
case OBJECT_VIEW:
tag = CMDTAG_DROP_VIEW;
break;
case OBJECT_MATVIEW:
tag = CMDTAG_DROP_MATERIALIZED_VIEW;
break;
case OBJECT_INDEX:
tag = CMDTAG_DROP_INDEX;
break;
case OBJECT_TYPE:
tag = CMDTAG_DROP_TYPE;
break;
case OBJECT_DOMAIN:
tag = CMDTAG_DROP_DOMAIN;
break;
case OBJECT_COLLATION:
tag = CMDTAG_DROP_COLLATION;
break;
case OBJECT_CONVERSION:
tag = CMDTAG_DROP_CONVERSION;
break;
case OBJECT_SCHEMA:
tag = CMDTAG_DROP_SCHEMA;
break;
case OBJECT_TSPARSER:
tag = CMDTAG_DROP_TEXT_SEARCH_PARSER;
break;
case OBJECT_TSDICTIONARY:
tag = CMDTAG_DROP_TEXT_SEARCH_DICTIONARY;
break;
case OBJECT_TSTEMPLATE:
tag = CMDTAG_DROP_TEXT_SEARCH_TEMPLATE;
break;
case OBJECT_TSCONFIGURATION:
tag = CMDTAG_DROP_TEXT_SEARCH_CONFIGURATION;
break;
case OBJECT_FOREIGN_TABLE:
tag = CMDTAG_DROP_FOREIGN_TABLE;
break;
case OBJECT_EXTENSION:
tag = CMDTAG_DROP_EXTENSION;
break;
case OBJECT_FUNCTION:
tag = CMDTAG_DROP_FUNCTION;
break;
case OBJECT_PROCEDURE:
tag = CMDTAG_DROP_PROCEDURE;
break;
case OBJECT_ROUTINE:
tag = CMDTAG_DROP_ROUTINE;
break;
case OBJECT_AGGREGATE:
tag = CMDTAG_DROP_AGGREGATE;
break;
case OBJECT_OPERATOR:
tag = CMDTAG_DROP_OPERATOR;
break;
case OBJECT_LANGUAGE:
tag = CMDTAG_DROP_LANGUAGE;
break;
case OBJECT_CAST:
tag = CMDTAG_DROP_CAST;
break;
case OBJECT_TRIGGER:
tag = CMDTAG_DROP_TRIGGER;
break;
case OBJECT_EVENT_TRIGGER:
tag = CMDTAG_DROP_EVENT_TRIGGER;
break;
case OBJECT_RULE:
tag = CMDTAG_DROP_RULE;
break;
case OBJECT_FDW:
tag = CMDTAG_DROP_FOREIGN_DATA_WRAPPER;
break;
case OBJECT_FOREIGN_SERVER:
tag = CMDTAG_DROP_SERVER;
break;
case OBJECT_OPCLASS:
tag = CMDTAG_DROP_OPERATOR_CLASS;
break;
case OBJECT_OPFAMILY:
tag = CMDTAG_DROP_OPERATOR_FAMILY;
break;
case OBJECT_POLICY:
tag = CMDTAG_DROP_POLICY;
break;
case OBJECT_TRANSFORM:
tag = CMDTAG_DROP_TRANSFORM;
break;
case OBJECT_ACCESS_METHOD:
tag = CMDTAG_DROP_ACCESS_METHOD;
break;
case OBJECT_PUBLICATION:
tag = CMDTAG_DROP_PUBLICATION;
break;
case OBJECT_STATISTIC_EXT:
tag = CMDTAG_DROP_STATISTICS;
break;
default:
tag = CMDTAG_UNKNOWN;
}
break;
case T_TruncateStmt:
tag = CMDTAG_TRUNCATE_TABLE;
break;
case T_CommentStmt:
tag = CMDTAG_COMMENT;
break;
case T_SecLabelStmt:
tag = CMDTAG_SECURITY_LABEL;
break;
case T_CopyStmt:
tag = CMDTAG_COPY;
break;
case T_RenameStmt:
/*
* When the column is renamed, the command tag is created from its
* relation type
*/
tag = AlterObjectTypeCommandTag(((RenameStmt *) parsetree)->renameType == OBJECT_COLUMN ?
((RenameStmt *) parsetree)->relationType :
((RenameStmt *) parsetree)->renameType);
break;
case T_AlterObjectDependsStmt:
tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
break;
case T_AlterObjectSchemaStmt:
tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
break;
case T_AlterOwnerStmt:
tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
break;
case T_AlterTableMoveAllStmt:
tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
break;
case T_AlterTableStmt:
tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
break;
case T_AlterDomainStmt:
tag = CMDTAG_ALTER_DOMAIN;
break;
case T_AlterFunctionStmt:
switch (((AlterFunctionStmt *) parsetree)->objtype)
{
case OBJECT_FUNCTION:
tag = CMDTAG_ALTER_FUNCTION;
break;
case OBJECT_PROCEDURE:
tag = CMDTAG_ALTER_PROCEDURE;
break;
case OBJECT_ROUTINE:
tag = CMDTAG_ALTER_ROUTINE;
break;
default:
tag = CMDTAG_UNKNOWN;
}
break;
case T_GrantStmt:
{
GrantStmt *stmt = (GrantStmt *) parsetree;
tag = (stmt->is_grant) ? CMDTAG_GRANT : CMDTAG_REVOKE;
}
break;
case T_GrantRoleStmt:
{
GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
tag = (stmt->is_grant) ? CMDTAG_GRANT_ROLE : CMDTAG_REVOKE_ROLE;
}
break;
case T_AlterDefaultPrivilegesStmt:
tag = CMDTAG_ALTER_DEFAULT_PRIVILEGES;
break;
case T_DefineStmt:
switch (((DefineStmt *) parsetree)->kind)
{
case OBJECT_AGGREGATE:
tag = CMDTAG_CREATE_AGGREGATE;
break;
case OBJECT_OPERATOR:
tag = CMDTAG_CREATE_OPERATOR;
break;
case OBJECT_TYPE:
tag = CMDTAG_CREATE_TYPE;
break;
case OBJECT_TSPARSER:
tag = CMDTAG_CREATE_TEXT_SEARCH_PARSER;
break;
case OBJECT_TSDICTIONARY:
tag = CMDTAG_CREATE_TEXT_SEARCH_DICTIONARY;
break;
case OBJECT_TSTEMPLATE:
tag = CMDTAG_CREATE_TEXT_SEARCH_TEMPLATE;
break;
case OBJECT_TSCONFIGURATION:
tag = CMDTAG_CREATE_TEXT_SEARCH_CONFIGURATION;
break;
case OBJECT_COLLATION:
tag = CMDTAG_CREATE_COLLATION;
break;
case OBJECT_ACCESS_METHOD:
tag = CMDTAG_CREATE_ACCESS_METHOD;
break;
default:
tag = CMDTAG_UNKNOWN;
}
break;
case T_CompositeTypeStmt:
tag = CMDTAG_CREATE_TYPE;
break;
case T_CreateEnumStmt:
tag = CMDTAG_CREATE_TYPE;
break;
case T_CreateRangeStmt:
tag = CMDTAG_CREATE_TYPE;
break;
case T_AlterEnumStmt:
tag = CMDTAG_ALTER_TYPE;
break;
case T_ViewStmt:
tag = CMDTAG_CREATE_VIEW;
break;
case T_CreateFunctionStmt:
if (((CreateFunctionStmt *) parsetree)->is_procedure)
tag = CMDTAG_CREATE_PROCEDURE;
else
tag = CMDTAG_CREATE_FUNCTION;
break;
case T_IndexStmt:
tag = CMDTAG_CREATE_INDEX;
break;
case T_RuleStmt:
tag = CMDTAG_CREATE_RULE;
break;
case T_CreateSeqStmt:
tag = CMDTAG_CREATE_SEQUENCE;
break;
case T_AlterSeqStmt:
tag = CMDTAG_ALTER_SEQUENCE;
break;
case T_DoStmt:
tag = CMDTAG_DO;
break;
case T_CreatedbStmt:
tag = CMDTAG_CREATE_DATABASE;
break;
case T_AlterDatabaseStmt:
tag = CMDTAG_ALTER_DATABASE;
break;
case T_AlterDatabaseSetStmt:
tag = CMDTAG_ALTER_DATABASE;
break;
case T_DropdbStmt:
tag = CMDTAG_DROP_DATABASE;
break;
case T_NotifyStmt:
tag = CMDTAG_NOTIFY;
break;
case T_ListenStmt:
tag = CMDTAG_LISTEN;
break;
case T_UnlistenStmt:
tag = CMDTAG_UNLISTEN;
break;
case T_LoadStmt:
tag = CMDTAG_LOAD;
break;
case T_CallStmt:
tag = CMDTAG_CALL;
break;
case T_ClusterStmt:
tag = CMDTAG_CLUSTER;
break;
case T_VacuumStmt:
if (((VacuumStmt *) parsetree)->is_vacuumcmd)
tag = CMDTAG_VACUUM;
else
tag = CMDTAG_ANALYZE;
break;
case T_ExplainStmt:
tag = CMDTAG_EXPLAIN;
break;
case T_CreateTableAsStmt:
switch (((CreateTableAsStmt *) parsetree)->relkind)
{
case OBJECT_TABLE:
if (((CreateTableAsStmt *) parsetree)->is_select_into)
tag = CMDTAG_SELECT_INTO;
else
tag = CMDTAG_CREATE_TABLE_AS;
break;
case OBJECT_MATVIEW:
tag = CMDTAG_CREATE_MATERIALIZED_VIEW;
break;
default:
tag = CMDTAG_UNKNOWN;
}
break;
case T_RefreshMatViewStmt:
tag = CMDTAG_REFRESH_MATERIALIZED_VIEW;
break;
case T_AlterSystemStmt:
tag = CMDTAG_ALTER_SYSTEM;
break;
case T_VariableSetStmt:
switch (((VariableSetStmt *) parsetree)->kind)
{
case VAR_SET_VALUE:
case VAR_SET_CURRENT:
case VAR_SET_DEFAULT:
case VAR_SET_MULTI:
tag = CMDTAG_SET;
break;
case VAR_RESET:
case VAR_RESET_ALL:
tag = CMDTAG_RESET;
break;
default:
tag = CMDTAG_UNKNOWN;
}
break;
case T_VariableShowStmt:
tag = CMDTAG_SHOW;
break;
case T_DiscardStmt:
switch (((DiscardStmt *) parsetree)->target)
{
case DISCARD_ALL:
tag = CMDTAG_DISCARD_ALL;
break;
case DISCARD_PLANS:
tag = CMDTAG_DISCARD_PLANS;
break;
case DISCARD_TEMP:
tag = CMDTAG_DISCARD_TEMP;
break;
case DISCARD_SEQUENCES:
tag = CMDTAG_DISCARD_SEQUENCES;
break;
default:
tag = CMDTAG_UNKNOWN;
}
break;
case T_CreateTransformStmt:
tag = CMDTAG_CREATE_TRANSFORM;
break;
case T_CreateTrigStmt:
tag = CMDTAG_CREATE_TRIGGER;
break;
case T_CreateEventTrigStmt:
tag = CMDTAG_CREATE_EVENT_TRIGGER;
break;
case T_AlterEventTrigStmt:
tag = CMDTAG_ALTER_EVENT_TRIGGER;
break;
case T_CreatePLangStmt:
tag = CMDTAG_CREATE_LANGUAGE;
break;
case T_CreateRoleStmt:
tag = CMDTAG_CREATE_ROLE;
break;
case T_AlterRoleStmt:
tag = CMDTAG_ALTER_ROLE;
break;
case T_AlterRoleSetStmt:
tag = CMDTAG_ALTER_ROLE;
break;
case T_DropRoleStmt:
tag = CMDTAG_DROP_ROLE;
break;
case T_DropOwnedStmt:
tag = CMDTAG_DROP_OWNED;
break;
case T_ReassignOwnedStmt:
tag = CMDTAG_REASSIGN_OWNED;
break;
case T_LockStmt:
tag = CMDTAG_LOCK_TABLE;
break;
case T_ConstraintsSetStmt:
tag = CMDTAG_SET_CONSTRAINTS;
break;
case T_CheckPointStmt:
tag = CMDTAG_CHECKPOINT;
break;
case T_ReindexStmt:
tag = CMDTAG_REINDEX;
break;
case T_CreateConversionStmt:
tag = CMDTAG_CREATE_CONVERSION;
break;
case T_CreateCastStmt:
tag = CMDTAG_CREATE_CAST;
break;
case T_CreateOpClassStmt:
tag = CMDTAG_CREATE_OPERATOR_CLASS;
break;
case T_CreateOpFamilyStmt:
tag = CMDTAG_CREATE_OPERATOR_FAMILY;
break;
case T_AlterOpFamilyStmt:
tag = CMDTAG_ALTER_OPERATOR_FAMILY;
break;
case T_AlterOperatorStmt:
tag = CMDTAG_ALTER_OPERATOR;
break;
case T_AlterTypeStmt:
tag = CMDTAG_ALTER_TYPE;
break;
case T_AlterTSDictionaryStmt:
tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
break;
case T_AlterTSConfigurationStmt:
tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
break;
case T_CreatePolicyStmt:
tag = CMDTAG_CREATE_POLICY;
break;
case T_AlterPolicyStmt:
tag = CMDTAG_ALTER_POLICY;
break;
case T_CreateAmStmt:
tag = CMDTAG_CREATE_ACCESS_METHOD;
break;
case T_CreatePublicationStmt:
tag = CMDTAG_CREATE_PUBLICATION;
break;
case T_AlterPublicationStmt:
tag = CMDTAG_ALTER_PUBLICATION;
break;
case T_CreateSubscriptionStmt:
tag = CMDTAG_CREATE_SUBSCRIPTION;
break;
case T_AlterSubscriptionStmt:
tag = CMDTAG_ALTER_SUBSCRIPTION;
break;
case T_DropSubscriptionStmt:
tag = CMDTAG_DROP_SUBSCRIPTION;
break;
case T_AlterCollationStmt:
tag = CMDTAG_ALTER_COLLATION;
break;
case T_PrepareStmt:
tag = CMDTAG_PREPARE;
break;
case T_ExecuteStmt:
tag = CMDTAG_EXECUTE;
break;
case T_CreateStatsStmt:
tag = CMDTAG_CREATE_STATISTICS;
break;
case T_AlterStatsStmt:
tag = CMDTAG_ALTER_STATISTICS;
break;
case T_DeallocateStmt:
{
DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
if (stmt->name == NULL)
tag = CMDTAG_DEALLOCATE_ALL;
else
tag = CMDTAG_DEALLOCATE;
}
break;
/* already-planned queries */
case T_PlannedStmt:
{
PlannedStmt *stmt = (PlannedStmt *) parsetree;
switch (stmt->commandType)
{
case CMD_SELECT:
/*
* We take a little extra care here so that the result
* will be useful for complaints about read-only
* statements
*/
if (stmt->rowMarks != NIL)
{
/* not 100% but probably close enough */
switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
{
case LCS_FORKEYSHARE:
tag = CMDTAG_SELECT_FOR_KEY_SHARE;
break;
case LCS_FORSHARE:
tag = CMDTAG_SELECT_FOR_SHARE;
break;
case LCS_FORNOKEYUPDATE:
tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
break;
case LCS_FORUPDATE:
tag = CMDTAG_SELECT_FOR_UPDATE;
break;
default:
tag = CMDTAG_SELECT;
break;
}
}
else
tag = CMDTAG_SELECT;
break;
case CMD_UPDATE:
tag = CMDTAG_UPDATE;
break;
case CMD_INSERT:
tag = CMDTAG_INSERT;
break;
case CMD_DELETE:
tag = CMDTAG_DELETE;
break;
case CMD_UTILITY:
tag = CreateCommandTag(stmt->utilityStmt);
break;
default:
elog(WARNING, "unrecognized commandType: %d",
(int) stmt->commandType);
tag = CMDTAG_UNKNOWN;
break;
}
}
break;
/* parsed-and-rewritten-but-not-planned queries */
case T_Query:
{
Query *stmt = (Query *) parsetree;
switch (stmt->commandType)
{
case CMD_SELECT:
/*
* We take a little extra care here so that the result
* will be useful for complaints about read-only
* statements
*/
if (stmt->rowMarks != NIL)
{
/* not 100% but probably close enough */
switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
{
case LCS_FORKEYSHARE:
tag = CMDTAG_SELECT_FOR_KEY_SHARE;
break;
case LCS_FORSHARE:
tag = CMDTAG_SELECT_FOR_SHARE;
break;
case LCS_FORNOKEYUPDATE:
tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
break;
case LCS_FORUPDATE:
tag = CMDTAG_SELECT_FOR_UPDATE;
break;
default:
tag = CMDTAG_UNKNOWN;
break;
}
}
else
tag = CMDTAG_SELECT;
break;
case CMD_UPDATE:
tag = CMDTAG_UPDATE;
break;
case CMD_INSERT:
tag = CMDTAG_INSERT;
break;
case CMD_DELETE:
tag = CMDTAG_DELETE;
break;
case CMD_UTILITY:
tag = CreateCommandTag(stmt->utilityStmt);
break;
default:
elog(WARNING, "unrecognized commandType: %d",
(int) stmt->commandType);
tag = CMDTAG_UNKNOWN;
break;
}
}
break;
default:
elog(WARNING, "unrecognized node type: %d",
(int) nodeTag(parsetree));
tag = CMDTAG_UNKNOWN;
break;
}
return tag;
}
/*
* GetCommandLogLevel
* utility to get the minimum log_statement level for a command,
* given either a raw (un-analyzed) parsetree, an analyzed Query,
* or a PlannedStmt.
*
* This must handle all command types, but since the vast majority
* of 'em are utility commands, it seems sensible to keep it here.
*/
LogStmtLevel
GetCommandLogLevel(Node *parsetree)
{
LogStmtLevel lev;
switch (nodeTag(parsetree))
{
/* recurse if we're given a RawStmt */
case T_RawStmt:
lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
break;
/* raw plannable queries */
case T_InsertStmt:
case T_DeleteStmt:
case T_UpdateStmt:
lev = LOGSTMT_MOD;
break;
case T_SelectStmt:
if (((SelectStmt *) parsetree)->intoClause)
lev = LOGSTMT_DDL; /* SELECT INTO */
else
lev = LOGSTMT_ALL;
break;
/* utility statements --- same whether raw or cooked */
case T_TransactionStmt:
lev = LOGSTMT_ALL;
break;
case T_DeclareCursorStmt:
lev = LOGSTMT_ALL;
break;
case T_ClosePortalStmt:
lev = LOGSTMT_ALL;
break;
case T_FetchStmt:
lev = LOGSTMT_ALL;
break;
case T_CreateSchemaStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateStmt:
case T_CreateForeignTableStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateTableSpaceStmt:
case T_DropTableSpaceStmt:
case T_AlterTableSpaceOptionsStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateExtensionStmt:
case T_AlterExtensionStmt:
case T_AlterExtensionContentsStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateFdwStmt:
case T_AlterFdwStmt:
case T_CreateForeignServerStmt:
case T_AlterForeignServerStmt:
case T_CreateUserMappingStmt:
case T_AlterUserMappingStmt:
case T_DropUserMappingStmt:
case T_ImportForeignSchemaStmt:
lev = LOGSTMT_DDL;
break;
case T_DropStmt:
lev = LOGSTMT_DDL;
break;
case T_TruncateStmt:
lev = LOGSTMT_MOD;
break;
case T_CommentStmt:
lev = LOGSTMT_DDL;
break;
case T_SecLabelStmt:
lev = LOGSTMT_DDL;
break;
case T_CopyStmt:
if (((CopyStmt *) parsetree)->is_from)
lev = LOGSTMT_MOD;
else
lev = LOGSTMT_ALL;
break;
case T_PrepareStmt:
{
PrepareStmt *stmt = (PrepareStmt *) parsetree;
/* Look through a PREPARE to the contained stmt */
lev = GetCommandLogLevel(stmt->query);
}
break;
case T_ExecuteStmt:
{
ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
PreparedStatement *ps;
/* Look through an EXECUTE to the referenced stmt */
ps = FetchPreparedStatement(stmt->name, false);
if (ps && ps->plansource->raw_parse_tree)
lev = GetCommandLogLevel(ps->plansource->raw_parse_tree->stmt);
else
lev = LOGSTMT_ALL;
}
break;
case T_DeallocateStmt:
lev = LOGSTMT_ALL;
break;
case T_RenameStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterObjectDependsStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterObjectSchemaStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterOwnerStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterOperatorStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterTypeStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterTableMoveAllStmt:
case T_AlterTableStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterDomainStmt:
lev = LOGSTMT_DDL;
break;
case T_GrantStmt:
lev = LOGSTMT_DDL;
break;
case T_GrantRoleStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterDefaultPrivilegesStmt:
lev = LOGSTMT_DDL;
break;
case T_DefineStmt:
lev = LOGSTMT_DDL;
break;
case T_CompositeTypeStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateEnumStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateRangeStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterEnumStmt:
lev = LOGSTMT_DDL;
break;
case T_ViewStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateFunctionStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterFunctionStmt:
lev = LOGSTMT_DDL;
break;
case T_IndexStmt:
lev = LOGSTMT_DDL;
break;
case T_RuleStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateSeqStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterSeqStmt:
lev = LOGSTMT_DDL;
break;
case T_DoStmt:
lev = LOGSTMT_ALL;
break;
case T_CreatedbStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterDatabaseStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterDatabaseSetStmt:
lev = LOGSTMT_DDL;
break;
case T_DropdbStmt:
lev = LOGSTMT_DDL;
break;
case T_NotifyStmt:
lev = LOGSTMT_ALL;
break;
case T_ListenStmt:
lev = LOGSTMT_ALL;
break;
case T_UnlistenStmt:
lev = LOGSTMT_ALL;
break;
case T_LoadStmt:
lev = LOGSTMT_ALL;
break;
case T_CallStmt:
lev = LOGSTMT_ALL;
break;
case T_ClusterStmt:
lev = LOGSTMT_DDL;
break;
case T_VacuumStmt:
lev = LOGSTMT_ALL;
break;
case T_ExplainStmt:
{
ExplainStmt *stmt = (ExplainStmt *) parsetree;
bool analyze = false;
ListCell *lc;
/* Look through an EXPLAIN ANALYZE to the contained stmt */
foreach(lc, stmt->options)
{
DefElem *opt = (DefElem *) lfirst(lc);
if (strcmp(opt->defname, "analyze") == 0)
analyze = defGetBoolean(opt);
/* don't "break", as explain.c will use the last value */
}
if (analyze)
return GetCommandLogLevel(stmt->query);
/* Plain EXPLAIN isn't so interesting */
lev = LOGSTMT_ALL;
}
break;
case T_CreateTableAsStmt:
lev = LOGSTMT_DDL;
break;
case T_RefreshMatViewStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterSystemStmt:
lev = LOGSTMT_DDL;
break;
case T_VariableSetStmt:
lev = LOGSTMT_ALL;
break;
case T_VariableShowStmt:
lev = LOGSTMT_ALL;
break;
case T_DiscardStmt:
lev = LOGSTMT_ALL;
break;
case T_CreateTrigStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateEventTrigStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterEventTrigStmt:
lev = LOGSTMT_DDL;
break;
case T_CreatePLangStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateDomainStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateRoleStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterRoleStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterRoleSetStmt:
lev = LOGSTMT_DDL;
break;
case T_DropRoleStmt:
lev = LOGSTMT_DDL;
break;
case T_DropOwnedStmt:
lev = LOGSTMT_DDL;
break;
case T_ReassignOwnedStmt:
lev = LOGSTMT_DDL;
break;
case T_LockStmt:
lev = LOGSTMT_ALL;
break;
case T_ConstraintsSetStmt:
lev = LOGSTMT_ALL;
break;
case T_CheckPointStmt:
lev = LOGSTMT_ALL;
break;
case T_ReindexStmt:
lev = LOGSTMT_ALL; /* should this be DDL? */
break;
case T_CreateConversionStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateCastStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateOpClassStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateOpFamilyStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateTransformStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterOpFamilyStmt:
lev = LOGSTMT_DDL;
break;
case T_CreatePolicyStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterPolicyStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterTSDictionaryStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterTSConfigurationStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateAmStmt:
lev = LOGSTMT_DDL;
break;
case T_CreatePublicationStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterPublicationStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateSubscriptionStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterSubscriptionStmt:
lev = LOGSTMT_DDL;
break;
case T_DropSubscriptionStmt:
lev = LOGSTMT_DDL;
break;
case T_CreateStatsStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterStatsStmt:
lev = LOGSTMT_DDL;
break;
case T_AlterCollationStmt:
lev = LOGSTMT_DDL;
break;
/* already-planned queries */
case T_PlannedStmt:
{
PlannedStmt *stmt = (PlannedStmt *) parsetree;
switch (stmt->commandType)
{
case CMD_SELECT:
lev = LOGSTMT_ALL;
break;
case CMD_UPDATE:
case CMD_INSERT:
case CMD_DELETE:
lev = LOGSTMT_MOD;
break;
case CMD_UTILITY:
lev = GetCommandLogLevel(stmt->utilityStmt);
break;
default:
elog(WARNING, "unrecognized commandType: %d",
(int) stmt->commandType);
lev = LOGSTMT_ALL;
break;
}
}
break;
/* parsed-and-rewritten-but-not-planned queries */
case T_Query:
{
Query *stmt = (Query *) parsetree;
switch (stmt->commandType)
{
case CMD_SELECT:
lev = LOGSTMT_ALL;
break;
case CMD_UPDATE:
case CMD_INSERT:
case CMD_DELETE:
lev = LOGSTMT_MOD;
break;
case CMD_UTILITY:
lev = GetCommandLogLevel(stmt->utilityStmt);
break;
default:
elog(WARNING, "unrecognized commandType: %d",
(int) stmt->commandType);
lev = LOGSTMT_ALL;
break;
}
}
break;
default:
elog(WARNING, "unrecognized node type: %d",
(int) nodeTag(parsetree));
lev = LOGSTMT_ALL;
break;
}
return lev;
}
|