165 int rtindex,
Relids relids);
175 Node *node,
int varno);
177 int varno,
Relids subrelids);
273 rtr->rtindex =
parse->mergeTargetRelation;
290 elog(
ERROR,
"unrecognized source node type: %d",
339 parse->mergeJoinCondition =
351 action->targetList = (
List *)
392 ntest->argisrow =
false;
396 parse->mergeJoinCondition =
429 for (rt_index = 0; rt_index < rtable_size; rt_index++)
454 rte->inh = relation->
rd_rel->relhassubclass;
505 for (
int i = 0;
i < tupdesc->
natts;
i++)
566 if (
parse->groupingSets)
600 if (
parse->jointree->fromlist !=
NIL)
604 if (
parse->setOperations)
795 elog(
ERROR,
"unrecognized join type: %d",
814 elog(
ERROR,
"unrecognized node type: %d",
860 return (
Node *) saop;
1099 foreach(l, ((
BoolExpr *) node)->args)
1158 foreach(
rt,
root->parse->rtable)
1177 rte->security_barrier =
false;
1186 rte->funcordinality =
false;
1329 switch (
j->jointype)
1366 elog(
ERROR,
"unrecognized join type: %d",
1372 elog(
ERROR,
"unrecognized node type: %d",
1417 subroot->
parse = subquery;
1421 subroot->parent_root =
root->parent_root;
1437 memset(subroot->upper_rels, 0,
sizeof(subroot->upper_rels));
1438 memset(subroot->upper_targets, 0,
sizeof(subroot->upper_targets));
1443 subroot->grouping_map =
NULL;
1476 if (subquery->hasSubLinks)
1591 if (
parse->groupingSets)
1648 subquery->
rtable, subquery->rteperminfos);
1667 if (
root->glob->lastPHId != 0 ||
root->append_rel_list)
1673 if (
root->glob->lastPHId != 0)
1710 parse->hasSubLinks |= subquery->hasSubLinks;
1713 parse->hasRowSecurity |= subquery->hasRowSecurity;
1788 rtable, subquery->rteperminfos);
1882 elog(
ERROR,
"unrecognized node type: %d",
1962 if (subquery->hasAggs ||
1963 subquery->hasWindowFuncs ||
1964 subquery->hasTargetSRFs ||
1972 subquery->hasForUpdate ||
1981 if (
rte->security_barrier)
2242 if (
rte->funcordinality)
2257 if (
rtf->funccolcount != 1)
2261 if (
rtf->funccolnames !=
NIL)
2300 if (
parse->groupingSets)
2325 rte->lateral =
false;
2401 elog(
ERROR,
"unrecognized node type: %d",
2523 elog(
ERROR,
"unrecognized node type: %d",
2576 if (
parse->onConflict)
2578 parse->onConflict->onConflictSet = (
List *)
2581 parse->onConflict->onConflictWhere =
2590 if (
parse->mergeActionList)
2592 foreach(
lc,
parse->mergeActionList)
2597 action->targetList = (
List *)
2610 foreach(
lc,
root->append_rel_list)
2659 if (varno != context->
varno)
2666 switch (
rte->rtekind)
2743 elog(
ERROR,
"unrecognized node type: %d",
2815 rcon->result_relation,
2851 if (
rcon->target_rte->lateral &&
2868 if (
rcon->target_rte->lateral &&
2932 if (!
rcon->target_rte->lateral)
2995 if (var->varnullingrels !=
NULL)
3003 var->varnullingrels);
3011 var->varnullingrels);
3034 if (
rcon->target_rte->lateral)
3065 var->varnullingrels);
3130 if (
root->hasRecursion)
3256 elog(
ERROR,
"so where are the outer joins?");
3288 foreach(
lc,
state2.partial_reduced)
3363 switch (
j->jointype)
3393 elog(
ERROR,
"unrecognized join type: %d",
3399 elog(
ERROR,
"unrecognized node type: %d",
3469 int rtindex =
j->rtindex;
3522 elog(
ERROR,
"unrecognized join type: %d",
3583 if (rtindex && jointype !=
j->jointype)
3589 rte->jointype = jointype;
3594 j->jointype = jointype;
3694 elog(
ERROR,
"unrecognized node type: %d",
3701 int rtindex,
Relids relids)
3706 statep->full_join_rti = rtindex;
3707 statep->unreduced_side = relids;
3916 foreach(cell,
root->rowMarks)
4019 f !=
root->parse->jointree &&
4065 switch (
j->jointype)
4095 if (
j->quals !=
NULL)
4111 if (
j->quals !=
NULL)
4140 (
j->quals ==
NULL ||
4180 if (
j->quals !=
NULL)
4194 elog(
ERROR,
"unrecognized join type: %d",
4200 elog(
ERROR,
"unrecognized node type: %d",
4245 if (
root->glob->lastPHId != 0)
4320 if (
root->glob->lastPHId == 0)
4344 if (
root->glob->lastPHId == 0)
4445 context.
varno = varno;
4480 foreach(l,
root->append_rel_list)
4487 if (
appinfo->child_relid == varno)
4495 if (
root->glob->lastPHId != 0)
4565 elog(
ERROR,
"unrecognized node type: %d",
4618 if (relid ==
j->rtindex)
4628 elog(
ERROR,
"unrecognized node type: %d",
4687 switch (
j->jointype)
4714 elog(
ERROR,
"unrecognized join type: %d",
4720 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_function_in_from(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 * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
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 castNode(_type_, nodeptr)
#define rt_fetch(rangetable_index, rangetable)
FormData_pg_attribute * Form_pg_attribute
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)
#define list_make2(x1, x2)
static rewind_source * source
PlaceHolderVar * make_placeholder_expr(PlannerInfo *root, Expr *expr, Relids phrels)
void get_relation_notnullatts(PlannerInfo *root, Relation relation)
Bitmapset * find_relation_notnullatts(PlannerInfo *root, Oid relid)
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 * pullup_replace_vars_callback(const Var *var, replace_rte_variables_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 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 * 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 bool has_notnull_forced_var(PlannerInfo *root, List *forced_null_vars, reduce_outer_joins_pass1_state *right_state)
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)
Query * preprocess_relation_rtes(PlannerInfo *root)
static Node * pull_up_simple_values(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte)
static bool is_safe_append_member(Query *subquery)
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 Query * expand_virtual_generated_columns(PlannerInfo *root, Query *parse, RangeTblEntry *rte, int rt_index, Relation relation)
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)
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
#define RelationGetDescr(relation)
Node * build_generation_expression(Relation rel, int attrno)
void IncrementVarSublevelsUp_rtable(List *rtable, int delta_sublevels_up, int min_sublevels_up)
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
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)
Node * ReplaceVarFromTargetList(const Var *var, RangeTblEntry *target_rte, List *targetlist, int result_relation, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno)
@ REPLACEVARS_REPORT_ERROR
void check_stack_depth(void)
Index qual_security_level
struct Path * non_recursive_path
List * processed_groupClause
List * processed_distinctClause
Relids leaf_result_relids
bool has_generated_virtual
nullingrel_info * nullinfo
ReplaceWrapOption wrap_option
RangeTblEntry * target_rte
JoinExpr * convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink, bool under_not, Relids available_rels)
ScalarArrayOpExpr * convert_VALUES_to_ANY(PlannerInfo *root, Node *testexpr, Query *values)
JoinExpr * convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink, bool under_not, Relids available_rels)
#define FirstLowInvalidHeapAttributeNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
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)