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