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