Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit18c0da8

Browse files
committed
Split QTW_EXAMINE_RTES flag into QTW_EXAMINE_RTES_BEFORE/_AFTER.
This change allows callers of query_tree_walker() to choose whetherto visit an RTE before or after visiting the contents of the RTE(i.e., prefix or postfix tree order). All existing users ofQTW_EXAMINE_RTES want the QTW_EXAMINE_RTES_BEFORE behavior, butan upcoming patch will want QTW_EXAMINE_RTES_AFTER, and it seemslike a potentially useful change on its own.Andreas Karlsson (extracted from CTE inlining patch)Discussion:https://postgr.es/m/8810.1542402910@sss.pgh.pa.us
1 parentff750ce commit18c0da8

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

‎src/backend/nodes/nodeFuncs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ expression_tree_walker(Node *node,
22552255
* Some callers want to suppress visitation of certain items in the sub-Query,
22562256
* typically because they need to process them specially, or don't actually
22572257
* want to recurse into subqueries. This is supported by the flags argument,
2258-
* which is the bitwise OR of flag values to suppress visitation of
2258+
* which is the bitwise OR of flag values toadd orsuppress visitation of
22592259
* indicated items. (More flag bits may be added as needed.)
22602260
*/
22612261
bool
@@ -2314,8 +2314,12 @@ range_table_walker(List *rtable,
23142314
{
23152315
RangeTblEntry*rte= (RangeTblEntry*)lfirst(rt);
23162316

2317-
/* For historical reasons, visiting RTEs is not the default */
2318-
if (flags&QTW_EXAMINE_RTES)
2317+
/*
2318+
* Walkers might need to examine the RTE node itself either before or
2319+
* after visiting its contents (or, conceivably, both). Note that if
2320+
* you specify neither flag, the walker won't visit the RTE at all.
2321+
*/
2322+
if (flags&QTW_EXAMINE_RTES_BEFORE)
23192323
if (walker(rte,context))
23202324
return true;
23212325

@@ -2355,6 +2359,10 @@ range_table_walker(List *rtable,
23552359

23562360
if (walker(rte->securityQuals,context))
23572361
return true;
2362+
2363+
if (flags&QTW_EXAMINE_RTES_AFTER)
2364+
if (walker(rte,context))
2365+
return true;
23582366
}
23592367
return false;
23602368
}

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ flatten_unplanned_rtes(PlannerGlobal *glob, RangeTblEntry *rte)
340340
(void)query_tree_walker(rte->subquery,
341341
flatten_rtes_walker,
342342
(void*)glob,
343-
QTW_EXAMINE_RTES);
343+
QTW_EXAMINE_RTES_BEFORE);
344344
}
345345

346346
staticbool
@@ -363,7 +363,7 @@ flatten_rtes_walker(Node *node, PlannerGlobal *glob)
363363
returnquery_tree_walker((Query*)node,
364364
flatten_rtes_walker,
365365
(void*)glob,
366-
QTW_EXAMINE_RTES);
366+
QTW_EXAMINE_RTES_BEFORE);
367367
}
368368
returnexpression_tree_walker(node,flatten_rtes_walker,
369369
(void*)glob);

‎src/backend/rewrite/rewriteManip.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ IncrementVarSublevelsUp_walker(Node *node,
761761
result=query_tree_walker((Query*)node,
762762
IncrementVarSublevelsUp_walker,
763763
(void*)context,
764-
QTW_EXAMINE_RTES);
764+
QTW_EXAMINE_RTES_BEFORE);
765765
context->min_sublevels_up--;
766766
returnresult;
767767
}
@@ -785,7 +785,7 @@ IncrementVarSublevelsUp(Node *node, int delta_sublevels_up,
785785
query_or_expression_tree_walker(node,
786786
IncrementVarSublevelsUp_walker,
787787
(void*)&context,
788-
QTW_EXAMINE_RTES);
788+
QTW_EXAMINE_RTES_BEFORE);
789789
}
790790

791791
/*
@@ -804,7 +804,7 @@ IncrementVarSublevelsUp_rtable(List *rtable, int delta_sublevels_up,
804804
range_table_walker(rtable,
805805
IncrementVarSublevelsUp_walker,
806806
(void*)&context,
807-
QTW_EXAMINE_RTES);
807+
QTW_EXAMINE_RTES_BEFORE);
808808
}
809809

810810

‎src/include/nodes/nodeFuncs.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
#defineQTW_IGNORE_RC_SUBQUERIES0x03/* both of above */
2323
#defineQTW_IGNORE_JOINALIASES0x04/* JOIN alias var lists */
2424
#defineQTW_IGNORE_RANGE_TABLE0x08/* skip rangetable entirely */
25-
#defineQTW_EXAMINE_RTES0x10/* examine RTEs */
26-
#defineQTW_DONT_COPY_QUERY0x20/* do not copy top Query */
25+
#defineQTW_EXAMINE_RTES_BEFORE0x10/* examine RTE nodes before their
26+
* contents */
27+
#defineQTW_EXAMINE_RTES_AFTER0x20/* examine RTE nodes after their
28+
* contents */
29+
#defineQTW_DONT_COPY_QUERY0x40/* do not copy top Query */
2730

2831
/* callback function for check_functions_in_node */
2932
typedefbool (*check_function_callback) (Oidfunc_id,void*context);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp