1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-31 17:02:12 +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:
Tom Lane
2019-01-29 15:26:44 -05:00
parent e77cfa54d7
commit a1b8c41e99
30 changed files with 309 additions and 345 deletions

View File

@@ -60,7 +60,7 @@ typedef struct
typedef struct
{
PlannerInfo *root;
Query *query; /* outer Query */
int sublevels_up;
bool possible_sublink; /* could aliases include a SubLink? */
bool inserted_sublink; /* have we inserted a SubLink? */
@@ -78,7 +78,7 @@ static bool pull_var_clause_walker(Node *node,
pull_var_clause_context *context);
static Node *flatten_join_alias_vars_mutator(Node *node,
flatten_join_alias_vars_context *context);
static Relids alias_relid_set(PlannerInfo *root, Relids relids);
static Relids alias_relid_set(Query *query, Relids relids);
/*
@@ -667,16 +667,16 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context)
* subqueries).
*/
Node *
flatten_join_alias_vars(PlannerInfo *root, Node *node)
flatten_join_alias_vars(Query *query, Node *node)
{
flatten_join_alias_vars_context context;
context.root = root;
context.query = query;
context.sublevels_up = 0;
/* flag whether join aliases could possibly contain SubLinks */
context.possible_sublink = root->parse->hasSubLinks;
context.possible_sublink = query->hasSubLinks;
/* if hasSubLinks is already true, no need to work hard */
context.inserted_sublink = root->parse->hasSubLinks;
context.inserted_sublink = query->hasSubLinks;
return flatten_join_alias_vars_mutator(node, &context);
}
@@ -696,7 +696,7 @@ flatten_join_alias_vars_mutator(Node *node,
/* No change unless Var belongs to a JOIN of the target level */
if (var->varlevelsup != context->sublevels_up)
return node; /* no need to copy, really */
rte = rt_fetch(var->varno, context->root->parse->rtable);
rte = rt_fetch(var->varno, context->query->rtable);
if (rte->rtekind != RTE_JOIN)
return node;
if (var->varattno == InvalidAttrNumber)
@@ -783,7 +783,7 @@ flatten_join_alias_vars_mutator(Node *node,
/* now fix PlaceHolderVar's relid sets */
if (phv->phlevelsup == context->sublevels_up)
{
phv->phrels = alias_relid_set(context->root,
phv->phrels = alias_relid_set(context->query,
phv->phrels);
}
return (Node *) phv;
@@ -823,7 +823,7 @@ flatten_join_alias_vars_mutator(Node *node,
* underlying base relids
*/
static Relids
alias_relid_set(PlannerInfo *root, Relids relids)
alias_relid_set(Query *query, Relids relids)
{
Relids result = NULL;
int rtindex;
@@ -831,10 +831,10 @@ alias_relid_set(PlannerInfo *root, Relids relids)
rtindex = -1;
while ((rtindex = bms_next_member(relids, rtindex)) >= 0)
{
RangeTblEntry *rte = rt_fetch(rtindex, root->parse->rtable);
RangeTblEntry *rte = rt_fetch(rtindex, query->rtable);
if (rte->rtekind == RTE_JOIN)
result = bms_join(result, get_relids_for_join(root, rtindex));
result = bms_join(result, get_relids_for_join(query, rtindex));
else
result = bms_add_member(result, rtindex);
}