106 Index security_level,
109 Relids outerjoin_nonnullable,
110 Relids incompatible_relids,
111 bool allow_equivalence,
114 List **postponed_oj_qual_list);
118 Index security_level,
121 Relids outerjoin_nonnullable,
122 Relids incompatible_relids,
123 bool allow_equivalence,
126 List **postponed_oj_qual_list);
182 elog(
ERROR,
"unrecognized node type: %d",
200 RelOptInfo *rel = root->simple_rel_array[rti];
240 if (tlist_vars !=
NIL)
256 if (having_vars !=
NIL)
299 if (rel->attr_needed[attno] == NULL)
309 var->varnullingrels = NULL;
370 RelOptInfo *brel = root->simple_rel_array[rti];
470 newvars =
lappend(newvars, node);
502 bool found_laterals =
false;
518 RelOptInfo *brel = root->simple_rel_array[rti];
531 lateral_relids = NULL;
542 found_laterals =
true;
551 found_laterals =
true;
587 found_laterals =
true;
649 RelOptInfo *brel = root->simple_rel_array[rti];
650 Relids outer_lateral_relids;
658 if (outer_lateral_relids == NULL)
664 RelOptInfo *brel2 = root->simple_rel_array[rti2];
672 outer_lateral_relids);
683 RelOptInfo *brel = root->simple_rel_array[rti];
702 RelOptInfo *brel2 = root->simple_rel_array[rti2];
777 foreach(lc, item_list)
790 foreach(lc, item_list)
843 jtitem->
jdomain = parent_domain;
859 jtitem->
jdomain = parent_domain;
888 if (sub_members <= 1 ||
892 joinlist =
lappend(joinlist, sub_joinlist);
919 jtitem->
jdomain = parent_domain;
946 jtitem->
jdomain = child_domain;
985 jtitem->
jdomain = parent_domain;
1059 elog(
ERROR,
"unrecognized join type: %d",
1061 leftjoinlist = rightjoinlist =
NIL;
1078 joinlist =
list_concat(leftjoinlist, rightjoinlist);
1090 leftpart = (
Node *) leftjoinlist;
1094 rightpart = (
Node *) rightjoinlist;
1100 elog(
ERROR,
"unrecognized node type: %d",
1106 *item_list =
lappend(*item_list, jtitem);
1168 List **postponed_oj_qual_list;
1232 postponed_oj_qual_list = NULL;
1244 postponed_oj_qual_list);
1252 elog(
ERROR,
"unrecognized node type: %d",
1275 Index security_level = 0;
1309 Assert(security_level <= root->qual_security_level);
1328 RelOptInfo *rel = root->simple_rel_array[relid];
1403 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1406 errmsg(
"%s cannot be applied to the nullable side of an outer join",
1467 commute_below_l = commute_below_r = NULL;
1471 bool have_unsafe_phvs;
1515 have_unsafe_phvs =
false;
1538 (have_unsafe_phvs ||
1670 if (commute_below_l || commute_below_r)
1701 List *semi_operators;
1702 List *semi_rhs_exprs;
1743 semi_operators =
NIL;
1744 semi_rhs_exprs =
NIL;
1786 all_varnos =
bms_union(left_varnos, right_varnos);
1817 right_expr = left_expr;
1839 if (!(all_btree || all_hash))
1843 semi_operators =
lappend_oid(semi_operators, opno);
1848 if (semi_rhs_exprs ==
NIL)
1904 Relids incompatible_joins;
1907 int save_last_rinfo_serial;
1943 incompatible_joins =
bms_union(joins_below, joins_above);
1957 joins_so_far = NULL;
1958 foreach(lc, jtitems)
1962 bool below_sjinfo =
false;
1963 bool above_sjinfo =
false;
1966 bool allow_equivalence,
1970 if (othersj == NULL)
1976 below_sjinfo =
true;
1978 else if (othersj ==
sjinfo)
1986 above_sjinfo =
true;
2022 this_ojscope =
bms_union(ojscope, joins_so_far);
2050 allow_equivalence = (joins_so_far == NULL);
2051 has_clone = allow_equivalence;
2052 is_clone = !has_clone;
2121 Index security_level,
2124 Relids outerjoin_nonnullable,
2125 Relids incompatible_relids,
2126 bool allow_equivalence,
2129 List **postponed_oj_qual_list)
2133 foreach(lc, clauses)
2143 outerjoin_nonnullable,
2144 incompatible_relids,
2148 postponed_oj_qual_list);
2199 Index security_level,
2202 Relids outerjoin_nonnullable,
2203 Relids incompatible_relids,
2204 bool allow_equivalence,
2207 List **postponed_oj_qual_list)
2210 bool is_pushed_down;
2211 bool pseudoconstant =
false;
2212 bool maybe_equivalence;
2213 bool maybe_outer_join;
2254 elog(
ERROR,
"failed to postpone qual containing lateral reference");
2262 elog(
ERROR,
"JOIN qualification cannot refer to other relations");
2314 pseudoconstant =
true;
2361 if (postponed_oj_qual_list != NULL)
2363 *postponed_oj_qual_list =
lappend(*postponed_oj_qual_list, clause);
2374 is_pushed_down =
false;
2375 maybe_equivalence =
false;
2376 maybe_outer_join =
true;
2395 is_pushed_down =
true;
2407 maybe_equivalence = allow_equivalence;
2413 maybe_outer_join =
false;
2427 incompatible_relids,
2428 outerjoin_nonnullable);
2459 where_needed = relids;
2503 if (restrictinfo->mergeopfamilies)
2505 if (maybe_equivalence)
2510 if (restrictinfo->mergeopfamilies)
2514 else if (maybe_outer_join && restrictinfo->can_join)
2521 outerjoin_nonnullable) &&
2523 outerjoin_nonnullable))
2528 ojcinfo->
rinfo = restrictinfo;
2535 outerjoin_nonnullable) &&
2537 outerjoin_nonnullable))
2542 ojcinfo->
rinfo = restrictinfo;
2553 ojcinfo->
rinfo = restrictinfo;
2585 Var *forced_null_var;
2590 if (forced_null_var == NULL)
2599 if (forced_null_var->varnullingrels == NULL)
2652 restrictinfo->pseudoconstant,
2738 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
2792 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
2865 elog(
ERROR,
"cannot cope with variable-free clause");
2907 Index security_level,
2913 bool pseudoconstant =
false;
2938 if (!cclause->constisnull &&
DatumGetBool(cclause->constvalue))
2964 pseudoconstant =
true;
3023 return restrictinfo;
3046 Index security_level)
3082 return restrictinfo;
3170 con_rel = root->simple_rel_array[fkinfo->
con_relid];
3171 if (con_rel == NULL)
3173 ref_rel = root->simple_rel_array[fkinfo->
ref_relid];
3174 if (ref_rel == NULL)
3193 for (colno = 0; colno < fkinfo->
nkeys; colno++)
3215 con_attno = fkinfo->conkey[colno];
3216 ref_attno = fkinfo->confkey[colno];
3236 if (!(leftvar &&
IsA(leftvar,
Var)))
3240 if (!(rightvar &&
IsA(rightvar,
Var)))
3244 if (fkinfo->
ref_relid == leftvar->varno &&
3245 ref_attno == leftvar->varattno &&
3247 con_attno == rightvar->varattno)
3250 if (clause->
opno == fkinfo->conpfeqop[colno])
3257 else if (fkinfo->
ref_relid == rightvar->varno &&
3258 ref_attno == rightvar->varattno &&
3260 con_attno == leftvar->varattno)
3271 if (clause->
opno == fpeqop)
3280 if (fkinfo->
rinfos[colno])
3291 newlist =
lappend(newlist, fkinfo);
3320 if (restrictinfo->pseudoconstant)
3327 opno = ((
OpExpr *) clause)->opno;
3357 if (restrictinfo->pseudoconstant)
3364 opno = ((
OpExpr *) clause)->opno;
3369 restrictinfo->hashjoinoperator = opno;
3386 if (restrictinfo->pseudoconstant)
3399 restrictinfo->left_hasheqoperator = typentry->
eq_opr;
3407 if (lefttype != righttype)
3412 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 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)
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)
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)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
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
int simple_rel_array_size
Index qual_security_level
List * right_join_clauses
bool hasPseudoConstantQuals
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)