92 int parentRTindex,
Query *setOpQuery,
110 Node *jtnode,
bool restricted,
111 Relids safe_upper_varnos);
129 List *forced_null_vars);
131 int rtindex,
Relids relids);
134 Relids *dropped_outer_joins);
139 Node *node,
int varno);
141 int varno,
Relids subrelids);
184 have_action[
action->matchKind] =
true;
201 joinrte->joinmergedcols = 0;
202 joinrte->joinaliasvars =
vars;
203 joinrte->joinleftcols =
NIL;
204 joinrte->joinrightcols =
NIL;
205 joinrte->join_using_alias = NULL;
207 joinrte->alias = NULL;
209 joinrte->lateral =
false;
210 joinrte->
inh =
false;
211 joinrte->inFromCl =
true;
251 elog(
ERROR,
"unrecognized source node type: %d",
262 joinexpr->usingClause =
NIL;
263 joinexpr->join_using_alias = NULL;
265 joinexpr->alias = NULL;
270 parse->jointree->quals = NULL;
300 parse->mergeJoinCondition =
346 sourcerti, 0,
false);
353 ntest->argisrow =
false;
357 parse->mergeJoinCondition =
361 parse->mergeJoinCondition = NULL;
386 if (
parse->jointree->fromlist !=
NIL)
390 if (
parse->setOperations)
499 newfromlist =
lappend(newfromlist, newchild);
500 frelids =
bms_join(frelids, childrelids);
505 jtlink = (
Node *) newf;
581 elog(
ERROR,
"unrecognized join type: %d",
594 *relids =
bms_join(leftrelids, rightrelids);
600 elog(
ERROR,
"unrecognized node type: %d",
637 available_rels1)) != NULL)
641 *jtlink1 = (
Node *)
j;
661 if (available_rels2 != NULL &&
663 available_rels2)) != NULL)
667 *jtlink2 = (
Node *)
j;
691 available_rels1)) != NULL)
695 *jtlink1 = (
Node *)
j;
715 if (available_rels2 != NULL &&
717 available_rels2)) != NULL)
721 *jtlink2 = (
Node *)
j;
757 available_rels1)) != NULL)
761 *jtlink1 = (
Node *)
j;
781 if (available_rels2 != NULL &&
783 available_rels2)) != NULL)
787 *jtlink2 = (
Node *)
j;
830 newclauses =
lappend(newclauses, newclause);
833 if (newclauses ==
NIL)
875 foreach(rt,
root->parse->rtable)
894 rte->security_barrier =
false;
980 (containing_appendrel == NULL ||
984 containing_appendrel);
1006 lowest_outer_join == NULL &&
1007 containing_appendrel == NULL &&
1016 containing_appendrel);
1025 Assert(containing_appendrel == NULL);
1038 Assert(containing_appendrel == NULL);
1040 switch (
j->jointype)
1077 elog(
ERROR,
"unrecognized join type: %d",
1083 elog(
ERROR,
"unrecognized node type: %d",
1128 subroot->
parse = subquery;
1131 subroot->parent_root =
root->parent_root;
1147 memset(subroot->upper_rels, 0,
sizeof(subroot->upper_rels));
1148 memset(subroot->upper_targets, 0,
sizeof(subroot->upper_targets));
1153 subroot->grouping_map = NULL;
1175 if (subquery->hasSubLinks)
1267 rvcontext.
varno = varno;
1281 if (containing_appendrel != NULL)
1293 if (
parse->groupingSets)
1302 containing_appendrel);
1313 foreach(lc, subquery->
rtable)
1321 child_rte->lateral =
true;
1327 child_rte->lateral =
true;
1346 subquery->
rtable, subquery->rteperminfos);
1365 if (
root->glob->lastPHId != 0 ||
root->append_rel_list)
1371 if (
root->glob->lastPHId != 0)
1408 parse->hasSubLinks |= subquery->hasSubLinks;
1411 parse->hasRowSecurity |= subquery->hasRowSecurity;
1478 child_rte->lateral =
true;
1486 rtable, subquery->rteperminfos);
1525 Query *setOpQuery,
int childRToffset)
1536 childRTindex = childRToffset + rtr->
rtindex;
1580 elog(
ERROR,
"unrecognized node type: %d",
1604 appinfo->parent_colnos = pcolnos =
1660 if (subquery->hasAggs ||
1661 subquery->hasWindowFuncs ||
1662 subquery->hasTargetSRFs ||
1670 subquery->hasForUpdate ||
1679 if (rte->security_barrier)
1688 Relids safe_upper_varnos;
1699 if (lowest_outer_join != NULL)
1708 safe_upper_varnos = NULL;
1713 restricted, safe_upper_varnos))
1729 if (lowest_outer_join != NULL)
1800 foreach(lc, values_list)
1814 rvcontext.
varno = varno;
1950 if (rtf->funccolcount != 1)
1954 if (rtf->funccolnames !=
NIL)
1991 if (containing_appendrel != NULL)
1998 if (
parse->groupingSets)
2007 containing_appendrel);
2023 rte->lateral =
false;
2079 Assert(subquery != NULL);
2099 elog(
ERROR,
"unrecognized node type: %d",
2136 if (jtnode->
quals != NULL)
2161 Relids safe_upper_varnos)
2199 safe_upper_varnos = NULL;
2221 elog(
ERROR,
"unrecognized node type: %d",
2248 if (containing_appendrel)
2274 if (
parse->onConflict)
2276 parse->onConflict->onConflictSet = (
List *)
2279 parse->onConflict->onConflictWhere =
2288 if (
parse->mergeActionList)
2290 foreach(lc,
parse->mergeActionList)
2308 foreach(lc,
root->append_rel_list)
2320 foreach(lc,
parse->rtable)
2325 otherrte->joinaliasvars = (
List *)
2329 otherrte->groupexprs = (
List *)
2417 bool save_wrap_non_vars =
context->wrap_non_vars;
2430 context->wrap_non_vars =
true;
2434 context->wrap_non_vars = save_wrap_non_vars;
2437 elog(
ERROR,
"unrecognized node type: %d",
2473 need_phv = (var->varnullingrels != NULL) || rcon->
wrap_non_vars;
2502 int save_sublevelsup =
context->sublevels_up;
2516 (var->vartype != RECORDOID),
2517 &colnames, &fields);
2524 context->sublevels_up = save_sublevelsup;
2527 rowexpr->
args = fields;
2528 rowexpr->row_typeid = var->vartype;
2530 rowexpr->colnames = (var->vartype == RECORDOID) ? colnames :
NIL;
2532 newnode = (
Node *) rowexpr;
2557 elog(
ERROR,
"could not find attribute %d in subquery targetlist",
2568 if (newnode &&
IsA(newnode,
Var) &&
2569 ((
Var *) newnode)->varlevelsup == 0)
2658 if (var->varnullingrels != NULL)
2662 Var *newvar = (
Var *) newnode;
2666 var->varnullingrels);
2674 var->varnullingrels);
2681 var->varnullingrels);
2734 Node *leftmostjtnode;
2746 if (
root->hasRecursion)
2760 leftmostjtnode = topop->
larg;
2764 leftmostRTI = ((
RangeTblRef *) leftmostjtnode)->rtindex;
2780 ((
RangeTblRef *) leftmostjtnode)->rtindex = childRTI;
2783 leftmostRTE->
inh =
true;
2798 parse->setOperations = NULL;
2868 elog(
ERROR,
"so where are the outer joins?");
2978 elog(
ERROR,
"unrecognized node type: %d",
3005 List *forced_null_vars)
3020 Relids pass_nonnullable_rels;
3021 List *pass_forced_null_vars;
3039 pass_nonnullable_rels,
3040 pass_forced_null_vars);
3048 int rtindex =
j->rtindex;
3101 elog(
ERROR,
"unrecognized join type: %d",
3137 List *nonnullable_vars;
3157 if (rtindex && jointype !=
j->jointype)
3168 j->jointype = jointype;
3173 Relids local_nonnullable_rels;
3174 List *local_forced_null_vars;
3175 Relids pass_nonnullable_rels;
3176 List *pass_forced_null_vars;
3215 local_nonnullable_rels = NULL;
3216 local_forced_null_vars =
NIL;
3224 pass_nonnullable_rels = local_nonnullable_rels;
3225 pass_forced_null_vars = local_forced_null_vars;
3230 pass_nonnullable_rels = nonnullable_rels;
3231 pass_forced_null_vars = forced_null_vars;
3236 pass_nonnullable_rels = NULL;
3237 pass_forced_null_vars =
NIL;
3241 pass_nonnullable_rels,
3242 pass_forced_null_vars);
3250 pass_nonnullable_rels = local_nonnullable_rels;
3251 pass_forced_null_vars = local_forced_null_vars;
3256 pass_nonnullable_rels = NULL;
3257 pass_forced_null_vars =
NIL;
3261 pass_nonnullable_rels,
3262 pass_forced_null_vars);
3268 elog(
ERROR,
"unrecognized node type: %d",
3275 int rtindex,
Relids relids)
3345 Relids dropped_outer_joins = NULL;
3355 &dropped_outer_joins);
3372 dropped_outer_joins,
3377 dropped_outer_joins,
3392 foreach(cell,
root->rowMarks)
3417 Node **parent_quals,
3418 Relids *dropped_outer_joins)
3428 Relids result_relids = NULL;
3448 dropped_outer_joins);
3495 f !=
root->parse->jointree &&
3496 (f->
quals == NULL || parent_quals != NULL))
3504 if (f->
quals != NULL)
3505 *parent_quals = (
Node *)
3532 parent_quals : NULL,
3533 dropped_outer_joins);
3538 dropped_outer_joins);
3541 switch (
j->jointype)
3565 if (
j->quals != NULL && parent_quals == NULL)
3571 if (
j->quals != NULL)
3572 *parent_quals = (
Node *)
3581 if (
j->quals != NULL && parent_quals == NULL)
3587 if (
j->quals != NULL)
3588 *parent_quals = (
Node *)
3616 (
j->quals == NULL ||
3650 if (
j->quals != NULL && parent_quals == NULL)
3656 if (
j->quals != NULL)
3657 *parent_quals = (
Node *)
3670 elog(
ERROR,
"unrecognized join type: %d",
3676 elog(
ERROR,
"unrecognized node type: %d",
3721 if (
root->glob->lastPHId != 0)
3797 if (
root->glob->lastPHId == 0)
3824 if (
root->glob->lastPHId == 0)
3931 context.subrelids = subrelids;
3964 foreach(l,
root->append_rel_list)
3979 if (
root->glob->lastPHId != 0)
3998 bool include_inner_joins)
4019 include_outer_joins,
4020 include_inner_joins));
4028 include_outer_joins,
4029 include_inner_joins);
4032 include_outer_joins,
4033 include_inner_joins));
4038 if (include_inner_joins)
4043 if (include_outer_joins)
4049 elog(
ERROR,
"unrecognized node type: %d",
4065 elog(
ERROR,
"could not find join node %d", joinrelid);
4102 if (relid ==
j->rtindex)
4112 elog(
ERROR,
"unrecognized node type: %d",
#define InvalidAttrNumber
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
int bms_singleton_member(const Bitmapset *a)
void bms_free(Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
#define Assert(condition)
List * find_forced_null_vars(Node *node)
Query * inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte)
Relids find_nonnullable_rels(Node *clause)
List * find_nonnullable_vars(Node *clause)
bool contain_nonstrict_functions(Node *clause)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
bool contain_volatile_functions(Node *clause)
TypeFuncClass get_expr_result_type(Node *expr, Oid *resultTypeId, TupleDesc *resultTupleDesc)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
Alias * makeAlias(const char *aliasname, List *colnames)
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
Var * makeVarFromTargetEntry(int varno, TargetEntry *tle)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Node * make_and_qual(Node *qual1, Node *qual2)
Expr * make_andclause(List *andclauses)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
#define CHECK_FOR_INTERRUPTS()
Bitmapset * mbms_overlap_sets(const List *a, const List *b)
List * mbms_add_members(List *a, const List *b)
bool expression_returns_set(Node *clause)
static bool is_andclause(const void *clause)
static Expr * get_notclausearg(const void *notclause)
#define query_tree_walker(q, w, c, f)
#define query_or_expression_tree_walker(n, w, c, f)
#define range_table_entry_walker(r, w, c, f)
#define expression_tree_walker(n, w, c)
static bool is_notclause(const void *clause)
#define IsA(nodeptr, _type_)
#define IS_OUTER_JOIN(jointype)
#define castNode(_type_, nodeptr)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
#define rt_fetch(rangetable_index, rangetable)
static int list_length(const List *l)
#define linitial_node(type, l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_delete_current(lst, var_or_cell)
#define foreach_node(type, var, lst)
static rewind_source * source
PlaceHolderVar * make_placeholder_expr(PlannerInfo *root, Expr *expr, Relids phrels)
void check_stack_depth(void)
static Node * pull_up_subqueries_recurse(PlannerInfo *root, Node *jtnode, JoinExpr *lowest_outer_join, AppendRelInfo *containing_appendrel)
static void remove_result_refs(PlannerInfo *root, int varno, Node *newjtloc)
static Node * pull_up_constant_function(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte, AppendRelInfo *containing_appendrel)
void preprocess_function_rtes(PlannerInfo *root)
static bool find_dependent_phvs_walker(Node *node, find_dependent_phvs_context *context)
static Node * find_jointree_node_for_rel(Node *jtnode, int relid)
static Node * pull_up_simple_union_all(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte)
static void reduce_outer_joins_pass2(Node *jtnode, reduce_outer_joins_pass1_state *state1, reduce_outer_joins_pass2_state *state2, PlannerInfo *root, Relids nonnullable_rels, List *forced_null_vars)
static void pull_up_union_leaf_queries(Node *setOp, PlannerInfo *root, int parentRTindex, Query *setOpQuery, int childRToffset)
static bool is_simple_values(PlannerInfo *root, RangeTblEntry *rte)
static void make_setop_translation_list(Query *query, int newvarno, AppendRelInfo *appinfo)
void flatten_simple_union_all(PlannerInfo *root)
void transform_MERGE_to_join(Query *parse)
static void report_reduced_full_join(reduce_outer_joins_pass2_state *state2, int rtindex, Relids relids)
static void perform_pullup_replace_vars(PlannerInfo *root, pullup_replace_vars_context *rvcontext, AppendRelInfo *containing_appendrel)
void remove_useless_result_rtes(PlannerInfo *root)
static Node * pull_up_sublinks_jointree_recurse(PlannerInfo *root, Node *jtnode, Relids *relids)
static reduce_outer_joins_pass1_state * reduce_outer_joins_pass1(Node *jtnode)
static void replace_vars_in_jointree(Node *jtnode, pullup_replace_vars_context *context)
static bool is_simple_subquery(PlannerInfo *root, Query *subquery, RangeTblEntry *rte, JoinExpr *lowest_outer_join)
static void substitute_phv_relids(Node *node, int varno, Relids subrelids)
void pull_up_sublinks(PlannerInfo *root)
static Node * pullup_replace_vars_callback(Var *var, replace_rte_variables_context *context)
static Node * pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte, JoinExpr *lowest_outer_join, AppendRelInfo *containing_appendrel)
void replace_empty_jointree(Query *parse)
static bool is_simple_union_all_recurse(Node *setOp, Query *setOpQuery, List *colTypes)
static bool substitute_phv_relids_walker(Node *node, substitute_phv_relids_context *context)
static void fix_append_rel_relids(PlannerInfo *root, int varno, Relids subrelids)
static Node * remove_useless_results_recurse(PlannerInfo *root, Node *jtnode, Node **parent_quals, Relids *dropped_outer_joins)
static Query * pullup_replace_vars_subquery(Query *query, pullup_replace_vars_context *context)
Relids get_relids_for_join(Query *query, int joinrelid)
void pull_up_subqueries(PlannerInfo *root)
Relids get_relids_in_jointree(Node *jtnode, bool include_outer_joins, bool include_inner_joins)
static int get_result_relid(PlannerInfo *root, Node *jtnode)
static Node * pull_up_simple_values(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte)
struct reduce_outer_joins_pass1_state reduce_outer_joins_pass1_state
struct reduce_outer_joins_partial_state reduce_outer_joins_partial_state
static bool is_safe_append_member(Query *subquery)
struct pullup_replace_vars_context pullup_replace_vars_context
static Node * pull_up_sublinks_qual_recurse(PlannerInfo *root, Node *node, Node **jtlink1, Relids available_rels1, Node **jtlink2, Relids available_rels2)
void reduce_outer_joins(PlannerInfo *root)
static bool find_dependent_phvs(PlannerInfo *root, int varno)
static bool jointree_contains_lateral_outer_refs(PlannerInfo *root, Node *jtnode, bool restricted, Relids safe_upper_varnos)
struct reduce_outer_joins_pass2_state reduce_outer_joins_pass2_state
static Node * pullup_replace_vars(Node *expr, pullup_replace_vars_context *context)
static bool is_simple_union_all(Query *subquery)
static bool find_dependent_phvs_in_jointree(PlannerInfo *root, Node *node, int varno)
#define NUM_MERGE_MATCH_KINDS
@ MERGE_WHEN_NOT_MATCHED_BY_TARGET
@ MERGE_WHEN_NOT_MATCHED_BY_SOURCE
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
void IncrementVarSublevelsUp_rtable(List *rtable, int delta_sublevels_up, int min_sublevels_up)
Node * replace_rte_variables_mutator(Node *node, replace_rte_variables_context *context)
void OffsetVarNodes(Node *node, int offset, int sublevels_up)
void CombineRangeTables(List **dst_rtable, List **dst_perminfos, List *src_rtable, List *src_perminfos)
Node * remove_nulling_relids(Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
Node * replace_rte_variables(Node *node, int target_varno, int sublevels_up, replace_rte_variables_callback callback, void *callback_arg, bool *outer_hasSubLinks)
Node * add_nulling_relids(Node *node, const Bitmapset *target_relids, const Bitmapset *added_relids)
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
NullTestType nulltesttype
Index qual_security_level
struct Path * non_recursive_path
List * processed_groupClause
List * processed_distinctClause
Relids leaf_result_relids
struct TableSampleClause * tablesample
RangeTblEntry * target_rte
JoinExpr * convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink, Relids available_rels)
JoinExpr * convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink, bool under_not, Relids available_rels)
bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)
bool contain_vars_of_level(Node *node, int levelsup)
Relids pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup)
Relids pull_varnos(PlannerInfo *root, Node *node)
Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)