Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 974bdd9

Browse files
committed
On second thought, expression_tree_walker should handle bare
SubLink nodes after all ...
1 parent db4a6a2 commit 974bdd9

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

src/backend/optimizer/util/clauses.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.36 1999/06/19 03:41:45 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.37 1999/06/21 01:18:02 tgl Exp $
1111
*
1212
* HISTORY
1313
* AUTHOR DATE MAJOR EVENT
@@ -810,7 +810,8 @@ CommuteClause(Node *clause)
810810
* The walker routine should return "false" to continue the tree walk, or
811811
* "true" to abort the walk and immediately return "true" to the top-level
812812
* caller. This can be used to short-circuit the traversal if the walker
813-
* has found what it came for.
813+
* has found what it came for. "false" is returned to the top-level caller
814+
* iff no invocation of the walker returned "true".
814815
*
815816
* The node types handled by expression_tree_walker include all those
816817
* normally found in target lists and qualifier clauses during the planning
@@ -827,10 +828,11 @@ CommuteClause(Node *clause)
827828
* appropriate behavior by recognizing subplan nodes and doing the right
828829
* thing.
829830
*
830-
* Bare SubLink nodes (without a SUBPLAN_EXPR) will trigger an error unless
831-
* detected and processed by the walker. We expect that walkers used before
832-
* sublink processing is done will handle them properly. (XXX Maybe ignoring
833-
* them would be better default behavior?)
831+
* Bare SubLink nodes (without a SUBPLAN_EXPR) are handled by recursing into
832+
* the "lefthand" argument list only. (A bare SubLink should be seen only if
833+
* the tree has not yet been processed by subselect.c.) Again, this can be
834+
* overridden by the walker, but it seems to be the most useful default
835+
* behavior.
834836
*--------------------
835837
*/
836838

@@ -923,6 +925,12 @@ expression_tree_walker(Node *node, bool (*walker) (), void *context)
923925
return true;
924926
}
925927
break;
928+
case T_SubLink:
929+
/* A "bare" SubLink (note we will not come here if we found
930+
* a SUBPLAN_EXPR node above). Examine the lefthand side,
931+
* but not the oper list nor the subquery.
932+
*/
933+
return walker(((SubLink *) node)->lefthand, context);
926934
case T_List:
927935
foreach(temp, (List *) node)
928936
{

src/backend/parser/parse_agg.c

+10-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.22 1999/06/19 03:48:31 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.23 1999/06/21 01:18:02 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -43,9 +43,7 @@ static bool exprIsAggOrGroupCol_walker(Node *node, List *groupClauses);
4343
* Returns true if any aggregate found.
4444
*
4545
* NOTE: we assume that the given clause has been transformed suitably for
46-
* parser output. This means we can use the planner's expression_tree_walker,
47-
* except that we have to process SubLink nodes specially, since they haven't
48-
* been turned into SubPlan nodes yet.
46+
* parser output. This means we can use the planner's expression_tree_walker.
4947
*/
5048
static bool
5149
contain_agg_clause(Node *clause)
@@ -60,12 +58,6 @@ contain_agg_clause_walker(Node *node, void *context)
6058
return false;
6159
if (IsA(node, Aggref))
6260
return true; /* abort the tree traversal and return true */
63-
if (IsA(node, SubLink))
64-
{
65-
/* Examine the lefthand side, but not the oper list nor the subquery */
66-
SubLink *sublink = (SubLink *) node;
67-
return contain_agg_clause_walker((Node *) sublink->lefthand, context);
68-
}
6961
return expression_tree_walker(node, contain_agg_clause_walker, context);
7062
}
7163

@@ -75,16 +67,15 @@ contain_agg_clause_walker(Node *node, void *context)
7567
* other than within the arguments of aggregate functions.
7668
*
7769
* NOTE: we assume that the given clause has been transformed suitably for
78-
* parser output. This means we can use the planner's expression_tree_walker,
79-
* except that we have to process SubLink nodes specially, since they haven't
80-
* been turned into SubPlan nodes yet.
70+
* parser output. This means we can use the planner's expression_tree_walker.
8171
*
82-
* NOTE: in the case of a SubLink, we do not descend into the subquery. This
83-
* means we will fail to detect ungrouped columns that appear as outer-level
84-
* variables within a subquery. That seems unreasonably hard to handle here.
85-
* Instead, we expect the planner to check for ungrouped columns after it's
86-
* found all the outer-level references inside the subquery and converted
87-
* them into a list of parameters for the subquery.
72+
* NOTE: in the case of a SubLink, expression_tree_walker does not descend
73+
* into the subquery. This means we will fail to detect ungrouped columns
74+
* that appear as outer-level variables within a subquery. That case seems
75+
* unreasonably hard to handle here. Instead, we expect the planner to check
76+
* for ungrouped columns after it's found all the outer-level references
77+
* inside the subquery and converted them into a list of parameters for the
78+
* subquery.
8879
*/
8980
static bool
9081
exprIsAggOrGroupCol(Node *expr, List *groupClauses)
@@ -128,13 +119,6 @@ exprIsAggOrGroupCol_walker(Node *node, List *groupClauses)
128119
return false; /* outer-level Var is acceptable */
129120
}
130121
/* Otherwise, recurse. */
131-
if (IsA(node, SubLink))
132-
{
133-
/* Examine the lefthand side, but not the oper list nor the subquery */
134-
SubLink *sublink = (SubLink *) node;
135-
return exprIsAggOrGroupCol_walker((Node *) sublink->lefthand,
136-
groupClauses);
137-
}
138122
return expression_tree_walker(node, exprIsAggOrGroupCol_walker,
139123
(void *) groupClauses);
140124
}

0 commit comments

Comments
 (0)