mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Make some small planner API cleanups.
Move a few very simple node-creation and node-type-testing functions from the planner's clauses.c to nodes/makefuncs and nodes/nodeFuncs. There's nothing planner-specific about them, as evidenced by the number of other places that were using them. While at it, rename and_clause() etc to is_andclause() etc, to clarify that they are node-type-testing functions not node-creation functions. And use "static inline" implementations for the shortest ones. Also, modify flatten_join_alias_vars() and some subsidiary functions to take a Query not a PlannerInfo to define the join structure that Vars should be translated according to. They were only using the "parse" field of the PlannerInfo anyway, so this just requires removing one level of indirection. The advantage is that now parse_agg.c can use flatten_join_alias_vars() without the horrid kluge of creating an incomplete PlannerInfo, which will allow that file to be decoupled from relation.h in a subsequent patch. Discussion: https://postgr.es/m/11460.1548706639@sss.pgh.pa.us
This commit is contained in:
@ -43,7 +43,7 @@ typedef struct
|
||||
{
|
||||
ParseState *pstate;
|
||||
Query *qry;
|
||||
PlannerInfo *root;
|
||||
bool hasJoinRTEs;
|
||||
List *groupClauses;
|
||||
List *groupClauseCommonVars;
|
||||
bool have_non_var_grouping;
|
||||
@ -65,7 +65,7 @@ static void check_ungrouped_columns(Node *node, ParseState *pstate, Query *qry,
|
||||
static bool check_ungrouped_columns_walker(Node *node,
|
||||
check_ungrouped_columns_context *context);
|
||||
static void finalize_grouping_exprs(Node *node, ParseState *pstate, Query *qry,
|
||||
List *groupClauses, PlannerInfo *root,
|
||||
List *groupClauses, bool hasJoinRTEs,
|
||||
bool have_non_var_grouping);
|
||||
static bool finalize_grouping_exprs_walker(Node *node,
|
||||
check_ungrouped_columns_context *context);
|
||||
@ -1039,7 +1039,6 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
|
||||
ListCell *l;
|
||||
bool hasJoinRTEs;
|
||||
bool hasSelfRefRTEs;
|
||||
PlannerInfo *root = NULL;
|
||||
Node *clause;
|
||||
|
||||
/* This should only be called if we found aggregates or grouping */
|
||||
@ -1130,20 +1129,11 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
|
||||
* If there are join alias vars involved, we have to flatten them to the
|
||||
* underlying vars, so that aliased and unaliased vars will be correctly
|
||||
* taken as equal. We can skip the expense of doing this if no rangetable
|
||||
* entries are RTE_JOIN kind. We use the planner's flatten_join_alias_vars
|
||||
* routine to do the flattening; it wants a PlannerInfo root node, which
|
||||
* fortunately can be mostly dummy.
|
||||
* entries are RTE_JOIN kind.
|
||||
*/
|
||||
if (hasJoinRTEs)
|
||||
{
|
||||
root = makeNode(PlannerInfo);
|
||||
root->parse = qry;
|
||||
root->planner_cxt = CurrentMemoryContext;
|
||||
root->hasJoinRTEs = true;
|
||||
|
||||
groupClauses = (List *) flatten_join_alias_vars(root,
|
||||
groupClauses = (List *) flatten_join_alias_vars(qry,
|
||||
(Node *) groupClauses);
|
||||
}
|
||||
|
||||
/*
|
||||
* Detect whether any of the grouping expressions aren't simple Vars; if
|
||||
@ -1183,10 +1173,10 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
|
||||
*/
|
||||
clause = (Node *) qry->targetList;
|
||||
finalize_grouping_exprs(clause, pstate, qry,
|
||||
groupClauses, root,
|
||||
groupClauses, hasJoinRTEs,
|
||||
have_non_var_grouping);
|
||||
if (hasJoinRTEs)
|
||||
clause = flatten_join_alias_vars(root, clause);
|
||||
clause = flatten_join_alias_vars(qry, clause);
|
||||
check_ungrouped_columns(clause, pstate, qry,
|
||||
groupClauses, groupClauseCommonVars,
|
||||
have_non_var_grouping,
|
||||
@ -1194,10 +1184,10 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
|
||||
|
||||
clause = (Node *) qry->havingQual;
|
||||
finalize_grouping_exprs(clause, pstate, qry,
|
||||
groupClauses, root,
|
||||
groupClauses, hasJoinRTEs,
|
||||
have_non_var_grouping);
|
||||
if (hasJoinRTEs)
|
||||
clause = flatten_join_alias_vars(root, clause);
|
||||
clause = flatten_join_alias_vars(qry, clause);
|
||||
check_ungrouped_columns(clause, pstate, qry,
|
||||
groupClauses, groupClauseCommonVars,
|
||||
have_non_var_grouping,
|
||||
@ -1245,7 +1235,7 @@ check_ungrouped_columns(Node *node, ParseState *pstate, Query *qry,
|
||||
|
||||
context.pstate = pstate;
|
||||
context.qry = qry;
|
||||
context.root = NULL;
|
||||
context.hasJoinRTEs = false; /* assume caller flattened join Vars */
|
||||
context.groupClauses = groupClauses;
|
||||
context.groupClauseCommonVars = groupClauseCommonVars;
|
||||
context.have_non_var_grouping = have_non_var_grouping;
|
||||
@ -1445,14 +1435,14 @@ check_ungrouped_columns_walker(Node *node,
|
||||
*/
|
||||
static void
|
||||
finalize_grouping_exprs(Node *node, ParseState *pstate, Query *qry,
|
||||
List *groupClauses, PlannerInfo *root,
|
||||
List *groupClauses, bool hasJoinRTEs,
|
||||
bool have_non_var_grouping)
|
||||
{
|
||||
check_ungrouped_columns_context context;
|
||||
|
||||
context.pstate = pstate;
|
||||
context.qry = qry;
|
||||
context.root = root;
|
||||
context.hasJoinRTEs = hasJoinRTEs;
|
||||
context.groupClauses = groupClauses;
|
||||
context.groupClauseCommonVars = NIL;
|
||||
context.have_non_var_grouping = have_non_var_grouping;
|
||||
@ -1525,8 +1515,8 @@ finalize_grouping_exprs_walker(Node *node,
|
||||
Node *expr = lfirst(lc);
|
||||
Index ref = 0;
|
||||
|
||||
if (context->root)
|
||||
expr = flatten_join_alias_vars(context->root, expr);
|
||||
if (context->hasJoinRTEs)
|
||||
expr = flatten_join_alias_vars(context->qry, expr);
|
||||
|
||||
/*
|
||||
* Each expression must match a grouping entry at the current
|
||||
|
Reference in New Issue
Block a user