Age Owner Branch data TLA Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * nodeFuncs.c
4 : : * Various general-purpose manipulations of Node trees
5 : : *
6 : : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 : : * Portions Copyright (c) 1994, Regents of the University of California
8 : : *
9 : : *
10 : : * IDENTIFICATION
11 : : * src/backend/nodes/nodeFuncs.c
12 : : *
13 : : *-------------------------------------------------------------------------
14 : : */
15 : : #include "postgres.h"
16 : :
17 : : #include "catalog/pg_collation.h"
18 : : #include "catalog/pg_type.h"
19 : : #include "miscadmin.h"
20 : : #include "nodes/execnodes.h"
21 : : #include "nodes/nodeFuncs.h"
22 : : #include "nodes/pathnodes.h"
23 : : #include "utils/builtins.h"
24 : : #include "utils/lsyscache.h"
25 : :
26 : : static bool expression_returns_set_walker(Node *node, void *context);
27 : : static int leftmostLoc(int loc1, int loc2);
28 : : static bool fix_opfuncids_walker(Node *node, void *context);
29 : : static bool planstate_walk_subplans(List *plans,
30 : : planstate_tree_walker_callback walker,
31 : : void *context);
32 : : static bool planstate_walk_members(PlanState **planstates, int nplans,
33 : : planstate_tree_walker_callback walker,
34 : : void *context);
35 : :
36 : :
37 : : /*
38 : : * exprType -
39 : : * returns the Oid of the type of the expression's result.
40 : : */
41 : : Oid
5470 peter_e@gmx.net 42 :CBC 23564872 : exprType(const Node *expr)
43 : : {
44 : : Oid type;
45 : :
6669 tgl@sss.pgh.pa.us 46 [ + + ]: 23564872 : if (!expr)
47 : 348 : return InvalidOid;
48 : :
49 [ + + + + : 23564524 : switch (nodeTag(expr))
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + - + +
- ]
50 : : {
51 : 13497925 : case T_Var:
5470 peter_e@gmx.net 52 : 13497925 : type = ((const Var *) expr)->vartype;
6669 tgl@sss.pgh.pa.us 53 : 13497925 : break;
54 : 3235104 : case T_Const:
5470 peter_e@gmx.net 55 : 3235104 : type = ((const Const *) expr)->consttype;
6669 tgl@sss.pgh.pa.us 56 : 3235104 : break;
57 : 2029045 : case T_Param:
5470 peter_e@gmx.net 58 : 2029045 : type = ((const Param *) expr)->paramtype;
6669 tgl@sss.pgh.pa.us 59 : 2029045 : break;
60 : 229311 : case T_Aggref:
3807 61 : 229311 : type = ((const Aggref *) expr)->aggtype;
6669 62 : 229311 : break;
4214 andres@anarazel.de 63 : 1784 : case T_GroupingFunc:
64 : 1784 : type = INT4OID;
65 : 1784 : break;
6544 tgl@sss.pgh.pa.us 66 : 16505 : case T_WindowFunc:
5470 peter_e@gmx.net 67 : 16505 : type = ((const WindowFunc *) expr)->wintype;
6544 tgl@sss.pgh.pa.us 68 : 16505 : break;
986 dean.a.rasheed@gmail 69 : 842 : case T_MergeSupportFunc:
70 : 842 : type = ((const MergeSupportFunc *) expr)->msftype;
71 : 842 : break;
2857 alvherre@alvh.no-ip. 72 : 107461 : case T_SubscriptingRef:
2180 tgl@sss.pgh.pa.us 73 : 107461 : type = ((const SubscriptingRef *) expr)->refrestype;
6669 74 : 107461 : break;
75 : 1405681 : case T_FuncExpr:
5470 peter_e@gmx.net 76 : 1405681 : type = ((const FuncExpr *) expr)->funcresulttype;
6669 tgl@sss.pgh.pa.us 77 : 1405681 : break;
6260 78 : 48983 : case T_NamedArgExpr:
5470 peter_e@gmx.net 79 : 48983 : type = exprType((Node *) ((const NamedArgExpr *) expr)->arg);
6260 tgl@sss.pgh.pa.us 80 : 48983 : break;
6669 81 : 1054965 : case T_OpExpr:
5470 peter_e@gmx.net 82 : 1054965 : type = ((const OpExpr *) expr)->opresulttype;
6669 tgl@sss.pgh.pa.us 83 : 1054965 : break;
84 : 1434 : case T_DistinctExpr:
5470 peter_e@gmx.net 85 : 1434 : type = ((const DistinctExpr *) expr)->opresulttype;
6669 tgl@sss.pgh.pa.us 86 : 1434 : break;
5733 87 : 2027 : case T_NullIfExpr:
5470 peter_e@gmx.net 88 : 2027 : type = ((const NullIfExpr *) expr)->opresulttype;
5733 tgl@sss.pgh.pa.us 89 : 2027 : break;
6669 90 : 76428 : case T_ScalarArrayOpExpr:
91 : 76428 : type = BOOLOID;
92 : 76428 : break;
93 : 244067 : case T_BoolExpr:
94 : 244067 : type = BOOLOID;
95 : 244067 : break;
96 : 80437 : case T_SubLink:
97 : : {
5284 bruce@momjian.us 98 : 80437 : const SubLink *sublink = (const SubLink *) expr;
99 : :
6669 tgl@sss.pgh.pa.us 100 [ + + ]: 80437 : if (sublink->subLinkType == EXPR_SUBLINK ||
101 [ + + ]: 36713 : sublink->subLinkType == ARRAY_SUBLINK)
102 : 55222 : {
103 : : /* get the type of the subselect's first target column */
104 : 55222 : Query *qtree = (Query *) sublink->subselect;
105 : : TargetEntry *tent;
106 : :
107 [ + - - + ]: 55222 : if (!qtree || !IsA(qtree, Query))
6669 tgl@sss.pgh.pa.us 108 [ # # ]:UBC 0 : elog(ERROR, "cannot get type for untransformed sublink");
3519 tgl@sss.pgh.pa.us 109 :CBC 55222 : tent = linitial_node(TargetEntry, qtree->targetList);
6669 110 [ - + ]: 55222 : Assert(!tent->resjunk);
111 : 55222 : type = exprType((Node *) tent->expr);
112 [ + + ]: 55222 : if (sublink->subLinkType == ARRAY_SUBLINK)
113 : : {
4386 114 : 11498 : type = get_promoted_array_type(type);
6669 115 [ - + ]: 11498 : if (!OidIsValid(type))
6669 tgl@sss.pgh.pa.us 116 [ # # ]:UBC 0 : ereport(ERROR,
117 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
118 : : errmsg("could not find array type for data type %s",
119 : : format_type_be(exprType((Node *) tent->expr)))));
120 : : }
121 : : }
4546 tgl@sss.pgh.pa.us 122 [ + + ]:CBC 25215 : else if (sublink->subLinkType == MULTIEXPR_SUBLINK)
123 : : {
124 : : /* MULTIEXPR is always considered to return RECORD */
125 : 91 : type = RECORDOID;
126 : : }
127 : : else
128 : : {
129 : : /* for all other sublink types, result is boolean */
6669 130 : 25124 : type = BOOLOID;
131 : : }
132 : : }
133 : 80437 : break;
134 : 37605 : case T_SubPlan:
135 : : {
5284 bruce@momjian.us 136 : 37605 : const SubPlan *subplan = (const SubPlan *) expr;
137 : :
6669 tgl@sss.pgh.pa.us 138 [ + + ]: 37605 : if (subplan->subLinkType == EXPR_SUBLINK ||
139 [ + + ]: 3319 : subplan->subLinkType == ARRAY_SUBLINK)
140 : : {
141 : : /* get the type of the subselect's first target column */
142 : 34648 : type = subplan->firstColType;
143 [ + + ]: 34648 : if (subplan->subLinkType == ARRAY_SUBLINK)
144 : : {
4386 145 : 362 : type = get_promoted_array_type(type);
6669 146 [ - + ]: 362 : if (!OidIsValid(type))
6669 tgl@sss.pgh.pa.us 147 [ # # ]:UBC 0 : ereport(ERROR,
148 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
149 : : errmsg("could not find array type for data type %s",
150 : : format_type_be(subplan->firstColType))));
151 : : }
152 : : }
4546 tgl@sss.pgh.pa.us 153 [ + + ]:CBC 2957 : else if (subplan->subLinkType == MULTIEXPR_SUBLINK)
154 : : {
155 : : /* MULTIEXPR is always considered to return RECORD */
156 : 126 : type = RECORDOID;
157 : : }
158 : : else
159 : : {
160 : : /* for all other subplan types, result is boolean */
6669 161 : 2831 : type = BOOLOID;
162 : : }
163 : : }
164 : 37605 : break;
165 : 1020 : case T_AlternativeSubPlan:
166 : : {
5470 peter_e@gmx.net 167 : 1020 : const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
168 : :
169 : : /* subplans should all return the same thing */
6669 tgl@sss.pgh.pa.us 170 : 1020 : type = exprType((Node *) linitial(asplan->subplans));
171 : : }
172 : 1020 : break;
173 : 35215 : case T_FieldSelect:
5470 peter_e@gmx.net 174 : 35215 : type = ((const FieldSelect *) expr)->resulttype;
6669 tgl@sss.pgh.pa.us 175 : 35215 : break;
176 : 1027 : case T_FieldStore:
5470 peter_e@gmx.net 177 : 1027 : type = ((const FieldStore *) expr)->resulttype;
6669 tgl@sss.pgh.pa.us 178 : 1027 : break;
179 : 536503 : case T_RelabelType:
5470 peter_e@gmx.net 180 : 536503 : type = ((const RelabelType *) expr)->resulttype;
6669 tgl@sss.pgh.pa.us 181 : 536503 : break;
182 : 105457 : case T_CoerceViaIO:
5470 peter_e@gmx.net 183 : 105457 : type = ((const CoerceViaIO *) expr)->resulttype;
6669 tgl@sss.pgh.pa.us 184 : 105457 : break;
185 : 11374 : case T_ArrayCoerceExpr:
5470 peter_e@gmx.net 186 : 11374 : type = ((const ArrayCoerceExpr *) expr)->resulttype;
6669 tgl@sss.pgh.pa.us 187 : 11374 : break;
188 : 1750 : case T_ConvertRowtypeExpr:
5470 peter_e@gmx.net 189 : 1750 : type = ((const ConvertRowtypeExpr *) expr)->resulttype;
6669 tgl@sss.pgh.pa.us 190 : 1750 : break;
5741 191 : 7629 : case T_CollateExpr:
5470 peter_e@gmx.net 192 : 7629 : type = exprType((Node *) ((const CollateExpr *) expr)->arg);
5741 tgl@sss.pgh.pa.us 193 : 7629 : break;
6669 194 : 272527 : case T_CaseExpr:
5470 peter_e@gmx.net 195 : 272527 : type = ((const CaseExpr *) expr)->casetype;
6669 tgl@sss.pgh.pa.us 196 : 272527 : break;
197 : 30310 : case T_CaseTestExpr:
5470 peter_e@gmx.net 198 : 30310 : type = ((const CaseTestExpr *) expr)->typeId;
6669 tgl@sss.pgh.pa.us 199 : 30310 : break;
200 : 75296 : case T_ArrayExpr:
5470 peter_e@gmx.net 201 : 75296 : type = ((const ArrayExpr *) expr)->array_typeid;
6669 tgl@sss.pgh.pa.us 202 : 75296 : break;
203 : 15310 : case T_RowExpr:
5470 peter_e@gmx.net 204 : 15310 : type = ((const RowExpr *) expr)->row_typeid;
6669 tgl@sss.pgh.pa.us 205 : 15310 : break;
206 : 386 : case T_RowCompareExpr:
207 : 386 : type = BOOLOID;
208 : 386 : break;
209 : 30515 : case T_CoalesceExpr:
5470 peter_e@gmx.net 210 : 30515 : type = ((const CoalesceExpr *) expr)->coalescetype;
6669 tgl@sss.pgh.pa.us 211 : 30515 : break;
212 : 3670 : case T_MinMaxExpr:
5470 peter_e@gmx.net 213 : 3670 : type = ((const MinMaxExpr *) expr)->minmaxtype;
6669 tgl@sss.pgh.pa.us 214 : 3670 : break;
1291 michael@paquier.xyz 215 : 7892 : case T_SQLValueFunction:
216 : 7892 : type = ((const SQLValueFunction *) expr)->type;
217 : 7892 : break;
6669 tgl@sss.pgh.pa.us 218 : 17068 : case T_XmlExpr:
5470 peter_e@gmx.net 219 [ + + ]: 17068 : if (((const XmlExpr *) expr)->op == IS_DOCUMENT)
6669 tgl@sss.pgh.pa.us 220 : 137 : type = BOOLOID;
5470 peter_e@gmx.net 221 [ + + ]: 16931 : else if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
6669 tgl@sss.pgh.pa.us 222 : 501 : type = TEXTOID;
223 : : else
224 : 16430 : type = XMLOID;
225 : 17068 : break;
1334 alvherre@alvh.no-ip. 226 : 958 : case T_JsonValueExpr:
227 : : {
228 : 958 : const JsonValueExpr *jve = (const JsonValueExpr *) expr;
229 : :
1226 amitlan@postgresql.o 230 : 958 : type = exprType((Node *) jve->formatted_expr);
231 : : }
1334 alvherre@alvh.no-ip. 232 : 958 : break;
233 : 5831 : case T_JsonConstructorExpr:
234 : 5831 : type = ((const JsonConstructorExpr *) expr)->returning->typid;
235 : 5831 : break;
236 : 1291 : case T_JsonIsPredicate:
237 : 1291 : type = BOOLOID;
238 : 1291 : break;
982 amitlan@postgresql.o 239 : 10103 : case T_JsonExpr:
240 : : {
241 : 10103 : const JsonExpr *jexpr = (const JsonExpr *) expr;
242 : :
243 : 10103 : type = jexpr->returning->typid;
244 : 10103 : break;
245 : : }
246 : 5088 : case T_JsonBehavior:
247 : : {
248 : 5088 : const JsonBehavior *behavior = (const JsonBehavior *) expr;
249 : :
250 : 5088 : type = exprType(behavior->expr);
251 : 5088 : break;
252 : : }
6669 tgl@sss.pgh.pa.us 253 : 31823 : case T_NullTest:
254 : 31823 : type = BOOLOID;
255 : 31823 : break;
256 : 2217 : case T_BooleanTest:
257 : 2217 : type = BOOLOID;
258 : 2217 : break;
259 : 178406 : case T_CoerceToDomain:
5470 peter_e@gmx.net 260 : 178406 : type = ((const CoerceToDomain *) expr)->resulttype;
6669 tgl@sss.pgh.pa.us 261 : 178406 : break;
262 : 1603 : case T_CoerceToDomainValue:
5470 peter_e@gmx.net 263 : 1603 : type = ((const CoerceToDomainValue *) expr)->typeId;
6669 tgl@sss.pgh.pa.us 264 : 1603 : break;
265 : 74743 : case T_SetToDefault:
5470 peter_e@gmx.net 266 : 74743 : type = ((const SetToDefault *) expr)->typeId;
6669 tgl@sss.pgh.pa.us 267 : 74743 : break;
268 : 172 : case T_CurrentOfExpr:
269 : 172 : type = BOOLOID;
270 : 172 : break;
3523 peter_e@gmx.net 271 : 7523 : case T_NextValueExpr:
272 : 7523 : type = ((const NextValueExpr *) expr)->typeId;
273 : 7523 : break;
4222 andres@anarazel.de 274 :UBC 0 : case T_InferenceElem:
275 : : {
276 : 0 : const InferenceElem *n = (const InferenceElem *) expr;
277 : :
278 : 0 : type = exprType((Node *) n->expr);
279 : : }
280 : 0 : break;
681 dean.a.rasheed@gmail 281 :CBC 640 : case T_ReturningExpr:
282 : 640 : type = exprType((Node *) ((const ReturningExpr *) expr)->retexpr);
283 : 640 : break;
6612 tgl@sss.pgh.pa.us 284 : 21573 : case T_PlaceHolderVar:
5470 peter_e@gmx.net 285 : 21573 : type = exprType((Node *) ((const PlaceHolderVar *) expr)->phexpr);
6612 tgl@sss.pgh.pa.us 286 : 21573 : break;
6669 tgl@sss.pgh.pa.us 287 :UBC 0 : default:
288 [ # # ]: 0 : elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
289 : : type = InvalidOid; /* keep compiler quiet */
290 : : break;
291 : : }
6669 tgl@sss.pgh.pa.us 292 :CBC 23564524 : return type;
293 : : }
294 : :
295 : : /*
296 : : * exprTypmod -
297 : : * returns the type-specific modifier of the expression's result type,
298 : : * if it can be determined. In many cases, it can't and we return -1.
299 : : */
300 : : int32
5470 peter_e@gmx.net 301 : 7715622 : exprTypmod(const Node *expr)
302 : : {
6669 tgl@sss.pgh.pa.us 303 [ - + ]: 7715622 : if (!expr)
6669 tgl@sss.pgh.pa.us 304 :UBC 0 : return -1;
305 : :
6669 tgl@sss.pgh.pa.us 306 [ + + + + :CBC 7715622 : switch (nodeTag(expr))
+ - + + +
+ + + + +
+ + + + +
+ + + + -
+ + + + +
+ ]
307 : : {
308 : 4567302 : case T_Var:
5470 peter_e@gmx.net 309 : 4567302 : return ((const Var *) expr)->vartypmod;
6669 tgl@sss.pgh.pa.us 310 : 1192779 : case T_Const:
5470 peter_e@gmx.net 311 : 1192779 : return ((const Const *) expr)->consttypmod;
6669 tgl@sss.pgh.pa.us 312 : 126531 : case T_Param:
5470 peter_e@gmx.net 313 : 126531 : return ((const Param *) expr)->paramtypmod;
2857 alvherre@alvh.no-ip. 314 : 30598 : case T_SubscriptingRef:
315 : 30598 : return ((const SubscriptingRef *) expr)->reftypmod;
6669 tgl@sss.pgh.pa.us 316 : 875551 : case T_FuncExpr:
317 : : {
318 : : int32 coercedTypmod;
319 : :
320 : : /* Be smart about length-coercion functions... */
321 [ + + ]: 875551 : if (exprIsLengthCoercion(expr, &coercedTypmod))
322 : 17439 : return coercedTypmod;
323 : : }
324 : 858112 : break;
6260 tgl@sss.pgh.pa.us 325 :UBC 0 : case T_NamedArgExpr:
5470 peter_e@gmx.net 326 : 0 : return exprTypmod((Node *) ((const NamedArgExpr *) expr)->arg);
5733 tgl@sss.pgh.pa.us 327 :CBC 421 : case T_NullIfExpr:
328 : : {
329 : : /*
330 : : * Result is either first argument or NULL, so we can report
331 : : * first argument's typmod if known.
332 : : */
5470 peter_e@gmx.net 333 : 421 : const NullIfExpr *nexpr = (const NullIfExpr *) expr;
334 : :
5733 tgl@sss.pgh.pa.us 335 : 421 : return exprTypmod((Node *) linitial(nexpr->args));
336 : : }
337 : : break;
6669 338 : 4802 : case T_SubLink:
339 : : {
5284 bruce@momjian.us 340 : 4802 : const SubLink *sublink = (const SubLink *) expr;
341 : :
6669 tgl@sss.pgh.pa.us 342 [ + + ]: 4802 : if (sublink->subLinkType == EXPR_SUBLINK ||
343 [ + + ]: 468 : sublink->subLinkType == ARRAY_SUBLINK)
344 : : {
345 : : /* get the typmod of the subselect's first target column */
346 : 4716 : Query *qtree = (Query *) sublink->subselect;
347 : : TargetEntry *tent;
348 : :
349 [ + - - + ]: 4716 : if (!qtree || !IsA(qtree, Query))
6669 tgl@sss.pgh.pa.us 350 [ # # ]:UBC 0 : elog(ERROR, "cannot get type for untransformed sublink");
3519 tgl@sss.pgh.pa.us 351 :CBC 4716 : tent = linitial_node(TargetEntry, qtree->targetList);
6669 352 [ - + ]: 4716 : Assert(!tent->resjunk);
353 : 4716 : return exprTypmod((Node *) tent->expr);
354 : : /* note we don't need to care if it's an array */
355 : : }
356 : : /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */
357 : : }
358 : 86 : break;
6472 359 : 26476 : case T_SubPlan:
360 : : {
5284 bruce@momjian.us 361 : 26476 : const SubPlan *subplan = (const SubPlan *) expr;
362 : :
6472 tgl@sss.pgh.pa.us 363 [ + + ]: 26476 : if (subplan->subLinkType == EXPR_SUBLINK ||
364 [ + + ]: 1761 : subplan->subLinkType == ARRAY_SUBLINK)
365 : : {
366 : : /* get the typmod of the subselect's first target column */
367 : : /* note we don't need to care if it's an array */
368 : 24896 : return subplan->firstColTypmod;
369 : : }
370 : : /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */
371 : : }
372 : 1580 : break;
373 : 515 : case T_AlternativeSubPlan:
374 : : {
5470 peter_e@gmx.net 375 : 515 : const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
376 : :
377 : : /* subplans should all return the same thing */
6472 tgl@sss.pgh.pa.us 378 : 515 : return exprTypmod((Node *) linitial(asplan->subplans));
379 : : }
380 : : break;
6669 381 : 15743 : case T_FieldSelect:
5470 peter_e@gmx.net 382 : 15743 : return ((const FieldSelect *) expr)->resulttypmod;
6669 tgl@sss.pgh.pa.us 383 : 166179 : case T_RelabelType:
5470 peter_e@gmx.net 384 : 166179 : return ((const RelabelType *) expr)->resulttypmod;
6669 tgl@sss.pgh.pa.us 385 : 5455 : case T_ArrayCoerceExpr:
5470 peter_e@gmx.net 386 : 5455 : return ((const ArrayCoerceExpr *) expr)->resulttypmod;
5741 tgl@sss.pgh.pa.us 387 : 153 : case T_CollateExpr:
5470 peter_e@gmx.net 388 : 153 : return exprTypmod((Node *) ((const CollateExpr *) expr)->arg);
6669 tgl@sss.pgh.pa.us 389 : 127671 : case T_CaseExpr:
390 : : {
391 : : /*
392 : : * If all the alternatives agree on type/typmod, return that
393 : : * typmod, else use -1
394 : : */
5284 bruce@momjian.us 395 : 127671 : const CaseExpr *cexpr = (const CaseExpr *) expr;
6669 tgl@sss.pgh.pa.us 396 : 127671 : Oid casetype = cexpr->casetype;
397 : : int32 typmod;
398 : : ListCell *arg;
399 : :
400 [ - + ]: 127671 : if (!cexpr->defresult)
6669 tgl@sss.pgh.pa.us 401 :UBC 0 : return -1;
6669 tgl@sss.pgh.pa.us 402 [ - + ]:CBC 127671 : if (exprType((Node *) cexpr->defresult) != casetype)
6669 tgl@sss.pgh.pa.us 403 :UBC 0 : return -1;
6669 tgl@sss.pgh.pa.us 404 :CBC 127671 : typmod = exprTypmod((Node *) cexpr->defresult);
405 [ + - ]: 127671 : if (typmod < 0)
406 : 127671 : return -1; /* no point in trying harder */
6669 tgl@sss.pgh.pa.us 407 [ # # # # :UBC 0 : foreach(arg, cexpr->args)
# # ]
408 : : {
3519 409 : 0 : CaseWhen *w = lfirst_node(CaseWhen, arg);
410 : :
6669 411 [ # # ]: 0 : if (exprType((Node *) w->result) != casetype)
412 : 0 : return -1;
413 [ # # ]: 0 : if (exprTypmod((Node *) w->result) != typmod)
414 : 0 : return -1;
415 : : }
416 : 0 : return typmod;
417 : : }
418 : : break;
6669 tgl@sss.pgh.pa.us 419 :CBC 9452 : case T_CaseTestExpr:
5470 peter_e@gmx.net 420 : 9452 : return ((const CaseTestExpr *) expr)->typeMod;
6669 tgl@sss.pgh.pa.us 421 : 28690 : case T_ArrayExpr:
422 : : {
423 : : /*
424 : : * If all the elements agree on type/typmod, return that
425 : : * typmod, else use -1
426 : : */
5284 bruce@momjian.us 427 : 28690 : const ArrayExpr *arrayexpr = (const ArrayExpr *) expr;
428 : : Oid commontype;
429 : : int32 typmod;
430 : : ListCell *elem;
431 : :
6669 tgl@sss.pgh.pa.us 432 [ + + ]: 28690 : if (arrayexpr->elements == NIL)
433 : 164 : return -1;
434 : 28526 : typmod = exprTypmod((Node *) linitial(arrayexpr->elements));
435 [ + + ]: 28526 : if (typmod < 0)
436 : 28514 : return -1; /* no point in trying harder */
437 [ - + ]: 12 : if (arrayexpr->multidims)
6669 tgl@sss.pgh.pa.us 438 :UBC 0 : commontype = arrayexpr->array_typeid;
439 : : else
6669 tgl@sss.pgh.pa.us 440 :CBC 12 : commontype = arrayexpr->element_typeid;
441 [ + - + + : 36 : foreach(elem, arrayexpr->elements)
+ + ]
442 : : {
443 : 24 : Node *e = (Node *) lfirst(elem);
444 : :
445 [ - + ]: 24 : if (exprType(e) != commontype)
6669 tgl@sss.pgh.pa.us 446 :UBC 0 : return -1;
6669 tgl@sss.pgh.pa.us 447 [ - + ]:CBC 24 : if (exprTypmod(e) != typmod)
6669 tgl@sss.pgh.pa.us 448 :UBC 0 : return -1;
449 : : }
6669 tgl@sss.pgh.pa.us 450 :CBC 12 : return typmod;
451 : : }
452 : : break;
453 : 15296 : case T_CoalesceExpr:
454 : : {
455 : : /*
456 : : * If all the alternatives agree on type/typmod, return that
457 : : * typmod, else use -1
458 : : */
5470 peter_e@gmx.net 459 : 15296 : const CoalesceExpr *cexpr = (const CoalesceExpr *) expr;
6669 tgl@sss.pgh.pa.us 460 : 15296 : Oid coalescetype = cexpr->coalescetype;
461 : : int32 typmod;
462 : : ListCell *arg;
463 : :
464 [ - + ]: 15296 : if (exprType((Node *) linitial(cexpr->args)) != coalescetype)
6669 tgl@sss.pgh.pa.us 465 :UBC 0 : return -1;
6669 tgl@sss.pgh.pa.us 466 :CBC 15296 : typmod = exprTypmod((Node *) linitial(cexpr->args));
467 [ + + ]: 15296 : if (typmod < 0)
468 : 15270 : return -1; /* no point in trying harder */
2252 469 [ + - + + : 52 : for_each_from(arg, cexpr->args, 1)
+ + ]
470 : : {
6669 471 : 26 : Node *e = (Node *) lfirst(arg);
472 : :
473 [ - + ]: 26 : if (exprType(e) != coalescetype)
6669 tgl@sss.pgh.pa.us 474 :UBC 0 : return -1;
6669 tgl@sss.pgh.pa.us 475 [ - + ]:CBC 26 : if (exprTypmod(e) != typmod)
6669 tgl@sss.pgh.pa.us 476 :UBC 0 : return -1;
477 : : }
6669 tgl@sss.pgh.pa.us 478 :CBC 26 : return typmod;
479 : : }
480 : : break;
481 : 1895 : case T_MinMaxExpr:
482 : : {
483 : : /*
484 : : * If all the alternatives agree on type/typmod, return that
485 : : * typmod, else use -1
486 : : */
5470 peter_e@gmx.net 487 : 1895 : const MinMaxExpr *mexpr = (const MinMaxExpr *) expr;
6669 tgl@sss.pgh.pa.us 488 : 1895 : Oid minmaxtype = mexpr->minmaxtype;
489 : : int32 typmod;
490 : : ListCell *arg;
491 : :
492 [ - + ]: 1895 : if (exprType((Node *) linitial(mexpr->args)) != minmaxtype)
6669 tgl@sss.pgh.pa.us 493 :UBC 0 : return -1;
6669 tgl@sss.pgh.pa.us 494 :CBC 1895 : typmod = exprTypmod((Node *) linitial(mexpr->args));
495 [ + - ]: 1895 : if (typmod < 0)
496 : 1895 : return -1; /* no point in trying harder */
2252 tgl@sss.pgh.pa.us 497 [ # # # # :UBC 0 : for_each_from(arg, mexpr->args, 1)
# # ]
498 : : {
6669 499 : 0 : Node *e = (Node *) lfirst(arg);
500 : :
501 [ # # ]: 0 : if (exprType(e) != minmaxtype)
502 : 0 : return -1;
503 [ # # ]: 0 : if (exprTypmod(e) != typmod)
504 : 0 : return -1;
505 : : }
506 : 0 : return typmod;
507 : : }
508 : : break;
1291 michael@paquier.xyz 509 :CBC 1624 : case T_SQLValueFunction:
510 : 1624 : return ((const SQLValueFunction *) expr)->typmod;
1334 alvherre@alvh.no-ip. 511 : 44 : case T_JsonValueExpr:
512 : 44 : return exprTypmod((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
513 : 2314 : case T_JsonConstructorExpr:
514 : 2314 : return ((const JsonConstructorExpr *) expr)->returning->typmod;
982 amitlan@postgresql.o 515 : 3598 : case T_JsonExpr:
516 : : {
517 : 3598 : const JsonExpr *jexpr = (const JsonExpr *) expr;
518 : :
519 : 3598 : return jexpr->returning->typmod;
520 : : }
521 : : break;
982 amitlan@postgresql.o 522 :UBC 0 : case T_JsonBehavior:
523 : : {
524 : 0 : const JsonBehavior *behavior = (const JsonBehavior *) expr;
525 : :
526 : 0 : return exprTypmod(behavior->expr);
527 : : }
528 : : break;
6669 tgl@sss.pgh.pa.us 529 :CBC 136328 : case T_CoerceToDomain:
5470 peter_e@gmx.net 530 : 136328 : return ((const CoerceToDomain *) expr)->resulttypmod;
6669 tgl@sss.pgh.pa.us 531 : 52 : case T_CoerceToDomainValue:
5470 peter_e@gmx.net 532 : 52 : return ((const CoerceToDomainValue *) expr)->typeMod;
6669 tgl@sss.pgh.pa.us 533 : 19601 : case T_SetToDefault:
5470 peter_e@gmx.net 534 : 19601 : return ((const SetToDefault *) expr)->typeMod;
681 dean.a.rasheed@gmail 535 : 352 : case T_ReturningExpr:
536 : 352 : return exprTypmod((Node *) ((const ReturningExpr *) expr)->retexpr);
6612 tgl@sss.pgh.pa.us 537 : 12141 : case T_PlaceHolderVar:
5470 peter_e@gmx.net 538 : 12141 : return exprTypmod((Node *) ((const PlaceHolderVar *) expr)->phexpr);
6669 tgl@sss.pgh.pa.us 539 : 344059 : default:
540 : 344059 : break;
541 : : }
542 : 1203837 : return -1;
543 : : }
544 : :
545 : : /*
546 : : * exprIsLengthCoercion
547 : : * Detect whether an expression tree is an application of a datatype's
548 : : * typmod-coercion function. Optionally extract the result's typmod.
549 : : *
550 : : * If coercedTypmod is not NULL, the typmod is stored there if the expression
551 : : * is a length-coercion function, else -1 is stored there.
552 : : *
553 : : * Note that a combined type-and-length coercion will be treated as a
554 : : * length coercion by this routine.
555 : : */
556 : : bool
5470 peter_e@gmx.net 557 : 876761 : exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
558 : : {
5733 tgl@sss.pgh.pa.us 559 [ + - ]: 876761 : if (coercedTypmod != NULL)
560 : 876761 : *coercedTypmod = -1; /* default result on failure */
561 : :
562 : : /*
563 : : * Scalar-type length coercions are FuncExprs, array-type length coercions
564 : : * are ArrayCoerceExprs
565 : : */
566 [ + - + - ]: 876761 : if (expr && IsA(expr, FuncExpr))
567 : : {
5284 bruce@momjian.us 568 : 876761 : const FuncExpr *func = (const FuncExpr *) expr;
569 : : int nargs;
570 : : Const *second_arg;
571 : :
572 : : /*
573 : : * If it didn't come from a coercion context, reject.
574 : : */
5733 tgl@sss.pgh.pa.us 575 [ + + ]: 876761 : if (func->funcformat != COERCE_EXPLICIT_CAST &&
576 [ + + ]: 849878 : func->funcformat != COERCE_IMPLICIT_CAST)
577 : 704795 : return false;
578 : :
579 : : /*
580 : : * If it's not a two-argument or three-argument function with the
581 : : * second argument being an int4 constant, it can't have been created
582 : : * from a length coercion (it must be a type coercion, instead).
583 : : */
584 : 171966 : nargs = list_length(func->args);
585 [ + + - + ]: 171966 : if (nargs < 2 || nargs > 3)
586 : 154467 : return false;
587 : :
588 : 17499 : second_arg = (Const *) lsecond(func->args);
589 [ + - ]: 17499 : if (!IsA(second_arg, Const) ||
590 [ + - ]: 17499 : second_arg->consttype != INT4OID ||
591 [ - + ]: 17499 : second_arg->constisnull)
5733 tgl@sss.pgh.pa.us 592 :UBC 0 : return false;
593 : :
594 : : /*
595 : : * OK, it is indeed a length-coercion function.
596 : : */
5733 tgl@sss.pgh.pa.us 597 [ + - ]:CBC 17499 : if (coercedTypmod != NULL)
598 : 17499 : *coercedTypmod = DatumGetInt32(second_arg->constvalue);
599 : :
600 : 17499 : return true;
601 : : }
602 : :
5733 tgl@sss.pgh.pa.us 603 [ # # # # ]:UBC 0 : if (expr && IsA(expr, ArrayCoerceExpr))
604 : : {
5470 peter_e@gmx.net 605 : 0 : const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
606 : :
607 : : /* It's not a length coercion unless there's a nondefault typmod */
5733 tgl@sss.pgh.pa.us 608 [ # # ]: 0 : if (acoerce->resulttypmod < 0)
609 : 0 : return false;
610 : :
611 : : /*
612 : : * OK, it is indeed a length-coercion expression.
613 : : */
614 [ # # ]: 0 : if (coercedTypmod != NULL)
615 : 0 : *coercedTypmod = acoerce->resulttypmod;
616 : :
617 : 0 : return true;
618 : : }
619 : :
620 : 0 : return false;
621 : : }
622 : :
623 : : /*
624 : : * applyRelabelType
625 : : * Add a RelabelType node if needed to make the expression expose
626 : : * the specified type, typmod, and collation.
627 : : *
628 : : * This is primarily intended to be used during planning. Therefore, it must
629 : : * maintain the post-eval_const_expressions invariants that there are not
630 : : * adjacent RelabelTypes, and that the tree is fully const-folded (hence,
631 : : * we mustn't return a RelabelType atop a Const). If we do find a Const,
632 : : * we'll modify it in-place if "overwrite_ok" is true; that should only be
633 : : * passed as true if caller knows the Const is newly generated.
634 : : */
635 : : Node *
2292 tgl@sss.pgh.pa.us 636 :CBC 247879 : applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid,
637 : : CoercionForm rformat, int rlocation, bool overwrite_ok)
638 : : {
639 : : /*
640 : : * If we find stacked RelabelTypes (eg, from foo::int::oid) we can discard
641 : : * all but the top one, and must do so to ensure that semantically
642 : : * equivalent expressions are equal().
643 : : */
644 [ + - + + ]: 250349 : while (arg && IsA(arg, RelabelType))
645 : 2470 : arg = (Node *) ((RelabelType *) arg)->arg;
646 : :
647 [ + - + + ]: 247879 : if (arg && IsA(arg, Const))
648 : : {
649 : : /* Modify the Const directly to preserve const-flatness. */
650 : 86931 : Const *con = (Const *) arg;
651 : :
652 [ + + ]: 86931 : if (!overwrite_ok)
653 : 12403 : con = copyObject(con);
654 : 86931 : con->consttype = rtype;
655 : 86931 : con->consttypmod = rtypmod;
656 : 86931 : con->constcollid = rcollid;
657 : : /* We keep the Const's original location. */
658 : 86931 : return (Node *) con;
659 : : }
660 [ + + + + ]: 167195 : else if (exprType(arg) == rtype &&
661 [ + + ]: 12430 : exprTypmod(arg) == rtypmod &&
662 : 6183 : exprCollation(arg) == rcollid)
663 : : {
664 : : /* Sometimes we find a nest of relabels that net out to nothing. */
665 : 2585 : return arg;
666 : : }
667 : : else
668 : : {
669 : : /* Nope, gotta have a RelabelType. */
670 : 158363 : RelabelType *newrelabel = makeNode(RelabelType);
671 : :
672 : 158363 : newrelabel->arg = (Expr *) arg;
673 : 158363 : newrelabel->resulttype = rtype;
674 : 158363 : newrelabel->resulttypmod = rtypmod;
675 : 158363 : newrelabel->resultcollid = rcollid;
676 : 158363 : newrelabel->relabelformat = rformat;
677 : 158363 : newrelabel->location = rlocation;
678 : 158363 : return (Node *) newrelabel;
679 : : }
680 : : }
681 : :
682 : : /*
683 : : * relabel_to_typmod
684 : : * Add a RelabelType node that changes just the typmod of the expression.
685 : : *
686 : : * Convenience function for a common usage of applyRelabelType.
687 : : */
688 : : Node *
5363 689 : 28 : relabel_to_typmod(Node *expr, int32 typmod)
690 : : {
2292 691 : 28 : return applyRelabelType(expr, exprType(expr), typmod, exprCollation(expr),
692 : : COERCE_EXPLICIT_CAST, -1, false);
693 : : }
694 : :
695 : : /*
696 : : * strip_implicit_coercions: remove implicit coercions at top level of tree
697 : : *
698 : : * This doesn't modify or copy the input expression tree, just return a
699 : : * pointer to a suitable place within it.
700 : : *
701 : : * Note: there isn't any useful thing we can do with a RowExpr here, so
702 : : * just return it unchanged, even if it's marked as an implicit coercion.
703 : : */
704 : : Node *
4876 705 : 727859 : strip_implicit_coercions(Node *node)
706 : : {
707 [ - + ]: 727859 : if (node == NULL)
4876 tgl@sss.pgh.pa.us 708 :UBC 0 : return NULL;
4876 tgl@sss.pgh.pa.us 709 [ + + ]:CBC 727859 : if (IsA(node, FuncExpr))
710 : : {
711 : 9505 : FuncExpr *f = (FuncExpr *) node;
712 : :
713 [ + + ]: 9505 : if (f->funcformat == COERCE_IMPLICIT_CAST)
714 : 36 : return strip_implicit_coercions(linitial(f->args));
715 : : }
716 [ + + ]: 718354 : else if (IsA(node, RelabelType))
717 : : {
718 : 7851 : RelabelType *r = (RelabelType *) node;
719 : :
720 [ + + ]: 7851 : if (r->relabelformat == COERCE_IMPLICIT_CAST)
721 : 9 : return strip_implicit_coercions((Node *) r->arg);
722 : : }
723 [ + + ]: 710503 : else if (IsA(node, CoerceViaIO))
724 : : {
725 : 458 : CoerceViaIO *c = (CoerceViaIO *) node;
726 : :
727 [ - + ]: 458 : if (c->coerceformat == COERCE_IMPLICIT_CAST)
4876 tgl@sss.pgh.pa.us 728 :UBC 0 : return strip_implicit_coercions((Node *) c->arg);
729 : : }
4876 tgl@sss.pgh.pa.us 730 [ - + ]:CBC 710045 : else if (IsA(node, ArrayCoerceExpr))
731 : : {
4876 tgl@sss.pgh.pa.us 732 :UBC 0 : ArrayCoerceExpr *c = (ArrayCoerceExpr *) node;
733 : :
734 [ # # ]: 0 : if (c->coerceformat == COERCE_IMPLICIT_CAST)
735 : 0 : return strip_implicit_coercions((Node *) c->arg);
736 : : }
4876 tgl@sss.pgh.pa.us 737 [ - + ]:CBC 710045 : else if (IsA(node, ConvertRowtypeExpr))
738 : : {
4876 tgl@sss.pgh.pa.us 739 :UBC 0 : ConvertRowtypeExpr *c = (ConvertRowtypeExpr *) node;
740 : :
741 [ # # ]: 0 : if (c->convertformat == COERCE_IMPLICIT_CAST)
742 : 0 : return strip_implicit_coercions((Node *) c->arg);
743 : : }
4876 tgl@sss.pgh.pa.us 744 [ + + ]:CBC 710045 : else if (IsA(node, CoerceToDomain))
745 : : {
746 : 5394 : CoerceToDomain *c = (CoerceToDomain *) node;
747 : :
748 [ - + ]: 5394 : if (c->coercionformat == COERCE_IMPLICIT_CAST)
4876 tgl@sss.pgh.pa.us 749 :UBC 0 : return strip_implicit_coercions((Node *) c->arg);
750 : : }
4876 tgl@sss.pgh.pa.us 751 :CBC 727814 : return node;
752 : : }
753 : :
754 : : /*
755 : : * expression_returns_set
756 : : * Test whether an expression returns a set result.
757 : : *
758 : : * Because we use expression_tree_walker(), this can also be applied to
759 : : * whole targetlists; it'll produce true if any one of the tlist items
760 : : * returns a set.
761 : : */
762 : : bool
5733 763 : 598926 : expression_returns_set(Node *clause)
764 : : {
765 : 598926 : return expression_returns_set_walker(clause, NULL);
766 : : }
767 : :
768 : : static bool
769 : 2579986 : expression_returns_set_walker(Node *node, void *context)
770 : : {
771 [ + + ]: 2579986 : if (node == NULL)
772 : 36739 : return false;
773 [ + + ]: 2543247 : if (IsA(node, FuncExpr))
774 : : {
775 : 80592 : FuncExpr *expr = (FuncExpr *) node;
776 : :
777 [ + + ]: 80592 : if (expr->funcretset)
778 : 12031 : return true;
779 : : /* else fall through to check args */
780 : : }
781 [ + + ]: 2531216 : if (IsA(node, OpExpr))
782 : : {
783 : 570294 : OpExpr *expr = (OpExpr *) node;
784 : :
785 [ + + ]: 570294 : if (expr->opretset)
786 : 5 : return true;
787 : : /* else fall through to check args */
788 : : }
789 : :
790 : : /*
791 : : * If you add any more cases that return sets, also fix
792 : : * expression_returns_set_rows() in clauses.c and IS_SRF_CALL() in
793 : : * tlist.c.
794 : : */
795 : :
796 : : /* Avoid recursion for some cases that parser checks not to return a set */
797 [ + + ]: 2531211 : if (IsA(node, Aggref))
798 : 812 : return false;
1713 799 [ + + ]: 2530399 : if (IsA(node, GroupingFunc))
800 : 40 : return false;
5733 801 [ + + ]: 2530359 : if (IsA(node, WindowFunc))
802 : 19 : return false;
803 : :
804 : 2530340 : return expression_tree_walker(node, expression_returns_set_walker,
805 : : context);
806 : : }
807 : :
808 : :
809 : : /*
810 : : * exprCollation -
811 : : * returns the Oid of the collation of the expression's result.
812 : : *
813 : : * Note: expression nodes that can invoke functions generally have an
814 : : * "inputcollid" field, which is what the function should use as collation.
815 : : * That is the resolved common collation of the node's inputs. It is often
816 : : * but not always the same as the result collation; in particular, if the
817 : : * function produces a non-collatable result type from collatable inputs
818 : : * or vice versa, the two are different.
819 : : */
820 : : Oid
5470 peter_e@gmx.net 821 : 10400636 : exprCollation(const Node *expr)
822 : : {
823 : : Oid coll;
824 : :
5772 825 [ - + ]: 10400636 : if (!expr)
5772 peter_e@gmx.net 826 :UBC 0 : return InvalidOid;
827 : :
5772 peter_e@gmx.net 828 [ + + + + :CBC 10400636 : switch (nodeTag(expr))
+ + + + +
- + + + +
+ + + - +
+ + + + +
+ + + + +
+ + + + +
+ + + + -
+ + + + +
+ + - + +
- ]
829 : : {
830 : 8052924 : case T_Var:
5470 831 : 8052924 : coll = ((const Var *) expr)->varcollid;
5772 832 : 8052924 : break;
833 : 1324067 : case T_Const:
5470 834 : 1324067 : coll = ((const Const *) expr)->constcollid;
5772 835 : 1324067 : break;
836 : 137500 : case T_Param:
5470 837 : 137500 : coll = ((const Param *) expr)->paramcollid;
5772 838 : 137500 : break;
839 : 73686 : case T_Aggref:
5470 840 : 73686 : coll = ((const Aggref *) expr)->aggcollid;
5772 841 : 73686 : break;
4214 andres@anarazel.de 842 : 635 : case T_GroupingFunc:
843 : 635 : coll = InvalidOid;
844 : 635 : break;
5772 peter_e@gmx.net 845 : 4392 : case T_WindowFunc:
5470 846 : 4392 : coll = ((const WindowFunc *) expr)->wincollid;
5772 847 : 4392 : break;
986 dean.a.rasheed@gmail 848 : 297 : case T_MergeSupportFunc:
849 : 297 : coll = ((const MergeSupportFunc *) expr)->msfcollid;
850 : 297 : break;
2857 alvherre@alvh.no-ip. 851 : 9307 : case T_SubscriptingRef:
852 : 9307 : coll = ((const SubscriptingRef *) expr)->refcollid;
5772 peter_e@gmx.net 853 : 9307 : break;
854 : 286565 : case T_FuncExpr:
5470 855 : 286565 : coll = ((const FuncExpr *) expr)->funccollid;
5772 856 : 286565 : break;
5772 peter_e@gmx.net 857 :UBC 0 : case T_NamedArgExpr:
5470 858 : 0 : coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
5772 859 : 0 : break;
5772 peter_e@gmx.net 860 :CBC 87711 : case T_OpExpr:
5470 861 : 87711 : coll = ((const OpExpr *) expr)->opcollid;
5772 862 : 87711 : break;
863 : 52 : case T_DistinctExpr:
5470 864 : 52 : coll = ((const DistinctExpr *) expr)->opcollid;
5733 tgl@sss.pgh.pa.us 865 : 52 : break;
866 : 207 : case T_NullIfExpr:
5470 peter_e@gmx.net 867 : 207 : coll = ((const NullIfExpr *) expr)->opcollid;
5772 868 : 207 : break;
869 : 14949 : case T_ScalarArrayOpExpr:
870 : : /* ScalarArrayOpExpr's result is boolean ... */
2058 drowley@postgresql.o 871 : 14949 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 872 : 14949 : break;
873 : 3098 : case T_BoolExpr:
874 : : /* BoolExpr's result is boolean ... */
2058 drowley@postgresql.o 875 : 3098 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 876 : 3098 : break;
877 : 2749 : case T_SubLink:
878 : : {
5284 bruce@momjian.us 879 : 2749 : const SubLink *sublink = (const SubLink *) expr;
880 : :
5772 peter_e@gmx.net 881 [ + + ]: 2749 : if (sublink->subLinkType == EXPR_SUBLINK ||
882 [ + + ]: 205 : sublink->subLinkType == ARRAY_SUBLINK)
883 : 2679 : {
884 : : /* get the collation of subselect's first target column */
885 : 2679 : Query *qtree = (Query *) sublink->subselect;
886 : : TargetEntry *tent;
887 : :
888 [ + - - + ]: 2679 : if (!qtree || !IsA(qtree, Query))
5772 peter_e@gmx.net 889 [ # # ]:UBC 0 : elog(ERROR, "cannot get collation for untransformed sublink");
3519 tgl@sss.pgh.pa.us 890 :CBC 2679 : tent = linitial_node(TargetEntry, qtree->targetList);
5772 peter_e@gmx.net 891 [ - + ]: 2679 : Assert(!tent->resjunk);
892 : 2679 : coll = exprCollation((Node *) tent->expr);
893 : : /* collation doesn't change if it's converted to array */
894 : : }
895 : : else
896 : : {
897 : : /* otherwise, SubLink's result is RECORD or BOOLEAN */
2058 drowley@postgresql.o 898 : 70 : coll = InvalidOid; /* ... so it has no collation */
899 : : }
900 : : }
5772 peter_e@gmx.net 901 : 2749 : break;
902 : 14744 : case T_SubPlan:
903 : : {
5284 bruce@momjian.us 904 : 14744 : const SubPlan *subplan = (const SubPlan *) expr;
905 : :
5772 peter_e@gmx.net 906 [ + + ]: 14744 : if (subplan->subLinkType == EXPR_SUBLINK ||
907 [ + + ]: 209 : subplan->subLinkType == ARRAY_SUBLINK)
908 : : {
909 : : /* get the collation of subselect's first target column */
910 : 14601 : coll = subplan->firstColCollation;
911 : : /* collation doesn't change if it's converted to array */
912 : : }
913 : : else
914 : : {
915 : : /* otherwise, SubPlan's result is RECORD or BOOLEAN */
2058 drowley@postgresql.o 916 : 143 : coll = InvalidOid; /* ... so it has no collation */
917 : : }
918 : : }
5772 peter_e@gmx.net 919 : 14744 : break;
5772 peter_e@gmx.net 920 :UBC 0 : case T_AlternativeSubPlan:
921 : : {
5470 922 : 0 : const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
923 : :
924 : : /* subplans should all return the same thing */
5772 925 : 0 : coll = exprCollation((Node *) linitial(asplan->subplans));
926 : : }
927 : 0 : break;
5772 peter_e@gmx.net 928 :CBC 9404 : case T_FieldSelect:
5470 929 : 9404 : coll = ((const FieldSelect *) expr)->resultcollid;
5772 930 : 9404 : break;
931 : 86 : case T_FieldStore:
932 : : /* FieldStore's result is composite ... */
2058 drowley@postgresql.o 933 : 86 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 934 : 86 : break;
935 : 106089 : case T_RelabelType:
5470 936 : 106089 : coll = ((const RelabelType *) expr)->resultcollid;
5772 937 : 106089 : break;
938 : 30752 : case T_CoerceViaIO:
5470 939 : 30752 : coll = ((const CoerceViaIO *) expr)->resultcollid;
5772 940 : 30752 : break;
941 : 1191 : case T_ArrayCoerceExpr:
5470 942 : 1191 : coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
5772 943 : 1191 : break;
944 : 356 : case T_ConvertRowtypeExpr:
945 : : /* ConvertRowtypeExpr's result is composite ... */
2058 drowley@postgresql.o 946 : 356 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 947 : 356 : break;
5741 tgl@sss.pgh.pa.us 948 : 162 : case T_CollateExpr:
5470 peter_e@gmx.net 949 : 162 : coll = ((const CollateExpr *) expr)->collOid;
5741 tgl@sss.pgh.pa.us 950 : 162 : break;
5772 peter_e@gmx.net 951 : 95569 : case T_CaseExpr:
5470 952 : 95569 : coll = ((const CaseExpr *) expr)->casecollid;
5772 953 : 95569 : break;
954 : 24307 : case T_CaseTestExpr:
5470 955 : 24307 : coll = ((const CaseTestExpr *) expr)->collation;
5772 956 : 24307 : break;
957 : 24223 : case T_ArrayExpr:
5470 958 : 24223 : coll = ((const ArrayExpr *) expr)->array_collid;
5772 959 : 24223 : break;
960 : 5536 : case T_RowExpr:
961 : : /* RowExpr's result is composite ... */
2058 drowley@postgresql.o 962 : 5536 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 963 : 5536 : break;
964 : 44 : case T_RowCompareExpr:
965 : : /* RowCompareExpr's result is boolean ... */
2058 drowley@postgresql.o 966 : 44 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 967 : 44 : break;
968 : 4079 : case T_CoalesceExpr:
5470 969 : 4079 : coll = ((const CoalesceExpr *) expr)->coalescecollid;
5772 970 : 4079 : break;
971 : 1718 : case T_MinMaxExpr:
5470 972 : 1718 : coll = ((const MinMaxExpr *) expr)->minmaxcollid;
5772 973 : 1718 : break;
1291 michael@paquier.xyz 974 : 1173 : case T_SQLValueFunction:
975 : : /* Returns either NAME or a non-collatable type */
976 [ + + ]: 1173 : if (((const SQLValueFunction *) expr)->type == NAMEOID)
977 : 1071 : coll = C_COLLATION_OID;
978 : : else
979 : 102 : coll = InvalidOid;
980 : 1173 : break;
5772 peter_e@gmx.net 981 : 606 : case T_XmlExpr:
982 : :
983 : : /*
984 : : * XMLSERIALIZE returns text from non-collatable inputs, so its
985 : : * collation is always default. The other cases return boolean or
986 : : * XML, which are non-collatable.
987 : : */
5470 988 [ + + ]: 606 : if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
5772 989 : 182 : coll = DEFAULT_COLLATION_OID;
990 : : else
991 : 424 : coll = InvalidOid;
992 : 606 : break;
1334 alvherre@alvh.no-ip. 993 : 8 : case T_JsonValueExpr:
994 : 8 : coll = exprCollation((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
995 : 8 : break;
996 : 1385 : case T_JsonConstructorExpr:
997 : : {
998 : 1385 : const JsonConstructorExpr *ctor = (const JsonConstructorExpr *) expr;
999 : :
1000 : : /*
1001 : : * Collation comes from coercion if present, otherwise from
1002 : : * func. The func fallback is needed in cases where func
1003 : : * already produces the final output type and no coercion is
1004 : : * needed (cf. the JSCTOR_JSON_ARRAY_QUERY case).
1005 : : */
1006 [ + + ]: 1385 : if (ctor->coercion)
1007 : 261 : coll = exprCollation((Node *) ctor->coercion);
211 rguo@postgresql.org 1008 [ + + ]: 1124 : else if (ctor->func)
1009 : 674 : coll = exprCollation((Node *) ctor->func);
1010 : : else
1334 alvherre@alvh.no-ip. 1011 : 450 : coll = InvalidOid;
1012 : : }
1013 : 1385 : break;
1014 : 226 : case T_JsonIsPredicate:
1015 : : /* IS JSON's result is boolean ... */
1016 : 226 : coll = InvalidOid; /* ... so it has no collation */
1017 : 226 : break;
982 amitlan@postgresql.o 1018 : 2324 : case T_JsonExpr:
1019 : : {
306 peter@eisentraut.org 1020 : 2324 : const JsonExpr *jsexpr = (const JsonExpr *) expr;
1021 : :
883 amitlan@postgresql.o 1022 : 2324 : coll = jsexpr->collation;
1023 : : }
982 1024 : 2324 : break;
982 amitlan@postgresql.o 1025 :UBC 0 : case T_JsonBehavior:
1026 : : {
306 peter@eisentraut.org 1027 : 0 : const JsonBehavior *behavior = (const JsonBehavior *) expr;
1028 : :
982 amitlan@postgresql.o 1029 [ # # ]: 0 : if (behavior->expr)
1030 : 0 : coll = exprCollation(behavior->expr);
1031 : : else
1032 : 0 : coll = InvalidOid;
1033 : : }
1034 : 0 : break;
5772 peter_e@gmx.net 1035 :CBC 1641 : case T_NullTest:
1036 : : /* NullTest's result is boolean ... */
2058 drowley@postgresql.o 1037 : 1641 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 1038 : 1641 : break;
1039 : 295 : case T_BooleanTest:
1040 : : /* BooleanTest's result is boolean ... */
2058 drowley@postgresql.o 1041 : 295 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 1042 : 295 : break;
1043 : 43434 : case T_CoerceToDomain:
5470 1044 : 43434 : coll = ((const CoerceToDomain *) expr)->resultcollid;
5772 1045 : 43434 : break;
1046 : 597 : case T_CoerceToDomainValue:
5470 1047 : 597 : coll = ((const CoerceToDomainValue *) expr)->collation;
5772 1048 : 597 : break;
1049 : 19361 : case T_SetToDefault:
5470 1050 : 19361 : coll = ((const SetToDefault *) expr)->collation;
5772 1051 : 19361 : break;
1052 : 172 : case T_CurrentOfExpr:
1053 : : /* CurrentOfExpr's result is boolean ... */
2058 drowley@postgresql.o 1054 : 172 : coll = InvalidOid; /* ... so it has no collation */
5772 peter_e@gmx.net 1055 : 172 : break;
3523 1056 : 2405 : case T_NextValueExpr:
1057 : : /* NextValueExpr's result is an integer type ... */
2058 drowley@postgresql.o 1058 : 2405 : coll = InvalidOid; /* ... so it has no collation */
3523 peter_e@gmx.net 1059 : 2405 : break;
4222 andres@anarazel.de 1060 :UBC 0 : case T_InferenceElem:
1061 : 0 : coll = exprCollation((Node *) ((const InferenceElem *) expr)->expr);
1062 : 0 : break;
681 dean.a.rasheed@gmail 1063 :CBC 352 : case T_ReturningExpr:
1064 : 352 : coll = exprCollation((Node *) ((const ReturningExpr *) expr)->retexpr);
1065 : 352 : break;
5772 peter_e@gmx.net 1066 : 10258 : case T_PlaceHolderVar:
5470 1067 : 10258 : coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
5772 1068 : 10258 : break;
5772 peter_e@gmx.net 1069 :UBC 0 : default:
1070 [ # # ]: 0 : elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1071 : : coll = InvalidOid; /* keep compiler quiet */
1072 : : break;
1073 : : }
5772 peter_e@gmx.net 1074 :CBC 10400636 : return coll;
1075 : : }
1076 : :
1077 : : /*
1078 : : * exprInputCollation -
1079 : : * returns the Oid of the collation a function should use, if available.
1080 : : *
1081 : : * Result is InvalidOid if the node type doesn't store this information.
1082 : : */
1083 : : Oid
5470 1084 : 354580 : exprInputCollation(const Node *expr)
1085 : : {
1086 : : Oid coll;
1087 : :
5733 tgl@sss.pgh.pa.us 1088 [ - + ]: 354580 : if (!expr)
5733 tgl@sss.pgh.pa.us 1089 :UBC 0 : return InvalidOid;
1090 : :
5733 tgl@sss.pgh.pa.us 1091 [ - - + + :CBC 354580 : switch (nodeTag(expr))
+ + + +
+ ]
1092 : : {
5733 tgl@sss.pgh.pa.us 1093 :UBC 0 : case T_Aggref:
5470 peter_e@gmx.net 1094 : 0 : coll = ((const Aggref *) expr)->inputcollid;
5733 tgl@sss.pgh.pa.us 1095 : 0 : break;
1096 : 0 : case T_WindowFunc:
5470 peter_e@gmx.net 1097 : 0 : coll = ((const WindowFunc *) expr)->inputcollid;
5733 tgl@sss.pgh.pa.us 1098 : 0 : break;
5733 tgl@sss.pgh.pa.us 1099 :CBC 65 : case T_FuncExpr:
5470 peter_e@gmx.net 1100 : 65 : coll = ((const FuncExpr *) expr)->inputcollid;
5733 tgl@sss.pgh.pa.us 1101 : 65 : break;
1102 : 353883 : case T_OpExpr:
5470 peter_e@gmx.net 1103 : 353883 : coll = ((const OpExpr *) expr)->inputcollid;
5733 tgl@sss.pgh.pa.us 1104 : 353883 : break;
1105 : 4 : case T_DistinctExpr:
5470 peter_e@gmx.net 1106 : 4 : coll = ((const DistinctExpr *) expr)->inputcollid;
5733 tgl@sss.pgh.pa.us 1107 : 4 : break;
1108 : 8 : case T_NullIfExpr:
5470 peter_e@gmx.net 1109 : 8 : coll = ((const NullIfExpr *) expr)->inputcollid;
5733 tgl@sss.pgh.pa.us 1110 : 8 : break;
1111 : 4 : case T_ScalarArrayOpExpr:
5470 peter_e@gmx.net 1112 : 4 : coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
5733 tgl@sss.pgh.pa.us 1113 : 4 : break;
1114 : 4 : case T_MinMaxExpr:
5470 peter_e@gmx.net 1115 : 4 : coll = ((const MinMaxExpr *) expr)->inputcollid;
5733 tgl@sss.pgh.pa.us 1116 : 4 : break;
1117 : 612 : default:
1118 : 612 : coll = InvalidOid;
1119 : 612 : break;
1120 : : }
1121 : 354580 : return coll;
1122 : : }
1123 : :
1124 : : /*
1125 : : * exprSetCollation -
1126 : : * Assign collation information to an expression tree node.
1127 : : *
1128 : : * Note: since this is only used during parse analysis, we don't need to
1129 : : * worry about subplans, PlaceHolderVars, or ReturningExprs.
1130 : : */
1131 : : void
1132 : 1207713 : exprSetCollation(Node *expr, Oid collation)
1133 : : {
1134 [ - - - + : 1207713 : switch (nodeTag(expr))
+ + + + +
+ + + + +
+ + - + +
+ + + + +
- - + + +
+ + + + +
+ + + + -
- - - - ]
1135 : : {
5733 tgl@sss.pgh.pa.us 1136 :UBC 0 : case T_Var:
1137 : 0 : ((Var *) expr)->varcollid = collation;
1138 : 0 : break;
1139 : 0 : case T_Const:
1140 : 0 : ((Const *) expr)->constcollid = collation;
1141 : 0 : break;
1142 : 0 : case T_Param:
1143 : 0 : ((Param *) expr)->paramcollid = collation;
1144 : 0 : break;
5733 tgl@sss.pgh.pa.us 1145 :CBC 32642 : case T_Aggref:
1146 : 32642 : ((Aggref *) expr)->aggcollid = collation;
1147 : 32642 : break;
4214 andres@anarazel.de 1148 : 256 : case T_GroupingFunc:
1149 [ - + ]: 256 : Assert(!OidIsValid(collation));
1150 : 256 : break;
5733 tgl@sss.pgh.pa.us 1151 : 2832 : case T_WindowFunc:
1152 : 2832 : ((WindowFunc *) expr)->wincollid = collation;
1153 : 2832 : break;
986 dean.a.rasheed@gmail 1154 : 172 : case T_MergeSupportFunc:
1155 : 172 : ((MergeSupportFunc *) expr)->msfcollid = collation;
1156 : 172 : break;
2857 alvherre@alvh.no-ip. 1157 : 8712 : case T_SubscriptingRef:
1158 : 8712 : ((SubscriptingRef *) expr)->refcollid = collation;
5733 tgl@sss.pgh.pa.us 1159 : 8712 : break;
1160 : 285530 : case T_FuncExpr:
1161 : 285530 : ((FuncExpr *) expr)->funccollid = collation;
1162 : 285530 : break;
1163 : 24452 : case T_NamedArgExpr:
1164 [ - + ]: 24452 : Assert(collation == exprCollation((Node *) ((NamedArgExpr *) expr)->arg));
1165 : 24452 : break;
1166 : 410906 : case T_OpExpr:
1167 : 410906 : ((OpExpr *) expr)->opcollid = collation;
1168 : 410906 : break;
1169 : 713 : case T_DistinctExpr:
1170 : 713 : ((DistinctExpr *) expr)->opcollid = collation;
1171 : 713 : break;
1172 : 480 : case T_NullIfExpr:
1173 : 480 : ((NullIfExpr *) expr)->opcollid = collation;
1174 : 480 : break;
1175 : 23232 : case T_ScalarArrayOpExpr:
1176 : : /* ScalarArrayOpExpr's result is boolean ... */
2058 drowley@postgresql.o 1177 [ - + ]: 23232 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1178 : 23232 : break;
1179 : 117603 : case T_BoolExpr:
1180 : : /* BoolExpr's result is boolean ... */
2058 drowley@postgresql.o 1181 [ - + ]: 117603 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1182 : 117603 : break;
1183 : 37626 : case T_SubLink:
1184 : : #ifdef USE_ASSERT_CHECKING
1185 : : {
1186 : 37626 : SubLink *sublink = (SubLink *) expr;
1187 : :
1188 [ + + ]: 37626 : if (sublink->subLinkType == EXPR_SUBLINK ||
1189 [ + + ]: 18118 : sublink->subLinkType == ARRAY_SUBLINK)
1190 : 25040 : {
1191 : : /* get the collation of subselect's first target column */
1192 : 25040 : Query *qtree = (Query *) sublink->subselect;
1193 : : TargetEntry *tent;
1194 : :
1195 [ + - - + ]: 25040 : if (!qtree || !IsA(qtree, Query))
5733 tgl@sss.pgh.pa.us 1196 [ # # ]:UBC 0 : elog(ERROR, "cannot set collation for untransformed sublink");
3519 tgl@sss.pgh.pa.us 1197 :CBC 25040 : tent = linitial_node(TargetEntry, qtree->targetList);
5733 1198 [ - + ]: 25040 : Assert(!tent->resjunk);
1199 [ - + ]: 25040 : Assert(collation == exprCollation((Node *) tent->expr));
1200 : : }
1201 : : else
1202 : : {
1203 : : /* otherwise, result is RECORD or BOOLEAN */
1204 [ - + ]: 12586 : Assert(!OidIsValid(collation));
1205 : : }
1206 : : }
1207 : : #endif /* USE_ASSERT_CHECKING */
1208 : 37626 : break;
5733 tgl@sss.pgh.pa.us 1209 :UBC 0 : case T_FieldSelect:
1210 : 0 : ((FieldSelect *) expr)->resultcollid = collation;
1211 : 0 : break;
5733 tgl@sss.pgh.pa.us 1212 :CBC 457 : case T_FieldStore:
1213 : : /* FieldStore's result is composite ... */
2058 drowley@postgresql.o 1214 [ - + ]: 457 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1215 : 457 : break;
1216 : 103131 : case T_RelabelType:
1217 : 103131 : ((RelabelType *) expr)->resultcollid = collation;
1218 : 103131 : break;
1219 : 19104 : case T_CoerceViaIO:
1220 : 19104 : ((CoerceViaIO *) expr)->resultcollid = collation;
1221 : 19104 : break;
1222 : 3674 : case T_ArrayCoerceExpr:
1223 : 3674 : ((ArrayCoerceExpr *) expr)->resultcollid = collation;
1224 : 3674 : break;
1225 : 44 : case T_ConvertRowtypeExpr:
1226 : : /* ConvertRowtypeExpr's result is composite ... */
2058 drowley@postgresql.o 1227 [ - + ]: 44 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1228 : 44 : break;
1229 : 30072 : case T_CaseExpr:
1230 : 30072 : ((CaseExpr *) expr)->casecollid = collation;
1231 : 30072 : break;
1232 : 18906 : case T_ArrayExpr:
1233 : 18906 : ((ArrayExpr *) expr)->array_collid = collation;
1234 : 18906 : break;
5733 tgl@sss.pgh.pa.us 1235 :UBC 0 : case T_RowExpr:
1236 : : /* RowExpr's result is composite ... */
2058 drowley@postgresql.o 1237 [ # # ]: 0 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1238 : 0 : break;
1239 : 0 : case T_RowCompareExpr:
1240 : : /* RowCompareExpr's result is boolean ... */
2058 drowley@postgresql.o 1241 [ # # ]: 0 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1242 : 0 : break;
5733 tgl@sss.pgh.pa.us 1243 :CBC 4500 : case T_CoalesceExpr:
1244 : 4500 : ((CoalesceExpr *) expr)->coalescecollid = collation;
1245 : 4500 : break;
1246 : 225 : case T_MinMaxExpr:
1247 : 225 : ((MinMaxExpr *) expr)->minmaxcollid = collation;
1248 : 225 : break;
1291 michael@paquier.xyz 1249 : 1767 : case T_SQLValueFunction:
1250 [ + + - + ]: 1767 : Assert((((SQLValueFunction *) expr)->type == NAMEOID) ?
1251 : : (collation == C_COLLATION_OID) :
1252 : : (collation == InvalidOid));
1253 : 1767 : break;
5733 tgl@sss.pgh.pa.us 1254 : 560 : case T_XmlExpr:
1255 [ + + - + ]: 560 : Assert((((XmlExpr *) expr)->op == IS_XMLSERIALIZE) ?
1256 : : (collation == DEFAULT_COLLATION_OID) :
1257 : : (collation == InvalidOid));
1258 : 560 : break;
1334 alvherre@alvh.no-ip. 1259 : 712 : case T_JsonValueExpr:
1260 : 712 : exprSetCollation((Node *) ((JsonValueExpr *) expr)->formatted_expr,
1261 : : collation);
1262 : 712 : break;
1263 : 1139 : case T_JsonConstructorExpr:
1264 : : {
1265 : 1139 : JsonConstructorExpr *ctor = (JsonConstructorExpr *) expr;
1266 : :
1267 : : /* See comment in exprCollation() */
1268 [ + + ]: 1139 : if (ctor->coercion)
1269 : 303 : exprSetCollation((Node *) ctor->coercion, collation);
211 rguo@postgresql.org 1270 [ + + ]: 836 : else if (ctor->func)
1271 : 379 : exprSetCollation((Node *) ctor->func, collation);
1272 : : else
1334 alvherre@alvh.no-ip. 1273 [ - + ]: 457 : Assert(!OidIsValid(collation)); /* result is always a
1274 : : * json[b] type */
1275 : : }
1276 : 1139 : break;
1277 : 264 : case T_JsonIsPredicate:
1278 [ - + ]: 264 : Assert(!OidIsValid(collation)); /* result is always boolean */
1279 : 264 : break;
982 amitlan@postgresql.o 1280 : 2940 : case T_JsonExpr:
1281 : : {
1282 : 2940 : JsonExpr *jexpr = (JsonExpr *) expr;
1283 : :
883 1284 : 2940 : jexpr->collation = collation;
1285 : : }
982 1286 : 2940 : break;
1287 : 5088 : case T_JsonBehavior:
415 1288 [ + + - + ]: 5088 : Assert(((JsonBehavior *) expr)->expr == NULL ||
1289 : : exprCollation(((JsonBehavior *) expr)->expr) == collation);
982 1290 : 5088 : break;
5733 tgl@sss.pgh.pa.us 1291 : 14676 : case T_NullTest:
1292 : : /* NullTest's result is boolean ... */
2058 drowley@postgresql.o 1293 [ - + ]: 14676 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1294 : 14676 : break;
1295 : 708 : case T_BooleanTest:
1296 : : /* BooleanTest's result is boolean ... */
2058 drowley@postgresql.o 1297 [ - + ]: 708 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1298 : 708 : break;
1299 : 54590 : case T_CoerceToDomain:
1300 : 54590 : ((CoerceToDomain *) expr)->resultcollid = collation;
1301 : 54590 : break;
5733 tgl@sss.pgh.pa.us 1302 :UBC 0 : case T_CoerceToDomainValue:
1303 : 0 : ((CoerceToDomainValue *) expr)->collation = collation;
1304 : 0 : break;
1305 : 0 : case T_SetToDefault:
1306 : 0 : ((SetToDefault *) expr)->collation = collation;
1307 : 0 : break;
1308 : 0 : case T_CurrentOfExpr:
1309 : : /* CurrentOfExpr's result is boolean ... */
2058 drowley@postgresql.o 1310 [ # # ]: 0 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
5733 tgl@sss.pgh.pa.us 1311 : 0 : break;
3523 peter_e@gmx.net 1312 : 0 : case T_NextValueExpr:
1313 : : /* NextValueExpr's result is an integer type ... */
2058 drowley@postgresql.o 1314 [ # # ]: 0 : Assert(!OidIsValid(collation)); /* ... so never set a collation */
3523 peter_e@gmx.net 1315 : 0 : break;
5733 tgl@sss.pgh.pa.us 1316 : 0 : default:
1317 [ # # ]: 0 : elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1318 : : break;
1319 : : }
6669 tgl@sss.pgh.pa.us 1320 :CBC 1207713 : }
1321 : :
1322 : : /*
1323 : : * exprSetInputCollation -
1324 : : * Assign input-collation information to an expression tree node.
1325 : : *
1326 : : * This is a no-op for node types that don't store their input collation.
1327 : : * Note we omit RowCompareExpr, which needs special treatment since it
1328 : : * contains multiple input collation OIDs.
1329 : : */
1330 : : void
5733 1331 : 1151737 : exprSetInputCollation(Node *expr, Oid inputcollation)
1332 : : {
1333 [ + + + + : 1151737 : switch (nodeTag(expr))
+ + + +
+ ]
1334 : : {
1335 : 32376 : case T_Aggref:
1336 : 32376 : ((Aggref *) expr)->inputcollid = inputcollation;
1337 : 32376 : break;
1338 : 2798 : case T_WindowFunc:
1339 : 2798 : ((WindowFunc *) expr)->inputcollid = inputcollation;
1340 : 2798 : break;
1341 : 285384 : case T_FuncExpr:
1342 : 285384 : ((FuncExpr *) expr)->inputcollid = inputcollation;
1343 : 285384 : break;
1344 : 410906 : case T_OpExpr:
1345 : 410906 : ((OpExpr *) expr)->inputcollid = inputcollation;
1346 : 410906 : break;
1347 : 713 : case T_DistinctExpr:
1348 : 713 : ((DistinctExpr *) expr)->inputcollid = inputcollation;
1349 : 713 : break;
1350 : 480 : case T_NullIfExpr:
1351 : 480 : ((NullIfExpr *) expr)->inputcollid = inputcollation;
1352 : 480 : break;
1353 : 23232 : case T_ScalarArrayOpExpr:
1354 : 23232 : ((ScalarArrayOpExpr *) expr)->inputcollid = inputcollation;
1355 : 23232 : break;
1356 : 225 : case T_MinMaxExpr:
1357 : 225 : ((MinMaxExpr *) expr)->inputcollid = inputcollation;
1358 : 225 : break;
1359 : 395623 : default:
1360 : 395623 : break;
1361 : : }
11099 scrappy@hub.org 1362 : 1151737 : }
1363 : :
1364 : :
1365 : : /*
1366 : : * exprLocation -
1367 : : * returns the parse location of an expression tree, for error reports
1368 : : *
1369 : : * -1 is returned if the location can't be determined.
1370 : : *
1371 : : * For expressions larger than a single token, the intent here is to
1372 : : * return the location of the expression's leftmost token, not necessarily
1373 : : * the topmost Node's location field. For example, an OpExpr's location
1374 : : * field will point at the operator name, but if it is not a prefix operator
1375 : : * then we should return the location of the left-hand operand instead.
1376 : : * The reason is that we want to reference the entire expression not just
1377 : : * that operator, and pointing to its start seems to be the most natural way.
1378 : : *
1379 : : * The location is not perfect --- for example, since the grammar doesn't
1380 : : * explicitly represent parentheses in the parsetree, given something that
1381 : : * had been written "(a + b) * c" we are going to point at "a" not "(".
1382 : : * But it should be plenty good enough for error reporting purposes.
1383 : : *
1384 : : * You might think that this code is overly general, for instance why check
1385 : : * the operands of a FuncExpr node, when the function name can be expected
1386 : : * to be to the left of them? There are a couple of reasons. The grammar
1387 : : * sometimes builds expressions that aren't quite what the user wrote;
1388 : : * for instance x IS NOT BETWEEN ... becomes a NOT-expression whose keyword
1389 : : * pointer is to the right of its leftmost argument. Also, nodes that were
1390 : : * inserted implicitly by parse analysis (such as FuncExprs for implicit
1391 : : * coercions) will have location -1, and so we can have odd combinations of
1392 : : * known and unknown locations in a tree.
1393 : : */
1394 : : int
5470 peter_e@gmx.net 1395 : 2910508 : exprLocation(const Node *expr)
1396 : : {
1397 : : int loc;
1398 : :
6666 tgl@sss.pgh.pa.us 1399 [ + + ]: 2910508 : if (expr == NULL)
1400 : 16902 : return -1;
1401 : :
1402 : : /* Guard against stack overflow due to overly complex expressions */
2 heikki.linnakangas@i 1403 : 2893606 : check_stack_depth();
1404 : :
6666 tgl@sss.pgh.pa.us 1405 [ + - + + : 2893606 : switch (nodeTag(expr))
+ + + + +
+ + + + -
+ + + - +
+ + + + +
- + + + +
+ + + - -
+ - + + +
- + + + -
- + + + +
- + + - +
- + + + -
- - + - -
- - + - -
+ - - - -
- - - - -
- - - - -
+ + + ]
1406 : : {
6662 1407 : 20 : case T_RangeVar:
5470 peter_e@gmx.net 1408 : 20 : loc = ((const RangeVar *) expr)->location;
6662 tgl@sss.pgh.pa.us 1409 : 20 : break;
3552 alvherre@alvh.no-ip. 1410 :UBC 0 : case T_TableFunc:
1411 : 0 : loc = ((const TableFunc *) expr)->location;
1412 : 0 : break;
6666 tgl@sss.pgh.pa.us 1413 :CBC 1504715 : case T_Var:
5470 peter_e@gmx.net 1414 : 1504715 : loc = ((const Var *) expr)->location;
6666 tgl@sss.pgh.pa.us 1415 : 1504715 : break;
1416 : 903459 : case T_Const:
5470 peter_e@gmx.net 1417 : 903459 : loc = ((const Const *) expr)->location;
6666 tgl@sss.pgh.pa.us 1418 : 903459 : break;
1419 : 69326 : case T_Param:
5470 peter_e@gmx.net 1420 : 69326 : loc = ((const Param *) expr)->location;
6666 tgl@sss.pgh.pa.us 1421 : 69326 : break;
1422 : 6651 : case T_Aggref:
1423 : : /* function name should always be the first thing */
5470 peter_e@gmx.net 1424 : 6651 : loc = ((const Aggref *) expr)->location;
6666 tgl@sss.pgh.pa.us 1425 : 6651 : break;
4214 andres@anarazel.de 1426 : 50 : case T_GroupingFunc:
1427 : 50 : loc = ((const GroupingFunc *) expr)->location;
1428 : 50 : break;
6544 tgl@sss.pgh.pa.us 1429 : 36 : case T_WindowFunc:
1430 : : /* function name should always be the first thing */
5470 peter_e@gmx.net 1431 : 36 : loc = ((const WindowFunc *) expr)->location;
6544 tgl@sss.pgh.pa.us 1432 : 36 : break;
986 dean.a.rasheed@gmail 1433 : 172 : case T_MergeSupportFunc:
1434 : 172 : loc = ((const MergeSupportFunc *) expr)->location;
1435 : 172 : break;
2857 alvherre@alvh.no-ip. 1436 : 199 : case T_SubscriptingRef:
1437 : : /* just use container argument's location */
1438 : 199 : loc = exprLocation((Node *) ((const SubscriptingRef *) expr)->refexpr);
6666 tgl@sss.pgh.pa.us 1439 : 199 : break;
1440 : 66904 : case T_FuncExpr:
1441 : : {
5284 bruce@momjian.us 1442 : 66904 : const FuncExpr *fexpr = (const FuncExpr *) expr;
1443 : :
1444 : : /* consider both function name and leftmost arg */
6666 tgl@sss.pgh.pa.us 1445 : 66904 : loc = leftmostLoc(fexpr->location,
1446 : 66904 : exprLocation((Node *) fexpr->args));
1447 : : }
1448 : 66904 : break;
6260 1449 : 4 : case T_NamedArgExpr:
1450 : : {
5470 peter_e@gmx.net 1451 : 4 : const NamedArgExpr *na = (const NamedArgExpr *) expr;
1452 : :
1453 : : /* consider both argument name and value */
6260 tgl@sss.pgh.pa.us 1454 : 4 : loc = leftmostLoc(na->location,
1455 : 4 : exprLocation((Node *) na->arg));
1456 : : }
1457 : 4 : break;
6666 1458 : 8692 : case T_OpExpr:
1459 : : case T_DistinctExpr: /* struct-equivalent to OpExpr */
1460 : : case T_NullIfExpr: /* struct-equivalent to OpExpr */
1461 : : {
5284 bruce@momjian.us 1462 : 8692 : const OpExpr *opexpr = (const OpExpr *) expr;
1463 : :
1464 : : /* consider both operator name and leftmost arg */
6666 tgl@sss.pgh.pa.us 1465 : 8692 : loc = leftmostLoc(opexpr->location,
1466 : 8692 : exprLocation((Node *) opexpr->args));
1467 : : }
1468 : 8692 : break;
6666 tgl@sss.pgh.pa.us 1469 :UBC 0 : case T_ScalarArrayOpExpr:
1470 : : {
5470 peter_e@gmx.net 1471 : 0 : const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
1472 : :
1473 : : /* consider both operator name and leftmost arg */
6666 tgl@sss.pgh.pa.us 1474 : 0 : loc = leftmostLoc(saopexpr->location,
1475 : 0 : exprLocation((Node *) saopexpr->args));
1476 : : }
1477 : 0 : break;
6666 tgl@sss.pgh.pa.us 1478 :CBC 92 : case T_BoolExpr:
1479 : : {
5284 bruce@momjian.us 1480 : 92 : const BoolExpr *bexpr = (const BoolExpr *) expr;
1481 : :
1482 : : /*
1483 : : * Same as above, to handle either NOT or AND/OR. We can't
1484 : : * special-case NOT because of the way that it's used for
1485 : : * things like IS NOT BETWEEN.
1486 : : */
6666 tgl@sss.pgh.pa.us 1487 : 92 : loc = leftmostLoc(bexpr->location,
1488 : 92 : exprLocation((Node *) bexpr->args));
1489 : : }
1490 : 92 : break;
1491 : 906 : case T_SubLink:
1492 : : {
5284 bruce@momjian.us 1493 : 906 : const SubLink *sublink = (const SubLink *) expr;
1494 : :
1495 : : /* check the testexpr, if any, and the operator/keyword */
6666 tgl@sss.pgh.pa.us 1496 : 906 : loc = leftmostLoc(exprLocation(sublink->testexpr),
1497 : 906 : sublink->location);
1498 : : }
1499 : 906 : break;
1500 : 2794 : case T_FieldSelect:
1501 : : /* just use argument's location */
5470 peter_e@gmx.net 1502 : 2794 : loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
6666 tgl@sss.pgh.pa.us 1503 : 2794 : break;
6666 tgl@sss.pgh.pa.us 1504 :UBC 0 : case T_FieldStore:
1505 : : /* just use argument's location */
5470 peter_e@gmx.net 1506 : 0 : loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
6666 tgl@sss.pgh.pa.us 1507 : 0 : break;
6666 tgl@sss.pgh.pa.us 1508 :CBC 9366 : case T_RelabelType:
1509 : : {
5470 peter_e@gmx.net 1510 : 9366 : const RelabelType *rexpr = (const RelabelType *) expr;
1511 : :
1512 : : /* Much as above */
6666 tgl@sss.pgh.pa.us 1513 : 9366 : loc = leftmostLoc(rexpr->location,
1514 : 9366 : exprLocation((Node *) rexpr->arg));
1515 : : }
1516 : 9366 : break;
1517 : 17001 : case T_CoerceViaIO:
1518 : : {
5470 peter_e@gmx.net 1519 : 17001 : const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
1520 : :
1521 : : /* Much as above */
6666 tgl@sss.pgh.pa.us 1522 : 17001 : loc = leftmostLoc(cexpr->location,
1523 : 17001 : exprLocation((Node *) cexpr->arg));
1524 : : }
1525 : 17001 : break;
1526 : 14 : case T_ArrayCoerceExpr:
1527 : : {
5470 peter_e@gmx.net 1528 : 14 : const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
1529 : :
1530 : : /* Much as above */
6666 tgl@sss.pgh.pa.us 1531 : 14 : loc = leftmostLoc(cexpr->location,
1532 : 14 : exprLocation((Node *) cexpr->arg));
1533 : : }
1534 : 14 : break;
1535 : 12 : case T_ConvertRowtypeExpr:
1536 : : {
5470 peter_e@gmx.net 1537 : 12 : const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
1538 : :
1539 : : /* Much as above */
6666 tgl@sss.pgh.pa.us 1540 : 12 : loc = leftmostLoc(cexpr->location,
1541 : 12 : exprLocation((Node *) cexpr->arg));
1542 : : }
1543 : 12 : break;
5741 1544 : 32 : case T_CollateExpr:
1545 : : /* just use argument's location */
5470 peter_e@gmx.net 1546 : 32 : loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
5741 tgl@sss.pgh.pa.us 1547 : 32 : break;
6666 1548 : 7194 : case T_CaseExpr:
1549 : : /* CASE keyword should always be the first thing */
5470 peter_e@gmx.net 1550 : 7194 : loc = ((const CaseExpr *) expr)->location;
6666 tgl@sss.pgh.pa.us 1551 : 7194 : break;
6666 tgl@sss.pgh.pa.us 1552 :UBC 0 : case T_CaseWhen:
1553 : : /* WHEN keyword should always be the first thing */
5470 peter_e@gmx.net 1554 : 0 : loc = ((const CaseWhen *) expr)->location;
6666 tgl@sss.pgh.pa.us 1555 : 0 : break;
6666 tgl@sss.pgh.pa.us 1556 :CBC 281 : case T_ArrayExpr:
1557 : : /* the location points at ARRAY or [, which must be leftmost */
5470 peter_e@gmx.net 1558 : 281 : loc = ((const ArrayExpr *) expr)->location;
6666 tgl@sss.pgh.pa.us 1559 : 281 : break;
1560 : 289 : case T_RowExpr:
1561 : : /* the location points at ROW or (, which must be leftmost */
5470 peter_e@gmx.net 1562 : 289 : loc = ((const RowExpr *) expr)->location;
6666 tgl@sss.pgh.pa.us 1563 : 289 : break;
1564 : 8 : case T_RowCompareExpr:
1565 : : /* just use leftmost argument's location */
5470 peter_e@gmx.net 1566 : 8 : loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
6666 tgl@sss.pgh.pa.us 1567 : 8 : break;
1568 : 1362 : case T_CoalesceExpr:
1569 : : /* COALESCE keyword should always be the first thing */
5470 peter_e@gmx.net 1570 : 1362 : loc = ((const CoalesceExpr *) expr)->location;
6666 tgl@sss.pgh.pa.us 1571 : 1362 : break;
1572 : 19 : case T_MinMaxExpr:
1573 : : /* GREATEST/LEAST keyword should always be the first thing */
5470 peter_e@gmx.net 1574 : 19 : loc = ((const MinMaxExpr *) expr)->location;
6666 tgl@sss.pgh.pa.us 1575 : 19 : break;
1291 michael@paquier.xyz 1576 : 1124 : case T_SQLValueFunction:
1577 : : /* function keyword should always be the first thing */
1578 : 1124 : loc = ((const SQLValueFunction *) expr)->location;
1579 : 1124 : break;
6666 tgl@sss.pgh.pa.us 1580 : 168 : case T_XmlExpr:
1581 : : {
5284 bruce@momjian.us 1582 : 168 : const XmlExpr *xexpr = (const XmlExpr *) expr;
1583 : :
1584 : : /* consider both function name and leftmost arg */
6666 tgl@sss.pgh.pa.us 1585 : 168 : loc = leftmostLoc(xexpr->location,
1586 : 168 : exprLocation((Node *) xexpr->args));
1587 : : }
1588 : 168 : break;
1334 alvherre@alvh.no-ip. 1589 :UBC 0 : case T_JsonFormat:
1590 : 0 : loc = ((const JsonFormat *) expr)->location;
1591 : 0 : break;
1592 : 0 : case T_JsonValueExpr:
1593 : 0 : loc = exprLocation((Node *) ((const JsonValueExpr *) expr)->raw_expr);
1594 : 0 : break;
1334 alvherre@alvh.no-ip. 1595 :CBC 164 : case T_JsonConstructorExpr:
1596 : 164 : loc = ((const JsonConstructorExpr *) expr)->location;
1597 : 164 : break;
1334 alvherre@alvh.no-ip. 1598 :UBC 0 : case T_JsonIsPredicate:
1599 : 0 : loc = ((const JsonIsPredicate *) expr)->location;
1600 : 0 : break;
982 amitlan@postgresql.o 1601 :CBC 421 : case T_JsonExpr:
1602 : : {
1603 : 421 : const JsonExpr *jsexpr = (const JsonExpr *) expr;
1604 : :
1605 : : /* consider both function name and leftmost arg */
1606 : 421 : loc = leftmostLoc(jsexpr->location,
1607 : 421 : exprLocation(jsexpr->formatted_expr));
1608 : : }
1609 : 421 : break;
1610 : 209 : case T_JsonBehavior:
306 peter@eisentraut.org 1611 : 209 : loc = exprLocation(((const JsonBehavior *) expr)->expr);
982 amitlan@postgresql.o 1612 : 209 : break;
6666 tgl@sss.pgh.pa.us 1613 : 120 : case T_NullTest:
1614 : : {
4297 1615 : 120 : const NullTest *nexpr = (const NullTest *) expr;
1616 : :
1617 : : /* Much as above */
1618 : 120 : loc = leftmostLoc(nexpr->location,
1619 : 120 : exprLocation((Node *) nexpr->arg));
1620 : : }
6666 1621 : 120 : break;
6666 tgl@sss.pgh.pa.us 1622 :UBC 0 : case T_BooleanTest:
1623 : : {
4297 1624 : 0 : const BooleanTest *bexpr = (const BooleanTest *) expr;
1625 : :
1626 : : /* Much as above */
1627 : 0 : loc = leftmostLoc(bexpr->location,
1628 : 0 : exprLocation((Node *) bexpr->arg));
1629 : : }
6666 1630 : 0 : break;
6666 tgl@sss.pgh.pa.us 1631 :CBC 51169 : case T_CoerceToDomain:
1632 : : {
5470 peter_e@gmx.net 1633 : 51169 : const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
1634 : :
1635 : : /* Much as above */
6666 tgl@sss.pgh.pa.us 1636 : 51169 : loc = leftmostLoc(cexpr->location,
1637 : 51169 : exprLocation((Node *) cexpr->arg));
1638 : : }
1639 : 51169 : break;
1640 : 754 : case T_CoerceToDomainValue:
5470 peter_e@gmx.net 1641 : 754 : loc = ((const CoerceToDomainValue *) expr)->location;
6666 tgl@sss.pgh.pa.us 1642 : 754 : break;
1643 : 37603 : case T_SetToDefault:
5470 peter_e@gmx.net 1644 : 37603 : loc = ((const SetToDefault *) expr)->location;
6666 tgl@sss.pgh.pa.us 1645 : 37603 : break;
681 dean.a.rasheed@gmail 1646 :UBC 0 : case T_ReturningExpr:
1647 : 0 : loc = exprLocation((Node *) ((const ReturningExpr *) expr)->retexpr);
1648 : 0 : break;
6666 tgl@sss.pgh.pa.us 1649 : 0 : case T_TargetEntry:
1650 : : /* just use argument's location */
5470 peter_e@gmx.net 1651 : 0 : loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
6666 tgl@sss.pgh.pa.us 1652 : 0 : break;
6662 tgl@sss.pgh.pa.us 1653 :CBC 12 : case T_IntoClause:
1654 : : /* use the contained RangeVar's location --- close enough */
5470 peter_e@gmx.net 1655 : 12 : loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
6662 tgl@sss.pgh.pa.us 1656 : 12 : break;
6666 1657 : 63674 : case T_List:
1658 : : {
1659 : : /* report location of first list member that has a location */
1660 : : ListCell *lc;
1661 : :
1662 : 63674 : loc = -1; /* just to suppress compiler warning */
5470 peter_e@gmx.net 1663 [ + - + + : 64186 : foreach(lc, (const List *) expr)
+ + ]
1664 : : {
6666 tgl@sss.pgh.pa.us 1665 : 63918 : loc = exprLocation((Node *) lfirst(lc));
1666 [ + + ]: 63918 : if (loc >= 0)
1667 : 63406 : break;
1668 : : }
1669 : : }
1670 : 63674 : break;
1671 : 3529 : case T_A_Expr:
1672 : : {
5284 bruce@momjian.us 1673 : 3529 : const A_Expr *aexpr = (const A_Expr *) expr;
1674 : :
1675 : : /* use leftmost of operator or left operand (if any) */
1676 : : /* we assume right operand can't be to left of operator */
6666 tgl@sss.pgh.pa.us 1677 : 3529 : loc = leftmostLoc(aexpr->location,
1678 : 3529 : exprLocation(aexpr->lexpr));
1679 : : }
1680 : 3529 : break;
1681 : 54222 : case T_ColumnRef:
5470 peter_e@gmx.net 1682 : 54222 : loc = ((const ColumnRef *) expr)->location;
6666 tgl@sss.pgh.pa.us 1683 : 54222 : break;
6666 tgl@sss.pgh.pa.us 1684 :UBC 0 : case T_ParamRef:
5470 peter_e@gmx.net 1685 : 0 : loc = ((const ParamRef *) expr)->location;
6666 tgl@sss.pgh.pa.us 1686 : 0 : break;
6666 tgl@sss.pgh.pa.us 1687 :CBC 45761 : case T_A_Const:
5470 peter_e@gmx.net 1688 : 45761 : loc = ((const A_Const *) expr)->location;
6666 tgl@sss.pgh.pa.us 1689 : 45761 : break;
1690 : 2533 : case T_FuncCall:
1691 : : {
5284 bruce@momjian.us 1692 : 2533 : const FuncCall *fc = (const FuncCall *) expr;
1693 : :
1694 : : /* consider both function name and leftmost arg */
1695 : : /* (we assume any ORDER BY nodes must be to right of name) */
6666 tgl@sss.pgh.pa.us 1696 : 2533 : loc = leftmostLoc(fc->location,
1697 : 2533 : exprLocation((Node *) fc->args));
1698 : : }
1699 : 2533 : break;
6666 tgl@sss.pgh.pa.us 1700 :UBC 0 : case T_A_ArrayExpr:
1701 : : /* the location points at ARRAY or [, which must be leftmost */
5470 peter_e@gmx.net 1702 : 0 : loc = ((const A_ArrayExpr *) expr)->location;
6666 tgl@sss.pgh.pa.us 1703 : 0 : break;
6666 tgl@sss.pgh.pa.us 1704 :CBC 12 : case T_ResTarget:
1705 : : /* we need not examine the contained expression (if any) */
5470 peter_e@gmx.net 1706 : 12 : loc = ((const ResTarget *) expr)->location;
6666 tgl@sss.pgh.pa.us 1707 : 12 : break;
4546 tgl@sss.pgh.pa.us 1708 :UBC 0 : case T_MultiAssignRef:
1709 : 0 : loc = exprLocation(((const MultiAssignRef *) expr)->source);
1710 : 0 : break;
6666 tgl@sss.pgh.pa.us 1711 :CBC 5245 : case T_TypeCast:
1712 : : {
5284 bruce@momjian.us 1713 : 5245 : const TypeCast *tc = (const TypeCast *) expr;
1714 : :
1715 : : /*
1716 : : * This could represent CAST(), ::, or TypeName 'literal', so
1717 : : * any of the components might be leftmost.
1718 : : */
6666 tgl@sss.pgh.pa.us 1719 : 5245 : loc = exprLocation(tc->arg);
6344 peter_e@gmx.net 1720 : 5245 : loc = leftmostLoc(loc, tc->typeName->location);
6666 tgl@sss.pgh.pa.us 1721 : 5245 : loc = leftmostLoc(loc, tc->location);
1722 : : }
1723 : 5245 : break;
5772 peter_e@gmx.net 1724 : 552 : case T_CollateClause:
1725 : : /* just use argument's location */
5470 1726 : 552 : loc = exprLocation(((const CollateClause *) expr)->arg);
5772 1727 : 552 : break;
6662 tgl@sss.pgh.pa.us 1728 : 8 : case T_SortBy:
1729 : : /* just use argument's location (ignore operator, if any) */
5470 peter_e@gmx.net 1730 : 8 : loc = exprLocation(((const SortBy *) expr)->node);
6662 tgl@sss.pgh.pa.us 1731 : 8 : break;
6544 tgl@sss.pgh.pa.us 1732 :UBC 0 : case T_WindowDef:
5470 peter_e@gmx.net 1733 : 0 : loc = ((const WindowDef *) expr)->location;
6544 tgl@sss.pgh.pa.us 1734 : 0 : break;
4144 1735 : 0 : case T_RangeTableSample:
1736 : 0 : loc = ((const RangeTableSample *) expr)->location;
1737 : 0 : break;
6666 1738 : 0 : case T_TypeName:
5470 peter_e@gmx.net 1739 : 0 : loc = ((const TypeName *) expr)->location;
6666 tgl@sss.pgh.pa.us 1740 : 0 : break;
4755 tgl@sss.pgh.pa.us 1741 :CBC 12 : case T_ColumnDef:
1742 : 12 : loc = ((const ColumnDef *) expr)->location;
1743 : 12 : break;
328 tgl@sss.pgh.pa.us 1744 :UBC 0 : case T_IndexElem:
1745 : 0 : loc = ((const IndexElem *) expr)->location;
1746 : 0 : break;
6330 1747 : 0 : case T_Constraint:
5470 peter_e@gmx.net 1748 : 0 : loc = ((const Constraint *) expr)->location;
6330 tgl@sss.pgh.pa.us 1749 : 0 : break;
4723 1750 : 0 : case T_FunctionParameter:
758 1751 : 0 : loc = ((const FunctionParameter *) expr)->location;
4723 1752 : 0 : break;
6666 1753 : 0 : case T_XmlSerialize:
1754 : : /* XMLSERIALIZE keyword should always be the first thing */
5470 peter_e@gmx.net 1755 : 0 : loc = ((const XmlSerialize *) expr)->location;
6666 tgl@sss.pgh.pa.us 1756 : 0 : break;
4214 andres@anarazel.de 1757 :CBC 28 : case T_GroupingSet:
1758 : 28 : loc = ((const GroupingSet *) expr)->location;
1759 : 28 : break;
6629 tgl@sss.pgh.pa.us 1760 :UBC 0 : case T_WithClause:
5470 peter_e@gmx.net 1761 : 0 : loc = ((const WithClause *) expr)->location;
6629 tgl@sss.pgh.pa.us 1762 : 0 : break;
4222 andres@anarazel.de 1763 : 0 : case T_InferClause:
1764 : 0 : loc = ((const InferClause *) expr)->location;
1765 : 0 : break;
4222 andres@anarazel.de 1766 :CBC 4 : case T_OnConflictClause:
1767 : 4 : loc = ((const OnConflictClause *) expr)->location;
1768 : 4 : break;
2126 peter@eisentraut.org 1769 :UBC 0 : case T_CTESearchClause:
1770 : 0 : loc = ((const CTESearchClause *) expr)->location;
1771 : 0 : break;
1772 : 0 : case T_CTECycleClause:
1773 : 0 : loc = ((const CTECycleClause *) expr)->location;
1774 : 0 : break;
6629 tgl@sss.pgh.pa.us 1775 : 0 : case T_CommonTableExpr:
5470 peter_e@gmx.net 1776 : 0 : loc = ((const CommonTableExpr *) expr)->location;
6629 tgl@sss.pgh.pa.us 1777 : 0 : break;
1334 alvherre@alvh.no-ip. 1778 : 0 : case T_JsonKeyValue:
1779 : : /* just use the key's location */
1780 : 0 : loc = exprLocation((Node *) ((const JsonKeyValue *) expr)->key);
1781 : 0 : break;
1782 : 0 : case T_JsonObjectConstructor:
1783 : 0 : loc = ((const JsonObjectConstructor *) expr)->location;
1784 : 0 : break;
1785 : 0 : case T_JsonArrayConstructor:
1786 : 0 : loc = ((const JsonArrayConstructor *) expr)->location;
1787 : 0 : break;
1788 : 0 : case T_JsonArrayQueryConstructor:
1789 : 0 : loc = ((const JsonArrayQueryConstructor *) expr)->location;
1790 : 0 : break;
1791 : 0 : case T_JsonAggConstructor:
1792 : 0 : loc = ((const JsonAggConstructor *) expr)->location;
1793 : 0 : break;
1794 : 0 : case T_JsonObjectAgg:
1795 : 0 : loc = exprLocation((Node *) ((const JsonObjectAgg *) expr)->constructor);
1796 : 0 : break;
1797 : 0 : case T_JsonArrayAgg:
1798 : 0 : loc = exprLocation((Node *) ((const JsonArrayAgg *) expr)->constructor);
1799 : 0 : break;
6612 tgl@sss.pgh.pa.us 1800 : 0 : case T_PlaceHolderVar:
1801 : : /* just use argument's location */
5470 peter_e@gmx.net 1802 : 0 : loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
6612 tgl@sss.pgh.pa.us 1803 : 0 : break;
4222 andres@anarazel.de 1804 : 0 : case T_InferenceElem:
1805 : : /* just use nested expr's location */
1806 : 0 : loc = exprLocation((Node *) ((const InferenceElem *) expr)->expr);
1807 : 0 : break;
3471 tgl@sss.pgh.pa.us 1808 : 0 : case T_PartitionElem:
1809 : 0 : loc = ((const PartitionElem *) expr)->location;
1810 : 0 : break;
1811 : 0 : case T_PartitionSpec:
1812 : 0 : loc = ((const PartitionSpec *) expr)->location;
1813 : 0 : break;
3643 rhaas@postgresql.org 1814 :CBC 32 : case T_PartitionBoundSpec:
1815 : 32 : loc = ((const PartitionBoundSpec *) expr)->location;
1816 : 32 : break;
1817 : 12 : case T_PartitionRangeDatum:
1818 : 12 : loc = ((const PartitionRangeDatum *) expr)->location;
1819 : 12 : break;
6666 tgl@sss.pgh.pa.us 1820 : 26640 : default:
1821 : : /* for any other node type it's just unknown... */
1822 : 26640 : loc = -1;
1823 : 26640 : break;
1824 : : }
1825 : 2893606 : return loc;
1826 : : }
1827 : :
1828 : : /*
1829 : : * leftmostLoc - support for exprLocation
1830 : : *
1831 : : * Take the minimum of two parse location values, but ignore unknowns
1832 : : */
1833 : : static int
1834 : 171421 : leftmostLoc(int loc1, int loc2)
1835 : : {
1836 [ + + ]: 171421 : if (loc1 < 0)
1837 : 14399 : return loc2;
1838 [ + + ]: 157022 : else if (loc2 < 0)
1839 : 16212 : return loc1;
1840 : : else
1841 : 140810 : return Min(loc1, loc2);
1842 : : }
1843 : :
1844 : :
1845 : : /*
1846 : : * fix_opfuncids
1847 : : * Calculate opfuncid field from opno for each OpExpr node in given tree.
1848 : : * The given tree can be anything expression_tree_walker handles.
1849 : : *
1850 : : * The argument is modified in-place. (This is OK since we'd want the
1851 : : * same change for any node, even if it gets visited more than once due to
1852 : : * shared structure.)
1853 : : */
1854 : : void
3823 1855 : 313986 : fix_opfuncids(Node *node)
1856 : : {
1857 : : /* This tree walk requires no special setup, so away we go... */
1858 : 313986 : fix_opfuncids_walker(node, NULL);
1859 : 313986 : }
1860 : :
1861 : : static bool
1862 : 748974 : fix_opfuncids_walker(Node *node, void *context)
1863 : : {
1864 [ + + ]: 748974 : if (node == NULL)
1865 : 38577 : return false;
1866 [ + + ]: 710397 : if (IsA(node, OpExpr))
1867 : 45527 : set_opfuncid((OpExpr *) node);
1868 [ + + ]: 664870 : else if (IsA(node, DistinctExpr))
1869 : 4 : set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1870 [ + + ]: 664866 : else if (IsA(node, NullIfExpr))
1871 : 675 : set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1872 [ + + ]: 664191 : else if (IsA(node, ScalarArrayOpExpr))
1873 : 1701 : set_sa_opfuncid((ScalarArrayOpExpr *) node);
1874 : 710397 : return expression_tree_walker(node, fix_opfuncids_walker, context);
1875 : : }
1876 : :
1877 : : /*
1878 : : * set_opfuncid
1879 : : * Set the opfuncid (procedure OID) in an OpExpr node,
1880 : : * if it hasn't been set already.
1881 : : *
1882 : : * Because of struct equivalence, this can also be used for
1883 : : * DistinctExpr and NullIfExpr nodes.
1884 : : */
1885 : : void
1886 : 3198074 : set_opfuncid(OpExpr *opexpr)
1887 : : {
1888 [ + + ]: 3198074 : if (opexpr->opfuncid == InvalidOid)
1889 : 190829 : opexpr->opfuncid = get_opcode(opexpr->opno);
1890 : 3198074 : }
1891 : :
1892 : : /*
1893 : : * set_sa_opfuncid
1894 : : * As above, for ScalarArrayOpExpr nodes.
1895 : : */
1896 : : void
1897 : 153741 : set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
1898 : : {
1899 [ + + ]: 153741 : if (opexpr->opfuncid == InvalidOid)
1900 : 392 : opexpr->opfuncid = get_opcode(opexpr->opno);
1901 : 153741 : }
1902 : :
1903 : :
1904 : : /*
1905 : : * check_functions_in_node -
1906 : : * apply checker() to each function OID contained in given expression node
1907 : : *
1908 : : * Returns true if the checker() function does; for nodes representing more
1909 : : * than one function call, returns true if the checker() function does so
1910 : : * for any of those functions. Returns false if node does not invoke any
1911 : : * SQL-visible function. Caller must not pass node == NULL.
1912 : : *
1913 : : * This function examines only the given node; it does not recurse into any
1914 : : * sub-expressions. Callers typically prefer to keep control of the recursion
1915 : : * for themselves, in case additional checks should be made, or because they
1916 : : * have special rules about which parts of the tree need to be visited.
1917 : : *
1918 : : * Note: we ignore MinMaxExpr, SQLValueFunction, XmlExpr, CoerceToDomain,
1919 : : * and NextValueExpr nodes, because they do not contain SQL function OIDs.
1920 : : * However, they can invoke SQL-visible functions, so callers should take
1921 : : * thought about how to treat them.
1922 : : */
1923 : : bool
1924 : 18847285 : check_functions_in_node(Node *node, check_function_callback checker,
1925 : : void *context)
1926 : : {
1927 [ + + + + : 18847285 : switch (nodeTag(node))
+ + + + ]
1928 : : {
1929 : 98254 : case T_Aggref:
1930 : : {
1931 : 98254 : Aggref *expr = (Aggref *) node;
1932 : :
1933 [ + + ]: 98254 : if (checker(expr->aggfnoid, context))
1934 : 860 : return true;
1935 : : }
1936 : 97394 : break;
1937 : 7055 : case T_WindowFunc:
1938 : : {
1939 : 7055 : WindowFunc *expr = (WindowFunc *) node;
1940 : :
1941 [ + + ]: 7055 : if (checker(expr->winfnoid, context))
1942 : 135 : return true;
1943 : : }
1944 : 6920 : break;
1945 : 549846 : case T_FuncExpr:
1946 : : {
1947 : 549846 : FuncExpr *expr = (FuncExpr *) node;
1948 : :
1949 [ + + ]: 549846 : if (checker(expr->funcid, context))
1950 : 82258 : return true;
1951 : : }
1952 : 467588 : break;
1953 : 1270965 : case T_OpExpr:
1954 : : case T_DistinctExpr: /* struct-equivalent to OpExpr */
1955 : : case T_NullIfExpr: /* struct-equivalent to OpExpr */
1956 : : {
1957 : 1270965 : OpExpr *expr = (OpExpr *) node;
1958 : :
1959 : : /* Set opfuncid if it wasn't set already */
1960 : 1270965 : set_opfuncid(expr);
1961 [ + + ]: 1270965 : if (checker(expr->opfuncid, context))
1962 : 1403 : return true;
1963 : : }
1964 : 1269562 : break;
1965 : 51964 : case T_ScalarArrayOpExpr:
1966 : : {
1967 : 51964 : ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
1968 : :
1969 : 51964 : set_sa_opfuncid(expr);
1970 [ + + ]: 51964 : if (checker(expr->opfuncid, context))
1971 : 167 : return true;
1972 : : }
1973 : 51797 : break;
1974 : 41146 : case T_CoerceViaIO:
1975 : : {
1976 : 41146 : CoerceViaIO *expr = (CoerceViaIO *) node;
1977 : : Oid iofunc;
1978 : : Oid typioparam;
1979 : : bool typisvarlena;
1980 : :
1981 : : /* check the result type's input function */
1982 : 41146 : getTypeInputInfo(expr->resulttype,
1983 : : &iofunc, &typioparam);
1984 [ + + ]: 41146 : if (checker(iofunc, context))
1985 : 405 : return true;
1986 : : /* check the input type's output function */
1987 : 41097 : getTypeOutputInfo(exprType((Node *) expr->arg),
1988 : : &iofunc, &typisvarlena);
1989 [ + + ]: 41097 : if (checker(iofunc, context))
1990 : 356 : return true;
1991 : : }
1992 : 40741 : break;
1993 : 364 : case T_RowCompareExpr:
1994 : : {
1995 : 364 : RowCompareExpr *rcexpr = (RowCompareExpr *) node;
1996 : : ListCell *opid;
1997 : :
1998 [ + - + + : 1177 : foreach(opid, rcexpr->opnos)
+ + ]
1999 : : {
2000 : 813 : Oid opfuncid = get_opcode(lfirst_oid(opid));
2001 : :
2002 [ - + ]: 813 : if (checker(opfuncid, context))
3823 tgl@sss.pgh.pa.us 2003 :UBC 0 : return true;
2004 : : }
2005 : : }
3823 tgl@sss.pgh.pa.us 2006 :CBC 364 : break;
2007 : 16827691 : default:
2008 : 16827691 : break;
2009 : : }
2010 : 18762057 : return false;
2011 : : }
2012 : :
2013 : :
2014 : : /*
2015 : : * Standard expression-tree walking support
2016 : : *
2017 : : * We used to have near-duplicate code in many different routines that
2018 : : * understood how to recurse through an expression node tree. That was
2019 : : * a pain to maintain, and we frequently had bugs due to some particular
2020 : : * routine neglecting to support a particular node type. In most cases,
2021 : : * these routines only actually care about certain node types, and don't
2022 : : * care about other types except insofar as they have to recurse through
2023 : : * non-primitive node types. Therefore, we now provide generic tree-walking
2024 : : * logic to consolidate the redundant "boilerplate" code. There are
2025 : : * two versions: expression_tree_walker() and expression_tree_mutator().
2026 : : */
2027 : :
2028 : : /*
2029 : : * expression_tree_walker() is designed to support routines that traverse
2030 : : * a tree in a read-only fashion (although it will also work for routines
2031 : : * that modify nodes in-place but never add/delete/replace nodes).
2032 : : * A walker routine should look like this:
2033 : : *
2034 : : * bool my_walker (Node *node, my_struct *context)
2035 : : * {
2036 : : * if (node == NULL)
2037 : : * return false;
2038 : : * // check for nodes that special work is required for, eg:
2039 : : * if (IsA(node, Var))
2040 : : * {
2041 : : * ... do special actions for Var nodes
2042 : : * }
2043 : : * else if (IsA(node, ...))
2044 : : * {
2045 : : * ... do special actions for other node types
2046 : : * }
2047 : : * // for any node type not specially processed, do:
2048 : : * return expression_tree_walker(node, my_walker, context);
2049 : : * }
2050 : : *
2051 : : * The "context" argument points to a struct that holds whatever context
2052 : : * information the walker routine needs --- it can be used to return data
2053 : : * gathered by the walker, too. This argument is not touched by
2054 : : * expression_tree_walker, but it is passed down to recursive sub-invocations
2055 : : * of my_walker. The tree walk is started from a setup routine that
2056 : : * fills in the appropriate context struct, calls my_walker with the top-level
2057 : : * node of the tree, and then examines the results.
2058 : : *
2059 : : * The walker routine should return "false" to continue the tree walk, or
2060 : : * "true" to abort the walk and immediately return "true" to the top-level
2061 : : * caller. This can be used to short-circuit the traversal if the walker
2062 : : * has found what it came for. "false" is returned to the top-level caller
2063 : : * iff no invocation of the walker returned "true".
2064 : : *
2065 : : * The node types handled by expression_tree_walker include all those
2066 : : * normally found in target lists and qualifier clauses during the planning
2067 : : * stage. In particular, it handles List nodes since a cnf-ified qual clause
2068 : : * will have List structure at the top level, and it handles TargetEntry nodes
2069 : : * so that a scan of a target list can be handled without additional code.
2070 : : * Also, RangeTblRef, FromExpr, JoinExpr, and SetOperationStmt nodes are
2071 : : * handled, so that query jointrees and setOperation trees can be processed
2072 : : * without additional code.
2073 : : *
2074 : : * expression_tree_walker will handle SubLink nodes by recursing normally
2075 : : * into the "testexpr" subtree (which is an expression belonging to the outer
2076 : : * plan). It will also call the walker on the sub-Query node; however, when
2077 : : * expression_tree_walker itself is called on a Query node, it does nothing
2078 : : * and returns "false". The net effect is that unless the walker does
2079 : : * something special at a Query node, sub-selects will not be visited during
2080 : : * an expression tree walk. This is exactly the behavior wanted in many cases
2081 : : * --- and for those walkers that do want to recurse into sub-selects, special
2082 : : * behavior is typically needed anyway at the entry to a sub-select (such as
2083 : : * incrementing a depth counter). A walker that wants to examine sub-selects
2084 : : * should include code along the lines of:
2085 : : *
2086 : : * if (IsA(node, Query))
2087 : : * {
2088 : : * adjust context for subquery;
2089 : : * result = query_tree_walker((Query *) node, my_walker, context,
2090 : : * 0); // adjust flags as needed
2091 : : * restore context if needed;
2092 : : * return result;
2093 : : * }
2094 : : *
2095 : : * query_tree_walker is a convenience routine (see below) that calls the
2096 : : * walker on all the expression subtrees of the given Query node.
2097 : : *
2098 : : * expression_tree_walker will handle SubPlan nodes by recursing normally
2099 : : * into the "testexpr" and the "args" list (which are expressions belonging to
2100 : : * the outer plan). It will not touch the completed subplan, however. Since
2101 : : * there is no link to the original Query, it is not possible to recurse into
2102 : : * subselects of an already-planned expression tree. This is OK for current
2103 : : * uses, but may need to be revisited in future.
2104 : : */
2105 : :
2106 : : pg_attribute_no_sanitize_function()
2107 : : bool
1530 2108 : 84876701 : expression_tree_walker_impl(Node *node,
2109 : : tree_walker_callback walker,
2110 : : void *context)
2111 : : {
2112 : : ListCell *temp;
2113 : :
2114 : : /*
2115 : : * The walker has already visited the current node, and so we need only
2116 : : * recurse into any sub-nodes it has.
2117 : : *
2118 : : * We assume that the walker is not interested in List nodes per se, so
2119 : : * when we expect a List we just recurse directly to self without
2120 : : * bothering to call the walker.
2121 : : */
2122 : : #define WALK(n) walker((Node *) (n), context)
2123 : :
2124 : : #define LIST_WALK(l) expression_tree_walker_impl((Node *) (l), walker, context)
2125 : :
6669 2126 [ + + ]: 84876701 : if (node == NULL)
2127 : 1700430 : return false;
2128 : :
2129 : : /* Guard against stack overflow due to overly complex expressions */
2130 : 83176271 : check_stack_depth();
2131 : :
2132 [ + + + + : 83176267 : switch (nodeTag(node))
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + - -
- - - - -
+ + + + +
+ + + + +
- + + + +
- + + +
- ]
2133 : : {
2134 : 35135545 : case T_Var:
2135 : : case T_Const:
2136 : : case T_Param:
2137 : : case T_CaseTestExpr:
2138 : : case T_SQLValueFunction:
2139 : : case T_CoerceToDomainValue:
2140 : : case T_SetToDefault:
2141 : : case T_CurrentOfExpr:
2142 : : case T_NextValueExpr:
2143 : : case T_RangeTblRef:
2144 : : case T_SortGroupClause:
2145 : : case T_CTESearchClause:
2146 : : case T_MergeSupportFunc:
2147 : : /* primitive node types with no expression subnodes */
2148 : 35135545 : break;
4881 sfrost@snowman.net 2149 : 8152 : case T_WithCheckOption:
1530 tgl@sss.pgh.pa.us 2150 : 8152 : return WALK(((WithCheckOption *) node)->qual);
6669 2151 : 294890 : case T_Aggref:
2152 : : {
2153 : 294890 : Aggref *expr = (Aggref *) node;
2154 : :
2155 : : /* recurse directly on Lists */
1530 2156 [ - + ]: 294890 : if (LIST_WALK(expr->aggdirectargs))
4723 tgl@sss.pgh.pa.us 2157 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2158 [ + + ]:CBC 294890 : if (LIST_WALK(expr->args))
6669 2159 : 14722 : return true;
1530 2160 [ - + ]: 280168 : if (LIST_WALK(expr->aggorder))
6192 tgl@sss.pgh.pa.us 2161 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2162 [ - + ]:CBC 280168 : if (LIST_WALK(expr->aggdistinct))
6192 tgl@sss.pgh.pa.us 2163 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2164 [ + + ]:CBC 280168 : if (WALK(expr->aggfilter))
4883 noah@leadboat.com 2165 : 71 : return true;
2166 : : }
6669 tgl@sss.pgh.pa.us 2167 : 280097 : break;
4214 andres@anarazel.de 2168 : 3340 : case T_GroupingFunc:
2169 : : {
2170 : 3340 : GroupingFunc *grouping = (GroupingFunc *) node;
2171 : :
1530 tgl@sss.pgh.pa.us 2172 [ + + ]: 3340 : if (LIST_WALK(grouping->args))
4214 andres@anarazel.de 2173 : 190 : return true;
2174 : : }
2175 : 3150 : break;
6544 tgl@sss.pgh.pa.us 2176 : 17346 : case T_WindowFunc:
2177 : : {
2178 : 17346 : WindowFunc *expr = (WindowFunc *) node;
2179 : :
2180 : : /* recurse directly on List */
1530 2181 [ + + ]: 17346 : if (LIST_WALK(expr->args))
6544 2182 : 492 : return true;
1530 2183 [ + + ]: 16854 : if (WALK(expr->aggfilter))
4883 noah@leadboat.com 2184 : 9 : return true;
937 drowley@postgresql.o 2185 [ - + ]: 16845 : if (WALK(expr->runCondition))
937 drowley@postgresql.o 2186 :UBC 0 : return true;
2187 : : }
937 drowley@postgresql.o 2188 :CBC 16845 : break;
2189 : 549 : case T_WindowFuncRunCondition:
2190 : : {
2191 : 549 : WindowFuncRunCondition *expr = (WindowFuncRunCondition *) node;
2192 : :
2193 [ - + ]: 549 : if (WALK(expr->arg))
937 drowley@postgresql.o 2194 :UBC 0 : return true;
2195 : : }
6544 tgl@sss.pgh.pa.us 2196 :CBC 549 : break;
2857 alvherre@alvh.no-ip. 2197 : 226197 : case T_SubscriptingRef:
2198 : : {
2199 : 226197 : SubscriptingRef *sbsref = (SubscriptingRef *) node;
2200 : :
2201 : : /* recurse directly for upper/lower container index lists */
1530 tgl@sss.pgh.pa.us 2202 [ + + ]: 226197 : if (LIST_WALK(sbsref->refupperindexpr))
6669 2203 : 9711 : return true;
1530 2204 [ - + ]: 216486 : if (LIST_WALK(sbsref->reflowerindexpr))
6669 tgl@sss.pgh.pa.us 2205 :UBC 0 : return true;
2206 : : /* walker must see the refexpr and refassgnexpr, however */
1530 tgl@sss.pgh.pa.us 2207 [ + + ]:CBC 216486 : if (WALK(sbsref->refexpr))
6669 2208 : 11931 : return true;
2209 : :
1530 2210 [ + + ]: 204555 : if (WALK(sbsref->refassgnexpr))
6669 2211 : 131 : return true;
2212 : : }
2213 : 204424 : break;
2214 : 2780544 : case T_FuncExpr:
2215 : : {
2216 : 2780544 : FuncExpr *expr = (FuncExpr *) node;
2217 : :
1530 2218 [ + + ]: 2780544 : if (LIST_WALK(expr->args))
6669 2219 : 58596 : return true;
2220 : : }
2221 : 2721940 : break;
6260 2222 : 51113 : case T_NamedArgExpr:
1530 2223 : 51113 : return WALK(((NamedArgExpr *) node)->arg);
6669 2224 : 6690226 : case T_OpExpr:
2225 : : case T_DistinctExpr: /* struct-equivalent to OpExpr */
2226 : : case T_NullIfExpr: /* struct-equivalent to OpExpr */
2227 : : {
2228 : 6690226 : OpExpr *expr = (OpExpr *) node;
2229 : :
1530 2230 [ + + ]: 6690226 : if (LIST_WALK(expr->args))
6669 2231 : 66169 : return true;
2232 : : }
2233 : 6623973 : break;
2234 : 370317 : case T_ScalarArrayOpExpr:
2235 : : {
2236 : 370317 : ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
2237 : :
1530 2238 [ + + ]: 370317 : if (LIST_WALK(expr->args))
6669 2239 : 33551 : return true;
2240 : : }
2241 : 336766 : break;
2242 : 987366 : case T_BoolExpr:
2243 : : {
2244 : 987366 : BoolExpr *expr = (BoolExpr *) node;
2245 : :
1530 2246 [ + + ]: 987366 : if (LIST_WALK(expr->args))
6669 2247 : 13547 : return true;
2248 : : }
2249 : 973815 : break;
2250 : 215022 : case T_SubLink:
2251 : : {
2252 : 215022 : SubLink *sublink = (SubLink *) node;
2253 : :
1530 2254 [ + + ]: 215022 : if (WALK(sublink->testexpr))
6669 2255 : 61 : return true;
2256 : :
2257 : : /*
2258 : : * Also invoke the walker on the sublink's Query node, so it
2259 : : * can recurse into the sub-query if it wants to.
2260 : : */
1530 2261 : 214961 : return WALK(sublink->subselect);
2262 : : }
2263 : : break;
6669 2264 : 91100 : case T_SubPlan:
2265 : : {
2266 : 91100 : SubPlan *subplan = (SubPlan *) node;
2267 : :
2268 : : /* recurse into the testexpr, but not into the Plan */
1530 2269 [ + + ]: 91100 : if (WALK(subplan->testexpr))
6669 2270 : 68 : return true;
2271 : : /* also examine args list */
1530 2272 [ + + ]: 91032 : if (LIST_WALK(subplan->args))
6669 2273 : 360 : return true;
2274 : : }
2275 : 90672 : break;
2276 : 5964 : case T_AlternativeSubPlan:
1530 2277 : 5964 : return LIST_WALK(((AlternativeSubPlan *) node)->subplans);
6669 2278 : 387524 : case T_FieldSelect:
1530 2279 : 387524 : return WALK(((FieldSelect *) node)->arg);
6669 2280 : 2909 : case T_FieldStore:
2281 : : {
2282 : 2909 : FieldStore *fstore = (FieldStore *) node;
2283 : :
1530 2284 [ - + ]: 2909 : if (WALK(fstore->arg))
6669 tgl@sss.pgh.pa.us 2285 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2286 [ + + ]:CBC 2909 : if (WALK(fstore->newvals))
6669 2287 : 38 : return true;
2288 : : }
2289 : 2871 : break;
2290 : 1015734 : case T_RelabelType:
1530 2291 : 1015734 : return WALK(((RelabelType *) node)->arg);
6669 2292 : 229904 : case T_CoerceViaIO:
1530 2293 : 229904 : return WALK(((CoerceViaIO *) node)->arg);
6669 2294 : 39052 : case T_ArrayCoerceExpr:
2295 : : {
3346 2296 : 39052 : ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
2297 : :
1530 2298 [ + + ]: 39052 : if (WALK(acoerce->arg))
3346 2299 : 3315 : return true;
1530 2300 [ + + ]: 35737 : if (WALK(acoerce->elemexpr))
3346 2301 : 39 : return true;
2302 : : }
2303 : 35698 : break;
6669 2304 : 2354 : case T_ConvertRowtypeExpr:
1530 2305 : 2354 : return WALK(((ConvertRowtypeExpr *) node)->arg);
5741 2306 : 25645 : case T_CollateExpr:
1530 2307 : 25645 : return WALK(((CollateExpr *) node)->arg);
6669 2308 : 386902 : case T_CaseExpr:
2309 : : {
2310 : 386902 : CaseExpr *caseexpr = (CaseExpr *) node;
2311 : :
1530 2312 [ + + ]: 386902 : if (WALK(caseexpr->arg))
6669 2313 : 274 : return true;
2314 : : /* we assume walker doesn't care about CaseWhens, either */
2315 [ + - + + : 1177241 : foreach(temp, caseexpr->args)
+ + ]
2316 : : {
3519 2317 : 798007 : CaseWhen *when = lfirst_node(CaseWhen, temp);
2318 : :
1530 2319 [ + + ]: 798007 : if (WALK(when->expr))
6669 2320 : 7394 : return true;
1530 2321 [ + + ]: 795968 : if (WALK(when->result))
6669 2322 : 5355 : return true;
2323 : : }
1530 2324 [ + + ]: 379234 : if (WALK(caseexpr->defresult))
6669 2325 : 7010 : return true;
2326 : : }
2327 : 372224 : break;
2328 : 168897 : case T_ArrayExpr:
1530 2329 : 168897 : return WALK(((ArrayExpr *) node)->elements);
6669 2330 : 34307 : case T_RowExpr:
2331 : : /* Assume colnames isn't interesting */
1530 2332 : 34307 : return WALK(((RowExpr *) node)->args);
6669 2333 : 2739 : case T_RowCompareExpr:
2334 : : {
2335 : 2739 : RowCompareExpr *rcexpr = (RowCompareExpr *) node;
2336 : :
1530 2337 [ - + ]: 2739 : if (WALK(rcexpr->largs))
6669 tgl@sss.pgh.pa.us 2338 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2339 [ - + ]:CBC 2739 : if (WALK(rcexpr->rargs))
6669 tgl@sss.pgh.pa.us 2340 :UBC 0 : return true;
2341 : : }
6669 tgl@sss.pgh.pa.us 2342 :CBC 2739 : break;
2343 : 66135 : case T_CoalesceExpr:
1530 2344 : 66135 : return WALK(((CoalesceExpr *) node)->args);
6669 2345 : 4473 : case T_MinMaxExpr:
1530 2346 : 4473 : return WALK(((MinMaxExpr *) node)->args);
6669 2347 : 3867 : case T_XmlExpr:
2348 : : {
2349 : 3867 : XmlExpr *xexpr = (XmlExpr *) node;
2350 : :
1530 2351 [ + + ]: 3867 : if (WALK(xexpr->named_args))
6669 2352 : 8 : return true;
2353 : : /* we assume walker doesn't care about arg_names */
1530 2354 [ + + ]: 3859 : if (WALK(xexpr->args))
6669 2355 : 31 : return true;
2356 : : }
2357 : 3828 : break;
1334 alvherre@alvh.no-ip. 2358 : 4638 : case T_JsonValueExpr:
2359 : : {
2360 : 4638 : JsonValueExpr *jve = (JsonValueExpr *) node;
2361 : :
2362 [ + + ]: 4638 : if (WALK(jve->raw_expr))
2363 : 50 : return true;
2364 [ - + ]: 4588 : if (WALK(jve->formatted_expr))
1334 alvherre@alvh.no-ip. 2365 :UBC 0 : return true;
2366 : : }
1334 alvherre@alvh.no-ip. 2367 :CBC 4588 : break;
2368 : 9538 : case T_JsonConstructorExpr:
2369 : : {
2370 : 9538 : JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
2371 : :
2372 [ + + ]: 9538 : if (WALK(ctor->args))
2373 : 83 : return true;
2374 [ + + ]: 9455 : if (WALK(ctor->func))
2375 : 105 : return true;
2376 [ + + ]: 9350 : if (WALK(ctor->coercion))
2377 : 10 : return true;
2378 : : }
2379 : 9340 : break;
2380 : 2209 : case T_JsonIsPredicate:
2381 : 2209 : return WALK(((JsonIsPredicate *) node)->expr);
982 amitlan@postgresql.o 2382 : 22098 : case T_JsonExpr:
2383 : : {
2384 : 22098 : JsonExpr *jexpr = (JsonExpr *) node;
2385 : :
2386 [ + + ]: 22098 : if (WALK(jexpr->formatted_expr))
2387 : 213 : return true;
2388 [ + + ]: 21885 : if (WALK(jexpr->path_spec))
2389 : 4 : return true;
2390 [ + + ]: 21881 : if (WALK(jexpr->passing_values))
2391 : 12 : return true;
2392 : : /* we assume walker doesn't care about passing_names */
2393 [ + + ]: 21869 : if (WALK(jexpr->on_empty))
2394 : 30 : return true;
2395 [ + + ]: 21839 : if (WALK(jexpr->on_error))
2396 : 59 : return true;
2397 : : }
2398 : 21780 : break;
2399 : 38212 : case T_JsonBehavior:
2400 : : {
2401 : 38212 : JsonBehavior *behavior = (JsonBehavior *) node;
2402 : :
2403 [ + + ]: 38212 : if (WALK(behavior->expr))
2404 : 89 : return true;
2405 : : }
2406 : 38123 : break;
6669 tgl@sss.pgh.pa.us 2407 : 208240 : case T_NullTest:
1530 2408 : 208240 : return WALK(((NullTest *) node)->arg);
6669 2409 : 11009 : case T_BooleanTest:
1530 2410 : 11009 : return WALK(((BooleanTest *) node)->arg);
6669 2411 : 291806 : case T_CoerceToDomain:
1530 2412 : 291806 : return WALK(((CoerceToDomain *) node)->arg);
6669 2413 : 13103000 : case T_TargetEntry:
1530 2414 : 13103000 : return WALK(((TargetEntry *) node)->expr);
6669 2415 : 107527 : case T_Query:
2416 : : /* Do nothing with a sub-Query, per discussion above */
2417 : 107527 : break;
6544 2418 : 270 : case T_WindowClause:
2419 : : {
6379 bruce@momjian.us 2420 : 270 : WindowClause *wc = (WindowClause *) node;
2421 : :
1530 tgl@sss.pgh.pa.us 2422 [ - + ]: 270 : if (WALK(wc->partitionClause))
6544 tgl@sss.pgh.pa.us 2423 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2424 [ - + ]:CBC 270 : if (WALK(wc->orderClause))
6544 tgl@sss.pgh.pa.us 2425 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2426 [ - + ]:CBC 270 : if (WALK(wc->startOffset))
6133 tgl@sss.pgh.pa.us 2427 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2428 [ - + ]:CBC 270 : if (WALK(wc->endOffset))
6133 tgl@sss.pgh.pa.us 2429 :UBC 0 : return true;
2430 : : }
6544 tgl@sss.pgh.pa.us 2431 :CBC 270 : break;
2126 peter@eisentraut.org 2432 : 91 : case T_CTECycleClause:
2433 : : {
2434 : 91 : CTECycleClause *cc = (CTECycleClause *) node;
2435 : :
1530 tgl@sss.pgh.pa.us 2436 [ - + ]: 91 : if (WALK(cc->cycle_mark_value))
2126 peter@eisentraut.org 2437 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2438 [ - + ]:CBC 91 : if (WALK(cc->cycle_mark_default))
2126 peter@eisentraut.org 2439 :UBC 0 : return true;
2440 : : }
2126 peter@eisentraut.org 2441 :CBC 91 : break;
6629 tgl@sss.pgh.pa.us 2442 : 6602 : case T_CommonTableExpr:
2443 : : {
2444 : 6602 : CommonTableExpr *cte = (CommonTableExpr *) node;
2445 : :
2446 : : /*
2447 : : * Invoke the walker on the CTE's Query node, so it can
2448 : : * recurse into the sub-query if it wants to.
2449 : : */
1530 2450 [ + + ]: 6602 : if (WALK(cte->ctequery))
2126 peter@eisentraut.org 2451 : 169 : return true;
2452 : :
1530 tgl@sss.pgh.pa.us 2453 [ - + ]: 6433 : if (WALK(cte->search_clause))
2126 peter@eisentraut.org 2454 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2455 [ - + ]:CBC 6433 : if (WALK(cte->cycle_clause))
2126 peter@eisentraut.org 2456 :UBC 0 : return true;
2457 : : }
6629 tgl@sss.pgh.pa.us 2458 :CBC 6433 : break;
1334 alvherre@alvh.no-ip. 2459 :UBC 0 : case T_JsonKeyValue:
2460 : : {
2461 : 0 : JsonKeyValue *kv = (JsonKeyValue *) node;
2462 : :
2463 [ # # ]: 0 : if (WALK(kv->key))
2464 : 0 : return true;
2465 [ # # ]: 0 : if (WALK(kv->value))
2466 : 0 : return true;
2467 : : }
2468 : 0 : break;
2469 : 0 : case T_JsonObjectConstructor:
2470 : : {
2471 : 0 : JsonObjectConstructor *ctor = (JsonObjectConstructor *) node;
2472 : :
2473 [ # # ]: 0 : if (LIST_WALK(ctor->exprs))
2474 : 0 : return true;
2475 : : }
2476 : 0 : break;
2477 : 0 : case T_JsonArrayConstructor:
2478 : : {
2479 : 0 : JsonArrayConstructor *ctor = (JsonArrayConstructor *) node;
2480 : :
2481 [ # # ]: 0 : if (LIST_WALK(ctor->exprs))
2482 : 0 : return true;
2483 : : }
2484 : 0 : break;
2485 : 0 : case T_JsonArrayQueryConstructor:
2486 : : {
2487 : 0 : JsonArrayQueryConstructor *ctor = (JsonArrayQueryConstructor *) node;
2488 : :
2489 [ # # ]: 0 : if (WALK(ctor->query))
2490 : 0 : return true;
2491 : : }
2492 : 0 : break;
2493 : 0 : case T_JsonAggConstructor:
2494 : : {
2495 : 0 : JsonAggConstructor *ctor = (JsonAggConstructor *) node;
2496 : :
2497 [ # # ]: 0 : if (WALK(ctor->agg_filter))
2498 : 0 : return true;
2499 [ # # ]: 0 : if (WALK(ctor->agg_order))
2500 : 0 : return true;
2501 [ # # ]: 0 : if (WALK(ctor->over))
2502 : 0 : return true;
2503 : : }
2504 : 0 : break;
2505 : 0 : case T_JsonObjectAgg:
2506 : : {
2507 : 0 : JsonObjectAgg *ctor = (JsonObjectAgg *) node;
2508 : :
2509 [ # # ]: 0 : if (WALK(ctor->constructor))
2510 : 0 : return true;
2511 [ # # ]: 0 : if (WALK(ctor->arg))
2512 : 0 : return true;
2513 : : }
2514 : 0 : break;
2515 : 0 : case T_JsonArrayAgg:
2516 : : {
2517 : 0 : JsonArrayAgg *ctor = (JsonArrayAgg *) node;
2518 : :
2519 [ # # ]: 0 : if (WALK(ctor->constructor))
2520 : 0 : return true;
2521 [ # # ]: 0 : if (WALK(ctor->arg))
2522 : 0 : return true;
2523 : : }
2524 : 0 : break;
2525 : :
1784 tgl@sss.pgh.pa.us 2526 :CBC 2436 : case T_PartitionBoundSpec:
2527 : : {
2528 : 2436 : PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
2529 : :
1530 2530 [ - + ]: 2436 : if (WALK(pbs->listdatums))
1784 tgl@sss.pgh.pa.us 2531 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2532 [ - + ]:CBC 2436 : if (WALK(pbs->lowerdatums))
1784 tgl@sss.pgh.pa.us 2533 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2534 [ - + ]:CBC 2436 : if (WALK(pbs->upperdatums))
1784 tgl@sss.pgh.pa.us 2535 :UBC 0 : return true;
2536 : : }
1784 tgl@sss.pgh.pa.us 2537 :CBC 2436 : break;
2538 : 3164 : case T_PartitionRangeDatum:
2539 : : {
2540 : 3164 : PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
2541 : :
1530 2542 [ - + ]: 3164 : if (WALK(prd->value))
1784 tgl@sss.pgh.pa.us 2543 :UBC 0 : return true;
2544 : : }
1784 tgl@sss.pgh.pa.us 2545 :CBC 3164 : break;
6669 2546 : 18517797 : case T_List:
2547 [ + - + + : 63426649 : foreach(temp, (List *) node)
+ + ]
2548 : : {
1530 2549 [ + + ]: 45518717 : if (WALK(lfirst(temp)))
6669 2550 : 609709 : return true;
2551 : : }
2552 : 17907932 : break;
2553 : 1095784 : case T_FromExpr:
2554 : : {
2555 : 1095784 : FromExpr *from = (FromExpr *) node;
2556 : :
1530 2557 [ + + ]: 1095784 : if (LIST_WALK(from->fromlist))
6669 2558 : 49535 : return true;
1530 2559 [ + + ]: 1046249 : if (WALK(from->quals))
6669 2560 : 2324 : return true;
2561 : : }
2562 : 1043917 : break;
4222 andres@anarazel.de 2563 : 3257 : case T_OnConflictExpr:
2564 : : {
4207 bruce@momjian.us 2565 : 3257 : OnConflictExpr *onconflict = (OnConflictExpr *) node;
2566 : :
1530 tgl@sss.pgh.pa.us 2567 [ - + ]: 3257 : if (WALK(onconflict->arbiterElems))
4222 andres@anarazel.de 2568 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2569 [ - + ]:CBC 3257 : if (WALK(onconflict->arbiterWhere))
4222 andres@anarazel.de 2570 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2571 [ - + ]:CBC 3257 : if (WALK(onconflict->onConflictSet))
4222 andres@anarazel.de 2572 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2573 [ - + ]:CBC 3257 : if (WALK(onconflict->onConflictWhere))
4222 andres@anarazel.de 2574 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2575 [ - + ]:CBC 3257 : if (WALK(onconflict->exclRelTlist))
4217 andres@anarazel.de 2576 :UBC 0 : return true;
2577 : : }
4222 andres@anarazel.de 2578 :CBC 3257 : break;
1706 alvherre@alvh.no-ip. 2579 : 4954 : case T_MergeAction:
2580 : : {
2581 : 4954 : MergeAction *action = (MergeAction *) node;
2582 : :
1530 tgl@sss.pgh.pa.us 2583 [ + + ]: 4954 : if (WALK(action->qual))
1706 alvherre@alvh.no-ip. 2584 : 93 : return true;
1523 2585 [ + + ]: 4861 : if (WALK(action->targetList))
2586 : 257 : return true;
2587 : : }
1706 2588 : 4604 : break;
3158 2589 : 659 : case T_PartitionPruneStepOp:
2590 : : {
2591 : 659 : PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
2592 : :
1530 tgl@sss.pgh.pa.us 2593 [ - + ]: 659 : if (WALK(opstep->exprs))
3158 alvherre@alvh.no-ip. 2594 :UBC 0 : return true;
2595 : : }
3158 alvherre@alvh.no-ip. 2596 :CBC 659 : break;
2597 : 115 : case T_PartitionPruneStepCombine:
2598 : : /* no expression subnodes */
2599 : 115 : break;
6669 tgl@sss.pgh.pa.us 2600 : 259925 : case T_JoinExpr:
2601 : : {
2602 : 259925 : JoinExpr *join = (JoinExpr *) node;
2603 : :
1530 2604 [ + + ]: 259925 : if (WALK(join->larg))
6669 2605 : 12161 : return true;
1530 2606 [ + + ]: 247764 : if (WALK(join->rarg))
6669 2607 : 16173 : return true;
1530 2608 [ + + ]: 231591 : if (WALK(join->quals))
6669 2609 : 66 : return true;
2610 : :
2611 : : /*
2612 : : * alias clause, using list are deemed uninteresting.
2613 : : */
2614 : : }
2615 : 231525 : break;
2616 : 29671 : case T_SetOperationStmt:
2617 : : {
2618 : 29671 : SetOperationStmt *setop = (SetOperationStmt *) node;
2619 : :
1530 2620 [ - + ]: 29671 : if (WALK(setop->larg))
6669 tgl@sss.pgh.pa.us 2621 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2622 [ - + ]:CBC 29671 : if (WALK(setop->rarg))
6669 tgl@sss.pgh.pa.us 2623 :UBC 0 : return true;
2624 : :
2625 : : /* groupClauses are deemed uninteresting */
2626 : : }
6669 tgl@sss.pgh.pa.us 2627 :CBC 29671 : break;
2849 tgl@sss.pgh.pa.us 2628 :UBC 0 : case T_IndexClause:
2629 : : {
2630 : 0 : IndexClause *iclause = (IndexClause *) node;
2631 : :
1530 2632 [ # # ]: 0 : if (WALK(iclause->rinfo))
2849 2633 : 0 : return true;
1530 2634 [ # # ]: 0 : if (LIST_WALK(iclause->indexquals))
2849 2635 : 0 : return true;
2636 : : }
2637 : 0 : break;
6612 tgl@sss.pgh.pa.us 2638 :CBC 40305 : case T_PlaceHolderVar:
1530 2639 : 40305 : return WALK(((PlaceHolderVar *) node)->phexpr);
4222 andres@anarazel.de 2640 : 3221 : case T_InferenceElem:
1530 tgl@sss.pgh.pa.us 2641 : 3221 : return WALK(((InferenceElem *) node)->expr);
681 dean.a.rasheed@gmail 2642 : 3021 : case T_ReturningExpr:
2643 : 3021 : return WALK(((ReturningExpr *) node)->retexpr);
6669 tgl@sss.pgh.pa.us 2644 : 1706 : case T_AppendRelInfo:
2645 : : {
2646 : 1706 : AppendRelInfo *appinfo = (AppendRelInfo *) node;
2647 : :
1530 2648 [ - + ]: 1706 : if (LIST_WALK(appinfo->translated_vars))
6669 tgl@sss.pgh.pa.us 2649 :UBC 0 : return true;
2650 : : }
6669 tgl@sss.pgh.pa.us 2651 :CBC 1706 : break;
6612 tgl@sss.pgh.pa.us 2652 :UBC 0 : case T_PlaceHolderInfo:
1530 2653 : 0 : return WALK(((PlaceHolderInfo *) node)->ph_var);
4755 tgl@sss.pgh.pa.us 2654 :CBC 152416 : case T_RangeTblFunction:
1530 2655 : 152416 : return WALK(((RangeTblFunction *) node)->funcexpr);
4144 2656 : 748 : case T_TableSampleClause:
2657 : : {
2658 : 748 : TableSampleClause *tsc = (TableSampleClause *) node;
2659 : :
1530 2660 [ + + ]: 748 : if (LIST_WALK(tsc->args))
4144 2661 : 10 : return true;
1530 2662 [ - + ]: 738 : if (WALK(tsc->repeatable))
4144 tgl@sss.pgh.pa.us 2663 :UBC 0 : return true;
2664 : : }
4144 tgl@sss.pgh.pa.us 2665 :CBC 738 : break;
3552 alvherre@alvh.no-ip. 2666 : 3735 : case T_TableFunc:
2667 : : {
2668 : 3735 : TableFunc *tf = (TableFunc *) node;
2669 : :
1530 tgl@sss.pgh.pa.us 2670 [ - + ]: 3735 : if (WALK(tf->ns_uris))
3552 alvherre@alvh.no-ip. 2671 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2672 [ + + ]:CBC 3735 : if (WALK(tf->docexpr))
3552 alvherre@alvh.no-ip. 2673 : 158 : return true;
1530 tgl@sss.pgh.pa.us 2674 [ - + ]: 3577 : if (WALK(tf->rowexpr))
3552 alvherre@alvh.no-ip. 2675 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2676 [ - + ]:CBC 3577 : if (WALK(tf->colexprs))
3552 alvherre@alvh.no-ip. 2677 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2678 [ - + ]:CBC 3577 : if (WALK(tf->coldefexprs))
3552 alvherre@alvh.no-ip. 2679 :UBC 0 : return true;
968 amitlan@postgresql.o 2680 [ - + ]:CBC 3577 : if (WALK(tf->colvalexprs))
968 amitlan@postgresql.o 2681 :UBC 0 : return true;
968 amitlan@postgresql.o 2682 [ - + ]:CBC 3577 : if (WALK(tf->passingvalexprs))
968 amitlan@postgresql.o 2683 :UBC 0 : return true;
2684 : : }
1731 andrew@dunslane.net 2685 :CBC 3577 : break;
6669 tgl@sss.pgh.pa.us 2686 :UBC 0 : default:
2687 [ # # ]: 0 : elog(ERROR, "unrecognized node type: %d",
2688 : : (int) nodeTag(node));
2689 : : break;
2690 : : }
6669 tgl@sss.pgh.pa.us 2691 :CBC 66226589 : return false;
2692 : :
2693 : : /* The WALK() macro can be re-used below, but LIST_WALK() not so much */
2694 : : #undef LIST_WALK
2695 : : }
2696 : :
2697 : : /*
2698 : : * query_tree_walker --- initiate a walk of a Query's expressions
2699 : : *
2700 : : * This routine exists just to reduce the number of places that need to know
2701 : : * where all the expression subtrees of a Query are. Note it can be used
2702 : : * for starting a walk at top level of a Query regardless of whether the
2703 : : * walker intends to descend into subqueries. It is also useful for
2704 : : * descending into subqueries within a walker.
2705 : : *
2706 : : * Some callers want to suppress visitation of certain items in the sub-Query,
2707 : : * typically because they need to process them specially, or don't actually
2708 : : * want to recurse into subqueries. This is supported by the flags argument,
2709 : : * which is the bitwise OR of flag values to add or suppress visitation of
2710 : : * indicated items. (More flag bits may be added as needed.)
2711 : : */
2712 : : pg_attribute_no_sanitize_function()
2713 : : bool
1530 2714 : 1322592 : query_tree_walker_impl(Query *query,
2715 : : tree_walker_callback walker,
2716 : : void *context,
2717 : : int flags)
2718 : : {
6669 2719 [ + - - + ]: 1322592 : Assert(query != NULL && IsA(query, Query));
2720 : :
2721 : : /*
2722 : : * We don't walk any utilityStmt here. However, we can't easily assert
2723 : : * that it is absent, since there are at least two code paths by which
2724 : : * action statements from CREATE RULE end up here, and NOTIFY is allowed
2725 : : * in a rule action.
2726 : : */
2727 : :
1530 2728 [ + + ]: 1322592 : if (WALK(query->targetList))
6669 2729 : 229027 : return true;
1530 2730 [ - + ]: 1093545 : if (WALK(query->withCheckOptions))
4881 sfrost@snowman.net 2731 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2732 [ - + ]:CBC 1093545 : if (WALK(query->onConflict))
4222 andres@anarazel.de 2733 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2734 [ + + ]:CBC 1093545 : if (WALK(query->mergeActionList))
1706 alvherre@alvh.no-ip. 2735 : 350 : return true;
973 dean.a.rasheed@gmail 2736 [ + + ]: 1093195 : if (WALK(query->mergeJoinCondition))
2737 : 227 : return true;
1530 tgl@sss.pgh.pa.us 2738 [ + + ]: 1092968 : if (WALK(query->returningList))
6669 2739 : 65 : return true;
1530 2740 [ + + ]: 1092903 : if (WALK(query->jointree))
6669 2741 : 51535 : return true;
1530 2742 [ - + ]: 1041360 : if (WALK(query->setOperations))
6669 tgl@sss.pgh.pa.us 2743 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2744 [ - + ]:CBC 1041360 : if (WALK(query->havingQual))
6669 tgl@sss.pgh.pa.us 2745 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2746 [ + + ]:CBC 1041360 : if (WALK(query->limitOffset))
6669 2747 : 4 : return true;
1530 2748 [ - + ]: 1041356 : if (WALK(query->limitCount))
6669 tgl@sss.pgh.pa.us 2749 :UBC 0 : return true;
2750 : :
2751 : : /*
2752 : : * Most callers aren't interested in SortGroupClause nodes since those
2753 : : * don't contain actual expressions. However they do contain OIDs which
2754 : : * may be needed by dependency walkers etc.
2755 : : */
2613 rhodiumtoad@postgres 2756 [ + + ]:CBC 1041356 : if ((flags & QTW_EXAMINE_SORTGROUP))
2757 : : {
1530 tgl@sss.pgh.pa.us 2758 [ - + ]: 66375 : if (WALK(query->groupClause))
2613 rhodiumtoad@postgres 2759 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2760 [ - + ]:CBC 66375 : if (WALK(query->windowClause))
2613 rhodiumtoad@postgres 2761 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2762 [ - + ]:CBC 66375 : if (WALK(query->sortClause))
2613 rhodiumtoad@postgres 2763 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 2764 [ - + ]:CBC 66375 : if (WALK(query->distinctClause))
2613 rhodiumtoad@postgres 2765 :UBC 0 : return true;
2766 : : }
2767 : : else
2768 : : {
2769 : : /*
2770 : : * But we need to walk the expressions under WindowClause nodes even
2771 : : * if we're not interested in SortGroupClause nodes.
2772 : : */
2773 : : ListCell *lc;
2774 : :
2613 rhodiumtoad@postgres 2775 [ + + + + :CBC 980064 : foreach(lc, query->windowClause)
+ + ]
2776 : : {
2777 : 5088 : WindowClause *wc = lfirst_node(WindowClause, lc);
2778 : :
1530 tgl@sss.pgh.pa.us 2779 [ + + ]: 5088 : if (WALK(wc->startOffset))
2613 rhodiumtoad@postgres 2780 : 5 : return true;
1530 tgl@sss.pgh.pa.us 2781 [ - + ]: 5083 : if (WALK(wc->endOffset))
2613 rhodiumtoad@postgres 2782 :UBC 0 : return true;
2783 : : }
2784 : : }
2785 : :
2786 : : /*
2787 : : * groupingSets and rowMarks are not walked:
2788 : : *
2789 : : * groupingSets contain only ressortgrouprefs (integers) which are
2790 : : * meaningless without the corresponding groupClause or tlist.
2791 : : * Accordingly, any walker that needs to care about them needs to handle
2792 : : * them itself in its Query processing.
2793 : : *
2794 : : * rowMarks is not walked because it contains only rangetable indexes (and
2795 : : * flags etc.) and therefore should be handled at Query level similarly.
2796 : : */
2797 : :
6629 tgl@sss.pgh.pa.us 2798 [ + + ]:CBC 1041351 : if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
2799 : : {
1530 2800 [ + + ]: 625856 : if (WALK(query->cteList))
6629 2801 : 165 : return true;
2802 : : }
5733 2803 [ + + ]: 1041186 : if (!(flags & QTW_IGNORE_RANGE_TABLE))
2804 : : {
2805 [ + + ]: 660009 : if (range_table_walker(query->rtable, walker, context, flags))
2806 : 16308 : return true;
2807 : : }
6669 2808 : 1024878 : return false;
2809 : : }
2810 : :
2811 : : /*
2812 : : * range_table_walker is just the part of query_tree_walker that scans
2813 : : * a query's rangetable. This is split out since it can be useful on
2814 : : * its own.
2815 : : */
2816 : : bool
1530 2817 : 663971 : range_table_walker_impl(List *rtable,
2818 : : tree_walker_callback walker,
2819 : : void *context,
2820 : : int flags)
2821 : : {
2822 : : ListCell *rt;
2823 : :
6669 2824 [ + + + + : 1730866 : foreach(rt, rtable)
+ + ]
2825 : : {
2541 2826 : 1083203 : RangeTblEntry *rte = lfirst_node(RangeTblEntry, rt);
2827 : :
2828 [ + + ]: 1083203 : if (range_table_entry_walker(rte, walker, context, flags))
2829 : 16308 : return true;
2830 : : }
2831 : 647663 : return false;
2832 : : }
2833 : :
2834 : : /*
2835 : : * Some callers even want to scan the expressions in individual RTEs.
2836 : : */
2837 : : pg_attribute_no_sanitize_function()
2838 : : bool
1530 2839 : 1083253 : range_table_entry_walker_impl(RangeTblEntry *rte,
2840 : : tree_walker_callback walker,
2841 : : void *context,
2842 : : int flags)
2843 : : {
2844 : : /*
2845 : : * Walkers might need to examine the RTE node itself either before or
2846 : : * after visiting its contents (or, conceivably, both). Note that if you
2847 : : * specify neither flag, the walker won't be called on the RTE at all.
2848 : : */
2541 2849 [ + + ]: 1083253 : if (flags & QTW_EXAMINE_RTES_BEFORE)
1530 2850 [ + + ]: 103077 : if (WALK(rte))
4613 sfrost@snowman.net 2851 : 10 : return true;
2852 : :
2541 tgl@sss.pgh.pa.us 2853 [ + + + + : 1083243 : switch (rte->rtekind)
+ + + +
- ]
2854 : : {
2855 : 628487 : case RTE_RELATION:
1530 2856 [ + + ]: 628487 : if (WALK(rte->tablesample))
2541 2857 : 10 : return true;
2858 : 628477 : break;
2859 : 126572 : case RTE_SUBQUERY:
2860 [ + + ]: 126572 : if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
1530 2861 [ + + ]: 124658 : if (WALK(rte->subquery))
2541 2862 : 3510 : return true;
2863 : 123062 : break;
2864 : 190773 : case RTE_JOIN:
2865 [ + + ]: 190773 : if (!(flags & QTW_IGNORE_JOINALIASES))
1530 2866 [ - + ]: 163617 : if (WALK(rte->joinaliasvars))
2541 tgl@sss.pgh.pa.us 2867 :UBC 0 : return true;
2541 tgl@sss.pgh.pa.us 2868 :CBC 190773 : break;
2869 : 71823 : case RTE_FUNCTION:
1530 2870 [ + + ]: 71823 : if (WALK(rte->functions))
2541 2871 : 12731 : return true;
2872 : 59092 : break;
2873 : 1152 : case RTE_TABLEFUNC:
1530 2874 [ - + ]: 1152 : if (WALK(rte->tablefunc))
2864 tgl@sss.pgh.pa.us 2875 :UBC 0 : return true;
2541 tgl@sss.pgh.pa.us 2876 :CBC 1152 : break;
2877 : 23400 : case RTE_VALUES:
1530 2878 [ + + ]: 23400 : if (WALK(rte->values_lists))
2541 2879 : 41 : return true;
2880 : 23359 : break;
2881 : 34607 : case RTE_CTE:
2882 : : case RTE_NAMEDTUPLESTORE:
2883 : : case RTE_RESULT:
2884 : : /* nothing to do */
2885 : 34607 : break;
809 rguo@postgresql.org 2886 : 6429 : case RTE_GROUP:
2887 [ + - ]: 6429 : if (!(flags & QTW_IGNORE_GROUPEXPRS))
2888 [ + + ]: 6429 : if (WALK(rte->groupexprs))
2889 : 21 : return true;
2890 : 6408 : break;
2891 : : }
2892 : :
1530 tgl@sss.pgh.pa.us 2893 [ + + ]: 1066930 : if (WALK(rte->securityQuals))
2541 2894 : 15 : return true;
2895 : :
2896 [ + + ]: 1066915 : if (flags & QTW_EXAMINE_RTES_AFTER)
1530 2897 [ - + ]: 12611 : if (WALK(rte))
2541 tgl@sss.pgh.pa.us 2898 :UBC 0 : return true;
2899 : :
6669 tgl@sss.pgh.pa.us 2900 :CBC 1066915 : return false;
2901 : : }
2902 : :
2903 : :
2904 : : /*
2905 : : * expression_tree_mutator() is designed to support routines that make a
2906 : : * modified copy of an expression tree, with some nodes being added,
2907 : : * removed, or replaced by new subtrees. The original tree is (normally)
2908 : : * not changed. Each recursion level is responsible for returning a copy of
2909 : : * (or appropriately modified substitute for) the subtree it is handed.
2910 : : * A mutator routine should look like this:
2911 : : *
2912 : : * Node * my_mutator (Node *node, my_struct *context)
2913 : : * {
2914 : : * if (node == NULL)
2915 : : * return NULL;
2916 : : * // check for nodes that special work is required for, eg:
2917 : : * if (IsA(node, Var))
2918 : : * {
2919 : : * ... create and return modified copy of Var node
2920 : : * }
2921 : : * else if (IsA(node, ...))
2922 : : * {
2923 : : * ... do special transformations of other node types
2924 : : * }
2925 : : * // for any node type not specially processed, do:
2926 : : * return expression_tree_mutator(node, my_mutator, context);
2927 : : * }
2928 : : *
2929 : : * The "context" argument points to a struct that holds whatever context
2930 : : * information the mutator routine needs --- it can be used to return extra
2931 : : * data gathered by the mutator, too. This argument is not touched by
2932 : : * expression_tree_mutator, but it is passed down to recursive sub-invocations
2933 : : * of my_mutator. The tree walk is started from a setup routine that
2934 : : * fills in the appropriate context struct, calls my_mutator with the
2935 : : * top-level node of the tree, and does any required post-processing.
2936 : : *
2937 : : * Each level of recursion must return an appropriately modified Node.
2938 : : * If expression_tree_mutator() is called, it will make an exact copy
2939 : : * of the given Node, but invoke my_mutator() to copy the sub-node(s)
2940 : : * of that Node. In this way, my_mutator() has full control over the
2941 : : * copying process but need not directly deal with expression trees
2942 : : * that it has no interest in.
2943 : : *
2944 : : * Just as for expression_tree_walker, the node types handled by
2945 : : * expression_tree_mutator include all those normally found in target lists
2946 : : * and qualifier clauses during the planning stage.
2947 : : *
2948 : : * expression_tree_mutator will handle SubLink nodes by recursing normally
2949 : : * into the "testexpr" subtree (which is an expression belonging to the outer
2950 : : * plan). It will also call the mutator on the sub-Query node; however, when
2951 : : * expression_tree_mutator itself is called on a Query node, it does nothing
2952 : : * and returns the unmodified Query node. The net effect is that unless the
2953 : : * mutator does something special at a Query node, sub-selects will not be
2954 : : * visited or modified; the original sub-select will be linked to by the new
2955 : : * SubLink node. Mutators that want to descend into sub-selects will usually
2956 : : * do so by recognizing Query nodes and calling query_tree_mutator (below).
2957 : : *
2958 : : * expression_tree_mutator will handle a SubPlan node by recursing into the
2959 : : * "testexpr" and the "args" list (which belong to the outer plan), but it
2960 : : * will simply copy the link to the inner plan, since that's typically what
2961 : : * expression tree mutators want. A mutator that wants to modify the subplan
2962 : : * can force appropriate behavior by recognizing SubPlan expression nodes
2963 : : * and doing the right thing.
2964 : : */
2965 : :
2966 : : pg_attribute_no_sanitize_function()
2967 : : Node *
1530 2968 : 17005500 : expression_tree_mutator_impl(Node *node,
2969 : : tree_mutator_callback mutator,
2970 : : void *context)
2971 : : {
2972 : : /*
2973 : : * The mutator has already decided not to modify the current node, but we
2974 : : * must call the mutator for any sub-nodes.
2975 : : */
2976 : :
2977 : : #define FLATCOPY(newnode, node, nodetype) \
2978 : : ( (newnode) = palloc_object(nodetype), \
2979 : : memcpy((newnode), (node), sizeof(nodetype)) )
2980 : :
2981 : : #define MUTATE(newfield, oldfield, fieldtype) \
2982 : : ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
2983 : :
6669 2984 [ + + ]: 17005500 : if (node == NULL)
2985 : 52678 : return NULL;
2986 : :
2987 : : /* Guard against stack overflow due to overly complex expressions */
2988 : 16952822 : check_stack_depth();
2989 : :
2990 [ + + + + : 16952822 : switch (nodeTag(node))
+ + + - +
+ - + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + - - +
- - + + +
+ + + + +
+ + + + -
+ + + - ]
2991 : : {
2992 : : /*
2993 : : * Primitive node types with no expression subnodes. Var and
2994 : : * Const are frequent enough to deserve special cases, the others
2995 : : * we just use copyObject for.
2996 : : */
2997 : 3194186 : case T_Var:
2998 : : {
2999 : 3194186 : Var *var = (Var *) node;
3000 : : Var *newnode;
3001 : :
3002 : 3194186 : FLATCOPY(newnode, var, Var);
3003 : : /* Assume we need not copy the varnullingrels bitmapset */
3004 : 3194186 : return (Node *) newnode;
3005 : : }
3006 : : break;
3007 : 2774560 : case T_Const:
3008 : : {
3009 : 2774560 : Const *oldnode = (Const *) node;
3010 : : Const *newnode;
3011 : :
3012 : 2774560 : FLATCOPY(newnode, oldnode, Const);
3013 : : /* XXX we don't bother with datumCopy; should we? */
3014 : 2774560 : return (Node *) newnode;
3015 : : }
3016 : : break;
3017 : 135679 : case T_Param:
3018 : : case T_CaseTestExpr:
3019 : : case T_SQLValueFunction:
3020 : : case T_JsonFormat:
3021 : : case T_CoerceToDomainValue:
3022 : : case T_SetToDefault:
3023 : : case T_CurrentOfExpr:
3024 : : case T_NextValueExpr:
3025 : : case T_RangeTblRef:
3026 : : case T_SortGroupClause:
3027 : : case T_CTESearchClause:
3028 : : case T_MergeSupportFunc:
772 peter@eisentraut.org 3029 : 135679 : return copyObject(node);
4881 sfrost@snowman.net 3030 : 1245 : case T_WithCheckOption:
3031 : : {
4589 bruce@momjian.us 3032 : 1245 : WithCheckOption *wco = (WithCheckOption *) node;
3033 : : WithCheckOption *newnode;
3034 : :
4881 sfrost@snowman.net 3035 : 1245 : FLATCOPY(newnode, wco, WithCheckOption);
3036 : 1245 : MUTATE(newnode->qual, wco->qual, Node *);
3037 : 1245 : return (Node *) newnode;
3038 : : }
6669 tgl@sss.pgh.pa.us 3039 : 146370 : case T_Aggref:
3040 : : {
3041 : 146370 : Aggref *aggref = (Aggref *) node;
3042 : : Aggref *newnode;
3043 : :
3044 : 146370 : FLATCOPY(newnode, aggref, Aggref);
3045 : : /* assume mutation doesn't change types of arguments */
3816 3046 : 146370 : newnode->aggargtypes = list_copy(aggref->aggargtypes);
4723 3047 : 146370 : MUTATE(newnode->aggdirectargs, aggref->aggdirectargs, List *);
6669 3048 : 146370 : MUTATE(newnode->args, aggref->args, List *);
6192 3049 : 146370 : MUTATE(newnode->aggorder, aggref->aggorder, List *);
3050 : 146370 : MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *);
4883 noah@leadboat.com 3051 : 146370 : MUTATE(newnode->aggfilter, aggref->aggfilter, Expr *);
6669 tgl@sss.pgh.pa.us 3052 : 146370 : return (Node *) newnode;
3053 : : }
3054 : : break;
4214 andres@anarazel.de 3055 : 1288 : case T_GroupingFunc:
3056 : : {
4207 bruce@momjian.us 3057 : 1288 : GroupingFunc *grouping = (GroupingFunc *) node;
3058 : : GroupingFunc *newnode;
3059 : :
4214 andres@anarazel.de 3060 : 1288 : FLATCOPY(newnode, grouping, GroupingFunc);
3061 : 1288 : MUTATE(newnode->args, grouping->args, List *);
3062 : :
3063 : : /*
3064 : : * We assume here that mutating the arguments does not change
3065 : : * the semantics, i.e. that the arguments are not mutated in a
3066 : : * way that makes them semantically different from their
3067 : : * previously matching expressions in the GROUP BY clause.
3068 : : *
3069 : : * If a mutator somehow wanted to do this, it would have to
3070 : : * handle the refs and cols lists itself as appropriate.
3071 : : */
3072 : 1288 : newnode->refs = list_copy(grouping->refs);
3073 : 1288 : newnode->cols = list_copy(grouping->cols);
3074 : :
3075 : 1288 : return (Node *) newnode;
3076 : : }
3077 : : break;
6544 tgl@sss.pgh.pa.us 3078 : 5156 : case T_WindowFunc:
3079 : : {
3080 : 5156 : WindowFunc *wfunc = (WindowFunc *) node;
3081 : : WindowFunc *newnode;
3082 : :
3083 : 5156 : FLATCOPY(newnode, wfunc, WindowFunc);
3084 : 5156 : MUTATE(newnode->args, wfunc->args, List *);
4883 noah@leadboat.com 3085 : 5156 : MUTATE(newnode->aggfilter, wfunc->aggfilter, Expr *);
6544 tgl@sss.pgh.pa.us 3086 : 5156 : return (Node *) newnode;
3087 : : }
3088 : : break;
937 drowley@postgresql.o 3089 :UBC 0 : case T_WindowFuncRunCondition:
3090 : : {
3091 : 0 : WindowFuncRunCondition *wfuncrc = (WindowFuncRunCondition *) node;
3092 : : WindowFuncRunCondition *newnode;
3093 : :
3094 : 0 : FLATCOPY(newnode, wfuncrc, WindowFuncRunCondition);
3095 : 0 : MUTATE(newnode->arg, wfuncrc->arg, Expr *);
3096 : 0 : return (Node *) newnode;
3097 : : }
3098 : : break;
2857 alvherre@alvh.no-ip. 3099 :CBC 59389 : case T_SubscriptingRef:
3100 : : {
3101 : 59389 : SubscriptingRef *sbsref = (SubscriptingRef *) node;
3102 : : SubscriptingRef *newnode;
3103 : :
3104 : 59389 : FLATCOPY(newnode, sbsref, SubscriptingRef);
3105 : 59389 : MUTATE(newnode->refupperindexpr, sbsref->refupperindexpr,
3106 : : List *);
3107 : 59389 : MUTATE(newnode->reflowerindexpr, sbsref->reflowerindexpr,
3108 : : List *);
3109 : 59389 : MUTATE(newnode->refexpr, sbsref->refexpr,
3110 : : Expr *);
3111 : 59389 : MUTATE(newnode->refassgnexpr, sbsref->refassgnexpr,
3112 : : Expr *);
3113 : :
6669 tgl@sss.pgh.pa.us 3114 : 59389 : return (Node *) newnode;
3115 : : }
3116 : : break;
3117 : 325087 : case T_FuncExpr:
3118 : : {
3119 : 325087 : FuncExpr *expr = (FuncExpr *) node;
3120 : : FuncExpr *newnode;
3121 : :
3122 : 325087 : FLATCOPY(newnode, expr, FuncExpr);
3123 : 325087 : MUTATE(newnode->args, expr->args, List *);
3124 : 325087 : return (Node *) newnode;
3125 : : }
3126 : : break;
6260 tgl@sss.pgh.pa.us 3127 :UBC 0 : case T_NamedArgExpr:
3128 : : {
3129 : 0 : NamedArgExpr *nexpr = (NamedArgExpr *) node;
3130 : : NamedArgExpr *newnode;
3131 : :
3132 : 0 : FLATCOPY(newnode, nexpr, NamedArgExpr);
3133 : 0 : MUTATE(newnode->arg, nexpr->arg, Expr *);
3134 : 0 : return (Node *) newnode;
3135 : : }
3136 : : break;
6669 tgl@sss.pgh.pa.us 3137 :CBC 1118303 : case T_OpExpr:
3138 : : {
3139 : 1118303 : OpExpr *expr = (OpExpr *) node;
3140 : : OpExpr *newnode;
3141 : :
3142 : 1118303 : FLATCOPY(newnode, expr, OpExpr);
3143 : 1118303 : MUTATE(newnode->args, expr->args, List *);
3144 : 1118299 : return (Node *) newnode;
3145 : : }
3146 : : break;
3147 : 1604 : case T_DistinctExpr:
3148 : : {
3149 : 1604 : DistinctExpr *expr = (DistinctExpr *) node;
3150 : : DistinctExpr *newnode;
3151 : :
3152 : 1604 : FLATCOPY(newnode, expr, DistinctExpr);
3153 : 1604 : MUTATE(newnode->args, expr->args, List *);
3154 : 1604 : return (Node *) newnode;
3155 : : }
3156 : : break;
5733 3157 : 1566 : case T_NullIfExpr:
3158 : : {
3159 : 1566 : NullIfExpr *expr = (NullIfExpr *) node;
3160 : : NullIfExpr *newnode;
3161 : :
3162 : 1566 : FLATCOPY(newnode, expr, NullIfExpr);
3163 : 1566 : MUTATE(newnode->args, expr->args, List *);
3164 : 1566 : return (Node *) newnode;
3165 : : }
3166 : : break;
6669 3167 : 69869 : case T_ScalarArrayOpExpr:
3168 : : {
3169 : 69869 : ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
3170 : : ScalarArrayOpExpr *newnode;
3171 : :
3172 : 69869 : FLATCOPY(newnode, expr, ScalarArrayOpExpr);
3173 : 69869 : MUTATE(newnode->args, expr->args, List *);
3174 : 69869 : return (Node *) newnode;
3175 : : }
3176 : : break;
3177 : 165859 : case T_BoolExpr:
3178 : : {
3179 : 165859 : BoolExpr *expr = (BoolExpr *) node;
3180 : : BoolExpr *newnode;
3181 : :
3182 : 165859 : FLATCOPY(newnode, expr, BoolExpr);
3183 : 165859 : MUTATE(newnode->args, expr->args, List *);
3184 : 165859 : return (Node *) newnode;
3185 : : }
3186 : : break;
3187 : 42767 : case T_SubLink:
3188 : : {
3189 : 42767 : SubLink *sublink = (SubLink *) node;
3190 : : SubLink *newnode;
3191 : :
3192 : 42767 : FLATCOPY(newnode, sublink, SubLink);
3193 : 42767 : MUTATE(newnode->testexpr, sublink->testexpr, Node *);
3194 : :
3195 : : /*
3196 : : * Also invoke the mutator on the sublink's Query node, so it
3197 : : * can recurse into the sub-query if it wants to.
3198 : : */
3199 : 42767 : MUTATE(newnode->subselect, sublink->subselect, Node *);
3200 : 42767 : return (Node *) newnode;
3201 : : }
3202 : : break;
3203 : 14751 : case T_SubPlan:
3204 : : {
3205 : 14751 : SubPlan *subplan = (SubPlan *) node;
3206 : : SubPlan *newnode;
3207 : :
3208 : 14751 : FLATCOPY(newnode, subplan, SubPlan);
3209 : : /* transform testexpr */
3210 : 14751 : MUTATE(newnode->testexpr, subplan->testexpr, Node *);
3211 : : /* transform args list (params to be passed to subplan) */
3212 : 14751 : MUTATE(newnode->args, subplan->args, List *);
3213 : : /* but not the sub-Plan itself, which is referenced as-is */
3214 : 14751 : return (Node *) newnode;
3215 : : }
3216 : : break;
3217 : 180 : case T_AlternativeSubPlan:
3218 : : {
3219 : 180 : AlternativeSubPlan *asplan = (AlternativeSubPlan *) node;
3220 : : AlternativeSubPlan *newnode;
3221 : :
3222 : 180 : FLATCOPY(newnode, asplan, AlternativeSubPlan);
3223 : 180 : MUTATE(newnode->subplans, asplan->subplans, List *);
3224 : 180 : return (Node *) newnode;
3225 : : }
3226 : : break;
3227 : 93490 : case T_FieldSelect:
3228 : : {
3229 : 93490 : FieldSelect *fselect = (FieldSelect *) node;
3230 : : FieldSelect *newnode;
3231 : :
3232 : 93490 : FLATCOPY(newnode, fselect, FieldSelect);
3233 : 93490 : MUTATE(newnode->arg, fselect->arg, Expr *);
3234 : 93490 : return (Node *) newnode;
3235 : : }
3236 : : break;
3237 : 600 : case T_FieldStore:
3238 : : {
3239 : 600 : FieldStore *fstore = (FieldStore *) node;
3240 : : FieldStore *newnode;
3241 : :
3242 : 600 : FLATCOPY(newnode, fstore, FieldStore);
3243 : 600 : MUTATE(newnode->arg, fstore->arg, Expr *);
3244 : 600 : MUTATE(newnode->newvals, fstore->newvals, List *);
3245 : 600 : newnode->fieldnums = list_copy(fstore->fieldnums);
3246 : 600 : return (Node *) newnode;
3247 : : }
3248 : : break;
3249 : 140531 : case T_RelabelType:
3250 : : {
3251 : 140531 : RelabelType *relabel = (RelabelType *) node;
3252 : : RelabelType *newnode;
3253 : :
3254 : 140531 : FLATCOPY(newnode, relabel, RelabelType);
3255 : 140531 : MUTATE(newnode->arg, relabel->arg, Expr *);
3256 : 140531 : return (Node *) newnode;
3257 : : }
3258 : : break;
3259 : 34240 : case T_CoerceViaIO:
3260 : : {
3261 : 34240 : CoerceViaIO *iocoerce = (CoerceViaIO *) node;
3262 : : CoerceViaIO *newnode;
3263 : :
3264 : 34240 : FLATCOPY(newnode, iocoerce, CoerceViaIO);
3265 : 34240 : MUTATE(newnode->arg, iocoerce->arg, Expr *);
3266 : 34240 : return (Node *) newnode;
3267 : : }
3268 : : break;
3269 : 10746 : case T_ArrayCoerceExpr:
3270 : : {
3271 : 10746 : ArrayCoerceExpr *acoerce = (ArrayCoerceExpr *) node;
3272 : : ArrayCoerceExpr *newnode;
3273 : :
3274 : 10746 : FLATCOPY(newnode, acoerce, ArrayCoerceExpr);
3275 : 10746 : MUTATE(newnode->arg, acoerce->arg, Expr *);
3346 3276 : 10746 : MUTATE(newnode->elemexpr, acoerce->elemexpr, Expr *);
6669 3277 : 10746 : return (Node *) newnode;
3278 : : }
3279 : : break;
3280 : 288 : case T_ConvertRowtypeExpr:
3281 : : {
3282 : 288 : ConvertRowtypeExpr *convexpr = (ConvertRowtypeExpr *) node;
3283 : : ConvertRowtypeExpr *newnode;
3284 : :
3285 : 288 : FLATCOPY(newnode, convexpr, ConvertRowtypeExpr);
3286 : 288 : MUTATE(newnode->arg, convexpr->arg, Expr *);
3287 : 288 : return (Node *) newnode;
3288 : : }
3289 : : break;
5741 3290 : 5997 : case T_CollateExpr:
3291 : : {
3292 : 5997 : CollateExpr *collate = (CollateExpr *) node;
3293 : : CollateExpr *newnode;
3294 : :
3295 : 5997 : FLATCOPY(newnode, collate, CollateExpr);
3296 : 5997 : MUTATE(newnode->arg, collate->arg, Expr *);
3297 : 5997 : return (Node *) newnode;
3298 : : }
3299 : : break;
6669 3300 : 68539 : case T_CaseExpr:
3301 : : {
3302 : 68539 : CaseExpr *caseexpr = (CaseExpr *) node;
3303 : : CaseExpr *newnode;
3304 : :
3305 : 68539 : FLATCOPY(newnode, caseexpr, CaseExpr);
3306 : 68539 : MUTATE(newnode->arg, caseexpr->arg, Expr *);
3307 : 68539 : MUTATE(newnode->args, caseexpr->args, List *);
3308 : 68539 : MUTATE(newnode->defresult, caseexpr->defresult, Expr *);
3309 : 68539 : return (Node *) newnode;
3310 : : }
3311 : : break;
3312 : 161952 : case T_CaseWhen:
3313 : : {
3314 : 161952 : CaseWhen *casewhen = (CaseWhen *) node;
3315 : : CaseWhen *newnode;
3316 : :
3317 : 161952 : FLATCOPY(newnode, casewhen, CaseWhen);
3318 : 161952 : MUTATE(newnode->expr, casewhen->expr, Expr *);
3319 : 161952 : MUTATE(newnode->result, casewhen->result, Expr *);
3320 : 161952 : return (Node *) newnode;
3321 : : }
3322 : : break;
3323 : 33249 : case T_ArrayExpr:
3324 : : {
3325 : 33249 : ArrayExpr *arrayexpr = (ArrayExpr *) node;
3326 : : ArrayExpr *newnode;
3327 : :
3328 : 33249 : FLATCOPY(newnode, arrayexpr, ArrayExpr);
3329 : 33249 : MUTATE(newnode->elements, arrayexpr->elements, List *);
3330 : 33249 : return (Node *) newnode;
3331 : : }
3332 : : break;
3333 : 9215 : case T_RowExpr:
3334 : : {
3335 : 9215 : RowExpr *rowexpr = (RowExpr *) node;
3336 : : RowExpr *newnode;
3337 : :
3338 : 9215 : FLATCOPY(newnode, rowexpr, RowExpr);
3339 : 9215 : MUTATE(newnode->args, rowexpr->args, List *);
3340 : : /* Assume colnames needn't be duplicated */
3341 : 9215 : return (Node *) newnode;
3342 : : }
3343 : : break;
3344 : 748 : case T_RowCompareExpr:
3345 : : {
3346 : 748 : RowCompareExpr *rcexpr = (RowCompareExpr *) node;
3347 : : RowCompareExpr *newnode;
3348 : :
3349 : 748 : FLATCOPY(newnode, rcexpr, RowCompareExpr);
3350 : 748 : MUTATE(newnode->largs, rcexpr->largs, List *);
3351 : 748 : MUTATE(newnode->rargs, rcexpr->rargs, List *);
3352 : 748 : return (Node *) newnode;
3353 : : }
3354 : : break;
3355 : 30781 : case T_CoalesceExpr:
3356 : : {
3357 : 30781 : CoalesceExpr *coalesceexpr = (CoalesceExpr *) node;
3358 : : CoalesceExpr *newnode;
3359 : :
3360 : 30781 : FLATCOPY(newnode, coalesceexpr, CoalesceExpr);
3361 : 30781 : MUTATE(newnode->args, coalesceexpr->args, List *);
3362 : 30781 : return (Node *) newnode;
3363 : : }
3364 : : break;
3365 : 1152 : case T_MinMaxExpr:
3366 : : {
3367 : 1152 : MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
3368 : : MinMaxExpr *newnode;
3369 : :
3370 : 1152 : FLATCOPY(newnode, minmaxexpr, MinMaxExpr);
3371 : 1152 : MUTATE(newnode->args, minmaxexpr->args, List *);
3372 : 1152 : return (Node *) newnode;
3373 : : }
3374 : : break;
3375 : 802 : case T_XmlExpr:
3376 : : {
3377 : 802 : XmlExpr *xexpr = (XmlExpr *) node;
3378 : : XmlExpr *newnode;
3379 : :
3380 : 802 : FLATCOPY(newnode, xexpr, XmlExpr);
3381 : 802 : MUTATE(newnode->named_args, xexpr->named_args, List *);
3382 : : /* assume mutator does not care about arg_names */
3383 : 802 : MUTATE(newnode->args, xexpr->args, List *);
3384 : 802 : return (Node *) newnode;
3385 : : }
3386 : : break;
1334 alvherre@alvh.no-ip. 3387 : 2010 : case T_JsonReturning:
3388 : : {
3389 : 2010 : JsonReturning *jr = (JsonReturning *) node;
3390 : : JsonReturning *newnode;
3391 : :
3392 : 2010 : FLATCOPY(newnode, jr, JsonReturning);
3393 : 2010 : MUTATE(newnode->format, jr->format, JsonFormat *);
3394 : :
3395 : 2010 : return (Node *) newnode;
3396 : : }
3397 : 232 : case T_JsonValueExpr:
3398 : : {
3399 : 232 : JsonValueExpr *jve = (JsonValueExpr *) node;
3400 : : JsonValueExpr *newnode;
3401 : :
3402 : 232 : FLATCOPY(newnode, jve, JsonValueExpr);
3403 : 232 : MUTATE(newnode->raw_expr, jve->raw_expr, Expr *);
3404 : 232 : MUTATE(newnode->formatted_expr, jve->formatted_expr, Expr *);
3405 : 232 : MUTATE(newnode->format, jve->format, JsonFormat *);
3406 : :
3407 : 232 : return (Node *) newnode;
3408 : : }
3409 : 2010 : case T_JsonConstructorExpr:
3410 : : {
3411 : 2010 : JsonConstructorExpr *jce = (JsonConstructorExpr *) node;
3412 : : JsonConstructorExpr *newnode;
3413 : :
3414 : 2010 : FLATCOPY(newnode, jce, JsonConstructorExpr);
3415 : 2010 : MUTATE(newnode->args, jce->args, List *);
3416 : 2010 : MUTATE(newnode->func, jce->func, Expr *);
3417 : 2010 : MUTATE(newnode->coercion, jce->coercion, Expr *);
3418 : 2010 : MUTATE(newnode->returning, jce->returning, JsonReturning *);
3419 : :
3420 : 2010 : return (Node *) newnode;
3421 : : }
3422 : 601 : case T_JsonIsPredicate:
3423 : : {
3424 : 601 : JsonIsPredicate *pred = (JsonIsPredicate *) node;
3425 : : JsonIsPredicate *newnode;
3426 : :
3427 : 601 : FLATCOPY(newnode, pred, JsonIsPredicate);
3428 : 601 : MUTATE(newnode->expr, pred->expr, Node *);
3429 : 601 : MUTATE(newnode->format, pred->format, JsonFormat *);
3430 : :
3431 : 601 : return (Node *) newnode;
3432 : : }
982 amitlan@postgresql.o 3433 : 5903 : case T_JsonExpr:
3434 : : {
3435 : 5903 : JsonExpr *jexpr = (JsonExpr *) node;
3436 : : JsonExpr *newnode;
3437 : :
3438 : 5903 : FLATCOPY(newnode, jexpr, JsonExpr);
3439 : 5903 : MUTATE(newnode->formatted_expr, jexpr->formatted_expr, Node *);
3440 : 5903 : MUTATE(newnode->path_spec, jexpr->path_spec, Node *);
3441 : 5899 : MUTATE(newnode->passing_values, jexpr->passing_values, List *);
3442 : : /* assume mutator does not care about passing_names */
3443 : 5899 : MUTATE(newnode->on_empty, jexpr->on_empty, JsonBehavior *);
3444 : 5875 : MUTATE(newnode->on_error, jexpr->on_error, JsonBehavior *);
3445 : 5871 : return (Node *) newnode;
3446 : : }
3447 : : break;
3448 : 10457 : case T_JsonBehavior:
3449 : : {
3450 : 10457 : JsonBehavior *behavior = (JsonBehavior *) node;
3451 : : JsonBehavior *newnode;
3452 : :
3453 : 10457 : FLATCOPY(newnode, behavior, JsonBehavior);
3454 : 10457 : MUTATE(newnode->expr, behavior->expr, Node *);
3455 : 10429 : return (Node *) newnode;
3456 : : }
3457 : : break;
6669 tgl@sss.pgh.pa.us 3458 : 38886 : case T_NullTest:
3459 : : {
3460 : 38886 : NullTest *ntest = (NullTest *) node;
3461 : : NullTest *newnode;
3462 : :
3463 : 38886 : FLATCOPY(newnode, ntest, NullTest);
3464 : 38886 : MUTATE(newnode->arg, ntest->arg, Expr *);
3465 : 38886 : return (Node *) newnode;
3466 : : }
3467 : : break;
3468 : 1881 : case T_BooleanTest:
3469 : : {
3470 : 1881 : BooleanTest *btest = (BooleanTest *) node;
3471 : : BooleanTest *newnode;
3472 : :
3473 : 1881 : FLATCOPY(newnode, btest, BooleanTest);
3474 : 1881 : MUTATE(newnode->arg, btest->arg, Expr *);
3475 : 1881 : return (Node *) newnode;
3476 : : }
3477 : : break;
3478 : 18952 : case T_CoerceToDomain:
3479 : : {
3480 : 18952 : CoerceToDomain *ctest = (CoerceToDomain *) node;
3481 : : CoerceToDomain *newnode;
3482 : :
3483 : 18952 : FLATCOPY(newnode, ctest, CoerceToDomain);
3484 : 18952 : MUTATE(newnode->arg, ctest->arg, Expr *);
3485 : 18952 : return (Node *) newnode;
3486 : : }
3487 : : break;
681 dean.a.rasheed@gmail 3488 : 1753 : case T_ReturningExpr:
3489 : : {
3490 : 1753 : ReturningExpr *rexpr = (ReturningExpr *) node;
3491 : : ReturningExpr *newnode;
3492 : :
3493 : 1753 : FLATCOPY(newnode, rexpr, ReturningExpr);
3494 : 1753 : MUTATE(newnode->retexpr, rexpr->retexpr, Expr *);
3495 : 1753 : return (Node *) newnode;
3496 : : }
3497 : : break;
6669 tgl@sss.pgh.pa.us 3498 : 3518905 : case T_TargetEntry:
3499 : : {
3500 : 3518905 : TargetEntry *targetentry = (TargetEntry *) node;
3501 : : TargetEntry *newnode;
3502 : :
3503 : 3518905 : FLATCOPY(newnode, targetentry, TargetEntry);
3504 : 3518905 : MUTATE(newnode->expr, targetentry->expr, Expr *);
3505 : 3516069 : return (Node *) newnode;
3506 : : }
3507 : : break;
3508 : 29993 : case T_Query:
3509 : : /* Do nothing with a sub-Query, per discussion above */
3510 : 29993 : return node;
6544 tgl@sss.pgh.pa.us 3511 :UBC 0 : case T_WindowClause:
3512 : : {
6379 bruce@momjian.us 3513 : 0 : WindowClause *wc = (WindowClause *) node;
3514 : : WindowClause *newnode;
3515 : :
6544 tgl@sss.pgh.pa.us 3516 : 0 : FLATCOPY(newnode, wc, WindowClause);
3517 : 0 : MUTATE(newnode->partitionClause, wc->partitionClause, List *);
3518 : 0 : MUTATE(newnode->orderClause, wc->orderClause, List *);
6133 3519 : 0 : MUTATE(newnode->startOffset, wc->startOffset, Node *);
3520 : 0 : MUTATE(newnode->endOffset, wc->endOffset, Node *);
6544 3521 : 0 : return (Node *) newnode;
3522 : : }
3523 : : break;
2126 peter@eisentraut.org 3524 : 0 : case T_CTECycleClause:
3525 : : {
3526 : 0 : CTECycleClause *cc = (CTECycleClause *) node;
3527 : : CTECycleClause *newnode;
3528 : :
3529 : 0 : FLATCOPY(newnode, cc, CTECycleClause);
3530 : 0 : MUTATE(newnode->cycle_mark_value, cc->cycle_mark_value, Node *);
3531 : 0 : MUTATE(newnode->cycle_mark_default, cc->cycle_mark_default, Node *);
3532 : 0 : return (Node *) newnode;
3533 : : }
3534 : : break;
6629 tgl@sss.pgh.pa.us 3535 :CBC 179 : case T_CommonTableExpr:
3536 : : {
3537 : 179 : CommonTableExpr *cte = (CommonTableExpr *) node;
3538 : : CommonTableExpr *newnode;
3539 : :
3540 : 179 : FLATCOPY(newnode, cte, CommonTableExpr);
3541 : :
3542 : : /*
3543 : : * Also invoke the mutator on the CTE's Query node, so it can
3544 : : * recurse into the sub-query if it wants to.
3545 : : */
3546 : 179 : MUTATE(newnode->ctequery, cte->ctequery, Node *);
3547 : :
2126 peter@eisentraut.org 3548 : 179 : MUTATE(newnode->search_clause, cte->search_clause, CTESearchClause *);
3549 : 179 : MUTATE(newnode->cycle_clause, cte->cycle_clause, CTECycleClause *);
3550 : :
6629 tgl@sss.pgh.pa.us 3551 : 179 : return (Node *) newnode;
3552 : : }
3553 : : break;
1784 tgl@sss.pgh.pa.us 3554 :UBC 0 : case T_PartitionBoundSpec:
3555 : : {
3556 : 0 : PartitionBoundSpec *pbs = (PartitionBoundSpec *) node;
3557 : : PartitionBoundSpec *newnode;
3558 : :
3559 : 0 : FLATCOPY(newnode, pbs, PartitionBoundSpec);
3560 : 0 : MUTATE(newnode->listdatums, pbs->listdatums, List *);
3561 : 0 : MUTATE(newnode->lowerdatums, pbs->lowerdatums, List *);
3562 : 0 : MUTATE(newnode->upperdatums, pbs->upperdatums, List *);
3563 : 0 : return (Node *) newnode;
3564 : : }
3565 : : break;
3566 : 0 : case T_PartitionRangeDatum:
3567 : : {
3568 : 0 : PartitionRangeDatum *prd = (PartitionRangeDatum *) node;
3569 : : PartitionRangeDatum *newnode;
3570 : :
3571 : 0 : FLATCOPY(newnode, prd, PartitionRangeDatum);
3572 : 0 : MUTATE(newnode->value, prd->value, Node *);
3573 : 0 : return (Node *) newnode;
3574 : : }
3575 : : break;
6669 tgl@sss.pgh.pa.us 3576 :CBC 4514135 : case T_List:
3577 : : {
3578 : : /*
3579 : : * We assume the mutator isn't interested in the list nodes
3580 : : * per se, so just invoke it on each list element. NOTE: this
3581 : : * would fail badly on a list with integer elements!
3582 : : */
3583 : : List *resultlist;
3584 : : ListCell *temp;
3585 : :
3586 : 4514135 : resultlist = NIL;
3587 [ + - + + : 14630047 : foreach(temp, (List *) node)
+ + ]
3588 : : {
3589 : 10115912 : resultlist = lappend(resultlist,
3590 : 10118857 : mutator((Node *) lfirst(temp),
3591 : : context));
3592 : : }
3593 : 4511190 : return (Node *) resultlist;
3594 : : }
3595 : : break;
3596 : 24941 : case T_FromExpr:
3597 : : {
3598 : 24941 : FromExpr *from = (FromExpr *) node;
3599 : : FromExpr *newnode;
3600 : :
3601 : 24941 : FLATCOPY(newnode, from, FromExpr);
3602 : 24941 : MUTATE(newnode->fromlist, from->fromlist, List *);
3603 : 24941 : MUTATE(newnode->quals, from->quals, Node *);
3604 : 24941 : return (Node *) newnode;
3605 : : }
3606 : : break;
4222 andres@anarazel.de 3607 : 760 : case T_OnConflictExpr:
3608 : : {
4207 bruce@momjian.us 3609 : 760 : OnConflictExpr *oc = (OnConflictExpr *) node;
3610 : : OnConflictExpr *newnode;
3611 : :
4222 andres@anarazel.de 3612 : 760 : FLATCOPY(newnode, oc, OnConflictExpr);
3613 : 760 : MUTATE(newnode->arbiterElems, oc->arbiterElems, List *);
3614 : 760 : MUTATE(newnode->arbiterWhere, oc->arbiterWhere, Node *);
3615 : 760 : MUTATE(newnode->onConflictSet, oc->onConflictSet, List *);
3616 : 760 : MUTATE(newnode->onConflictWhere, oc->onConflictWhere, Node *);
4217 3617 : 760 : MUTATE(newnode->exclRelTlist, oc->exclRelTlist, List *);
3618 : :
4222 3619 : 760 : return (Node *) newnode;
3620 : : }
3621 : : break;
1706 alvherre@alvh.no-ip. 3622 : 720 : case T_MergeAction:
3623 : : {
3624 : 720 : MergeAction *action = (MergeAction *) node;
3625 : : MergeAction *newnode;
3626 : :
3627 : 720 : FLATCOPY(newnode, action, MergeAction);
3628 : 720 : MUTATE(newnode->qual, action->qual, Node *);
3629 : 720 : MUTATE(newnode->targetList, action->targetList, List *);
3630 : :
3631 : 720 : return (Node *) newnode;
3632 : : }
3633 : : break;
3158 3634 : 146 : case T_PartitionPruneStepOp:
3635 : : {
3636 : 146 : PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
3637 : : PartitionPruneStepOp *newnode;
3638 : :
3639 : 146 : FLATCOPY(newnode, opstep, PartitionPruneStepOp);
3640 : 146 : MUTATE(newnode->exprs, opstep->exprs, List *);
3641 : :
3642 : 146 : return (Node *) newnode;
3643 : : }
3644 : : break;
3645 : 16 : case T_PartitionPruneStepCombine:
3646 : : /* no expression sub-nodes */
772 peter@eisentraut.org 3647 : 16 : return copyObject(node);
6669 tgl@sss.pgh.pa.us 3648 : 6906 : case T_JoinExpr:
3649 : : {
3650 : 6906 : JoinExpr *join = (JoinExpr *) node;
3651 : : JoinExpr *newnode;
3652 : :
3653 : 6906 : FLATCOPY(newnode, join, JoinExpr);
3654 : 6906 : MUTATE(newnode->larg, join->larg, Node *);
3655 : 6906 : MUTATE(newnode->rarg, join->rarg, Node *);
3656 : 6906 : MUTATE(newnode->quals, join->quals, Node *);
3657 : : /* We do not mutate alias or using by default */
3658 : 6906 : return (Node *) newnode;
3659 : : }
3660 : : break;
3661 : 281 : case T_SetOperationStmt:
3662 : : {
3663 : 281 : SetOperationStmt *setop = (SetOperationStmt *) node;
3664 : : SetOperationStmt *newnode;
3665 : :
3666 : 281 : FLATCOPY(newnode, setop, SetOperationStmt);
3667 : 281 : MUTATE(newnode->larg, setop->larg, Node *);
3668 : 281 : MUTATE(newnode->rarg, setop->rarg, Node *);
3669 : : /* We do not mutate groupClauses by default */
3670 : 281 : return (Node *) newnode;
3671 : : }
3672 : : break;
2849 3673 : 684 : case T_IndexClause:
3674 : : {
3675 : 684 : IndexClause *iclause = (IndexClause *) node;
3676 : : IndexClause *newnode;
3677 : :
3678 : 684 : FLATCOPY(newnode, iclause, IndexClause);
3679 : 684 : MUTATE(newnode->rinfo, iclause->rinfo, RestrictInfo *);
3680 : 684 : MUTATE(newnode->indexquals, iclause->indexquals, List *);
3681 : 684 : return (Node *) newnode;
3682 : : }
3683 : : break;
6612 3684 : 26673 : case T_PlaceHolderVar:
3685 : : {
3686 : 26673 : PlaceHolderVar *phv = (PlaceHolderVar *) node;
3687 : : PlaceHolderVar *newnode;
3688 : :
3689 : 26673 : FLATCOPY(newnode, phv, PlaceHolderVar);
3690 : 26673 : MUTATE(newnode->phexpr, phv->phexpr, Expr *);
3691 : : /* Assume we need not copy the relids bitmapsets */
3692 : 26673 : return (Node *) newnode;
3693 : : }
3694 : : break;
4222 andres@anarazel.de 3695 : 3025 : case T_InferenceElem:
3696 : : {
3697 : 3025 : InferenceElem *inferenceelemdexpr = (InferenceElem *) node;
3698 : : InferenceElem *newnode;
3699 : :
3700 : 3025 : FLATCOPY(newnode, inferenceelemdexpr, InferenceElem);
3701 : 3025 : MUTATE(newnode->expr, newnode->expr, Node *);
3702 : 3025 : return (Node *) newnode;
3703 : : }
3704 : : break;
6669 tgl@sss.pgh.pa.us 3705 : 19968 : case T_AppendRelInfo:
3706 : : {
3707 : 19968 : AppendRelInfo *appinfo = (AppendRelInfo *) node;
3708 : : AppendRelInfo *newnode;
3709 : :
3710 : 19968 : FLATCOPY(newnode, appinfo, AppendRelInfo);
3711 : 19968 : MUTATE(newnode->translated_vars, appinfo->translated_vars, List *);
3712 : : /* Assume nothing need be done with parent_colnos[] */
3713 : 19968 : return (Node *) newnode;
3714 : : }
3715 : : break;
6612 tgl@sss.pgh.pa.us 3716 :UBC 0 : case T_PlaceHolderInfo:
3717 : : {
3718 : 0 : PlaceHolderInfo *phinfo = (PlaceHolderInfo *) node;
3719 : : PlaceHolderInfo *newnode;
3720 : :
3721 : 0 : FLATCOPY(newnode, phinfo, PlaceHolderInfo);
3722 : 0 : MUTATE(newnode->ph_var, phinfo->ph_var, PlaceHolderVar *);
3723 : : /* Assume we need not copy the relids bitmapsets */
3724 : 0 : return (Node *) newnode;
3725 : : }
3726 : : break;
4755 tgl@sss.pgh.pa.us 3727 :CBC 70948 : case T_RangeTblFunction:
3728 : : {
3729 : 70948 : RangeTblFunction *rtfunc = (RangeTblFunction *) node;
3730 : : RangeTblFunction *newnode;
3731 : :
3732 : 70948 : FLATCOPY(newnode, rtfunc, RangeTblFunction);
3733 : 70948 : MUTATE(newnode->funcexpr, rtfunc->funcexpr, Node *);
3734 : : /* Assume we need not copy the coldef info lists */
3735 : 70948 : return (Node *) newnode;
3736 : : }
3737 : : break;
4144 3738 : 482 : case T_TableSampleClause:
3739 : : {
3740 : 482 : TableSampleClause *tsc = (TableSampleClause *) node;
3741 : : TableSampleClause *newnode;
3742 : :
3743 : 482 : FLATCOPY(newnode, tsc, TableSampleClause);
3744 : 482 : MUTATE(newnode->args, tsc->args, List *);
3745 : 482 : MUTATE(newnode->repeatable, tsc->repeatable, Expr *);
3746 : 482 : return (Node *) newnode;
3747 : : }
3748 : : break;
3552 alvherre@alvh.no-ip. 3749 : 1186 : case T_TableFunc:
3750 : : {
3751 : 1186 : TableFunc *tf = (TableFunc *) node;
3752 : : TableFunc *newnode;
3753 : :
3754 : 1186 : FLATCOPY(newnode, tf, TableFunc);
3755 : 1186 : MUTATE(newnode->ns_uris, tf->ns_uris, List *);
3756 : 1186 : MUTATE(newnode->docexpr, tf->docexpr, Node *);
3757 : 1186 : MUTATE(newnode->rowexpr, tf->rowexpr, Node *);
3758 : 1186 : MUTATE(newnode->colexprs, tf->colexprs, List *);
3759 : 1186 : MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);
968 amitlan@postgresql.o 3760 : 1186 : MUTATE(newnode->colvalexprs, tf->colvalexprs, List *);
3761 : 1178 : MUTATE(newnode->passingvalexprs, tf->passingvalexprs, List *);
1731 andrew@dunslane.net 3762 : 1178 : return (Node *) newnode;
3763 : : }
3764 : : break;
6669 tgl@sss.pgh.pa.us 3765 :UBC 0 : default:
3766 [ # # ]: 0 : elog(ERROR, "unrecognized node type: %d",
3767 : : (int) nodeTag(node));
3768 : : break;
3769 : : }
3770 : : /* can't get here, but keep compiler happy */
3771 : : return NULL;
3772 : : }
3773 : :
3774 : :
3775 : : /*
3776 : : * query_tree_mutator --- initiate modification of a Query's expressions
3777 : : *
3778 : : * This routine exists just to reduce the number of places that need to know
3779 : : * where all the expression subtrees of a Query are. Note it can be used
3780 : : * for starting a walk at top level of a Query regardless of whether the
3781 : : * mutator intends to descend into subqueries. It is also useful for
3782 : : * descending into subqueries within a mutator.
3783 : : *
3784 : : * Some callers want to suppress mutating of certain items in the Query,
3785 : : * typically because they need to process them specially, or don't actually
3786 : : * want to recurse into subqueries. This is supported by the flags argument,
3787 : : * which is the bitwise OR of flag values to suppress mutating of
3788 : : * indicated items. (More flag bits may be added as needed.)
3789 : : *
3790 : : * Normally the top-level Query node itself is copied, but some callers want
3791 : : * it to be modified in-place; they must pass QTW_DONT_COPY_QUERY in flags.
3792 : : * All modified substructure is safely copied in any case.
3793 : : */
3794 : : pg_attribute_no_sanitize_function()
3795 : : Query *
1530 tgl@sss.pgh.pa.us 3796 :CBC 24639 : query_tree_mutator_impl(Query *query,
3797 : : tree_mutator_callback mutator,
3798 : : void *context,
3799 : : int flags)
3800 : : {
6669 3801 [ + - - + ]: 24639 : Assert(query != NULL && IsA(query, Query));
3802 : :
3803 [ + - ]: 24639 : if (!(flags & QTW_DONT_COPY_QUERY))
3804 : : {
3805 : : Query *newquery;
3806 : :
3807 : 24639 : FLATCOPY(newquery, query, Query);
3808 : 24639 : query = newquery;
3809 : : }
3810 : :
3811 : 24639 : MUTATE(query->targetList, query->targetList, List *);
4881 sfrost@snowman.net 3812 : 24639 : MUTATE(query->withCheckOptions, query->withCheckOptions, List *);
4222 andres@anarazel.de 3813 : 24639 : MUTATE(query->onConflict, query->onConflict, OnConflictExpr *);
1706 alvherre@alvh.no-ip. 3814 : 24639 : MUTATE(query->mergeActionList, query->mergeActionList, List *);
973 dean.a.rasheed@gmail 3815 : 24639 : MUTATE(query->mergeJoinCondition, query->mergeJoinCondition, Node *);
6669 tgl@sss.pgh.pa.us 3816 : 24639 : MUTATE(query->returningList, query->returningList, List *);
3817 : 24639 : MUTATE(query->jointree, query->jointree, FromExpr *);
3818 : 24639 : MUTATE(query->setOperations, query->setOperations, Node *);
3819 : 24639 : MUTATE(query->havingQual, query->havingQual, Node *);
3820 : 24639 : MUTATE(query->limitOffset, query->limitOffset, Node *);
3821 : 24639 : MUTATE(query->limitCount, query->limitCount, Node *);
3822 : :
3823 : : /*
3824 : : * Most callers aren't interested in SortGroupClause nodes since those
3825 : : * don't contain actual expressions. However they do contain OIDs, which
3826 : : * may be of interest to some mutators.
3827 : : */
3828 : :
2613 rhodiumtoad@postgres 3829 [ - + ]: 24639 : if ((flags & QTW_EXAMINE_SORTGROUP))
3830 : : {
2613 rhodiumtoad@postgres 3831 :UBC 0 : MUTATE(query->groupClause, query->groupClause, List *);
3832 : 0 : MUTATE(query->windowClause, query->windowClause, List *);
3833 : 0 : MUTATE(query->sortClause, query->sortClause, List *);
3834 : 0 : MUTATE(query->distinctClause, query->distinctClause, List *);
3835 : : }
3836 : : else
3837 : : {
3838 : : /*
3839 : : * But we need to mutate the expressions under WindowClause nodes even
3840 : : * if we're not interested in SortGroupClause nodes.
3841 : : */
3842 : : List *resultlist;
3843 : : ListCell *temp;
3844 : :
2613 rhodiumtoad@postgres 3845 :CBC 24639 : resultlist = NIL;
3846 [ + + + + : 24791 : foreach(temp, query->windowClause)
+ + ]
3847 : : {
3848 : 152 : WindowClause *wc = lfirst_node(WindowClause, temp);
3849 : : WindowClause *newnode;
3850 : :
3851 : 152 : FLATCOPY(newnode, wc, WindowClause);
3852 : 152 : MUTATE(newnode->startOffset, wc->startOffset, Node *);
3853 : 152 : MUTATE(newnode->endOffset, wc->endOffset, Node *);
3854 : :
3855 : 152 : resultlist = lappend(resultlist, (Node *) newnode);
3856 : : }
3857 : 24639 : query->windowClause = resultlist;
3858 : : }
3859 : :
3860 : : /*
3861 : : * groupingSets and rowMarks are not mutated:
3862 : : *
3863 : : * groupingSets contain only ressortgroup refs (integers) which are
3864 : : * meaningless without the groupClause or tlist. Accordingly, any mutator
3865 : : * that needs to care about them needs to handle them itself in its Query
3866 : : * processing.
3867 : : *
3868 : : * rowMarks contains only rangetable indexes (and flags etc.) and
3869 : : * therefore should be handled at Query level similarly.
3870 : : */
3871 : :
6629 tgl@sss.pgh.pa.us 3872 [ + - ]: 24639 : if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
3873 : 24639 : MUTATE(query->cteList, query->cteList, List *);
3874 : : else /* else copy CTE list as-is */
6629 tgl@sss.pgh.pa.us 3875 :UBC 0 : query->cteList = copyObject(query->cteList);
6669 tgl@sss.pgh.pa.us 3876 :CBC 24639 : query->rtable = range_table_mutator(query->rtable,
3877 : : mutator, context, flags);
3878 : 24639 : return query;
3879 : : }
3880 : :
3881 : : /*
3882 : : * range_table_mutator is just the part of query_tree_mutator that processes
3883 : : * a query's rangetable. This is split out since it can be useful on
3884 : : * its own.
3885 : : */
3886 : : pg_attribute_no_sanitize_function()
3887 : : List *
1530 3888 : 24639 : range_table_mutator_impl(List *rtable,
3889 : : tree_mutator_callback mutator,
3890 : : void *context,
3891 : : int flags)
3892 : : {
6669 3893 : 24639 : List *newrt = NIL;
3894 : : ListCell *rt;
3895 : :
3896 [ + + + + : 73030 : foreach(rt, rtable)
+ + ]
3897 : : {
3898 : 48391 : RangeTblEntry *rte = (RangeTblEntry *) lfirst(rt);
3899 : : RangeTblEntry *newrte;
3900 : :
3901 : 48391 : FLATCOPY(newrte, rte, RangeTblEntry);
3902 [ + + + + : 48391 : switch (rte->rtekind)
- + + +
- ]
3903 : : {
3904 : 29523 : case RTE_RELATION:
4144 3905 : 29523 : MUTATE(newrte->tablesample, rte->tablesample,
3906 : : TableSampleClause *);
3907 : : /* we don't bother to copy eref, aliases, etc; OK? */
4215 simon@2ndQuadrant.co 3908 : 29523 : break;
6669 tgl@sss.pgh.pa.us 3909 : 4089 : case RTE_SUBQUERY:
3910 [ + - ]: 4089 : if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
1616 3911 : 4089 : MUTATE(newrte->subquery, rte->subquery, Query *);
3912 : : else
3913 : : {
3914 : : /* else, copy RT subqueries as-is */
6669 tgl@sss.pgh.pa.us 3915 :UBC 0 : newrte->subquery = copyObject(rte->subquery);
3916 : : }
6669 tgl@sss.pgh.pa.us 3917 :CBC 4089 : break;
3918 : 6966 : case RTE_JOIN:
3919 [ + + ]: 6966 : if (!(flags & QTW_IGNORE_JOINALIASES))
3920 : 6567 : MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
3921 : : else
3922 : : {
3923 : : /* else, copy join aliases as-is */
3924 : 399 : newrte->joinaliasvars = copyObject(rte->joinaliasvars);
3925 : : }
3926 : 6966 : break;
3927 : 5949 : case RTE_FUNCTION:
4755 3928 : 5949 : MUTATE(newrte->functions, rte->functions, List *);
6669 3929 : 5949 : break;
3552 alvherre@alvh.no-ip. 3930 :UBC 0 : case RTE_TABLEFUNC:
3931 : 0 : MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *);
3932 : 0 : break;
6669 tgl@sss.pgh.pa.us 3933 :CBC 1050 : case RTE_VALUES:
3934 : 1050 : MUTATE(newrte->values_lists, rte->values_lists, List *);
3935 : 1050 : break;
2861 3936 : 603 : case RTE_CTE:
3937 : : case RTE_NAMEDTUPLESTORE:
3938 : : case RTE_RESULT:
3939 : : /* nothing to do */
3940 : 603 : break;
809 rguo@postgresql.org 3941 : 211 : case RTE_GROUP:
3942 [ + - ]: 211 : if (!(flags & QTW_IGNORE_GROUPEXPRS))
3943 : 211 : MUTATE(newrte->groupexprs, rte->groupexprs, List *);
3944 : : else
3945 : : {
3946 : : /* else, copy grouping exprs as-is */
809 rguo@postgresql.org 3947 :UBC 0 : newrte->groupexprs = copyObject(rte->groupexprs);
3948 : : }
809 rguo@postgresql.org 3949 :CBC 211 : break;
3950 : : }
4613 sfrost@snowman.net 3951 : 48391 : MUTATE(newrte->securityQuals, rte->securityQuals, List *);
6669 tgl@sss.pgh.pa.us 3952 : 48391 : newrt = lappend(newrt, newrte);
3953 : : }
3954 : 24639 : return newrt;
3955 : : }
3956 : :
3957 : : /*
3958 : : * query_or_expression_tree_walker --- hybrid form
3959 : : *
3960 : : * This routine will invoke query_tree_walker if called on a Query node,
3961 : : * else will invoke the walker directly. This is a useful way of starting
3962 : : * the recursion when the walker's normal change of state is not appropriate
3963 : : * for the outermost Query node.
3964 : : */
3965 : : pg_attribute_no_sanitize_function()
3966 : : bool
1530 3967 : 3415631 : query_or_expression_tree_walker_impl(Node *node,
3968 : : tree_walker_callback walker,
3969 : : void *context,
3970 : : int flags)
3971 : : {
6669 3972 [ + + + + ]: 3415631 : if (node && IsA(node, Query))
3973 : 323255 : return query_tree_walker((Query *) node,
3974 : : walker,
3975 : : context,
3976 : : flags);
3977 : : else
1530 3978 : 3092376 : return WALK(node);
3979 : : }
3980 : :
3981 : : /*
3982 : : * query_or_expression_tree_mutator --- hybrid form
3983 : : *
3984 : : * This routine will invoke query_tree_mutator if called on a Query node,
3985 : : * else will invoke the mutator directly. This is a useful way of starting
3986 : : * the recursion when the mutator's normal change of state is not appropriate
3987 : : * for the outermost Query node.
3988 : : */
3989 : : pg_attribute_no_sanitize_function()
3990 : : Node *
3991 : 591350 : query_or_expression_tree_mutator_impl(Node *node,
3992 : : tree_mutator_callback mutator,
3993 : : void *context,
3994 : : int flags)
3995 : : {
6669 3996 [ + + + + ]: 591350 : if (node && IsA(node, Query))
3997 : 7461 : return (Node *) query_tree_mutator((Query *) node,
3998 : : mutator,
3999 : : context,
4000 : : flags);
4001 : : else
4002 : 583889 : return mutator(node, context);
4003 : : }
4004 : :
4005 : :
4006 : : /*
4007 : : * raw_expression_tree_walker --- walk raw parse trees
4008 : : *
4009 : : * This has exactly the same API as expression_tree_walker, but instead of
4010 : : * walking post-analysis parse trees, it knows how to walk the node types
4011 : : * found in raw grammar output. (There is not currently any need for a
4012 : : * combined walker, so we keep them separate in the name of efficiency.)
4013 : : * Unlike expression_tree_walker, there is no special rule about query
4014 : : * boundaries: we descend to everything that's possibly interesting.
4015 : : *
4016 : : * Currently, the node type coverage here extends only to DML statements
4017 : : * (SELECT/INSERT/UPDATE/DELETE/MERGE) and nodes that can appear in them,
4018 : : * because this is used mainly during analysis of CTEs, and only DML
4019 : : * statements can appear in CTEs.
4020 : : */
4021 : : pg_attribute_no_sanitize_function()
4022 : : bool
1530 4023 : 86455 : raw_expression_tree_walker_impl(Node *node,
4024 : : tree_walker_callback walker,
4025 : : void *context)
4026 : : {
4027 : : ListCell *temp;
4028 : :
4029 : : /*
4030 : : * The walker has already visited the current node, and so we need only
4031 : : * recurse into any sub-nodes it has.
4032 : : */
6629 4033 [ - + ]: 86455 : if (node == NULL)
6629 tgl@sss.pgh.pa.us 4034 :UBC 0 : return false;
4035 : :
4036 : : /* Guard against stack overflow due to overly complex expressions */
6629 tgl@sss.pgh.pa.us 4037 :CBC 86455 : check_stack_depth();
4038 : :
4039 [ + + - - : 86455 : switch (nodeTag(node))
+ - + - -
- - - - -
- - - - -
- - - - -
- + - + +
+ + + + +
+ - + + +
+ - - - +
+ - + + +
+ + + - -
- + - - -
+ - - - -
+ - - - -
- - - -
- ]
4040 : : {
1334 alvherre@alvh.no-ip. 4041 : 8264 : case T_JsonFormat:
4042 : : case T_SetToDefault:
4043 : : case T_CurrentOfExpr:
4044 : : case T_SQLValueFunction:
4045 : : case T_Integer:
4046 : : case T_Float:
4047 : : case T_Boolean:
4048 : : case T_String:
4049 : : case T_BitString:
4050 : : case T_ParamRef:
4051 : : case T_A_Const:
4052 : : case T_A_Star:
4053 : : case T_MergeSupportFunc:
4054 : : case T_ReturningOption:
4055 : : /* primitive node types with no subnodes */
6629 tgl@sss.pgh.pa.us 4056 : 8264 : break;
4057 : 460 : case T_Alias:
4058 : : /* we assume the colnames list isn't interesting */
4059 : 460 : break;
6629 tgl@sss.pgh.pa.us 4060 :UBC 0 : case T_RangeVar:
1530 4061 : 0 : return WALK(((RangeVar *) node)->alias);
4214 andres@anarazel.de 4062 : 0 : case T_GroupingFunc:
1530 tgl@sss.pgh.pa.us 4063 : 0 : return WALK(((GroupingFunc *) node)->args);
6629 tgl@sss.pgh.pa.us 4064 :CBC 78 : case T_SubLink:
4065 : : {
4066 : 78 : SubLink *sublink = (SubLink *) node;
4067 : :
1530 4068 [ - + ]: 78 : if (WALK(sublink->testexpr))
6629 tgl@sss.pgh.pa.us 4069 :UBC 0 : return true;
4070 : : /* we assume the operName is not interesting */
1530 tgl@sss.pgh.pa.us 4071 [ - + ]:CBC 78 : if (WALK(sublink->subselect))
6629 tgl@sss.pgh.pa.us 4072 :UBC 0 : return true;
4073 : : }
6629 tgl@sss.pgh.pa.us 4074 :CBC 78 : break;
6629 tgl@sss.pgh.pa.us 4075 :UBC 0 : case T_CaseExpr:
4076 : : {
4077 : 0 : CaseExpr *caseexpr = (CaseExpr *) node;
4078 : :
1530 4079 [ # # ]: 0 : if (WALK(caseexpr->arg))
6629 4080 : 0 : return true;
4081 : : /* we assume walker doesn't care about CaseWhens, either */
4082 [ # # # # : 0 : foreach(temp, caseexpr->args)
# # ]
4083 : : {
3519 4084 : 0 : CaseWhen *when = lfirst_node(CaseWhen, temp);
4085 : :
1530 4086 [ # # ]: 0 : if (WALK(when->expr))
6629 4087 : 0 : return true;
1530 4088 [ # # ]: 0 : if (WALK(when->result))
6629 4089 : 0 : return true;
4090 : : }
1530 4091 [ # # ]: 0 : if (WALK(caseexpr->defresult))
6629 4092 : 0 : return true;
4093 : : }
4094 : 0 : break;
6629 tgl@sss.pgh.pa.us 4095 :CBC 72 : case T_RowExpr:
4096 : : /* Assume colnames isn't interesting */
1530 4097 : 72 : return WALK(((RowExpr *) node)->args);
6629 tgl@sss.pgh.pa.us 4098 :UBC 0 : case T_CoalesceExpr:
1530 4099 : 0 : return WALK(((CoalesceExpr *) node)->args);
6629 4100 : 0 : case T_MinMaxExpr:
1530 4101 : 0 : return WALK(((MinMaxExpr *) node)->args);
6629 4102 : 0 : case T_XmlExpr:
4103 : : {
4104 : 0 : XmlExpr *xexpr = (XmlExpr *) node;
4105 : :
1530 4106 [ # # ]: 0 : if (WALK(xexpr->named_args))
6629 4107 : 0 : return true;
4108 : : /* we assume walker doesn't care about arg_names */
1530 4109 [ # # ]: 0 : if (WALK(xexpr->args))
6629 4110 : 0 : return true;
4111 : : }
4112 : 0 : break;
1334 alvherre@alvh.no-ip. 4113 : 0 : case T_JsonReturning:
4114 : 0 : return WALK(((JsonReturning *) node)->format);
4115 : 0 : case T_JsonValueExpr:
4116 : : {
4117 : 0 : JsonValueExpr *jve = (JsonValueExpr *) node;
4118 : :
4119 [ # # ]: 0 : if (WALK(jve->raw_expr))
4120 : 0 : return true;
4121 [ # # ]: 0 : if (WALK(jve->formatted_expr))
4122 : 0 : return true;
4123 [ # # ]: 0 : if (WALK(jve->format))
4124 : 0 : return true;
4125 : : }
4126 : 0 : break;
1227 amitlan@postgresql.o 4127 : 0 : case T_JsonParseExpr:
4128 : : {
4129 : 0 : JsonParseExpr *jpe = (JsonParseExpr *) node;
4130 : :
4131 [ # # ]: 0 : if (WALK(jpe->expr))
4132 : 0 : return true;
4133 [ # # ]: 0 : if (WALK(jpe->output))
4134 : 0 : return true;
4135 : : }
4136 : 0 : break;
4137 : 0 : case T_JsonScalarExpr:
4138 : : {
4139 : 0 : JsonScalarExpr *jse = (JsonScalarExpr *) node;
4140 : :
4141 [ # # ]: 0 : if (WALK(jse->expr))
4142 : 0 : return true;
4143 [ # # ]: 0 : if (WALK(jse->output))
4144 : 0 : return true;
4145 : : }
4146 : 0 : break;
4147 : 0 : case T_JsonSerializeExpr:
4148 : : {
4149 : 0 : JsonSerializeExpr *jse = (JsonSerializeExpr *) node;
4150 : :
4151 [ # # ]: 0 : if (WALK(jse->expr))
4152 : 0 : return true;
4153 [ # # ]: 0 : if (WALK(jse->output))
4154 : 0 : return true;
4155 : : }
4156 : 0 : break;
1334 alvherre@alvh.no-ip. 4157 : 0 : case T_JsonConstructorExpr:
4158 : : {
4159 : 0 : JsonConstructorExpr *ctor = (JsonConstructorExpr *) node;
4160 : :
4161 [ # # ]: 0 : if (WALK(ctor->args))
4162 : 0 : return true;
4163 [ # # ]: 0 : if (WALK(ctor->func))
4164 : 0 : return true;
4165 [ # # ]: 0 : if (WALK(ctor->coercion))
4166 : 0 : return true;
4167 [ # # ]: 0 : if (WALK(ctor->returning))
4168 : 0 : return true;
4169 : : }
4170 : 0 : break;
4171 : 0 : case T_JsonIsPredicate:
4172 : 0 : return WALK(((JsonIsPredicate *) node)->expr);
982 amitlan@postgresql.o 4173 : 0 : case T_JsonArgument:
4174 : 0 : return WALK(((JsonArgument *) node)->val);
4175 : 0 : case T_JsonFuncExpr:
4176 : : {
4177 : 0 : JsonFuncExpr *jfe = (JsonFuncExpr *) node;
4178 : :
4179 [ # # ]: 0 : if (WALK(jfe->context_item))
4180 : 0 : return true;
4181 [ # # ]: 0 : if (WALK(jfe->pathspec))
4182 : 0 : return true;
4183 [ # # ]: 0 : if (WALK(jfe->passing))
4184 : 0 : return true;
4185 [ # # ]: 0 : if (WALK(jfe->output))
4186 : 0 : return true;
4187 [ # # ]: 0 : if (WALK(jfe->on_empty))
4188 : 0 : return true;
4189 [ # # ]: 0 : if (WALK(jfe->on_error))
4190 : 0 : return true;
4191 : : }
4192 : 0 : break;
4193 : 0 : case T_JsonBehavior:
4194 : : {
4195 : 0 : JsonBehavior *jb = (JsonBehavior *) node;
4196 : :
4197 [ # # ]: 0 : if (WALK(jb->expr))
4198 : 0 : return true;
4199 : : }
4200 : 0 : break;
968 4201 : 0 : case T_JsonTable:
4202 : : {
4203 : 0 : JsonTable *jt = (JsonTable *) node;
4204 : :
4205 [ # # ]: 0 : if (WALK(jt->context_item))
4206 : 0 : return true;
4207 [ # # ]: 0 : if (WALK(jt->pathspec))
4208 : 0 : return true;
4209 [ # # ]: 0 : if (WALK(jt->passing))
4210 : 0 : return true;
4211 [ # # ]: 0 : if (WALK(jt->columns))
4212 : 0 : return true;
4213 [ # # ]: 0 : if (WALK(jt->on_error))
4214 : 0 : return true;
4215 : : }
4216 : 0 : break;
4217 : 0 : case T_JsonTableColumn:
4218 : : {
4219 : 0 : JsonTableColumn *jtc = (JsonTableColumn *) node;
4220 : :
4221 [ # # ]: 0 : if (WALK(jtc->typeName))
4222 : 0 : return true;
4223 [ # # ]: 0 : if (WALK(jtc->on_empty))
4224 : 0 : return true;
4225 [ # # ]: 0 : if (WALK(jtc->on_error))
4226 : 0 : return true;
964 4227 [ # # ]: 0 : if (WALK(jtc->columns))
4228 : 0 : return true;
4229 : : }
968 4230 : 0 : break;
4231 : 0 : case T_JsonTablePathSpec:
4232 : 0 : return WALK(((JsonTablePathSpec *) node)->string);
6629 tgl@sss.pgh.pa.us 4233 : 0 : case T_NullTest:
1530 4234 : 0 : return WALK(((NullTest *) node)->arg);
6629 4235 : 0 : case T_BooleanTest:
1530 4236 : 0 : return WALK(((BooleanTest *) node)->arg);
6629 tgl@sss.pgh.pa.us 4237 :CBC 1397 : case T_JoinExpr:
4238 : : {
4239 : 1397 : JoinExpr *join = (JoinExpr *) node;
4240 : :
1530 4241 [ - + ]: 1397 : if (WALK(join->larg))
6629 tgl@sss.pgh.pa.us 4242 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4243 [ - + ]:CBC 1397 : if (WALK(join->rarg))
6629 tgl@sss.pgh.pa.us 4244 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4245 [ - + ]:CBC 1397 : if (WALK(join->quals))
6629 tgl@sss.pgh.pa.us 4246 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4247 [ - + ]:CBC 1397 : if (WALK(join->alias))
6629 tgl@sss.pgh.pa.us 4248 :UBC 0 : return true;
4249 : : /* using list is deemed uninteresting */
4250 : : }
6629 tgl@sss.pgh.pa.us 4251 :CBC 1397 : break;
6629 tgl@sss.pgh.pa.us 4252 :UBC 0 : case T_IntoClause:
4253 : : {
4254 : 0 : IntoClause *into = (IntoClause *) node;
4255 : :
1530 4256 [ # # ]: 0 : if (WALK(into->rel))
6629 4257 : 0 : return true;
4258 : : /* colNames, options are deemed uninteresting */
4259 : : /* viewQuery should be null in raw parsetree, but check it */
1530 4260 [ # # ]: 0 : if (WALK(into->viewQuery))
4978 4261 : 0 : return true;
4262 : : }
6629 4263 : 0 : break;
6629 tgl@sss.pgh.pa.us 4264 :CBC 16636 : case T_List:
4265 [ + - + + : 45734 : foreach(temp, (List *) node)
+ + ]
4266 : : {
1530 4267 [ - + ]: 29166 : if (WALK((Node *) lfirst(temp)))
6629 tgl@sss.pgh.pa.us 4268 :UBC 0 : return true;
4269 : : }
6629 tgl@sss.pgh.pa.us 4270 :CBC 16568 : break;
5755 4271 : 28 : case T_InsertStmt:
4272 : : {
4273 : 28 : InsertStmt *stmt = (InsertStmt *) node;
4274 : :
1530 4275 [ - + ]: 28 : if (WALK(stmt->relation))
5755 tgl@sss.pgh.pa.us 4276 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4277 [ - + ]:CBC 28 : if (WALK(stmt->cols))
5755 tgl@sss.pgh.pa.us 4278 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4279 [ - + ]:CBC 28 : if (WALK(stmt->selectStmt))
5755 tgl@sss.pgh.pa.us 4280 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4281 [ - + ]:CBC 28 : if (WALK(stmt->onConflictClause))
4222 andres@anarazel.de 4282 :UBC 0 : return true;
681 dean.a.rasheed@gmail 4283 [ - + ]:CBC 28 : if (WALK(stmt->returningClause))
5755 tgl@sss.pgh.pa.us 4284 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4285 [ - + ]:CBC 28 : if (WALK(stmt->withClause))
5755 tgl@sss.pgh.pa.us 4286 :UBC 0 : return true;
4287 : : }
5755 tgl@sss.pgh.pa.us 4288 :CBC 28 : break;
4289 : 4 : case T_DeleteStmt:
4290 : : {
4291 : 4 : DeleteStmt *stmt = (DeleteStmt *) node;
4292 : :
1530 4293 [ - + ]: 4 : if (WALK(stmt->relation))
5755 tgl@sss.pgh.pa.us 4294 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4295 [ - + ]:CBC 4 : if (WALK(stmt->usingClause))
5755 tgl@sss.pgh.pa.us 4296 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4297 [ - + ]:CBC 4 : if (WALK(stmt->whereClause))
5755 tgl@sss.pgh.pa.us 4298 :UBC 0 : return true;
681 dean.a.rasheed@gmail 4299 [ - + ]:CBC 4 : if (WALK(stmt->returningClause))
5755 tgl@sss.pgh.pa.us 4300 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4301 [ - + ]:CBC 4 : if (WALK(stmt->withClause))
5755 tgl@sss.pgh.pa.us 4302 :UBC 0 : return true;
4303 : : }
5755 tgl@sss.pgh.pa.us 4304 :CBC 4 : break;
4305 : 4 : case T_UpdateStmt:
4306 : : {
4307 : 4 : UpdateStmt *stmt = (UpdateStmt *) node;
4308 : :
1530 4309 [ - + ]: 4 : if (WALK(stmt->relation))
5755 tgl@sss.pgh.pa.us 4310 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4311 [ - + ]:CBC 4 : if (WALK(stmt->targetList))
5755 tgl@sss.pgh.pa.us 4312 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4313 [ - + ]:CBC 4 : if (WALK(stmt->whereClause))
5755 tgl@sss.pgh.pa.us 4314 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4315 [ - + ]:CBC 4 : if (WALK(stmt->fromClause))
5755 tgl@sss.pgh.pa.us 4316 :UBC 0 : return true;
681 dean.a.rasheed@gmail 4317 [ - + ]:CBC 4 : if (WALK(stmt->returningClause))
5755 tgl@sss.pgh.pa.us 4318 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4319 [ - + ]:CBC 4 : if (WALK(stmt->withClause))
5755 tgl@sss.pgh.pa.us 4320 :UBC 0 : return true;
4321 : : }
5755 tgl@sss.pgh.pa.us 4322 :CBC 4 : break;
1706 alvherre@alvh.no-ip. 4323 : 4 : case T_MergeStmt:
4324 : : {
4325 : 4 : MergeStmt *stmt = (MergeStmt *) node;
4326 : :
1530 tgl@sss.pgh.pa.us 4327 [ - + ]: 4 : if (WALK(stmt->relation))
1706 alvherre@alvh.no-ip. 4328 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4329 [ - + ]:CBC 4 : if (WALK(stmt->sourceRelation))
1706 alvherre@alvh.no-ip. 4330 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4331 [ - + ]:CBC 4 : if (WALK(stmt->joinCondition))
1706 alvherre@alvh.no-ip. 4332 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4333 [ - + ]:CBC 4 : if (WALK(stmt->mergeWhenClauses))
1706 alvherre@alvh.no-ip. 4334 :UBC 0 : return true;
681 dean.a.rasheed@gmail 4335 [ - + ]:CBC 4 : if (WALK(stmt->returningClause))
986 dean.a.rasheed@gmail 4336 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4337 [ - + ]:CBC 4 : if (WALK(stmt->withClause))
1706 alvherre@alvh.no-ip. 4338 :UBC 0 : return true;
4339 : : }
1706 alvherre@alvh.no-ip. 4340 :CBC 4 : break;
4341 : 4 : case T_MergeWhenClause:
4342 : : {
4343 : 4 : MergeWhenClause *mergeWhenClause = (MergeWhenClause *) node;
4344 : :
1530 tgl@sss.pgh.pa.us 4345 [ - + ]: 4 : if (WALK(mergeWhenClause->condition))
1706 alvherre@alvh.no-ip. 4346 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4347 [ - + ]:CBC 4 : if (WALK(mergeWhenClause->targetList))
1706 alvherre@alvh.no-ip. 4348 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4349 [ - + ]:CBC 4 : if (WALK(mergeWhenClause->values))
1706 alvherre@alvh.no-ip. 4350 :UBC 0 : return true;
4351 : : }
1706 alvherre@alvh.no-ip. 4352 :CBC 4 : break;
681 dean.a.rasheed@gmail 4353 : 36 : case T_ReturningClause:
4354 : : {
4355 : 36 : ReturningClause *returning = (ReturningClause *) node;
4356 : :
4357 [ - + ]: 36 : if (WALK(returning->options))
681 dean.a.rasheed@gmail 4358 :UBC 0 : return true;
681 dean.a.rasheed@gmail 4359 [ - + ]:CBC 36 : if (WALK(returning->exprs))
681 dean.a.rasheed@gmail 4360 :UBC 0 : return true;
4361 : : }
681 dean.a.rasheed@gmail 4362 :CBC 36 : break;
6629 tgl@sss.pgh.pa.us 4363 : 7812 : case T_SelectStmt:
4364 : : {
4365 : 7812 : SelectStmt *stmt = (SelectStmt *) node;
4366 : :
1530 4367 [ - + ]: 7812 : if (WALK(stmt->distinctClause))
6629 tgl@sss.pgh.pa.us 4368 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4369 [ - + ]:CBC 7812 : if (WALK(stmt->intoClause))
6629 tgl@sss.pgh.pa.us 4370 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4371 [ - + ]:CBC 7812 : if (WALK(stmt->targetList))
6629 tgl@sss.pgh.pa.us 4372 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4373 [ - + ]:CBC 7808 : if (WALK(stmt->fromClause))
6629 tgl@sss.pgh.pa.us 4374 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4375 [ - + ]:CBC 7752 : if (WALK(stmt->whereClause))
6629 tgl@sss.pgh.pa.us 4376 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4377 [ - + ]:CBC 7748 : if (WALK(stmt->groupClause))
6629 tgl@sss.pgh.pa.us 4378 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4379 [ - + ]:CBC 7748 : if (WALK(stmt->havingClause))
6629 tgl@sss.pgh.pa.us 4380 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4381 [ - + ]:CBC 7748 : if (WALK(stmt->windowClause))
6544 tgl@sss.pgh.pa.us 4382 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4383 [ - + ]:CBC 7748 : if (WALK(stmt->valuesLists))
6629 tgl@sss.pgh.pa.us 4384 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4385 [ - + ]:CBC 7748 : if (WALK(stmt->sortClause))
6629 tgl@sss.pgh.pa.us 4386 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4387 [ - + ]:CBC 7748 : if (WALK(stmt->limitOffset))
6629 tgl@sss.pgh.pa.us 4388 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4389 [ - + ]:CBC 7748 : if (WALK(stmt->limitCount))
6629 tgl@sss.pgh.pa.us 4390 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4391 [ - + ]:CBC 7748 : if (WALK(stmt->lockingClause))
6629 tgl@sss.pgh.pa.us 4392 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4393 [ - + ]:CBC 7748 : if (WALK(stmt->withClause))
5233 tgl@sss.pgh.pa.us 4394 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4395 [ - + ]:CBC 7748 : if (WALK(stmt->larg))
6629 tgl@sss.pgh.pa.us 4396 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4397 [ - + ]:CBC 7748 : if (WALK(stmt->rarg))
6629 tgl@sss.pgh.pa.us 4398 :UBC 0 : return true;
4399 : : }
6629 tgl@sss.pgh.pa.us 4400 :CBC 7740 : break;
2154 tgl@sss.pgh.pa.us 4401 :UBC 0 : case T_PLAssignStmt:
4402 : : {
4403 : 0 : PLAssignStmt *stmt = (PLAssignStmt *) node;
4404 : :
1530 4405 [ # # ]: 0 : if (WALK(stmt->indirection))
2154 4406 : 0 : return true;
1530 4407 [ # # ]: 0 : if (WALK(stmt->val))
2154 4408 : 0 : return true;
4409 : : }
4410 : 0 : break;
6629 tgl@sss.pgh.pa.us 4411 :CBC 12112 : case T_A_Expr:
4412 : : {
6379 bruce@momjian.us 4413 : 12112 : A_Expr *expr = (A_Expr *) node;
4414 : :
1530 tgl@sss.pgh.pa.us 4415 [ - + ]: 12112 : if (WALK(expr->lexpr))
6629 tgl@sss.pgh.pa.us 4416 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4417 [ - + ]:CBC 12112 : if (WALK(expr->rexpr))
6629 tgl@sss.pgh.pa.us 4418 :UBC 0 : return true;
4419 : : /* operator name is deemed uninteresting */
4420 : : }
6629 tgl@sss.pgh.pa.us 4421 :CBC 12112 : break;
4548 4422 : 4154 : case T_BoolExpr:
4423 : : {
4424 : 4154 : BoolExpr *expr = (BoolExpr *) node;
4425 : :
1530 4426 [ - + ]: 4154 : if (WALK(expr->args))
4548 tgl@sss.pgh.pa.us 4427 :UBC 0 : return true;
4428 : : }
4548 tgl@sss.pgh.pa.us 4429 :CBC 4154 : break;
6629 4430 : 25072 : case T_ColumnRef:
4431 : : /* we assume the fields contain nothing interesting */
4432 : 25072 : break;
4433 : 174 : case T_FuncCall:
4434 : : {
6379 bruce@momjian.us 4435 : 174 : FuncCall *fcall = (FuncCall *) node;
4436 : :
1530 tgl@sss.pgh.pa.us 4437 [ - + ]: 174 : if (WALK(fcall->args))
6629 tgl@sss.pgh.pa.us 4438 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4439 [ - + ]:CBC 174 : if (WALK(fcall->agg_order))
6192 tgl@sss.pgh.pa.us 4440 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4441 [ - + ]:CBC 174 : if (WALK(fcall->agg_filter))
4883 noah@leadboat.com 4442 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4443 [ - + ]:CBC 174 : if (WALK(fcall->over))
6544 tgl@sss.pgh.pa.us 4444 :UBC 0 : return true;
4445 : : /* function name is deemed uninteresting */
4446 : : }
6629 tgl@sss.pgh.pa.us 4447 :CBC 174 : break;
6260 tgl@sss.pgh.pa.us 4448 :UBC 0 : case T_NamedArgExpr:
1530 4449 : 0 : return WALK(((NamedArgExpr *) node)->arg);
6629 4450 : 0 : case T_A_Indices:
4451 : : {
6379 bruce@momjian.us 4452 : 0 : A_Indices *indices = (A_Indices *) node;
4453 : :
1530 tgl@sss.pgh.pa.us 4454 [ # # ]: 0 : if (WALK(indices->lidx))
6629 4455 : 0 : return true;
1530 4456 [ # # ]: 0 : if (WALK(indices->uidx))
6629 4457 : 0 : return true;
4458 : : }
4459 : 0 : break;
4460 : 0 : case T_A_Indirection:
4461 : : {
4462 : 0 : A_Indirection *indir = (A_Indirection *) node;
4463 : :
1530 4464 [ # # ]: 0 : if (WALK(indir->arg))
6629 4465 : 0 : return true;
1530 4466 [ # # ]: 0 : if (WALK(indir->indirection))
6629 4467 : 0 : return true;
4468 : : }
4469 : 0 : break;
6629 tgl@sss.pgh.pa.us 4470 :CBC 60 : case T_A_ArrayExpr:
1530 4471 : 60 : return WALK(((A_ArrayExpr *) node)->elements);
6629 4472 : 7294 : case T_ResTarget:
4473 : : {
6379 bruce@momjian.us 4474 : 7294 : ResTarget *rt = (ResTarget *) node;
4475 : :
1530 tgl@sss.pgh.pa.us 4476 [ - + ]: 7294 : if (WALK(rt->indirection))
6629 tgl@sss.pgh.pa.us 4477 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4478 [ - + ]:CBC 7294 : if (WALK(rt->val))
6629 tgl@sss.pgh.pa.us 4479 :UBC 0 : return true;
4480 : : }
6629 tgl@sss.pgh.pa.us 4481 :CBC 7290 : break;
4546 tgl@sss.pgh.pa.us 4482 :UBC 0 : case T_MultiAssignRef:
1530 4483 : 0 : return WALK(((MultiAssignRef *) node)->source);
6629 tgl@sss.pgh.pa.us 4484 :CBC 1102 : case T_TypeCast:
4485 : : {
6379 bruce@momjian.us 4486 : 1102 : TypeCast *tc = (TypeCast *) node;
4487 : :
1530 tgl@sss.pgh.pa.us 4488 [ - + ]: 1102 : if (WALK(tc->arg))
6629 tgl@sss.pgh.pa.us 4489 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4490 [ - + ]:CBC 1102 : if (WALK(tc->typeName))
6629 tgl@sss.pgh.pa.us 4491 :UBC 0 : return true;
4492 : : }
6629 tgl@sss.pgh.pa.us 4493 :CBC 1102 : break;
5772 peter_e@gmx.net 4494 : 50 : case T_CollateClause:
1530 tgl@sss.pgh.pa.us 4495 : 50 : return WALK(((CollateClause *) node)->arg);
6629 4496 : 24 : case T_SortBy:
1530 4497 : 24 : return WALK(((SortBy *) node)->node);
6544 4498 : 32 : case T_WindowDef:
4499 : : {
6379 bruce@momjian.us 4500 : 32 : WindowDef *wd = (WindowDef *) node;
4501 : :
1530 tgl@sss.pgh.pa.us 4502 [ - + ]: 32 : if (WALK(wd->partitionClause))
6544 tgl@sss.pgh.pa.us 4503 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4504 [ - + ]:CBC 32 : if (WALK(wd->orderClause))
6544 tgl@sss.pgh.pa.us 4505 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4506 [ - + ]:CBC 32 : if (WALK(wd->startOffset))
6133 tgl@sss.pgh.pa.us 4507 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4508 [ - + ]:CBC 32 : if (WALK(wd->endOffset))
6133 tgl@sss.pgh.pa.us 4509 :UBC 0 : return true;
4510 : : }
6544 tgl@sss.pgh.pa.us 4511 :CBC 32 : break;
6629 4512 : 416 : case T_RangeSubselect:
4513 : : {
4514 : 416 : RangeSubselect *rs = (RangeSubselect *) node;
4515 : :
1530 4516 [ - + ]: 416 : if (WALK(rs->subquery))
6629 tgl@sss.pgh.pa.us 4517 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4518 [ - + ]:CBC 412 : if (WALK(rs->alias))
6629 tgl@sss.pgh.pa.us 4519 :UBC 0 : return true;
4520 : : }
6629 tgl@sss.pgh.pa.us 4521 :CBC 412 : break;
4522 : 48 : case T_RangeFunction:
4523 : : {
4524 : 48 : RangeFunction *rf = (RangeFunction *) node;
4525 : :
1530 4526 [ - + ]: 48 : if (WALK(rf->functions))
6629 tgl@sss.pgh.pa.us 4527 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4528 [ - + ]:CBC 48 : if (WALK(rf->alias))
6629 tgl@sss.pgh.pa.us 4529 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4530 [ - + ]:CBC 48 : if (WALK(rf->coldeflist))
4755 tgl@sss.pgh.pa.us 4531 :UBC 0 : return true;
4532 : : }
6629 tgl@sss.pgh.pa.us 4533 :CBC 48 : break;
4144 tgl@sss.pgh.pa.us 4534 :UBC 0 : case T_RangeTableSample:
4535 : : {
4536 : 0 : RangeTableSample *rts = (RangeTableSample *) node;
4537 : :
1530 4538 [ # # ]: 0 : if (WALK(rts->relation))
4144 4539 : 0 : return true;
4540 : : /* method name is deemed uninteresting */
1530 4541 [ # # ]: 0 : if (WALK(rts->args))
4144 4542 : 0 : return true;
1530 4543 [ # # ]: 0 : if (WALK(rts->repeatable))
4144 4544 : 0 : return true;
4545 : : }
4546 : 0 : break;
3552 alvherre@alvh.no-ip. 4547 : 0 : case T_RangeTableFunc:
4548 : : {
4549 : 0 : RangeTableFunc *rtf = (RangeTableFunc *) node;
4550 : :
1530 tgl@sss.pgh.pa.us 4551 [ # # ]: 0 : if (WALK(rtf->docexpr))
3552 alvherre@alvh.no-ip. 4552 : 0 : return true;
1530 tgl@sss.pgh.pa.us 4553 [ # # ]: 0 : if (WALK(rtf->rowexpr))
3552 alvherre@alvh.no-ip. 4554 : 0 : return true;
1530 tgl@sss.pgh.pa.us 4555 [ # # ]: 0 : if (WALK(rtf->namespaces))
3552 alvherre@alvh.no-ip. 4556 : 0 : return true;
1530 tgl@sss.pgh.pa.us 4557 [ # # ]: 0 : if (WALK(rtf->columns))
3552 alvherre@alvh.no-ip. 4558 : 0 : return true;
1530 tgl@sss.pgh.pa.us 4559 [ # # ]: 0 : if (WALK(rtf->alias))
3552 alvherre@alvh.no-ip. 4560 : 0 : return true;
4561 : : }
4562 : 0 : break;
4563 : 0 : case T_RangeTableFuncCol:
4564 : : {
4565 : 0 : RangeTableFuncCol *rtfc = (RangeTableFuncCol *) node;
4566 : :
1530 tgl@sss.pgh.pa.us 4567 [ # # ]: 0 : if (WALK(rtfc->colexpr))
3552 alvherre@alvh.no-ip. 4568 : 0 : return true;
1530 tgl@sss.pgh.pa.us 4569 [ # # ]: 0 : if (WALK(rtfc->coldefexpr))
3552 alvherre@alvh.no-ip. 4570 : 0 : return true;
4571 : : }
4572 : 0 : break;
6629 tgl@sss.pgh.pa.us 4573 :CBC 1102 : case T_TypeName:
4574 : : {
6379 bruce@momjian.us 4575 : 1102 : TypeName *tn = (TypeName *) node;
4576 : :
1530 tgl@sss.pgh.pa.us 4577 [ - + ]: 1102 : if (WALK(tn->typmods))
6629 tgl@sss.pgh.pa.us 4578 :UBC 0 : return true;
1530 tgl@sss.pgh.pa.us 4579 [ - + ]:CBC 1102 : if (WALK(tn->arrayBounds))
6629 tgl@sss.pgh.pa.us 4580 :UBC 0 : return true;
4581 : : /* type name itself is deemed uninteresting */
4582 : : }
6629 tgl@sss.pgh.pa.us 4583 :CBC 1102 : break;
6629 tgl@sss.pgh.pa.us 4584 :UBC 0 : case T_ColumnDef:
4585 : : {
6379 bruce@momjian.us 4586 : 0 : ColumnDef *coldef = (ColumnDef *) node;
4587 : :
1530 tgl@sss.pgh.pa.us 4588 [ # # ]: 0 : if (WALK(coldef->typeName))
6629 4589 : 0 : return true;
1530 4590 [ # # ]: 0 : if (WALK(coldef->raw_default))
6629 4591 : 0 : return true;
1530 4592 [ # # ]: 0 : if (WALK(coldef->collClause))
5726 4593 : 0 : return true;
4594 : : /* for now, constraints are ignored */
4595 : : }
6629 4596 : 0 : break;
3841 4597 : 0 : case T_IndexElem:
4598 : : {
4599 : 0 : IndexElem *indelem = (IndexElem *) node;
4600 : :
1530 4601 [ # # ]: 0 : if (WALK(indelem->expr))
3841 4602 : 0 : return true;
4603 : : /* collation and opclass names are deemed uninteresting */
4604 : : }
4605 : 0 : break;
4214 andres@anarazel.de 4606 : 0 : case T_GroupingSet:
1530 tgl@sss.pgh.pa.us 4607 : 0 : return WALK(((GroupingSet *) node)->content);
6629 tgl@sss.pgh.pa.us 4608 :CBC 4 : case T_LockingClause:
1530 4609 : 4 : return WALK(((LockingClause *) node)->lockedRels);
6629 tgl@sss.pgh.pa.us 4610 :UBC 0 : case T_XmlSerialize:
4611 : : {
4612 : 0 : XmlSerialize *xs = (XmlSerialize *) node;
4613 : :
1530 4614 [ # # ]: 0 : if (WALK(xs->expr))
6629 4615 : 0 : return true;
1530 4616 [ # # ]: 0 : if (WALK(xs->typeName))
6629 4617 : 0 : return true;
4618 : : }
4619 : 0 : break;
4620 : 0 : case T_WithClause:
1530 4621 : 0 : return WALK(((WithClause *) node)->ctes);
4222 andres@anarazel.de 4622 : 0 : case T_InferClause:
4623 : : {
4624 : 0 : InferClause *stmt = (InferClause *) node;
4625 : :
1530 tgl@sss.pgh.pa.us 4626 [ # # ]: 0 : if (WALK(stmt->indexElems))
4222 andres@anarazel.de 4627 : 0 : return true;
1530 tgl@sss.pgh.pa.us 4628 [ # # ]: 0 : if (WALK(stmt->whereClause))
4222 andres@anarazel.de 4629 : 0 : return true;
4630 : : }
4631 : 0 : break;
4632 : 0 : case T_OnConflictClause:
4633 : : {
4634 : 0 : OnConflictClause *stmt = (OnConflictClause *) node;
4635 : :
1530 tgl@sss.pgh.pa.us 4636 [ # # ]: 0 : if (WALK(stmt->infer))
4222 andres@anarazel.de 4637 : 0 : return true;
1530 tgl@sss.pgh.pa.us 4638 [ # # ]: 0 : if (WALK(stmt->targetList))
4222 andres@anarazel.de 4639 : 0 : return true;
1530 tgl@sss.pgh.pa.us 4640 [ # # ]: 0 : if (WALK(stmt->whereClause))
4222 andres@anarazel.de 4641 : 0 : return true;
4642 : : }
4643 : 0 : break;
6629 tgl@sss.pgh.pa.us 4644 :CBC 12 : case T_CommonTableExpr:
4645 : : /* search_clause and cycle_clause are not interesting here */
1530 4646 : 12 : return WALK(((CommonTableExpr *) node)->ctequery);
1340 alvherre@alvh.no-ip. 4647 :UBC 0 : case T_JsonOutput:
4648 : : {
4649 : 0 : JsonOutput *out = (JsonOutput *) node;
4650 : :
4651 [ # # ]: 0 : if (WALK(out->typeName))
4652 : 0 : return true;
4653 [ # # ]: 0 : if (WALK(out->returning))
4654 : 0 : return true;
4655 : : }
4656 : 0 : break;
4657 : 0 : case T_JsonKeyValue:
4658 : : {
4659 : 0 : JsonKeyValue *jkv = (JsonKeyValue *) node;
4660 : :
4661 [ # # ]: 0 : if (WALK(jkv->key))
4662 : 0 : return true;
4663 [ # # ]: 0 : if (WALK(jkv->value))
4664 : 0 : return true;
4665 : : }
4666 : 0 : break;
4667 : 0 : case T_JsonObjectConstructor:
4668 : : {
4669 : 0 : JsonObjectConstructor *joc = (JsonObjectConstructor *) node;
4670 : :
4671 [ # # ]: 0 : if (WALK(joc->output))
4672 : 0 : return true;
4673 [ # # ]: 0 : if (WALK(joc->exprs))
4674 : 0 : return true;
4675 : : }
4676 : 0 : break;
4677 : 0 : case T_JsonArrayConstructor:
4678 : : {
4679 : 0 : JsonArrayConstructor *jac = (JsonArrayConstructor *) node;
4680 : :
4681 [ # # ]: 0 : if (WALK(jac->output))
4682 : 0 : return true;
4683 [ # # ]: 0 : if (WALK(jac->exprs))
4684 : 0 : return true;
4685 : : }
4686 : 0 : break;
4687 : 0 : case T_JsonAggConstructor:
4688 : : {
4689 : 0 : JsonAggConstructor *ctor = (JsonAggConstructor *) node;
4690 : :
4691 [ # # ]: 0 : if (WALK(ctor->output))
4692 : 0 : return true;
4693 [ # # ]: 0 : if (WALK(ctor->agg_order))
4694 : 0 : return true;
4695 [ # # ]: 0 : if (WALK(ctor->agg_filter))
4696 : 0 : return true;
4697 [ # # ]: 0 : if (WALK(ctor->over))
4698 : 0 : return true;
4699 : : }
4700 : 0 : break;
4701 : 0 : case T_JsonObjectAgg:
4702 : : {
4703 : 0 : JsonObjectAgg *joa = (JsonObjectAgg *) node;
4704 : :
4705 [ # # ]: 0 : if (WALK(joa->constructor))
4706 : 0 : return true;
4707 [ # # ]: 0 : if (WALK(joa->arg))
4708 : 0 : return true;
4709 : : }
4710 : 0 : break;
4711 : 0 : case T_JsonArrayAgg:
4712 : : {
4713 : 0 : JsonArrayAgg *jaa = (JsonArrayAgg *) node;
4714 : :
4715 [ # # ]: 0 : if (WALK(jaa->constructor))
4716 : 0 : return true;
4717 [ # # ]: 0 : if (WALK(jaa->arg))
4718 : 0 : return true;
4719 : : }
4720 : 0 : break;
4721 : 0 : case T_JsonArrayQueryConstructor:
4722 : : {
4723 : 0 : JsonArrayQueryConstructor *jaqc = (JsonArrayQueryConstructor *) node;
4724 : :
4725 [ # # ]: 0 : if (WALK(jaqc->output))
4726 : 0 : return true;
4727 [ # # ]: 0 : if (WALK(jaqc->query))
4728 : 0 : return true;
4729 : : }
4730 : 0 : break;
6629 tgl@sss.pgh.pa.us 4731 : 0 : default:
4732 [ # # ]: 0 : elog(ERROR, "unrecognized node type: %d",
4733 : : (int) nodeTag(node));
4734 : : break;
4735 : : }
6629 tgl@sss.pgh.pa.us 4736 :CBC 86085 : return false;
4737 : : }
4738 : :
4739 : : /*
4740 : : * planstate_tree_walker --- walk plan state trees
4741 : : *
4742 : : * The walker has already visited the current node, and so we need only
4743 : : * recurse into any sub-nodes it has.
4744 : : */
4745 : : pg_attribute_no_sanitize_function()
4746 : : bool
1530 4747 : 935609 : planstate_tree_walker_impl(PlanState *planstate,
4748 : : planstate_tree_walker_callback walker,
4749 : : void *context)
4750 : : {
4090 rhaas@postgresql.org 4751 : 935609 : Plan *plan = planstate->plan;
4752 : : ListCell *lc;
4753 : :
4754 : : /* We don't need implicit coercions to Node here */
4755 : : #define PSWALK(n) walker(n, context)
4756 : :
4757 : : /* Guard against stack overflow due to overly complex plan trees */
2910 tgl@sss.pgh.pa.us 4758 : 935609 : check_stack_depth();
4759 : :
4760 : : /* initPlan-s */
4090 rhaas@postgresql.org 4761 [ - + ]: 935609 : if (planstate_walk_subplans(planstate->initPlan, walker, context))
4090 rhaas@postgresql.org 4762 :UBC 0 : return true;
4763 : :
4764 : : /* lefttree */
4090 rhaas@postgresql.org 4765 [ + + ]:CBC 935609 : if (outerPlanState(planstate))
4766 : : {
1530 tgl@sss.pgh.pa.us 4767 [ - + ]: 367538 : if (PSWALK(outerPlanState(planstate)))
4090 rhaas@postgresql.org 4768 :UBC 0 : return true;
4769 : : }
4770 : :
4771 : : /* righttree */
4090 rhaas@postgresql.org 4772 [ + + ]:CBC 935609 : if (innerPlanState(planstate))
4773 : : {
1530 tgl@sss.pgh.pa.us 4774 [ - + ]: 105337 : if (PSWALK(innerPlanState(planstate)))
4090 rhaas@postgresql.org 4775 :UBC 0 : return true;
4776 : : }
4777 : :
4778 : : /* special child plans */
4090 rhaas@postgresql.org 4779 [ + + + + :CBC 935609 : switch (nodeTag(plan))
+ + + ]
4780 : : {
4781 : 13273 : case T_Append:
3157 alvherre@alvh.no-ip. 4782 [ - + ]: 13273 : if (planstate_walk_members(((AppendState *) planstate)->appendplans,
4783 : : ((AppendState *) planstate)->as_nplans,
4784 : : walker, context))
4090 rhaas@postgresql.org 4785 :UBC 0 : return true;
4090 rhaas@postgresql.org 4786 :CBC 13273 : break;
4787 : 462 : case T_MergeAppend:
3157 alvherre@alvh.no-ip. 4788 [ - + ]: 462 : if (planstate_walk_members(((MergeAppendState *) planstate)->mergeplans,
4789 : : ((MergeAppendState *) planstate)->ms_nplans,
4790 : : walker, context))
4090 rhaas@postgresql.org 4791 :UBC 0 : return true;
4090 rhaas@postgresql.org 4792 :CBC 462 : break;
4793 : 154 : case T_BitmapAnd:
3157 alvherre@alvh.no-ip. 4794 [ - + ]: 154 : if (planstate_walk_members(((BitmapAndState *) planstate)->bitmapplans,
4795 : : ((BitmapAndState *) planstate)->nplans,
4796 : : walker, context))
4090 rhaas@postgresql.org 4797 :UBC 0 : return true;
4090 rhaas@postgresql.org 4798 :CBC 154 : break;
4799 : 276 : case T_BitmapOr:
3157 alvherre@alvh.no-ip. 4800 [ - + ]: 276 : if (planstate_walk_members(((BitmapOrState *) planstate)->bitmapplans,
4801 : : ((BitmapOrState *) planstate)->nplans,
4802 : : walker, context))
4090 rhaas@postgresql.org 4803 :UBC 0 : return true;
4090 rhaas@postgresql.org 4804 :CBC 276 : break;
4805 : 16110 : case T_SubqueryScan:
1530 tgl@sss.pgh.pa.us 4806 [ - + ]: 16110 : if (PSWALK(((SubqueryScanState *) planstate)->subplan))
4090 rhaas@postgresql.org 4807 :UBC 0 : return true;
4090 rhaas@postgresql.org 4808 :CBC 16110 : break;
4085 rhaas@postgresql.org 4809 :GBC 14 : case T_CustomScan:
3824 4810 [ - + - - : 14 : foreach(lc, ((CustomScanState *) planstate)->custom_ps)
- + ]
4811 : : {
1530 tgl@sss.pgh.pa.us 4812 [ # # ]:UBC 0 : if (PSWALK(lfirst(lc)))
4085 rhaas@postgresql.org 4813 : 0 : return true;
4814 : : }
4085 rhaas@postgresql.org 4815 :GBC 14 : break;
4090 rhaas@postgresql.org 4816 :CBC 905320 : default:
4817 : 905320 : break;
4818 : : }
4819 : :
4820 : : /* subPlan-s */
4821 [ - + ]: 935609 : if (planstate_walk_subplans(planstate->subPlan, walker, context))
4090 rhaas@postgresql.org 4822 :UBC 0 : return true;
4823 : :
4090 rhaas@postgresql.org 4824 :CBC 935609 : return false;
4825 : : }
4826 : :
4827 : : /*
4828 : : * Walk a list of SubPlans (or initPlans, which also use SubPlan nodes).
4829 : : */
4830 : : pg_attribute_no_sanitize_function()
4831 : : static bool
3867 4832 : 1871218 : planstate_walk_subplans(List *plans,
4833 : : planstate_tree_walker_callback walker,
4834 : : void *context)
4835 : : {
4836 : : ListCell *lc;
4837 : :
4090 4838 [ + + + + : 1900196 : foreach(lc, plans)
+ + ]
4839 : : {
3519 tgl@sss.pgh.pa.us 4840 : 28978 : SubPlanState *sps = lfirst_node(SubPlanState, lc);
4841 : :
1530 4842 [ - + ]: 28978 : if (PSWALK(sps->planstate))
4090 rhaas@postgresql.org 4843 :UBC 0 : return true;
4844 : : }
4845 : :
4090 rhaas@postgresql.org 4846 :CBC 1871218 : return false;
4847 : : }
4848 : :
4849 : : /*
4850 : : * Walk the constituent plans of a ModifyTable, Append, MergeAppend,
4851 : : * BitmapAnd, or BitmapOr node.
4852 : : */
4853 : : pg_attribute_no_sanitize_function()
4854 : : static bool
3157 alvherre@alvh.no-ip. 4855 : 14165 : planstate_walk_members(PlanState **planstates, int nplans,
4856 : : planstate_tree_walker_callback walker,
4857 : : void *context)
4858 : : {
368 peter@eisentraut.org 4859 [ + + ]: 60045 : for (int j = 0; j < nplans; j++)
4860 : : {
1530 tgl@sss.pgh.pa.us 4861 [ - + ]: 45880 : if (PSWALK(planstates[j]))
4090 rhaas@postgresql.org 4862 :UBC 0 : return true;
4863 : : }
4864 : :
4090 rhaas@postgresql.org 4865 :CBC 14165 : return false;
4866 : : }
|