107 Index security_level,
110 Relids outerjoin_nonnullable,
111 Relids incompatible_relids,
112 bool allow_equivalence,
115 List **postponed_oj_qual_list);
119 Index security_level,
122 Relids outerjoin_nonnullable,
123 Relids incompatible_relids,
124 bool allow_equivalence,
127 List **postponed_oj_qual_list);
183 elog(
ERROR,
"unrecognized node type: %d",
199 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
241 if (tlist_vars !=
NIL)
251 if (
root->parse->havingQual)
257 if (having_vars !=
NIL)
302 if (rel->attr_needed[attno] == NULL)
312 var->varnullingrels = NULL;
422 if (!
root->hasLateralRTEs)
428 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
530 newvars =
lappend(newvars, node);
571 if (!
root->hasLateralRTEs)
575 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
606 bool found_laterals =
false;
611 if (!
root->hasLateralRTEs)
620 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
635 lateral_relids = NULL;
646 found_laterals =
true;
655 found_laterals =
true;
681 foreach(lc,
root->placeholder_list)
691 found_laterals =
true;
736 root->hasLateralRTEs =
false;
751 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
754 Relids outer_lateral_relids;
762 if (outer_lateral_relids == NULL)
766 for (rti2 = 1; rti2 <
root->simple_rel_array_size; rti2++)
776 outer_lateral_relids);
785 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
855 root->placeholdersFrozen =
true;
866 root->all_baserels = NULL;
867 root->outer_join_rels = NULL;
881 foreach(lc, item_list)
892 if (
root->join_info_list)
894 foreach(lc, item_list)
947 jtitem->
jdomain = parent_domain;
963 jtitem->
jdomain = parent_domain;
992 if (sub_members <= 1 ||
996 joinlist =
lappend(joinlist, sub_joinlist);
1019 switch (
j->jointype)
1023 jtitem->
jdomain = parent_domain;
1050 jtitem->
jdomain = child_domain;
1069 if (
j->rtindex != 0)
1089 jtitem->
jdomain = parent_domain;
1163 elog(
ERROR,
"unrecognized join type: %d",
1165 leftjoinlist = rightjoinlist =
NIL;
1182 joinlist =
list_concat(leftjoinlist, rightjoinlist);
1194 leftpart = (
Node *) leftjoinlist;
1198 rightpart = (
Node *) rightjoinlist;
1204 elog(
ERROR,
"unrecognized node type: %d",
1210 *item_list =
lappend(*item_list, jtitem);
1232 if (
root->qual_security_level > 0)
1248 root->qual_security_level,
1260 root->qual_security_level,
1272 List **postponed_oj_qual_list;
1336 postponed_oj_qual_list = NULL;
1342 root->qual_security_level,
1348 postponed_oj_qual_list);
1356 elog(
ERROR,
"unrecognized node type: %d",
1379 Index security_level = 0;
1388 foreach(lc, rte->securityQuals)
1413 Assert(security_level <= root->qual_security_level);
1435 if (relid ==
root->group_rtindex)
1504 foreach(l,
root->parse->rowMarks)
1511 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1514 errmsg(
"%s cannot be applied to the nullable side of an outer join",
1575 commute_below_l = commute_below_r = NULL;
1576 foreach(l,
root->join_info_list)
1579 bool have_unsafe_phvs;
1623 have_unsafe_phvs =
false;
1646 (have_unsafe_phvs ||
1732 foreach(l,
root->placeholder_list)
1778 if (commute_below_l || commute_below_r)
1783 foreach(l,
root->join_info_list)
1809 List *semi_operators;
1810 List *semi_rhs_exprs;
1851 semi_operators =
NIL;
1852 semi_rhs_exprs =
NIL;
1894 all_varnos =
bms_union(left_varnos, right_varnos);
1925 right_expr = left_expr;
1947 if (!(all_btree || all_hash))
1951 semi_operators =
lappend_oid(semi_operators, opno);
1956 if (semi_rhs_exprs ==
NIL)
2012 Relids incompatible_joins;
2015 int save_last_rinfo_serial;
2051 incompatible_joins =
bms_union(joins_below, joins_above);
2063 save_last_rinfo_serial =
root->last_rinfo_serial;
2065 joins_so_far = NULL;
2066 foreach(lc, jtitems)
2070 bool below_sjinfo =
false;
2071 bool above_sjinfo =
false;
2074 bool allow_equivalence,
2078 if (othersj == NULL)
2084 below_sjinfo =
true;
2086 else if (othersj ==
sjinfo)
2094 above_sjinfo =
true;
2103 root->last_rinfo_serial = save_last_rinfo_serial;
2130 this_ojscope =
bms_union(ojscope, joins_so_far);
2158 allow_equivalence = (joins_so_far == NULL);
2159 has_clone = allow_equivalence;
2160 is_clone = !has_clone;
2165 root->qual_security_level,
2203 root->qual_security_level,
2229 Index security_level,
2232 Relids outerjoin_nonnullable,
2233 Relids incompatible_relids,
2234 bool allow_equivalence,
2237 List **postponed_oj_qual_list)
2241 foreach(lc, clauses)
2251 outerjoin_nonnullable,
2252 incompatible_relids,
2256 postponed_oj_qual_list);
2307 Index security_level,
2310 Relids outerjoin_nonnullable,
2311 Relids incompatible_relids,
2312 bool allow_equivalence,
2315 List **postponed_oj_qual_list)
2318 bool is_pushed_down;
2319 bool pseudoconstant =
false;
2320 bool maybe_equivalence;
2321 bool maybe_outer_join;
2362 elog(
ERROR,
"failed to postpone qual containing lateral reference");
2370 elog(
ERROR,
"JOIN qualification cannot refer to other relations");
2422 pseudoconstant =
true;
2424 root->hasPseudoConstantQuals =
true;
2469 if (postponed_oj_qual_list != NULL)
2471 *postponed_oj_qual_list =
lappend(*postponed_oj_qual_list, clause);
2482 is_pushed_down =
false;
2483 maybe_equivalence =
false;
2484 maybe_outer_join =
true;
2503 is_pushed_down =
true;
2515 maybe_equivalence = allow_equivalence;
2521 maybe_outer_join =
false;
2535 incompatible_relids,
2536 outerjoin_nonnullable);
2570 where_needed = relids;
2614 if (restrictinfo->mergeopfamilies)
2616 if (maybe_equivalence)
2621 if (restrictinfo->mergeopfamilies)
2625 else if (maybe_outer_join && restrictinfo->can_join)
2632 outerjoin_nonnullable) &&
2634 outerjoin_nonnullable))
2639 ojcinfo->
rinfo = restrictinfo;
2646 outerjoin_nonnullable) &&
2648 outerjoin_nonnullable))
2653 ojcinfo->
rinfo = restrictinfo;
2664 ojcinfo->
rinfo = restrictinfo;
2696 Var *forced_null_var;
2701 if (forced_null_var == NULL)
2710 if (forced_null_var->varnullingrels == NULL)
2713 foreach(lc,
root->join_info_list)
2762 if (!rte->
inh || rte->relkind == RELKIND_PARTITIONED_TABLE)
2781 restrictinfo->pseudoconstant,
2868 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
2922 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
2995 elog(
ERROR,
"cannot cope with variable-free clause");
3037 Index security_level,
3043 bool pseudoconstant =
false;
3068 if (!cclause->constisnull &&
DatumGetBool(cclause->constvalue))
3094 pseudoconstant =
true;
3096 root->hasPseudoConstantQuals =
true;
3158 return restrictinfo;
3181 Index security_level)
3217 return restrictinfo;
3254 foreach(lc,
root->join_info_list)
3292 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
3326 where_needed = relids;
3355 foreach(lc,
root->fkey_list)
3372 if (con_rel == NULL)
3375 if (ref_rel == NULL)
3394 for (colno = 0; colno < fkinfo->
nkeys; colno++)
3416 con_attno = fkinfo->conkey[colno];
3417 ref_attno = fkinfo->confkey[colno];
3437 if (!(leftvar &&
IsA(leftvar,
Var)))
3441 if (!(rightvar &&
IsA(rightvar,
Var)))
3445 if (fkinfo->
ref_relid == leftvar->varno &&
3446 ref_attno == leftvar->varattno &&
3448 con_attno == rightvar->varattno)
3451 if (clause->
opno == fkinfo->conpfeqop[colno])
3458 else if (fkinfo->
ref_relid == rightvar->varno &&
3459 ref_attno == rightvar->varattno &&
3461 con_attno == leftvar->varattno)
3472 if (clause->
opno == fpeqop)
3481 if (fkinfo->
rinfos[colno])
3492 newlist =
lappend(newlist, fkinfo);
3495 root->fkey_list = newlist;
3521 if (restrictinfo->pseudoconstant)
3528 opno = ((
OpExpr *) clause)->opno;
3558 if (restrictinfo->pseudoconstant)
3565 opno = ((
OpExpr *) clause)->opno;
3570 restrictinfo->hashjoinoperator = opno;
3587 if (restrictinfo->pseudoconstant)
3600 restrictinfo->left_hasheqoperator = typentry->
eq_opr;
3608 if (lefttype != righttype)
3613 restrictinfo->right_hasheqoperator = typentry->
eq_opr;
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)
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_intersect(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
BMS_Membership bms_membership(const Bitmapset *a)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
bool bms_get_singleton_member(const Bitmapset *a, int *member)
#define Assert(condition)
#define OidIsValid(objectId)
Var * find_forced_null_var(Node *node)
Relids find_nonnullable_rels(Node *clause)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
bool contain_volatile_functions(Node *clause)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool process_equivalence(PlannerInfo *root, RestrictInfo **p_restrictinfo, JoinDomain *jdomain)
EquivalenceClass * match_eclasses_to_foreign_key_col(PlannerInfo *root, ForeignKeyOptInfo *fkinfo, int colno)
#define palloc0_object(type)
void expand_inherited_rtentry(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, Index rti)
static void check_hashjoinable(RestrictInfo *restrictinfo)
static void extract_lateral_references(PlannerInfo *root, RelOptInfo *brel, Index rtindex)
List * deconstruct_jointree(PlannerInfo *root)
void rebuild_lateral_attr_needed(PlannerInfo *root)
static void check_mergejoinable(RestrictInfo *restrictinfo)
void distribute_restrictinfo_to_rels(PlannerInfo *root, RestrictInfo *restrictinfo)
static List * deconstruct_recurse(PlannerInfo *root, Node *jtnode, JoinDomain *parent_domain, JoinTreeItem *parent_jtitem, List **item_list)
static void compute_semijoin_info(PlannerInfo *root, SpecialJoinInfo *sjinfo, List *clause)
struct JoinTreeItem JoinTreeItem
void match_foreign_keys_to_quals(PlannerInfo *root)
void find_lateral_references(PlannerInfo *root)
static void add_base_clause_to_rel(PlannerInfo *root, Index relid, RestrictInfo *restrictinfo)
void add_base_rels_to_query(PlannerInfo *root, Node *jtnode)
void build_base_rel_tlists(PlannerInfo *root, List *final_tlist)
bool restriction_is_always_true(PlannerInfo *root, RestrictInfo *restrictinfo)
static void deconstruct_distribute_oj_quals(PlannerInfo *root, List *jtitems, JoinTreeItem *jtitem)
static void distribute_quals_to_rels(PlannerInfo *root, List *clauses, JoinTreeItem *jtitem, SpecialJoinInfo *sjinfo, Index security_level, Relids qualscope, Relids ojscope, Relids outerjoin_nonnullable, Relids incompatible_relids, bool allow_equivalence, bool has_clone, bool is_clone, List **postponed_oj_qual_list)
static SpecialJoinInfo * make_outerjoininfo(PlannerInfo *root, Relids left_rels, Relids right_rels, Relids inner_join_rels, JoinType jointype, Index ojrelid, List *clause)
void add_vars_to_targetlist(PlannerInfo *root, List *vars, Relids where_needed)
bool restriction_is_always_false(PlannerInfo *root, RestrictInfo *restrictinfo)
static void distribute_qual_to_rels(PlannerInfo *root, Node *clause, JoinTreeItem *jtitem, SpecialJoinInfo *sjinfo, Index security_level, Relids qualscope, Relids ojscope, Relids outerjoin_nonnullable, Relids incompatible_relids, bool allow_equivalence, bool has_clone, bool is_clone, List **postponed_oj_qual_list)
static bool check_redundant_nullability_qual(PlannerInfo *root, Node *clause)
void rebuild_joinclause_attr_needed(PlannerInfo *root)
RestrictInfo * build_implied_join_equality(PlannerInfo *root, Oid opno, Oid collation, Expr *item1, Expr *item2, Relids qualscope, Index security_level)
static bool expr_is_nonnullable(PlannerInfo *root, Expr *expr)
void add_other_rels_to_query(PlannerInfo *root)
static void mark_rels_nulled_by_join(PlannerInfo *root, Index ojrelid, Relids lower_rels)
void create_lateral_join_info(PlannerInfo *root)
static void process_security_barrier_quals(PlannerInfo *root, int rti, JoinTreeItem *jtitem)
RestrictInfo * process_implied_equality(PlannerInfo *root, Oid opno, Oid collation, Expr *item1, Expr *item2, Relids qualscope, Index security_level, bool both_const)
static void deconstruct_distribute(PlannerInfo *root, JoinTreeItem *jtitem)
void add_vars_to_attr_needed(PlannerInfo *root, List *vars, Relids where_needed)
static void check_memoizable(RestrictInfo *restrictinfo)
static Relids get_join_domain_min_rels(PlannerInfo *root, Relids domain_relids)
if(TABLE==NULL||TABLE_index==NULL)
void add_join_clause_to_rels(PlannerInfo *root, RestrictInfo *restrictinfo, Relids join_relids)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
List * list_concat(List *list1, const List *list2)
void list_free_deep(List *list)
List * get_mergejoin_opfamilies(Oid opno)
bool op_hashjoinable(Oid opno, Oid inputtype)
bool op_mergejoinable(Oid opno, Oid inputtype)
Oid get_commutator(Oid opno)
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
Node * makeBoolConst(bool value, bool isnull)
Oid exprType(const Node *expr)
static bool is_orclause(const void *clause)
static bool is_opclause(const void *clause)
static Node * get_rightop(const void *clause)
static Node * get_leftop(const void *clause)
#define IsA(nodeptr, _type_)
#define PVC_RECURSE_AGGREGATES
#define PVC_RECURSE_WINDOWFUNCS
#define PVC_INCLUDE_PLACEHOLDERS
const char * LCS_asString(LockClauseStrength strength)
void initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
static int list_length(const List *l)
#define linitial_node(type, l)
#define list_make2(x1, x2)
bool contain_placeholder_references_to(PlannerInfo *root, Node *clause, int relid)
PlaceHolderInfo * find_placeholder_info(PlannerInfo *root, PlaceHolderVar *phv)
Expr * preprocess_phv_expression(PlannerInfo *root, Expr *expr)
static bool DatumGetBool(Datum X)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
RelOptInfo * find_base_rel_ignore_join(PlannerInfo *root, int relid)
bool restriction_is_or_clause(RestrictInfo *restrictinfo)
RestrictInfo * make_restrictinfo(PlannerInfo *root, Expr *clause, bool is_pushed_down, bool has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_relids, Relids outer_relids)
Node * remove_nulling_relids(Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
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)
List * rinfos[INDEX_MAX_KEYS]
struct JoinTreeItem * jti_parent
NullTestType nulltesttype
struct TableSampleClause * tablesample
Bitmapset * notnullattnums
struct PathTarget * reltarget
Relids lateral_referencers
Relids direct_lateral_relids
Index baserestrict_min_security
Relids incompatible_relids
LockClauseStrength strength
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define TYPECACHE_HASH_PROC
List * pull_vars_of_level(Node *node, int levelsup)
List * pull_var_clause(Node *node, int flags)
Relids pull_varnos(PlannerInfo *root, Node *node)