PostgreSQL Source Code: src/backend/nodes/nodeFuncs.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
25
27static int leftmostLoc(int loc1, int loc2);
31 void *context);
34 void *context);
35
36
37
38
39
40
43{
45
46 if (!expr)
48
50 {
51 case T_Var:
52 type = ((const Var *) expr)->vartype;
53 break;
54 case T_Const:
55 type = ((const Const *) expr)->consttype;
56 break;
57 case T_Param:
58 type = ((const Param *) expr)->paramtype;
59 break;
60 case T_Aggref:
61 type = ((const Aggref *) expr)->aggtype;
62 break;
63 case T_GroupingFunc:
64 type = INT4OID;
65 break;
66 case T_WindowFunc:
68 break;
69 case T_MergeSupportFunc:
71 break;
72 case T_SubscriptingRef:
74 break;
75 case T_FuncExpr:
76 type = ((const FuncExpr *) expr)->funcresulttype;
77 break;
78 case T_NamedArgExpr:
80 break;
81 case T_OpExpr:
82 type = ((const OpExpr *) expr)->opresulttype;
83 break;
84 case T_DistinctExpr:
86 break;
87 case T_NullIfExpr:
89 break;
90 case T_ScalarArrayOpExpr:
91 type = BOOLOID;
92 break;
93 case T_BoolExpr:
94 type = BOOLOID;
95 break;
96 case T_SubLink:
97 {
99
102 {
103
106
108 elog(ERROR, "cannot get type for untransformed sublink");
110 Assert(!tent->resjunk);
113 {
117 (errcode(ERRCODE_UNDEFINED_OBJECT),
118 errmsg("could not find array type for data type %s",
120 }
121 }
123 {
124
125 type = RECORDOID;
126 }
127 else
128 {
129
130 type = BOOLOID;
131 }
132 }
133 break;
134 case T_SubPlan:
135 {
137
140 {
141
144 {
148 (errcode(ERRCODE_UNDEFINED_OBJECT),
149 errmsg("could not find array type for data type %s",
151 }
152 }
154 {
155
156 type = RECORDOID;
157 }
158 else
159 {
160
161 type = BOOLOID;
162 }
163 }
164 break;
165 case T_AlternativeSubPlan:
166 {
168
169
171 }
172 break;
173 case T_FieldSelect:
175 break;
176 case T_FieldStore:
178 break;
179 case T_RelabelType:
181 break;
182 case T_CoerceViaIO:
184 break;
185 case T_ArrayCoerceExpr:
187 break;
188 case T_ConvertRowtypeExpr:
190 break;
191 case T_CollateExpr:
193 break;
194 case T_CaseExpr:
196 break;
197 case T_CaseTestExpr:
199 break;
200 case T_ArrayExpr:
202 break;
203 case T_RowExpr:
204 type = ((const RowExpr *) expr)->row_typeid;
205 break;
206 case T_RowCompareExpr:
207 type = BOOLOID;
208 break;
209 case T_CoalesceExpr:
211 break;
212 case T_MinMaxExpr:
214 break;
215 case T_SQLValueFunction:
217 break;
218 case T_XmlExpr:
220 type = BOOLOID;
222 type = TEXTOID;
223 else
224 type = XMLOID;
225 break;
226 case T_JsonValueExpr:
227 {
229
231 }
232 break;
233 case T_JsonConstructorExpr:
235 break;
236 case T_JsonIsPredicate:
237 type = BOOLOID;
238 break;
239 case T_JsonExpr:
240 {
242
244 break;
245 }
246 case T_JsonBehavior:
247 {
249
251 break;
252 }
253 case T_NullTest:
254 type = BOOLOID;
255 break;
256 case T_BooleanTest:
257 type = BOOLOID;
258 break;
259 case T_CoerceToDomain:
261 break;
262 case T_CoerceToDomainValue:
264 break;
265 case T_SetToDefault:
267 break;
268 case T_CurrentOfExpr:
269 type = BOOLOID;
270 break;
271 case T_NextValueExpr:
273 break;
274 case T_InferenceElem:
275 {
277
279 }
280 break;
281 case T_ReturningExpr:
283 break;
284 case T_PlaceHolderVar:
286 break;
287 default:
288 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
290 break;
291 }
293}
294
295
296
297
298
299
302{
303 if (!expr)
304 return -1;
305
307 {
308 case T_Var:
309 return ((const Var *) expr)->vartypmod;
310 case T_Const:
311 return ((const Const *) expr)->consttypmod;
312 case T_Param:
313 return ((const Param *) expr)->paramtypmod;
314 case T_SubscriptingRef:
316 case T_FuncExpr:
317 {
318 int32 coercedTypmod;
319
320
322 return coercedTypmod;
323 }
324 break;
325 case T_NamedArgExpr:
327 case T_NullIfExpr:
328 {
329
330
331
332
334
336 }
337 break;
338 case T_SubLink:
339 {
341
344 {
345
348
350 elog(ERROR, "cannot get type for untransformed sublink");
352 Assert(!tent->resjunk);
354
355 }
356
357 }
358 break;
359 case T_SubPlan:
360 {
362
365 {
366
367
369 }
370
371 }
372 break;
373 case T_AlternativeSubPlan:
374 {
376
377
379 }
380 break;
381 case T_FieldSelect:
382 return ((const FieldSelect *) expr)->resulttypmod;
383 case T_RelabelType:
384 return ((const RelabelType *) expr)->resulttypmod;
385 case T_ArrayCoerceExpr:
387 case T_CollateExpr:
389 case T_CaseExpr:
390 {
391
392
393
394
396 Oid casetype = cexpr->casetype;
399
401 return -1;
403 return -1;
405 if (typmod < 0)
406 return -1;
408 {
410
412 return -1;
414 return -1;
415 }
416 return typmod;
417 }
418 break;
419 case T_CaseTestExpr:
420 return ((const CaseTestExpr *) expr)->typeMod;
421 case T_ArrayExpr:
422 {
423
424
425
426
428 Oid commontype;
431
432 if (arrayexpr->elements == NIL)
433 return -1;
435 if (typmod < 0)
436 return -1;
437 if (arrayexpr->multidims)
438 commontype = arrayexpr->array_typeid;
439 else
440 commontype = arrayexpr->element_typeid;
441 foreach(elem, arrayexpr->elements)
442 {
444
446 return -1;
448 return -1;
449 }
450 return typmod;
451 }
452 break;
453 case T_CoalesceExpr:
454 {
455
456
457
458
460 Oid coalescetype = cexpr->coalescetype;
463
465 return -1;
467 if (typmod < 0)
468 return -1;
470 {
472
474 return -1;
476 return -1;
477 }
478 return typmod;
479 }
480 break;
481 case T_MinMaxExpr:
482 {
483
484
485
486
488 Oid minmaxtype = mexpr->minmaxtype;
491
493 return -1;
495 if (typmod < 0)
496 return -1;
498 {
500
502 return -1;
504 return -1;
505 }
506 return typmod;
507 }
508 break;
509 case T_SQLValueFunction:
511 case T_JsonValueExpr:
513 case T_JsonConstructorExpr:
515 case T_JsonExpr:
516 {
518
520 }
521 break;
522 case T_JsonBehavior:
523 {
525
527 }
528 break;
529 case T_CoerceToDomain:
530 return ((const CoerceToDomain *) expr)->resulttypmod;
531 case T_CoerceToDomainValue:
533 case T_SetToDefault:
534 return ((const SetToDefault *) expr)->typeMod;
535 case T_ReturningExpr:
537 case T_PlaceHolderVar:
539 default:
540 break;
541 }
542 return -1;
543}
544
545
546
547
548
549
550
551
552
553
554
555
556bool
558{
559 if (coercedTypmod != NULL)
560 *coercedTypmod = -1;
561
562
563
564
565
567 {
569 int nargs;
570 Const *second_arg;
571
572
573
574
577 return false;
578
579
580
581
582
583
585 if (nargs < 2 || nargs > 3)
586 return false;
587
589 if ((second_arg, Const) ||
590 second_arg->consttype != INT4OID ||
591 second_arg->constisnull)
592 return false;
593
594
595
596
597 if (coercedTypmod != NULL)
598 *coercedTypmod = DatumGetInt32(second_arg->constvalue);
599
600 return true;
601 }
602
604 {
606
607
608 if (acoerce->resulttypmod < 0)
609 return false;
610
611
612
613
614 if (coercedTypmod != NULL)
615 *coercedTypmod = acoerce->resulttypmod;
616
617 return true;
618 }
619
620 return false;
621}
622
623
624
625
626
627
628
629
630
631
632
633
634
637 CoercionForm rformat, int rlocation, bool overwrite_ok)
638{
639
640
641
642
643
646
648 {
649
651
652 if (!overwrite_ok)
655 con->consttypmod = rtypmod;
656 con->constcollid = rcollid;
657
658 return (Node *) con;
659 }
663 {
664
665 return arg;
666 }
667 else
668 {
669
671
674 newrelabel->resulttypmod = rtypmod;
675 newrelabel->resultcollid = rcollid;
676 newrelabel->relabelformat = rformat;
677 newrelabel->location = rlocation;
678 return (Node *) newrelabel;
679 }
680}
681
682
683
684
685
686
687
690{
693}
694
695
696
697
698
699
700
701
702
703
706{
707 if (node == NULL)
708 return NULL;
710 {
712
715 }
717 {
719
722 }
724 {
726
729 }
731 {
733
736 }
738 {
740
743 }
745 {
747
750 }
751 return node;
752}
753
754
755
756
757
758
759
760
761
762bool
764{
766}
767
768static bool
770{
771 if (node == NULL)
772 return false;
774 {
776
777 if (expr->funcretset)
778 return true;
779
780 }
782 {
784
785 if (expr->opretset)
786 return true;
787
788 }
789
790
791
792
793
794
795
796
798 return false;
800 return false;
802 return false;
803
805 context);
806}
807
808
809
810
811
812
813
814
815
816
817
818
819
822{
823 Oid coll;
824
825 if (!expr)
827
829 {
830 case T_Var:
831 coll = ((const Var *) expr)->varcollid;
832 break;
833 case T_Const:
834 coll = ((const Const *) expr)->constcollid;
835 break;
836 case T_Param:
837 coll = ((const Param *) expr)->paramcollid;
838 break;
839 case T_Aggref:
840 coll = ((const Aggref *) expr)->aggcollid;
841 break;
842 case T_GroupingFunc:
844 break;
845 case T_WindowFunc:
846 coll = ((const WindowFunc *) expr)->wincollid;
847 break;
848 case T_MergeSupportFunc:
850 break;
851 case T_SubscriptingRef:
853 break;
854 case T_FuncExpr:
855 coll = ((const FuncExpr *) expr)->funccollid;
856 break;
857 case T_NamedArgExpr:
859 break;
860 case T_OpExpr:
861 coll = ((const OpExpr *) expr)->opcollid;
862 break;
863 case T_DistinctExpr:
864 coll = ((const DistinctExpr *) expr)->opcollid;
865 break;
866 case T_NullIfExpr:
867 coll = ((const NullIfExpr *) expr)->opcollid;
868 break;
869 case T_ScalarArrayOpExpr:
870
871 coll = InvalidOid;
872 break;
873 case T_BoolExpr:
874
875 coll = InvalidOid;
876 break;
877 case T_SubLink:
878 {
880
883 {
884
887
889 elog(ERROR, "cannot get collation for untransformed sublink");
891 Assert(!tent->resjunk);
893
894 }
895 else
896 {
897
898 coll = InvalidOid;
899 }
900 }
901 break;
902 case T_SubPlan:
903 {
905
908 {
909
911
912 }
913 else
914 {
915
916 coll = InvalidOid;
917 }
918 }
919 break;
920 case T_AlternativeSubPlan:
921 {
923
924
926 }
927 break;
928 case T_FieldSelect:
929 coll = ((const FieldSelect *) expr)->resultcollid;
930 break;
931 case T_FieldStore:
932
933 coll = InvalidOid;
934 break;
935 case T_RelabelType:
936 coll = ((const RelabelType *) expr)->resultcollid;
937 break;
938 case T_CoerceViaIO:
939 coll = ((const CoerceViaIO *) expr)->resultcollid;
940 break;
941 case T_ArrayCoerceExpr:
943 break;
944 case T_ConvertRowtypeExpr:
945
946 coll = InvalidOid;
947 break;
948 case T_CollateExpr:
949 coll = ((const CollateExpr *) expr)->collOid;
950 break;
951 case T_CaseExpr:
952 coll = ((const CaseExpr *) expr)->casecollid;
953 break;
954 case T_CaseTestExpr:
955 coll = ((const CaseTestExpr *) expr)->collation;
956 break;
957 case T_ArrayExpr:
958 coll = ((const ArrayExpr *) expr)->array_collid;
959 break;
960 case T_RowExpr:
961
962 coll = InvalidOid;
963 break;
964 case T_RowCompareExpr:
965
966 coll = InvalidOid;
967 break;
968 case T_CoalesceExpr:
969 coll = ((const CoalesceExpr *) expr)->coalescecollid;
970 break;
971 case T_MinMaxExpr:
972 coll = ((const MinMaxExpr *) expr)->minmaxcollid;
973 break;
974 case T_SQLValueFunction:
975
977 coll = C_COLLATION_OID;
978 else
980 break;
981 case T_XmlExpr:
982
983
984
985
986
987
989 coll = DEFAULT_COLLATION_OID;
990 else
992 break;
993 case T_JsonValueExpr:
995 break;
996 case T_JsonConstructorExpr:
997 {
999
1002 else
1004 }
1005 break;
1006 case T_JsonIsPredicate:
1007
1008 coll = InvalidOid;
1009 break;
1010 case T_JsonExpr:
1011 {
1013
1015 }
1016 break;
1017 case T_JsonBehavior:
1018 {
1020
1021 if (behavior->expr)
1023 else
1025 }
1026 break;
1027 case T_NullTest:
1028
1029 coll = InvalidOid;
1030 break;
1031 case T_BooleanTest:
1032
1033 coll = InvalidOid;
1034 break;
1035 case T_CoerceToDomain:
1036 coll = ((const CoerceToDomain *) expr)->resultcollid;
1037 break;
1038 case T_CoerceToDomainValue:
1040 break;
1041 case T_SetToDefault:
1042 coll = ((const SetToDefault *) expr)->collation;
1043 break;
1044 case T_CurrentOfExpr:
1045
1046 coll = InvalidOid;
1047 break;
1048 case T_NextValueExpr:
1049
1050 coll = InvalidOid;
1051 break;
1052 case T_InferenceElem:
1054 break;
1055 case T_ReturningExpr:
1057 break;
1058 case T_PlaceHolderVar:
1060 break;
1061 default:
1062 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1063 coll = InvalidOid;
1064 break;
1065 }
1066 return coll;
1067}
1068
1069
1070
1071
1072
1073
1074
1077{
1078 Oid coll;
1079
1080 if (!expr)
1082
1084 {
1085 case T_Aggref:
1086 coll = ((const Aggref *) expr)->inputcollid;
1087 break;
1088 case T_WindowFunc:
1089 coll = ((const WindowFunc *) expr)->inputcollid;
1090 break;
1091 case T_FuncExpr:
1092 coll = ((const FuncExpr *) expr)->inputcollid;
1093 break;
1094 case T_OpExpr:
1095 coll = ((const OpExpr *) expr)->inputcollid;
1096 break;
1097 case T_DistinctExpr:
1098 coll = ((const DistinctExpr *) expr)->inputcollid;
1099 break;
1100 case T_NullIfExpr:
1101 coll = ((const NullIfExpr *) expr)->inputcollid;
1102 break;
1103 case T_ScalarArrayOpExpr:
1105 break;
1106 case T_MinMaxExpr:
1107 coll = ((const MinMaxExpr *) expr)->inputcollid;
1108 break;
1109 default:
1111 break;
1112 }
1113 return coll;
1114}
1115
1116
1117
1118
1119
1120
1121
1122
1123void
1125{
1127 {
1128 case T_Var:
1129 ((Var *) expr)->varcollid = collation;
1130 break;
1131 case T_Const:
1132 ((Const *) expr)->constcollid = collation;
1133 break;
1134 case T_Param:
1135 ((Param *) expr)->paramcollid = collation;
1136 break;
1137 case T_Aggref:
1138 ((Aggref *) expr)->aggcollid = collation;
1139 break;
1140 case T_GroupingFunc:
1142 break;
1143 case T_WindowFunc:
1144 ((WindowFunc *) expr)->wincollid = collation;
1145 break;
1146 case T_MergeSupportFunc:
1148 break;
1149 case T_SubscriptingRef:
1151 break;
1152 case T_FuncExpr:
1153 ((FuncExpr *) expr)->funccollid = collation;
1154 break;
1155 case T_NamedArgExpr:
1157 break;
1158 case T_OpExpr:
1159 ((OpExpr *) expr)->opcollid = collation;
1160 break;
1161 case T_DistinctExpr:
1162 ((DistinctExpr *) expr)->opcollid = collation;
1163 break;
1164 case T_NullIfExpr:
1165 ((NullIfExpr *) expr)->opcollid = collation;
1166 break;
1167 case T_ScalarArrayOpExpr:
1168
1169 Assert((collation));
1170 break;
1171 case T_BoolExpr:
1172
1173 Assert((collation));
1174 break;
1175 case T_SubLink:
1176#ifdef USE_ASSERT_CHECKING
1177 {
1179
1182 {
1183
1186
1188 elog(ERROR, "cannot set collation for untransformed sublink");
1190 Assert(!tent->resjunk);
1192 }
1193 else
1194 {
1195
1197 }
1198 }
1199#endif
1200 break;
1201 case T_FieldSelect:
1202 ((FieldSelect *) expr)->resultcollid = collation;
1203 break;
1204 case T_FieldStore:
1205
1206 Assert((collation));
1207 break;
1208 case T_RelabelType:
1209 ((RelabelType *) expr)->resultcollid = collation;
1210 break;
1211 case T_CoerceViaIO:
1212 ((CoerceViaIO *) expr)->resultcollid = collation;
1213 break;
1214 case T_ArrayCoerceExpr:
1216 break;
1217 case T_ConvertRowtypeExpr:
1218
1219 Assert((collation));
1220 break;
1221 case T_CaseExpr:
1222 ((CaseExpr *) expr)->casecollid = collation;
1223 break;
1224 case T_ArrayExpr:
1225 ((ArrayExpr *) expr)->array_collid = collation;
1226 break;
1227 case T_RowExpr:
1228
1229 Assert((collation));
1230 break;
1231 case T_RowCompareExpr:
1232
1233 Assert((collation));
1234 break;
1235 case T_CoalesceExpr:
1236 ((CoalesceExpr *) expr)->coalescecollid = collation;
1237 break;
1238 case T_MinMaxExpr:
1239 ((MinMaxExpr *) expr)->minmaxcollid = collation;
1240 break;
1241 case T_SQLValueFunction:
1243 (collation == C_COLLATION_OID) :
1245 break;
1246 case T_XmlExpr:
1248 (collation == DEFAULT_COLLATION_OID) :
1250 break;
1251 case T_JsonValueExpr:
1253 collation);
1254 break;
1255 case T_JsonConstructorExpr:
1256 {
1258
1261 else
1263
1264 }
1265 break;
1266 case T_JsonIsPredicate:
1267 Assert((collation));
1268 break;
1269 case T_JsonExpr:
1270 {
1272
1274 }
1275 break;
1276 case T_JsonBehavior:
1279 break;
1280 case T_NullTest:
1281
1282 Assert((collation));
1283 break;
1284 case T_BooleanTest:
1285
1286 Assert((collation));
1287 break;
1288 case T_CoerceToDomain:
1289 ((CoerceToDomain *) expr)->resultcollid = collation;
1290 break;
1291 case T_CoerceToDomainValue:
1293 break;
1294 case T_SetToDefault:
1295 ((SetToDefault *) expr)->collation = collation;
1296 break;
1297 case T_CurrentOfExpr:
1298
1299 Assert((collation));
1300 break;
1301 case T_NextValueExpr:
1302
1303 Assert((collation));
1304 break;
1305 default:
1306 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1307 break;
1308 }
1309}
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319void
1321{
1323 {
1324 case T_Aggref:
1325 ((Aggref *) expr)->inputcollid = inputcollation;
1326 break;
1327 case T_WindowFunc:
1328 ((WindowFunc *) expr)->inputcollid = inputcollation;
1329 break;
1330 case T_FuncExpr:
1331 ((FuncExpr *) expr)->inputcollid = inputcollation;
1332 break;
1333 case T_OpExpr:
1334 ((OpExpr *) expr)->inputcollid = inputcollation;
1335 break;
1336 case T_DistinctExpr:
1337 ((DistinctExpr *) expr)->inputcollid = inputcollation;
1338 break;
1339 case T_NullIfExpr:
1340 ((NullIfExpr *) expr)->inputcollid = inputcollation;
1341 break;
1342 case T_ScalarArrayOpExpr:
1344 break;
1345 case T_MinMaxExpr:
1346 ((MinMaxExpr *) expr)->inputcollid = inputcollation;
1347 break;
1348 default:
1349 break;
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
1383int
1385{
1386 int loc;
1387
1388 if (expr == NULL)
1389 return -1;
1391 {
1392 case T_RangeVar:
1393 loc = ((const RangeVar *) expr)->location;
1394 break;
1395 case T_TableFunc:
1396 loc = ((const TableFunc *) expr)->location;
1397 break;
1398 case T_Var:
1399 loc = ((const Var *) expr)->location;
1400 break;
1401 case T_Const:
1402 loc = ((const Const *) expr)->location;
1403 break;
1404 case T_Param:
1405 loc = ((const Param *) expr)->location;
1406 break;
1407 case T_Aggref:
1408
1409 loc = ((const Aggref *) expr)->location;
1410 break;
1411 case T_GroupingFunc:
1412 loc = ((const GroupingFunc *) expr)->location;
1413 break;
1414 case T_WindowFunc:
1415
1416 loc = ((const WindowFunc *) expr)->location;
1417 break;
1418 case T_MergeSupportFunc:
1420 break;
1421 case T_SubscriptingRef:
1422
1424 break;
1425 case T_FuncExpr:
1426 {
1428
1429
1432 }
1433 break;
1434 case T_NamedArgExpr:
1435 {
1437
1438
1441 }
1442 break;
1443 case T_OpExpr:
1444 case T_DistinctExpr:
1445 case T_NullIfExpr:
1446 {
1447 const OpExpr *opexpr = (const OpExpr *) expr;
1448
1449
1452 }
1453 break;
1454 case T_ScalarArrayOpExpr:
1455 {
1457
1458
1461 }
1462 break;
1463 case T_BoolExpr:
1464 {
1466
1467
1468
1469
1470
1471
1474 }
1475 break;
1476 case T_SubLink:
1477 {
1479
1480
1483 }
1484 break;
1485 case T_FieldSelect:
1486
1488 break;
1489 case T_FieldStore:
1490
1492 break;
1493 case T_RelabelType:
1494 {
1496
1497
1500 }
1501 break;
1502 case T_CoerceViaIO:
1503 {
1505
1506
1509 }
1510 break;
1511 case T_ArrayCoerceExpr:
1512 {
1514
1515
1518 }
1519 break;
1520 case T_ConvertRowtypeExpr:
1521 {
1523
1524
1527 }
1528 break;
1529 case T_CollateExpr:
1530
1532 break;
1533 case T_CaseExpr:
1534
1535 loc = ((const CaseExpr *) expr)->location;
1536 break;
1537 case T_CaseWhen:
1538
1539 loc = ((const CaseWhen *) expr)->location;
1540 break;
1541 case T_ArrayExpr:
1542
1543 loc = ((const ArrayExpr *) expr)->location;
1544 break;
1545 case T_RowExpr:
1546
1547 loc = ((const RowExpr *) expr)->location;
1548 break;
1549 case T_RowCompareExpr:
1550
1552 break;
1553 case T_CoalesceExpr:
1554
1555 loc = ((const CoalesceExpr *) expr)->location;
1556 break;
1557 case T_MinMaxExpr:
1558
1559 loc = ((const MinMaxExpr *) expr)->location;
1560 break;
1561 case T_SQLValueFunction:
1562
1564 break;
1565 case T_XmlExpr:
1566 {
1568
1569
1572 }
1573 break;
1574 case T_JsonFormat:
1575 loc = ((const JsonFormat *) expr)->location;
1576 break;
1577 case T_JsonValueExpr:
1579 break;
1580 case T_JsonConstructorExpr:
1582 break;
1583 case T_JsonIsPredicate:
1585 break;
1586 case T_JsonExpr:
1587 {
1589
1590
1593 }
1594 break;
1595 case T_JsonBehavior:
1597 break;
1598 case T_NullTest:
1599 {
1601
1602
1605 }
1606 break;
1607 case T_BooleanTest:
1608 {
1610
1611
1614 }
1615 break;
1616 case T_CoerceToDomain:
1617 {
1619
1620
1623 }
1624 break;
1625 case T_CoerceToDomainValue:
1627 break;
1628 case T_SetToDefault:
1629 loc = ((const SetToDefault *) expr)->location;
1630 break;
1631 case T_ReturningExpr:
1633 break;
1634 case T_TargetEntry:
1635
1637 break;
1638 case T_IntoClause:
1639
1641 break;
1642 case T_List:
1643 {
1644
1646
1647 loc = -1;
1648 foreach(lc, (const List *) expr)
1649 {
1651 if (loc >= 0)
1652 break;
1653 }
1654 }
1655 break;
1656 case T_A_Expr:
1657 {
1658 const A_Expr *aexpr = (const A_Expr *) expr;
1659
1660
1661
1664 }
1665 break;
1666 case T_ColumnRef:
1667 loc = ((const ColumnRef *) expr)->location;
1668 break;
1669 case T_ParamRef:
1670 loc = ((const ParamRef *) expr)->location;
1671 break;
1672 case T_A_Const:
1673 loc = ((const A_Const *) expr)->location;
1674 break;
1675 case T_FuncCall:
1676 {
1678
1679
1680
1683 }
1684 break;
1685 case T_A_ArrayExpr:
1686
1687 loc = ((const A_ArrayExpr *) expr)->location;
1688 break;
1689 case T_ResTarget:
1690
1691 loc = ((const ResTarget *) expr)->location;
1692 break;
1693 case T_MultiAssignRef:
1695 break;
1696 case T_TypeCast:
1697 {
1699
1700
1701
1702
1703
1707 }
1708 break;
1709 case T_CollateClause:
1710
1712 break;
1713 case T_SortBy:
1714
1716 break;
1717 case T_WindowDef:
1718 loc = ((const WindowDef *) expr)->location;
1719 break;
1720 case T_RangeTableSample:
1722 break;
1723 case T_TypeName:
1724 loc = ((const TypeName *) expr)->location;
1725 break;
1726 case T_ColumnDef:
1727 loc = ((const ColumnDef *) expr)->location;
1728 break;
1729 case T_Constraint:
1730 loc = ((const Constraint *) expr)->location;
1731 break;
1732 case T_FunctionParameter:
1734 break;
1735 case T_XmlSerialize:
1736
1737 loc = ((const XmlSerialize *) expr)->location;
1738 break;
1739 case T_GroupingSet:
1740 loc = ((const GroupingSet *) expr)->location;
1741 break;
1742 case T_WithClause:
1743 loc = ((const WithClause *) expr)->location;
1744 break;
1745 case T_InferClause:
1746 loc = ((const InferClause *) expr)->location;
1747 break;
1748 case T_OnConflictClause:
1750 break;
1751 case T_CTESearchClause:
1753 break;
1754 case T_CTECycleClause:
1756 break;
1757 case T_CommonTableExpr:
1759 break;
1760 case T_JsonKeyValue:
1761
1763 break;
1764 case T_JsonObjectConstructor:
1766 break;
1767 case T_JsonArrayConstructor:
1769 break;
1770 case T_JsonArrayQueryConstructor:
1772 break;
1773 case T_JsonAggConstructor:
1775 break;
1776 case T_JsonObjectAgg:
1778 break;
1779 case T_JsonArrayAgg:
1781 break;
1782 case T_PlaceHolderVar:
1783
1785 break;
1786 case T_InferenceElem:
1787
1789 break;
1790 case T_PartitionElem:
1792 break;
1793 case T_PartitionSpec:
1795 break;
1796 case T_PartitionBoundSpec:
1798 break;
1799 case T_PartitionRangeDatum:
1801 break;
1802 default:
1803
1804 loc = -1;
1805 break;
1806 }
1807 return loc;
1808}
1809
1810
1811
1812
1813
1814
1815static int
1817{
1818 if (loc1 < 0)
1819 return loc2;
1820 else if (loc2 < 0)
1821 return loc1;
1822 else
1823 return Min(loc1, loc2);
1824}
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836void
1838{
1839
1841}
1842
1843static bool
1845{
1846 if (node == NULL)
1847 return false;
1857}
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867void
1869{
1872}
1873
1874
1875
1876
1877
1878void
1880{
1883}
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905bool
1907 void *context)
1908{
1910 {
1911 case T_Aggref:
1912 {
1914
1915 if (checker(expr->aggfnoid, context))
1916 return true;
1917 }
1918 break;
1919 case T_WindowFunc:
1920 {
1922
1923 if (checker(expr->winfnoid, context))
1924 return true;
1925 }
1926 break;
1927 case T_FuncExpr:
1928 {
1930
1931 if (checker(expr->funcid, context))
1932 return true;
1933 }
1934 break;
1935 case T_OpExpr:
1936 case T_DistinctExpr:
1937 case T_NullIfExpr:
1938 {
1940
1941
1943 if (checker(expr->opfuncid, context))
1944 return true;
1945 }
1946 break;
1947 case T_ScalarArrayOpExpr:
1948 {
1950
1952 if (checker(expr->opfuncid, context))
1953 return true;
1954 }
1955 break;
1956 case T_CoerceViaIO:
1957 {
1959 Oid iofunc;
1960 Oid typioparam;
1961 bool typisvarlena;
1962
1963
1965 &iofunc, &typioparam);
1966 if (checker(iofunc, context))
1967 return true;
1968
1970 &iofunc, &typisvarlena);
1971 if (checker(iofunc, context))
1972 return true;
1973 }
1974 break;
1975 case T_RowCompareExpr:
1976 {
1979
1980 foreach(opid, rcexpr->opnos)
1981 {
1983
1984 if (checker(opfuncid, context))
1985 return true;
1986 }
1987 }
1988 break;
1989 default:
1990 break;
1991 }
1992 return false;
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
2088bool
2091 void *context)
2092{
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103#define WALK(n) walker((Node *) (n), context)
2104
2105#define LIST_WALK(l) expression_tree_walker_impl((Node *) (l), walker, context)
2106
2107 if (node == NULL)
2108 return false;
2109
2110
2112
2114 {
2115 case T_Var:
2116 case T_Const:
2117 case T_Param:
2118 case T_CaseTestExpr:
2119 case T_SQLValueFunction:
2120 case T_CoerceToDomainValue:
2121 case T_SetToDefault:
2122 case T_CurrentOfExpr:
2123 case T_NextValueExpr:
2124 case T_RangeTblRef:
2125 case T_SortGroupClause:
2126 case T_CTESearchClause:
2127 case T_MergeSupportFunc:
2128
2129 break;
2130 case T_WithCheckOption:
2132 case T_Aggref:
2133 {
2135
2136
2138 return true;
2140 return true;
2142 return true;
2144 return true;
2146 return true;
2147 }
2148 break;
2149 case T_GroupingFunc:
2150 {
2152
2154 return true;
2155 }
2156 break;
2157 case T_WindowFunc:
2158 {
2160
2161
2163 return true;
2165 return true;
2166 if (WALK(expr->runCondition))
2167 return true;
2168 }
2169 break;
2170 case T_WindowFuncRunCondition:
2171 {
2173
2175 return true;
2176 }
2177 break;
2178 case T_SubscriptingRef:
2179 {
2181
2182
2184 return true;
2186 return true;
2187
2189 return true;
2190
2192 return true;
2193 }
2194 break;
2195 case T_FuncExpr:
2196 {
2198
2200 return true;
2201 }
2202 break;
2203 case T_NamedArgExpr:
2205 case T_OpExpr:
2206 case T_DistinctExpr:
2207 case T_NullIfExpr:
2208 {
2210
2212 return true;
2213 }
2214 break;
2215 case T_ScalarArrayOpExpr:
2216 {
2218
2220 return true;
2221 }
2222 break;
2223 case T_BoolExpr:
2224 {
2226
2228 return true;
2229 }
2230 break;
2231 case T_SubLink:
2232 {
2234
2236 return true;
2237
2238
2239
2240
2241
2243 }
2244 break;
2245 case T_SubPlan:
2246 {
2248
2249
2251 return true;
2252
2254 return true;
2255 }
2256 break;
2257 case T_AlternativeSubPlan:
2259 case T_FieldSelect:
2261 case T_FieldStore:
2262 {
2264
2266 return true;
2268 return true;
2269 }
2270 break;
2271 case T_RelabelType:
2273 case T_CoerceViaIO:
2275 case T_ArrayCoerceExpr:
2276 {
2278
2280 return true;
2282 return true;
2283 }
2284 break;
2285 case T_ConvertRowtypeExpr:
2287 case T_CollateExpr:
2289 case T_CaseExpr:
2290 {
2292
2294 return true;
2295
2296 foreach(temp, caseexpr->args)
2297 {
2299
2301 return true;
2303 return true;
2304 }
2306 return true;
2307 }
2308 break;
2309 case T_ArrayExpr:
2311 case T_RowExpr:
2312
2314 case T_RowCompareExpr:
2315 {
2317
2319 return true;
2321 return true;
2322 }
2323 break;
2324 case T_CoalesceExpr:
2326 case T_MinMaxExpr:
2328 case T_XmlExpr:
2329 {
2331
2333 return true;
2334
2336 return true;
2337 }
2338 break;
2339 case T_JsonValueExpr:
2340 {
2342
2344 return true;
2346 return true;
2347 }
2348 break;
2349 case T_JsonConstructorExpr:
2350 {
2352
2354 return true;
2356 return true;
2358 return true;
2359 }
2360 break;
2361 case T_JsonIsPredicate:
2363 case T_JsonExpr:
2364 {
2366
2368 return true;
2370 return true;
2372 return true;
2373
2375 return true;
2377 return true;
2378 }
2379 break;
2380 case T_JsonBehavior:
2381 {
2383
2385 return true;
2386 }
2387 break;
2388 case T_NullTest:
2390 case T_BooleanTest:
2392 case T_CoerceToDomain:
2394 case T_TargetEntry:
2396 case T_Query:
2397
2398 break;
2399 case T_WindowClause:
2400 {
2402
2404 return true;
2406 return true;
2408 return true;
2410 return true;
2411 }
2412 break;
2413 case T_CTECycleClause:
2414 {
2416
2418 return true;
2420 return true;
2421 }
2422 break;
2423 case T_CommonTableExpr:
2424 {
2426
2427
2428
2429
2430
2432 return true;
2433
2434 if (WALK(cte->search_clause))
2435 return true;
2436 if (WALK(cte->cycle_clause))
2437 return true;
2438 }
2439 break;
2440 case T_JsonKeyValue:
2441 {
2443
2445 return true;
2447 return true;
2448 }
2449 break;
2450 case T_JsonObjectConstructor:
2451 {
2453
2455 return true;
2456 }
2457 break;
2458 case T_JsonArrayConstructor:
2459 {
2461
2463 return true;
2464 }
2465 break;
2466 case T_JsonArrayQueryConstructor:
2467 {
2469
2471 return true;
2472 }
2473 break;
2474 case T_JsonAggConstructor:
2475 {
2477
2479 return true;
2481 return true;
2483 return true;
2484 }
2485 break;
2486 case T_JsonObjectAgg:
2487 {
2489
2491 return true;
2493 return true;
2494 }
2495 break;
2496 case T_JsonArrayAgg:
2497 {
2499
2501 return true;
2503 return true;
2504 }
2505 break;
2506
2507 case T_PartitionBoundSpec:
2508 {
2510
2512 return true;
2514 return true;
2516 return true;
2517 }
2518 break;
2519 case T_PartitionRangeDatum:
2520 {
2522
2524 return true;
2525 }
2526 break;
2527 case T_List:
2528 foreach(temp, (List *) node)
2529 {
2531 return true;
2532 }
2533 break;
2534 case T_FromExpr:
2535 {
2537
2539 return true;
2541 return true;
2542 }
2543 break;
2544 case T_OnConflictExpr:
2545 {
2547
2549 return true;
2551 return true;
2553 return true;
2555 return true;
2557 return true;
2558 }
2559 break;
2560 case T_MergeAction:
2561 {
2563
2565 return true;
2567 return true;
2568 }
2569 break;
2570 case T_PartitionPruneStepOp:
2571 {
2573
2575 return true;
2576 }
2577 break;
2578 case T_PartitionPruneStepCombine:
2579
2580 break;
2581 case T_JoinExpr:
2582 {
2584
2586 return true;
2588 return true;
2590 return true;
2591
2592
2593
2594
2595 }
2596 break;
2597 case T_SetOperationStmt:
2598 {
2600
2602 return true;
2604 return true;
2605
2606
2607 }
2608 break;
2609 case T_IndexClause:
2610 {
2612
2614 return true;
2616 return true;
2617 }
2618 break;
2619 case T_PlaceHolderVar:
2621 case T_InferenceElem:
2623 case T_ReturningExpr:
2625 case T_AppendRelInfo:
2626 {
2628
2630 return true;
2631 }
2632 break;
2633 case T_PlaceHolderInfo:
2635 case T_RangeTblFunction:
2637 case T_TableSampleClause:
2638 {
2640
2642 return true;
2644 return true;
2645 }
2646 break;
2647 case T_TableFunc:
2648 {
2650
2651 if (WALK(tf->ns_uris))
2652 return true;
2654 return true;
2656 return true;
2658 return true;
2659 if (WALK(tf->coldefexprs))
2660 return true;
2661 if (WALK(tf->colvalexprs))
2662 return true;
2663 if (WALK(tf->passingvalexprs))
2664 return true;
2665 }
2666 break;
2667 default:
2668 elog(ERROR, "unrecognized node type: %d",
2670 break;
2671 }
2672 return false;
2673
2674
2675#undef LIST_WALK
2676}
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693bool
2696 void *context,
2697 int flags)
2698{
2700
2701
2702
2703
2704
2705
2706
2707
2709 return true;
2710 if (WALK(query->withCheckOptions))
2711 return true;
2713 return true;
2715 return true;
2717 return true;
2719 return true;
2721 return true;
2723 return true;
2725 return true;
2727 return true;
2729 return true;
2730
2731
2732
2733
2734
2735
2737 {
2739 return true;
2741 return true;
2743 return true;
2745 return true;
2746 }
2747 else
2748 {
2749
2750
2751
2752
2754
2756 {
2758
2760 return true;
2762 return true;
2763 }
2764 }
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2779 {
2781 return true;
2782 }
2784 {
2786 return true;
2787 }
2788 return false;
2789}
2790
2791
2792
2793
2794
2795
2796bool
2799 void *context,
2800 int flags)
2801{
2803
2804 foreach(rt, rtable)
2805 {
2807
2809 return true;
2810 }
2811 return false;
2812}
2813
2814
2815
2816
2817bool
2820 void *context,
2821 int flags)
2822{
2823
2824
2825
2826
2827
2829 if (WALK(rte))
2830 return true;
2831
2833 {
2836 return true;
2837 break;
2841 return true;
2842 break;
2845 if (WALK(rte->joinaliasvars))
2846 return true;
2847 break;
2850 return true;
2851 break;
2854 return true;
2855 break;
2858 return true;
2859 break;
2863
2864 break;
2867 if (WALK(rte->groupexprs))
2868 return true;
2869 break;
2870 }
2871
2872 if (WALK(rte->securityQuals))
2873 return true;
2874
2876 if (WALK(rte))
2877 return true;
2878
2879 return false;
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
2948 void *context)
2949{
2950
2951
2952
2953
2954
2955#define FLATCOPY(newnode, node, nodetype) \
2956 ( (newnode) = palloc_object(nodetype), \
2957 memcpy((newnode), (node), sizeof(nodetype)) )
2958
2959#define MUTATE(newfield, oldfield, fieldtype) \
2960 ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
2961
2962 if (node == NULL)
2963 return NULL;
2964
2965
2967
2969 {
2970
2971
2972
2973
2974
2975 case T_Var:
2976 {
2978 Var *newnode;
2979
2981
2982 return (Node *) newnode;
2983 }
2984 break;
2985 case T_Const:
2986 {
2989
2991
2992 return (Node *) newnode;
2993 }
2994 break;
2995 case T_Param:
2996 case T_CaseTestExpr:
2997 case T_SQLValueFunction:
2998 case T_JsonFormat:
2999 case T_CoerceToDomainValue:
3000 case T_SetToDefault:
3001 case T_CurrentOfExpr:
3002 case T_NextValueExpr:
3003 case T_RangeTblRef:
3004 case T_SortGroupClause:
3005 case T_CTESearchClause:
3006 case T_MergeSupportFunc:
3008 case T_WithCheckOption:
3009 {
3012
3015 return (Node *) newnode;
3016 }
3017 case T_Aggref:
3018 {
3021
3023
3024 newnode->aggargtypes = list_copy(aggref->aggargtypes);
3030 return (Node *) newnode;
3031 }
3032 break;
3033 case T_GroupingFunc:
3034 {
3037
3039 MUTATE(newnode->args, grouping->args, List *);
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050 newnode->refs = list_copy(grouping->refs);
3051 newnode->cols = list_copy(grouping->cols);
3052
3053 return (Node *) newnode;
3054 }
3055 break;
3056 case T_WindowFunc:
3057 {
3060
3064 return (Node *) newnode;
3065 }
3066 break;
3067 case T_WindowFuncRunCondition:
3068 {
3071
3074 return (Node *) newnode;
3075 }
3076 break;
3077 case T_SubscriptingRef:
3078 {
3081
3091
3092 return (Node *) newnode;
3093 }
3094 break;
3095 case T_FuncExpr:
3096 {
3099
3102 return (Node *) newnode;
3103 }
3104 break;
3105 case T_NamedArgExpr:
3106 {
3109
3112 return (Node *) newnode;
3113 }
3114 break;
3115 case T_OpExpr:
3116 {
3119
3122 return (Node *) newnode;
3123 }
3124 break;
3125 case T_DistinctExpr:
3126 {
3129
3132 return (Node *) newnode;
3133 }
3134 break;
3135 case T_NullIfExpr:
3136 {
3139
3142 return (Node *) newnode;
3143 }
3144 break;
3145 case T_ScalarArrayOpExpr:
3146 {
3149
3152 return (Node *) newnode;
3153 }
3154 break;
3155 case T_BoolExpr:
3156 {
3159
3162 return (Node *) newnode;
3163 }
3164 break;
3165 case T_SubLink:
3166 {
3169
3172
3173
3174
3175
3176
3178 return (Node *) newnode;
3179 }
3180 break;
3181 case T_SubPlan:
3182 {
3185
3187
3189
3191
3192 return (Node *) newnode;
3193 }
3194 break;
3195 case T_AlternativeSubPlan:
3196 {
3199
3202 return (Node *) newnode;
3203 }
3204 break;
3205 case T_FieldSelect:
3206 {
3209
3212 return (Node *) newnode;
3213 }
3214 break;
3215 case T_FieldStore:
3216 {
3219
3223 newnode->fieldnums = list_copy(fstore->fieldnums);
3224 return (Node *) newnode;
3225 }
3226 break;
3227 case T_RelabelType:
3228 {
3231
3234 return (Node *) newnode;
3235 }
3236 break;
3237 case T_CoerceViaIO:
3238 {
3241
3244 return (Node *) newnode;
3245 }
3246 break;
3247 case T_ArrayCoerceExpr:
3248 {
3251
3255 return (Node *) newnode;
3256 }
3257 break;
3258 case T_ConvertRowtypeExpr:
3259 {
3262
3265 return (Node *) newnode;
3266 }
3267 break;
3268 case T_CollateExpr:
3269 {
3272
3275 return (Node *) newnode;
3276 }
3277 break;
3278 case T_CaseExpr:
3279 {
3282
3287 return (Node *) newnode;
3288 }
3289 break;
3290 case T_CaseWhen:
3291 {
3294
3298 return (Node *) newnode;
3299 }
3300 break;
3301 case T_ArrayExpr:
3302 {
3305
3307 MUTATE(newnode->elements, arrayexpr->elements, List *);
3308 return (Node *) newnode;
3309 }
3310 break;
3311 case T_RowExpr:
3312 {
3315
3318
3319 return (Node *) newnode;
3320 }
3321 break;
3322 case T_RowCompareExpr:
3323 {
3326
3330 return (Node *) newnode;
3331 }
3332 break;
3333 case T_CoalesceExpr:
3334 {
3337
3340 return (Node *) newnode;
3341 }
3342 break;
3343 case T_MinMaxExpr:
3344 {
3347
3350 return (Node *) newnode;
3351 }
3352 break;
3353 case T_XmlExpr:
3354 {
3357
3360
3362 return (Node *) newnode;
3363 }
3364 break;
3365 case T_JsonReturning:
3366 {
3369
3372
3373 return (Node *) newnode;
3374 }
3375 case T_JsonValueExpr:
3376 {
3379
3384
3385 return (Node *) newnode;
3386 }
3387 case T_JsonConstructorExpr:
3388 {
3391
3397
3398 return (Node *) newnode;
3399 }
3400 case T_JsonIsPredicate:
3401 {
3404
3408
3409 return (Node *) newnode;
3410 }
3411 case T_JsonExpr:
3412 {
3415
3420
3423 return (Node *) newnode;
3424 }
3425 break;
3426 case T_JsonBehavior:
3427 {
3430
3433 return (Node *) newnode;
3434 }
3435 break;
3436 case T_NullTest:
3437 {
3440
3443 return (Node *) newnode;
3444 }
3445 break;
3446 case T_BooleanTest:
3447 {
3450
3453 return (Node *) newnode;
3454 }
3455 break;
3456 case T_CoerceToDomain:
3457 {
3460
3463 return (Node *) newnode;
3464 }
3465 break;
3466 case T_ReturningExpr:
3467 {
3470
3473 return (Node *) newnode;
3474 }
3475 break;
3476 case T_TargetEntry:
3477 {
3480
3483 return (Node *) newnode;
3484 }
3485 break;
3486 case T_Query:
3487
3488 return node;
3489 case T_WindowClause:
3490 {
3493
3499 return (Node *) newnode;
3500 }
3501 break;
3502 case T_CTECycleClause:
3503 {
3506
3510 return (Node *) newnode;
3511 }
3512 break;
3513 case T_CommonTableExpr:
3514 {
3517
3519
3520
3521
3522
3523
3525
3528
3529 return (Node *) newnode;
3530 }
3531 break;
3532 case T_PartitionBoundSpec:
3533 {
3536
3541 return (Node *) newnode;
3542 }
3543 break;
3544 case T_PartitionRangeDatum:
3545 {
3548
3551 return (Node *) newnode;
3552 }
3553 break;
3554 case T_List:
3555 {
3556
3557
3558
3559
3560
3561 List *resultlist;
3563
3564 resultlist = NIL;
3565 foreach(temp, (List *) node)
3566 {
3567 resultlist = lappend(resultlist,
3569 context));
3570 }
3571 return (Node *) resultlist;
3572 }
3573 break;
3574 case T_FromExpr:
3575 {
3578
3582 return (Node *) newnode;
3583 }
3584 break;
3585 case T_OnConflictExpr:
3586 {
3589
3596
3597 return (Node *) newnode;
3598 }
3599 break;
3600 case T_MergeAction:
3601 {
3604
3608
3609 return (Node *) newnode;
3610 }
3611 break;
3612 case T_PartitionPruneStepOp:
3613 {
3616
3619
3620 return (Node *) newnode;
3621 }
3622 break;
3623 case T_PartitionPruneStepCombine:
3624
3626 case T_JoinExpr:
3627 {
3630
3635
3636 return (Node *) newnode;
3637 }
3638 break;
3639 case T_SetOperationStmt:
3640 {
3643
3647
3648 return (Node *) newnode;
3649 }
3650 break;
3651 case T_IndexClause:
3652 {
3655
3659 return (Node *) newnode;
3660 }
3661 break;
3662 case T_PlaceHolderVar:
3663 {
3666
3668 MUTATE(newnode->phexpr, phv->phexpr, Expr *);
3669
3670 return (Node *) newnode;
3671 }
3672 break;
3673 case T_InferenceElem:
3674 {
3677
3680 return (Node *) newnode;
3681 }
3682 break;
3683 case T_AppendRelInfo:
3684 {
3687
3690
3691 return (Node *) newnode;
3692 }
3693 break;
3694 case T_PlaceHolderInfo:
3695 {
3698
3701
3702 return (Node *) newnode;
3703 }
3704 break;
3705 case T_RangeTblFunction:
3706 {
3709
3712
3713 return (Node *) newnode;
3714 }
3715 break;
3716 case T_TableSampleClause:
3717 {
3720
3724 return (Node *) newnode;
3725 }
3726 break;
3727 case T_TableFunc:
3728 {
3731
3733 MUTATE(newnode->ns_uris, tf->ns_uris, List *);
3737 MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);
3738 MUTATE(newnode->colvalexprs, tf->colvalexprs, List *);
3739 MUTATE(newnode->passingvalexprs, tf->passingvalexprs, List *);
3740 return (Node *) newnode;
3741 }
3742 break;
3743 default:
3744 elog(ERROR, "unrecognized node type: %d",
3746 break;
3747 }
3748
3749 return NULL;
3750}
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3775 void *context,
3776 int flags)
3777{
3779
3781 {
3782 Query *newquery;
3783
3785 query = newquery;
3786 }
3787
3789 MUTATE(query->withCheckOptions, query->withCheckOptions, List *);
3799
3800
3801
3802
3803
3804
3805
3807 {
3812 }
3813 else
3814 {
3815
3816
3817
3818
3819 List *resultlist;
3821
3822 resultlist = NIL;
3824 {
3827
3831
3832 resultlist = lappend(resultlist, (Node *) newnode);
3833 }
3835 }
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3851 else
3854 mutator, context, flags);
3855 return query;
3856}
3857
3858
3859
3860
3861
3862
3866 void *context,
3867 int flags)
3868{
3871
3872 foreach(rt, rtable)
3873 {
3876
3879 {
3883
3884 break;
3888 else
3889 {
3890
3892 }
3893 break;
3896 MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
3897 else
3898 {
3899
3900 newrte->joinaliasvars = copyObject(rte->joinaliasvars);
3901 }
3902 break;
3905 break;
3908 break;
3911 break;
3915
3916 break;
3919 MUTATE(newrte->groupexprs, rte->groupexprs, List *);
3920 else
3921 {
3922
3923 newrte->groupexprs = copyObject(rte->groupexprs);
3924 }
3925 break;
3926 }
3927 MUTATE(newrte->securityQuals, rte->securityQuals, List *);
3928 newrt = lappend(newrt, newrte);
3929 }
3930 return newrt;
3931}
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941bool
3944 void *context,
3945 int flags)
3946{
3947 if (node && IsA(node, Query))
3949 walker,
3950 context,
3951 flags);
3952 else
3953 return WALK(node);
3954}
3955
3956
3957
3958
3959
3960
3961
3962
3963
3967 void *context,
3968 int flags)
3969{
3970 if (node && IsA(node, Query))
3972 mutator,
3973 context,
3974 flags);
3975 else
3976 return mutator(node, context);
3977}
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995bool
3998 void *context)
3999{
4001
4002
4003
4004
4005
4006 if (node == NULL)
4007 return false;
4008
4009
4011
4013 {
4014 case T_JsonFormat:
4015 case T_SetToDefault:
4016 case T_CurrentOfExpr:
4017 case T_SQLValueFunction:
4018 case T_Integer:
4019 case T_Float:
4020 case T_Boolean:
4021 case T_String:
4022 case T_BitString:
4023 case T_ParamRef:
4024 case T_A_Const:
4025 case T_A_Star:
4026 case T_MergeSupportFunc:
4027 case T_ReturningOption:
4028
4029 break;
4030 case T_Alias:
4031
4032 break;
4033 case T_RangeVar:
4035 case T_GroupingFunc:
4037 case T_SubLink:
4038 {
4040
4042 return true;
4043
4045 return true;
4046 }
4047 break;
4048 case T_CaseExpr:
4049 {
4051
4053 return true;
4054
4055 foreach(temp, caseexpr->args)
4056 {
4058
4060 return true;
4062 return true;
4063 }
4065 return true;
4066 }
4067 break;
4068 case T_RowExpr:
4069
4071 case T_CoalesceExpr:
4073 case T_MinMaxExpr:
4075 case T_XmlExpr:
4076 {
4078
4080 return true;
4081
4083 return true;
4084 }
4085 break;
4086 case T_JsonReturning:
4088 case T_JsonValueExpr:
4089 {
4091
4093 return true;
4095 return true;
4097 return true;
4098 }
4099 break;
4100 case T_JsonParseExpr:
4101 {
4103
4105 return true;
4107 return true;
4108 }
4109 break;
4110 case T_JsonScalarExpr:
4111 {
4113
4115 return true;
4117 return true;
4118 }
4119 break;
4120 case T_JsonSerializeExpr:
4121 {
4123
4125 return true;
4127 return true;
4128 }
4129 break;
4130 case T_JsonConstructorExpr:
4131 {
4133
4135 return true;
4137 return true;
4139 return true;
4141 return true;
4142 }
4143 break;
4144 case T_JsonIsPredicate:
4146 case T_JsonArgument:
4148 case T_JsonFuncExpr:
4149 {
4151
4153 return true;
4155 return true;
4157 return true;
4159 return true;
4161 return true;
4163 return true;
4164 }
4165 break;
4166 case T_JsonBehavior:
4167 {
4169
4171 return true;
4172 }
4173 break;
4174 case T_JsonTable:
4175 {
4177
4179 return true;
4181 return true;
4183 return true;
4185 return true;
4187 return true;
4188 }
4189 break;
4190 case T_JsonTableColumn:
4191 {
4193
4195 return true;
4197 return true;
4199 return true;
4201 return true;
4202 }
4203 break;
4204 case T_JsonTablePathSpec:
4206 case T_NullTest:
4208 case T_BooleanTest:
4210 case T_JoinExpr:
4211 {
4213
4215 return true;
4217 return true;
4219 return true;
4220 if (WALK(join->alias))
4221 return true;
4222
4223 }
4224 break;
4225 case T_IntoClause:
4226 {
4228
4230 return true;
4231
4232
4233 if (WALK(into->viewQuery))
4234 return true;
4235 }
4236 break;
4237 case T_List:
4238 foreach(temp, (List *) node)
4239 {
4241 return true;
4242 }
4243 break;
4244 case T_InsertStmt:
4245 {
4247
4249 return true;
4251 return true;
4253 return true;
4254 if (WALK(stmt->onConflictClause))
4255 return true;
4256 if (WALK(stmt->returningClause))
4257 return true;
4259 return true;
4260 }
4261 break;
4262 case T_DeleteStmt:
4263 {
4265
4267 return true;
4268 if (WALK(stmt->usingClause))
4269 return true;
4270 if (WALK(stmt->whereClause))
4271 return true;
4272 if (WALK(stmt->returningClause))
4273 return true;
4275 return true;
4276 }
4277 break;
4278 case T_UpdateStmt:
4279 {
4281
4283 return true;
4285 return true;
4286 if (WALK(stmt->whereClause))
4287 return true;
4289 return true;
4290 if (WALK(stmt->returningClause))
4291 return true;
4293 return true;
4294 }
4295 break;
4296 case T_MergeStmt:
4297 {
4299
4301 return true;
4302 if (WALK(stmt->sourceRelation))
4303 return true;
4304 if (WALK(stmt->joinCondition))
4305 return true;
4306 if (WALK(stmt->mergeWhenClauses))
4307 return true;
4308 if (WALK(stmt->returningClause))
4309 return true;
4311 return true;
4312 }
4313 break;
4314 case T_MergeWhenClause:
4315 {
4317
4319 return true;
4321 return true;
4323 return true;
4324 }
4325 break;
4326 case T_ReturningClause:
4327 {
4329
4331 return true;
4333 return true;
4334 }
4335 break;
4336 case T_SelectStmt:
4337 {
4339
4340 if (WALK(stmt->distinctClause))
4341 return true;
4343 return true;
4345 return true;
4347 return true;
4348 if (WALK(stmt->whereClause))
4349 return true;
4350 if (WALK(stmt->groupClause))
4351 return true;
4352 if (WALK(stmt->havingClause))
4353 return true;
4354 if (WALK(stmt->windowClause))
4355 return true;
4356 if (WALK(stmt->valuesLists))
4357 return true;
4359 return true;
4360 if (WALK(stmt->limitOffset))
4361 return true;
4363 return true;
4364 if (WALK(stmt->lockingClause))
4365 return true;
4367 return true;
4369 return true;
4371 return true;
4372 }
4373 break;
4374 case T_PLAssignStmt:
4375 {
4377
4378 if (WALK(stmt->indirection))
4379 return true;
4381 return true;
4382 }
4383 break;
4384 case T_A_Expr:
4385 {
4387
4389 return true;
4391 return true;
4392
4393 }
4394 break;
4395 case T_BoolExpr:
4396 {
4398
4400 return true;
4401 }
4402 break;
4403 case T_ColumnRef:
4404
4405 break;
4406 case T_FuncCall:
4407 {
4409
4411 return true;
4413 return true;
4415 return true;
4417 return true;
4418
4419 }
4420 break;
4421 case T_NamedArgExpr:
4423 case T_A_Indices:
4424 {
4426
4428 return true;
4430 return true;
4431 }
4432 break;
4433 case T_A_Indirection:
4434 {
4436
4438 return true;
4440 return true;
4441 }
4442 break;
4443 case T_A_ArrayExpr:
4445 case T_ResTarget:
4446 {
4448
4450 return true;
4452 return true;
4453 }
4454 break;
4455 case T_MultiAssignRef:
4457 case T_TypeCast:
4458 {
4460
4462 return true;
4464 return true;
4465 }
4466 break;
4467 case T_CollateClause:
4469 case T_SortBy:
4470 return WALK(((SortBy *) node)->node);
4471 case T_WindowDef:
4472 {
4474
4476 return true;
4478 return true;
4480 return true;
4482 return true;
4483 }
4484 break;
4485 case T_RangeSubselect:
4486 {
4488
4490 return true;
4492 return true;
4493 }
4494 break;
4495 case T_RangeFunction:
4496 {
4498
4500 return true;
4502 return true;
4504 return true;
4505 }
4506 break;
4507 case T_RangeTableSample:
4508 {
4510
4512 return true;
4513
4515 return true;
4517 return true;
4518 }
4519 break;
4520 case T_RangeTableFunc:
4521 {
4523
4525 return true;
4527 return true;
4529 return true;
4531 return true;
4533 return true;
4534 }
4535 break;
4536 case T_RangeTableFuncCol:
4537 {
4539
4541 return true;
4543 return true;
4544 }
4545 break;
4546 case T_TypeName:
4547 {
4549
4551 return true;
4553 return true;
4554
4555 }
4556 break;
4557 case T_ColumnDef:
4558 {
4560
4562 return true;
4564 return true;
4566 return true;
4567
4568 }
4569 break;
4570 case T_IndexElem:
4571 {
4573
4575 return true;
4576
4577 }
4578 break;
4579 case T_GroupingSet:
4581 case T_LockingClause:
4583 case T_XmlSerialize:
4584 {
4586
4588 return true;
4590 return true;
4591 }
4592 break;
4593 case T_WithClause:
4595 case T_InferClause:
4596 {
4598
4600 return true;
4601 if (WALK(stmt->whereClause))
4602 return true;
4603 }
4604 break;
4605 case T_OnConflictClause:
4606 {
4608
4610 return true;
4612 return true;
4613 if (WALK(stmt->whereClause))
4614 return true;
4615 }
4616 break;
4617 case T_CommonTableExpr:
4618
4620 case T_JsonOutput:
4621 {
4623
4625 return true;
4627 return true;
4628 }
4629 break;
4630 case T_JsonKeyValue:
4631 {
4633
4635 return true;
4637 return true;
4638 }
4639 break;
4640 case T_JsonObjectConstructor:
4641 {
4643
4645 return true;
4647 return true;
4648 }
4649 break;
4650 case T_JsonArrayConstructor:
4651 {
4653
4655 return true;
4657 return true;
4658 }
4659 break;
4660 case T_JsonAggConstructor:
4661 {
4663
4665 return true;
4667 return true;
4669 return true;
4671 return true;
4672 }
4673 break;
4674 case T_JsonObjectAgg:
4675 {
4677
4679 return true;
4681 return true;
4682 }
4683 break;
4684 case T_JsonArrayAgg:
4685 {
4687
4689 return true;
4691 return true;
4692 }
4693 break;
4694 case T_JsonArrayQueryConstructor:
4695 {
4697
4699 return true;
4701 return true;
4702 }
4703 break;
4704 default:
4705 elog(ERROR, "unrecognized node type: %d",
4707 break;
4708 }
4709 return false;
4710}
4711
4712
4713
4714
4715
4716
4717
4718bool
4721 void *context)
4722{
4725
4726
4727#define PSWALK(n) walker(n, context)
4728
4729
4731
4732
4734 return true;
4735
4736
4738 {
4740 return true;
4741 }
4742
4743
4745 {
4747 return true;
4748 }
4749
4750
4752 {
4753 case T_Append:
4756 walker, context))
4757 return true;
4758 break;
4759 case T_MergeAppend:
4762 walker, context))
4763 return true;
4764 break;
4765 case T_BitmapAnd:
4768 walker, context))
4769 return true;
4770 break;
4771 case T_BitmapOr:
4774 walker, context))
4775 return true;
4776 break;
4777 case T_SubqueryScan:
4779 return true;
4780 break;
4781 case T_CustomScan:
4783 {
4785 return true;
4786 }
4787 break;
4788 default:
4789 break;
4790 }
4791
4792
4794 return true;
4795
4796 return false;
4797}
4798
4799
4800
4801
4802static bool
4805 void *context)
4806{
4808
4809 foreach(lc, plans)
4810 {
4812
4814 return true;
4815 }
4816
4817 return false;
4818}
4819
4820
4821
4822
4823
4824static bool
4827 void *context)
4828{
4829 for (int j = 0; j < nplans; j++)
4830 {
4831 if (PSWALK(planstates[j]))
4832 return true;
4833 }
4834
4835 return false;
4836}
#define OidIsValid(objectId)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define outerPlanState(node)
#define innerPlanState(node)
char * format_type_be(Oid type_oid)
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_copy(const List *oldlist)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
RegProcedure get_opcode(Oid opno)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Oid get_promoted_array_type(Oid typid)
bool query_tree_walker_impl(Query *query, tree_walker_callback walker, void *context, int flags)
#define FLATCOPY(newnode, node, nodetype)
bool raw_expression_tree_walker_impl(Node *node, tree_walker_callback walker, void *context)
Oid exprType(const Node *expr)
bool range_table_entry_walker_impl(RangeTblEntry *rte, tree_walker_callback walker, void *context, int flags)
bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
void exprSetCollation(Node *expr, Oid collation)
Oid exprInputCollation(const Node *expr)
int32 exprTypmod(const Node *expr)
static bool planstate_walk_subplans(List *plans, planstate_tree_walker_callback walker, void *context)
bool check_functions_in_node(Node *node, check_function_callback checker, void *context)
Oid exprCollation(const Node *expr)
static bool fix_opfuncids_walker(Node *node, void *context)
void exprSetInputCollation(Node *expr, Oid inputcollation)
bool query_or_expression_tree_walker_impl(Node *node, tree_walker_callback walker, void *context, int flags)
bool expression_tree_walker_impl(Node *node, tree_walker_callback walker, void *context)
bool range_table_walker_impl(List *rtable, tree_walker_callback walker, void *context, int flags)
Node * query_or_expression_tree_mutator_impl(Node *node, tree_mutator_callback mutator, void *context, int flags)
Query * query_tree_mutator_impl(Query *query, tree_mutator_callback mutator, void *context, int flags)
#define MUTATE(newfield, oldfield, fieldtype)
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
static int leftmostLoc(int loc1, int loc2)
Node * strip_implicit_coercions(Node *node)
int exprLocation(const Node *expr)
List * range_table_mutator_impl(List *rtable, tree_mutator_callback mutator, void *context, int flags)
bool expression_returns_set(Node *clause)
bool planstate_tree_walker_impl(PlanState *planstate, planstate_tree_walker_callback walker, void *context)
void fix_opfuncids(Node *node)
Node * expression_tree_mutator_impl(Node *node, tree_mutator_callback mutator, void *context)
Node * relabel_to_typmod(Node *expr, int32 typmod)
static bool expression_returns_set_walker(Node *node, void *context)
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
static bool planstate_walk_members(PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
void set_opfuncid(OpExpr *opexpr)
Node *(* tree_mutator_callback)(Node *node, void *context)
#define QTW_DONT_COPY_QUERY
#define QTW_IGNORE_CTE_SUBQUERIES
#define QTW_IGNORE_RT_SUBQUERIES
#define range_table_walker(rt, w, c, f)
#define query_tree_walker(q, w, c, f)
#define range_table_entry_walker(r, w, c, f)
#define QTW_EXAMINE_RTES_AFTER
#define QTW_EXAMINE_SORTGROUP
bool(* tree_walker_callback)(Node *node, void *context)
#define QTW_IGNORE_GROUPEXPRS
#define expression_tree_walker(n, w, c)
#define query_tree_mutator(q, m, c, f)
bool(* check_function_callback)(Oid func_id, void *context)
bool(* planstate_tree_walker_callback)(PlanState *planstate, void *context)
#define QTW_EXAMINE_RTES_BEFORE
#define range_table_mutator(rt, m, c, f)
#define QTW_IGNORE_RANGE_TABLE
#define QTW_IGNORE_JOINALIASES
#define IsA(nodeptr, _type_)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define for_each_from(cell, lst, N)
static rewind_source * source
static int32 DatumGetInt32(Datum X)
static int fc(const char *x)
void check_stack_depth(void)
Node * cycle_mark_default
CollateClause * collClause
struct RestrictInfo * rinfo
JsonAggConstructor * constructor
JsonReturning * returning
JsonReturning * returning
JsonValueExpr * context_item
JsonAggConstructor * constructor
JsonReturning * returning
JsonTablePathSpec * pathspec
JsonValueExpr * context_item
Node * mergeJoinCondition
OnConflictExpr * onConflict
struct TableSampleClause * tablesample