108 Index security_level,
111 Relids outerjoin_nonnullable,
112 Relids incompatible_relids,
113 bool allow_equivalence,
116 List **postponed_oj_qual_list);
120 Index security_level,
123 Relids outerjoin_nonnullable,
124 Relids incompatible_relids,
125 bool allow_equivalence,
128 List **postponed_oj_qual_list);
184 elog(
ERROR,
"unrecognized node type: %d",
200 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
242 if (tlist_vars !=
NIL)
252 if (
root->parse->havingQual)
258 if (having_vars !=
NIL)
303 if (rel->attr_needed[attno] == NULL)
313 var->varnullingrels = NULL;
417 bool tryremove =
false;
426 if (
parse->groupingSets)
436 foreach(lc,
root->processed_groupClause)
483 foreach(lc,
parse->rtable)
502 if (rte->
inh && rte->relkind != RELKIND_PARTITIONED_TABLE)
506 relattnos = groupbyattnos[relid];
510 rel =
root->simple_rel_array[relid];
535 nulls_check_ok =
true;
536 for (
int i = 0;
i <
index->nkeycolumns;
i++)
546 if (!
index->nullsnotdistinct &&
550 nulls_check_ok =
false;
578 if (
index->nkeycolumns < best_nkeycolumns)
580 best_keycolumns = ind_attnos;
581 best_nkeycolumns =
index->nkeycolumns;
592 if (surplusvars == NULL)
606 if (surplusvars != NULL)
610 foreach(lc,
root->processed_groupClause)
623 surplusvars[var->
varno]))
624 new_groupby =
lappend(new_groupby, sgc);
627 root->processed_groupClause = new_groupby;
663 if (!
root->hasLateralRTEs)
669 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
771 newvars =
lappend(newvars, node);
812 if (!
root->hasLateralRTEs)
816 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
847 bool found_laterals =
false;
852 if (!
root->hasLateralRTEs)
861 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
876 lateral_relids = NULL;
887 found_laterals =
true;
896 found_laterals =
true;
922 foreach(lc,
root->placeholder_list)
932 found_laterals =
true;
977 root->hasLateralRTEs =
false;
992 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
995 Relids outer_lateral_relids;
1003 if (outer_lateral_relids == NULL)
1007 for (rti2 = 1; rti2 <
root->simple_rel_array_size; rti2++)
1017 outer_lateral_relids);
1026 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1096 root->placeholdersFrozen =
true;
1107 root->all_baserels = NULL;
1108 root->outer_join_rels = NULL;
1122 foreach(lc, item_list)
1133 if (
root->join_info_list)
1135 foreach(lc, item_list)
1188 jtitem->
jdomain = parent_domain;
1204 jtitem->
jdomain = parent_domain;
1233 if (sub_members <= 1 ||
1237 joinlist =
lappend(joinlist, sub_joinlist);
1260 switch (
j->jointype)
1264 jtitem->
jdomain = parent_domain;
1291 jtitem->
jdomain = child_domain;
1310 if (
j->rtindex != 0)
1330 jtitem->
jdomain = parent_domain;
1404 elog(
ERROR,
"unrecognized join type: %d",
1406 leftjoinlist = rightjoinlist =
NIL;
1423 joinlist =
list_concat(leftjoinlist, rightjoinlist);
1435 leftpart = (
Node *) leftjoinlist;
1439 rightpart = (
Node *) rightjoinlist;
1445 elog(
ERROR,
"unrecognized node type: %d",
1451 *item_list =
lappend(*item_list, jtitem);
1473 if (
root->qual_security_level > 0)
1489 root->qual_security_level,
1501 root->qual_security_level,
1513 List **postponed_oj_qual_list;
1577 postponed_oj_qual_list = NULL;
1583 root->qual_security_level,
1589 postponed_oj_qual_list);
1597 elog(
ERROR,
"unrecognized node type: %d",
1620 Index security_level = 0;
1629 foreach(lc, rte->securityQuals)
1654 Assert(security_level <= root->qual_security_level);
1676 if (relid ==
root->group_rtindex)
1745 foreach(l,
root->parse->rowMarks)
1752 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1755 errmsg(
"%s cannot be applied to the nullable side of an outer join",
1816 commute_below_l = commute_below_r = NULL;
1817 foreach(l,
root->join_info_list)
1820 bool have_unsafe_phvs;
1864 have_unsafe_phvs =
false;
1887 (have_unsafe_phvs ||
1973 foreach(l,
root->placeholder_list)
2019 if (commute_below_l || commute_below_r)
2024 foreach(l,
root->join_info_list)
2050 List *semi_operators;
2051 List *semi_rhs_exprs;
2092 semi_operators =
NIL;
2093 semi_rhs_exprs =
NIL;
2135 all_varnos =
bms_union(left_varnos, right_varnos);
2166 right_expr = left_expr;
2188 if (!(all_btree || all_hash))
2192 semi_operators =
lappend_oid(semi_operators, opno);
2197 if (semi_rhs_exprs ==
NIL)
2253 Relids incompatible_joins;
2256 int save_last_rinfo_serial;
2292 incompatible_joins =
bms_union(joins_below, joins_above);
2304 save_last_rinfo_serial =
root->last_rinfo_serial;
2306 joins_so_far = NULL;
2307 foreach(lc, jtitems)
2311 bool below_sjinfo =
false;
2312 bool above_sjinfo =
false;
2315 bool allow_equivalence,
2319 if (othersj == NULL)
2325 below_sjinfo =
true;
2327 else if (othersj ==
sjinfo)
2335 above_sjinfo =
true;
2344 root->last_rinfo_serial = save_last_rinfo_serial;
2371 this_ojscope =
bms_union(ojscope, joins_so_far);
2399 allow_equivalence = (joins_so_far == NULL);
2400 has_clone = allow_equivalence;
2401 is_clone = !has_clone;
2406 root->qual_security_level,
2444 root->qual_security_level,
2470 Index security_level,
2473 Relids outerjoin_nonnullable,
2474 Relids incompatible_relids,
2475 bool allow_equivalence,
2478 List **postponed_oj_qual_list)
2482 foreach(lc, clauses)
2492 outerjoin_nonnullable,
2493 incompatible_relids,
2497 postponed_oj_qual_list);
2548 Index security_level,
2551 Relids outerjoin_nonnullable,
2552 Relids incompatible_relids,
2553 bool allow_equivalence,
2556 List **postponed_oj_qual_list)
2559 bool is_pushed_down;
2560 bool pseudoconstant =
false;
2561 bool maybe_equivalence;
2562 bool maybe_outer_join;
2603 elog(
ERROR,
"failed to postpone qual containing lateral reference");
2611 elog(
ERROR,
"JOIN qualification cannot refer to other relations");
2663 pseudoconstant =
true;
2665 root->hasPseudoConstantQuals =
true;
2710 if (postponed_oj_qual_list != NULL)
2712 *postponed_oj_qual_list =
lappend(*postponed_oj_qual_list, clause);
2723 is_pushed_down =
false;
2724 maybe_equivalence =
false;
2725 maybe_outer_join =
true;
2744 is_pushed_down =
true;
2756 maybe_equivalence = allow_equivalence;
2762 maybe_outer_join =
false;
2776 incompatible_relids,
2777 outerjoin_nonnullable);
2811 where_needed = relids;
2855 if (restrictinfo->mergeopfamilies)
2857 if (maybe_equivalence)
2862 if (restrictinfo->mergeopfamilies)
2866 else if (maybe_outer_join && restrictinfo->can_join)
2873 outerjoin_nonnullable) &&
2875 outerjoin_nonnullable))
2880 ojcinfo->
rinfo = restrictinfo;
2887 outerjoin_nonnullable) &&
2889 outerjoin_nonnullable))
2894 ojcinfo->
rinfo = restrictinfo;
2905 ojcinfo->
rinfo = restrictinfo;
2937 Var *forced_null_var;
2942 if (forced_null_var == NULL)
2951 if (forced_null_var->varnullingrels == NULL)
2954 foreach(lc,
root->join_info_list)
3003 if (!rte->
inh || rte->relkind == RELKIND_PARTITIONED_TABLE)
3022 int save_last_rinfo_serial =
root->last_rinfo_serial;
3029 restrictinfo->pseudoconstant,
3035 root->last_rinfo_serial = save_last_rinfo_serial;
3117 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
3171 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
3244 elog(
ERROR,
"cannot cope with variable-free clause");
3286 Index security_level,
3292 bool pseudoconstant =
false;
3317 if (!cclause->constisnull &&
DatumGetBool(cclause->constvalue))
3343 pseudoconstant =
true;
3345 root->hasPseudoConstantQuals =
true;
3407 return restrictinfo;
3430 Index security_level)
3466 return restrictinfo;
3503 foreach(lc,
root->join_info_list)
3541 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
3575 where_needed = relids;
3604 foreach(lc,
root->fkey_list)
3621 if (con_rel == NULL)
3624 if (ref_rel == NULL)
3643 for (colno = 0; colno < fkinfo->
nkeys; colno++)
3665 con_attno = fkinfo->conkey[colno];
3666 ref_attno = fkinfo->confkey[colno];
3686 if (!(leftvar &&
IsA(leftvar,
Var)))
3690 if (!(rightvar &&
IsA(rightvar,
Var)))
3694 if (fkinfo->
ref_relid == leftvar->varno &&
3695 ref_attno == leftvar->varattno &&
3697 con_attno == rightvar->varattno)
3700 if (clause->
opno == fkinfo->conpfeqop[colno])
3707 else if (fkinfo->
ref_relid == rightvar->varno &&
3708 ref_attno == rightvar->varattno &&
3710 con_attno == leftvar->varattno)
3721 if (clause->
opno == fpeqop)
3730 if (fkinfo->
rinfos[colno])
3741 newlist =
lappend(newlist, fkinfo);
3744 root->fkey_list = newlist;
3770 if (restrictinfo->pseudoconstant)
3777 opno = ((
OpExpr *) clause)->opno;
3807 if (restrictinfo->pseudoconstant)
3814 opno = ((
OpExpr *) clause)->opno;
3819 restrictinfo->hashjoinoperator = opno;
3836 if (restrictinfo->pseudoconstant)
3849 restrictinfo->left_hasheqoperator = typentry->
eq_opr;
3857 if (lefttype != righttype)
3862 restrictinfo->right_hasheqoperator = typentry->
eq_opr;
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
BMS_Comparison bms_subset_compare(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)
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)
BMS_Membership bms_membership(const Bitmapset *a)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
bool bms_get_singleton_member(const Bitmapset *a, int *member)
Bitmapset * bms_copy(const Bitmapset *a)
#define Assert(condition)
#define OidIsValid(objectId)
Var * find_forced_null_var(Node *node)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Relids find_nonnullable_rels(Node *clause)
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)
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)
void remove_useless_groupby_columns(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)
RestrictInfo * build_implied_join_equality(PlannerInfo *root, Oid opno, Oid collation, Expr *item1, Expr *item2, Relids qualscope, Index security_level)
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)
List * deconstruct_jointree(PlannerInfo *root)
static bool check_redundant_nullability_qual(PlannerInfo *root, Node *clause)
void rebuild_joinclause_attr_needed(PlannerInfo *root)
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)
RestrictInfo * process_implied_equality(PlannerInfo *root, Oid opno, Oid collation, Expr *item1, Expr *item2, Relids qualscope, Index security_level, bool both_const)
void create_lateral_join_info(PlannerInfo *root)
static void process_security_barrier_quals(PlannerInfo *root, int rti, JoinTreeItem *jtitem)
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 * list_concat(List *list1, const List *list2)
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
void list_free_deep(List *list)
bool op_hashjoinable(Oid opno, Oid inputtype)
bool op_mergejoinable(Oid opno, Oid inputtype)
List * get_mergejoin_opfamilies(Oid opno)
Oid get_commutator(Oid opno)
Node * makeBoolConst(bool value, bool isnull)
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
void * palloc0(Size size)
Oid exprType(const Node *expr)
static bool is_orclause(const void *clause)
static Node * get_rightop(const void *clause)
static bool is_opclause(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)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define foreach_node(type, var, lst)
#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)
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
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 * 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)
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
#define FirstLowInvalidHeapAttributeNumber
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define TYPECACHE_HASH_PROC
Relids pull_varnos(PlannerInfo *root, Node *node)
List * pull_vars_of_level(Node *node, int levelsup)
List * pull_var_clause(Node *node, int flags)