1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +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

@@ -497,7 +497,7 @@ pull_up_sublinks_qual_recurse(PlannerInfo *root, Node *node,
/* Else return it unmodified */
return node;
}
if (not_clause(node))
if (is_notclause(node))
{
/* If the immediate argument of NOT is EXISTS, try to convert */
SubLink *sublink = (SubLink *) get_notclausearg((Expr *) node);
@@ -564,7 +564,7 @@ pull_up_sublinks_qual_recurse(PlannerInfo *root, Node *node,
/* Else return it unmodified */
return node;
}
if (and_clause(node))
if (is_andclause(node))
{
/* Recurse into AND clause */
List *newclauses = NIL;
@@ -968,7 +968,7 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
* maybe even in the rewriter; but for now let's just fix this case here.)
*/
subquery->targetList = (List *)
flatten_join_alias_vars(subroot, (Node *) subquery->targetList);
flatten_join_alias_vars(subroot->parse, (Node *) subquery->targetList);
/*
* Adjust level-0 varnos in subquery so that we can append its rangetable
@@ -3317,11 +3317,11 @@ get_relids_in_jointree(Node *jtnode, bool include_joins)
* get_relids_for_join: get set of base RT indexes making up a join
*/
Relids
get_relids_for_join(PlannerInfo *root, int joinrelid)
get_relids_for_join(Query *query, int joinrelid)
{
Node *jtnode;
jtnode = find_jointree_node_for_rel((Node *) root->parse->jointree,
jtnode = find_jointree_node_for_rel((Node *) query->jointree,
joinrelid);
if (!jtnode)
elog(ERROR, "could not find join node %d", joinrelid);

View File

@@ -32,6 +32,7 @@
#include "postgres.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/prep.h"
#include "utils/lsyscache.h"
@@ -333,7 +334,7 @@ pull_ands(List *andlist)
* built a new arglist not shared with any other expr. Otherwise we'd
* need a list_copy here.
*/
if (and_clause(subexpr))
if (is_andclause(subexpr))
out_list = list_concat(out_list,
pull_ands(((BoolExpr *) subexpr)->args));
else
@@ -365,7 +366,7 @@ pull_ors(List *orlist)
* built a new arglist not shared with any other expr. Otherwise we'd
* need a list_copy here.
*/
if (or_clause(subexpr))
if (is_orclause(subexpr))
out_list = list_concat(out_list,
pull_ors(((BoolExpr *) subexpr)->args));
else
@@ -415,7 +416,7 @@ pull_ors(List *orlist)
static Expr *
find_duplicate_ors(Expr *qual, bool is_check)
{
if (or_clause((Node *) qual))
if (is_orclause(qual))
{
List *orlist = NIL;
ListCell *temp;
@@ -459,7 +460,7 @@ find_duplicate_ors(Expr *qual, bool is_check)
/* Now we can look for duplicate ORs */
return process_duplicate_ors(orlist);
}
else if (and_clause((Node *) qual))
else if (is_andclause(qual))
{
List *andlist = NIL;
ListCell *temp;
@@ -550,7 +551,7 @@ process_duplicate_ors(List *orlist)
{
Expr *clause = (Expr *) lfirst(temp);
if (and_clause((Node *) clause))
if (is_andclause(clause))
{
List *subclauses = ((BoolExpr *) clause)->args;
int nclauses = list_length(subclauses);
@@ -588,7 +589,7 @@ process_duplicate_ors(List *orlist)
{
Expr *clause = (Expr *) lfirst(temp2);
if (and_clause((Node *) clause))
if (is_andclause(clause))
{
if (!list_member(((BoolExpr *) clause)->args, refclause))
{
@@ -631,7 +632,7 @@ process_duplicate_ors(List *orlist)
{
Expr *clause = (Expr *) lfirst(temp);
if (and_clause((Node *) clause))
if (is_andclause(clause))
{
List *subclauses = ((BoolExpr *) clause)->args;