105 int parentRTindex,
Query *setOpQuery,
123 Node *jtnode,
bool restricted,
124 Relids safe_upper_varnos);
142 List *forced_null_vars);
144 int rtindex,
Relids relids);
147 Relids *dropped_outer_joins);
152 Node *node,
int varno);
154 int varno,
Relids subrelids);
200 have_action[
action->matchKind] =
true;
217 joinrte->joinmergedcols = 0;
218 joinrte->joinaliasvars =
vars;
219 joinrte->joinleftcols =
NIL;
220 joinrte->joinrightcols =
NIL;
221 joinrte->join_using_alias = NULL;
223 joinrte->alias = NULL;
225 joinrte->lateral =
false;
226 joinrte->
inh =
false;
227 joinrte->inFromCl =
true;
267 elog(
ERROR,
"unrecognized source node type: %d",
278 joinexpr->usingClause =
NIL;
279 joinexpr->join_using_alias = NULL;
281 joinexpr->alias = NULL;
286 parse->jointree->quals = NULL;
316 parse->mergeJoinCondition =
362 sourcerti, 0,
false);
369 ntest->argisrow =
false;
373 parse->mergeJoinCondition =
377 parse->mergeJoinCondition = NULL;
402 if (
parse->jointree->fromlist !=
NIL)
406 if (
parse->setOperations)
515 newfromlist =
lappend(newfromlist, newchild);
516 frelids =
bms_join(frelids, childrelids);
521 jtlink = (
Node *) newf;
597 elog(
ERROR,
"unrecognized join type: %d",
610 *relids =
bms_join(leftrelids, rightrelids);
616 elog(
ERROR,
"unrecognized node type: %d",
653 available_rels1)) != NULL)
657 *jtlink1 = (
Node *)
j;
677 if (available_rels2 != NULL &&
679 available_rels2)) != NULL)
683 *jtlink2 = (
Node *)
j;
707 available_rels1)) != NULL)
711 *jtlink1 = (
Node *)
j;
731 if (available_rels2 != NULL &&
733 available_rels2)) != NULL)
737 *jtlink2 = (
Node *)
j;
773 available_rels1)) != NULL)
777 *jtlink1 = (
Node *)
j;
797 if (available_rels2 != NULL &&
799 available_rels2)) != NULL)
803 *jtlink2 = (
Node *)
j;
846 newclauses =
lappend(newclauses, newclause);
849 if (newclauses ==
NIL)
891 foreach(rt,
root->parse->rtable)
910 rte->security_barrier =
false;
996 (containing_appendrel == NULL ||
1000 containing_appendrel);
1022 lowest_outer_join == NULL &&
1023 containing_appendrel == NULL &&
1032 containing_appendrel);
1041 Assert(containing_appendrel == NULL);
1054 Assert(containing_appendrel == NULL);
1056 switch (
j->jointype)
1093 elog(
ERROR,
"unrecognized join type: %d",
1099 elog(
ERROR,
"unrecognized node type: %d",
1144 subroot->
parse = subquery;
1147 subroot->parent_root =
root->parent_root;
1163 memset(subroot->upper_rels, 0,
sizeof(subroot->upper_rels));
1164 memset(subroot->upper_targets, 0,
sizeof(subroot->upper_targets));
1169 subroot->grouping_map = NULL;
1191 if (subquery->hasSubLinks)
1289 rvcontext.
varno = varno;
1303 if (containing_appendrel != NULL)
1315 if (
parse->groupingSets)
1324 containing_appendrel);
1335 foreach(lc, subquery->
rtable)
1343 child_rte->lateral =
true;
1349 child_rte->lateral =
true;
1368 subquery->
rtable, subquery->rteperminfos);
1387 if (
root->glob->lastPHId != 0 ||
root->append_rel_list)
1393 if (
root->glob->lastPHId != 0)
1430 parse->hasSubLinks |= subquery->hasSubLinks;
1433 parse->hasRowSecurity |= subquery->hasRowSecurity;
1500 child_rte->lateral =
true;
1508 rtable, subquery->rteperminfos);
1547 Query *setOpQuery,
int childRToffset)
1558 childRTindex = childRToffset + rtr->
rtindex;
1602 elog(
ERROR,
"unrecognized node type: %d",
1626 appinfo->parent_colnos = pcolnos =
1682 if (subquery->hasAggs ||
1683 subquery->hasWindowFuncs ||
1684 subquery->hasTargetSRFs ||
1692 subquery->hasForUpdate ||
1701 if (rte->security_barrier)
1710 Relids safe_upper_varnos;
1721 if (lowest_outer_join != NULL)
1730 safe_upper_varnos = NULL;
1735 restricted, safe_upper_varnos))
1754 if (lowest_outer_join != NULL)
1825 foreach(lc, values_list)
1840 rvcontext.
varno = varno;
1976 if (rtf->funccolcount != 1)
1980 if (rtf->funccolnames !=
NIL)
2018 if (containing_appendrel != NULL)
2025 if (
parse->groupingSets)
2034 containing_appendrel);
2050 rte->lateral =
false;
2106 Assert(subquery != NULL);
2126 elog(
ERROR,
"unrecognized node type: %d",
2163 if (jtnode->
quals != NULL)
2188 Relids safe_upper_varnos)
2226 safe_upper_varnos = NULL;
2248 elog(
ERROR,
"unrecognized node type: %d",
2275 if (containing_appendrel)
2301 if (
parse->onConflict)
2303 parse->onConflict->onConflictSet = (
List *)
2306 parse->onConflict->onConflictWhere =
2315 if (
parse->mergeActionList)
2317 foreach(lc,
parse->mergeActionList)
2335 foreach(lc,
root->append_rel_list)
2347 foreach(lc,
parse->rtable)
2352 otherrte->joinaliasvars = (
List *)
2356 otherrte->groupexprs = (
List *)
2444 bool save_wrap_non_vars =
context->wrap_non_vars;
2457 context->wrap_non_vars =
true;
2461 context->wrap_non_vars = save_wrap_non_vars;
2464 elog(
ERROR,
"unrecognized node type: %d",
2500 need_phv = (var->varnullingrels != NULL) || rcon->
wrap_non_vars;
2529 int save_sublevelsup =
context->sublevels_up;
2543 (var->vartype != RECORDOID),
2544 &colnames, &fields);
2551 context->sublevels_up = save_sublevelsup;
2554 rowexpr->
args = fields;
2555 rowexpr->row_typeid = var->vartype;
2557 rowexpr->colnames = (var->vartype == RECORDOID) ? colnames :
NIL;
2559 newnode = (
Node *) rowexpr;
2584 elog(
ERROR,
"could not find attribute %d in subquery targetlist",
2595 if (newnode &&
IsA(newnode,
Var) &&
2596 ((
Var *) newnode)->varlevelsup == 0)
2609 int lvarno = ((
Var *) newnode)->varno;
2611 Assert(lvarno > 0 && lvarno <= nullinfo->rtlength);
2633 Assert(lvarno > 0 && lvarno <= nullinfo->rtlength);
2685 bool contain_nullable_vars =
false;
2690 contain_nullable_vars =
true;
2698 contain_nullable_vars =
true;
2707 Assert(varno > 0 && varno <= nullinfo->rtlength);
2711 contain_nullable_vars =
true;
2718 if (contain_nullable_vars &&
2750 if (var->varnullingrels != NULL)
2754 Var *newvar = (
Var *) newnode;
2758 var->varnullingrels);
2766 var->varnullingrels);
2807 Assert(lvarno > 0 && lvarno <= nullinfo->rtlength);
2820 var->varnullingrels);
2873 Node *leftmostjtnode;
2885 if (
root->hasRecursion)
2899 leftmostjtnode = topop->
larg;
2903 leftmostRTI = ((
RangeTblRef *) leftmostjtnode)->rtindex;
2919 ((
RangeTblRef *) leftmostjtnode)->rtindex = childRTI;
2922 leftmostRTE->
inh =
true;
2937 parse->setOperations = NULL;
3007 elog(
ERROR,
"so where are the outer joins?");
3117 elog(
ERROR,
"unrecognized node type: %d",
3144 List *forced_null_vars)
3159 Relids pass_nonnullable_rels;
3160 List *pass_forced_null_vars;
3178 pass_nonnullable_rels,
3179 pass_forced_null_vars);
3187 int rtindex =
j->rtindex;
3240 elog(
ERROR,
"unrecognized join type: %d",
3276 List *nonnullable_vars;
3296 if (rtindex && jointype !=
j->jointype)
3307 j->jointype = jointype;
3312 Relids local_nonnullable_rels;
3313 List *local_forced_null_vars;
3314 Relids pass_nonnullable_rels;
3315 List *pass_forced_null_vars;
3354 local_nonnullable_rels = NULL;
3355 local_forced_null_vars =
NIL;
3363 pass_nonnullable_rels = local_nonnullable_rels;
3364 pass_forced_null_vars = local_forced_null_vars;
3369 pass_nonnullable_rels = nonnullable_rels;
3370 pass_forced_null_vars = forced_null_vars;
3375 pass_nonnullable_rels = NULL;
3376 pass_forced_null_vars =
NIL;
3380 pass_nonnullable_rels,
3381 pass_forced_null_vars);
3389 pass_nonnullable_rels = local_nonnullable_rels;
3390 pass_forced_null_vars = local_forced_null_vars;
3395 pass_nonnullable_rels = NULL;
3396 pass_forced_null_vars =
NIL;
3400 pass_nonnullable_rels,
3401 pass_forced_null_vars);
3407 elog(
ERROR,
"unrecognized node type: %d",
3414 int rtindex,
Relids relids)
3484 Relids dropped_outer_joins = NULL;
3494 &dropped_outer_joins);
3511 dropped_outer_joins,
3516 dropped_outer_joins,
3531 foreach(cell,
root->rowMarks)
3556 Node **parent_quals,
3557 Relids *dropped_outer_joins)
3567 Relids result_relids = NULL;
3587 dropped_outer_joins);
3634 f !=
root->parse->jointree &&
3635 (f->
quals == NULL || parent_quals != NULL))
3643 if (f->
quals != NULL)
3644 *parent_quals = (
Node *)
3671 parent_quals : NULL,
3672 dropped_outer_joins);
3677 dropped_outer_joins);
3680 switch (
j->jointype)
3704 if (
j->quals != NULL && parent_quals == NULL)
3710 if (
j->quals != NULL)
3711 *parent_quals = (
Node *)
3720 if (
j->quals != NULL && parent_quals == NULL)
3726 if (
j->quals != NULL)
3727 *parent_quals = (
Node *)
3755 (
j->quals == NULL ||
3789 if (
j->quals != NULL && parent_quals == NULL)
3795 if (
j->quals != NULL)
3796 *parent_quals = (
Node *)
3809 elog(
ERROR,
"unrecognized join type: %d",
3815 elog(
ERROR,
"unrecognized node type: %d",
3860 if (
root->glob->lastPHId != 0)
3935 if (
root->glob->lastPHId == 0)
3959 if (
root->glob->lastPHId == 0)
4062 context.subrelids = subrelids;
4095 foreach(l,
root->append_rel_list)
4110 if (
root->glob->lastPHId != 0)
4129 bool include_inner_joins)
4150 include_outer_joins,
4151 include_inner_joins));
4159 include_outer_joins,
4160 include_inner_joins);
4163 include_outer_joins,
4164 include_inner_joins));
4169 if (include_inner_joins)
4174 if (include_outer_joins)
4180 elog(
ERROR,
"unrecognized node type: %d",
4196 elog(
ERROR,
"could not find join node %d", joinrelid);
4233 if (relid ==
j->rtindex)
4243 elog(
ERROR,
"unrecognized node type: %d",
4284 Assert(varno > 0 && varno <= info->rtlength);
4300 Relids local_nullingrels;
4302 switch (
j->jointype)
4329 elog(
ERROR,
"unrecognized join type: %d",
4335 elog(
ERROR,
"unrecognized node type: %d",
#define InvalidAttrNumber
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
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_add_member(Bitmapset *a, int x)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
#define Assert(condition)
List * find_forced_null_vars(Node *node)
Query * inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
List * find_nonnullable_vars(Node *clause)
Relids find_nonnullable_rels(Node *clause)
bool contain_nonstrict_functions(Node *clause)
bool contain_volatile_functions(Node *clause)
#define palloc_object(type)
#define palloc0_array(type, count)
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 * makeVarFromTargetEntry(int varno, TargetEntry *tle)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
Expr * make_andclause(List *andclauses)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Node * make_and_qual(Node *qual1, Node *qual2)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
#define CHECK_FOR_INTERRUPTS()
List * mbms_add_members(List *a, const List *b)
Bitmapset * mbms_overlap_sets(const List *a, const List *b)
bool expression_returns_set(Node *clause)
static bool is_andclause(const void *clause)
#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)
static Expr * get_notclausearg(const void *notclause)
#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)
static Node * pull_up_subqueries_recurse(PlannerInfo *root, Node *jtnode, JoinExpr *lowest_outer_join, AppendRelInfo *containing_appendrel)
static nullingrel_info * get_nullingrels(Query *parse)
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)
struct nullingrel_info nullingrel_info
void remove_useless_result_rtes(PlannerInfo *root)
static Node * pull_up_sublinks_jointree_recurse(PlannerInfo *root, Node *jtnode, Relids *relids)
static void get_nullingrels_recurse(Node *jtnode, Relids upper_nullingrels, nullingrel_info *info)
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 * add_nulling_relids(Node *node, const Bitmapset *target_relids, const Bitmapset *added_relids)
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)
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
void check_stack_depth(void)
NullTestType nulltesttype
Index qual_security_level
struct Path * non_recursive_path
List * processed_groupClause
List * processed_distinctClause
Relids leaf_result_relids
struct TableSampleClause * tablesample
nullingrel_info * nullinfo
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)