115 Index security_level,
118 Relids outerjoin_nonnullable,
119 Relids incompatible_relids,
120 bool allow_equivalence,
123 List **postponed_oj_qual_list);
127 Index security_level,
130 Relids outerjoin_nonnullable,
131 Relids incompatible_relids,
132 bool allow_equivalence,
135 List **postponed_oj_qual_list);
191 elog(
ERROR,
"unrecognized node type: %d",
207 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
249 if (tlist_vars !=
NIL)
259 if (
root->parse->havingQual)
265 if (having_vars !=
NIL)
310 if (rel->attr_needed[attno] == NULL)
320 var->varnullingrels = NULL;
424 bool tryremove =
false;
433 if (
parse->groupingSets)
443 foreach(lc,
root->processed_groupClause)
490 foreach(lc,
parse->rtable)
509 if (rte->
inh && rte->relkind != RELKIND_PARTITIONED_TABLE)
513 relattnos = groupbyattnos[relid];
517 rel =
root->simple_rel_array[relid];
542 nulls_check_ok =
true;
543 for (
int i = 0;
i <
index->nkeycolumns;
i++)
553 if (!
index->nullsnotdistinct &&
557 nulls_check_ok =
false;
585 if (
index->nkeycolumns < best_nkeycolumns)
587 best_keycolumns = ind_attnos;
588 best_nkeycolumns =
index->nkeycolumns;
599 if (surplusvars == NULL)
613 if (surplusvars != NULL)
617 foreach(lc,
root->processed_groupClause)
630 surplusvars[var->
varno]))
631 new_groupby =
lappend(new_groupby, sgc);
634 root->processed_groupClause = new_groupby;
656 if (!
root->processed_groupClause)
662 if (
root->parse->groupingSets)
668 if (
root->numOrderedAggs > 0)
676 if (
root->hasNonPartialAggs ||
root->hasNonSerialAggs)
683 if (
root->parse->hasTargetSRFs)
710 if (
root->agg_clause_list ==
NIL)
735 foreach(lc,
root->aggtransinfos)
757 Relids aggregate_relids = NULL;
758 bool eager_agg_applicable =
true;
774 if (
root->parse->havingQual != NULL)
781 if (having_exprs !=
NIL)
783 tlist_exprs =
list_concat(tlist_exprs, having_exprs);
788 foreach(lc, tlist_exprs)
798 eager_agg_applicable =
false;
819 if (
root->qual_security_level > 0 &&
822 eager_agg_applicable =
false;
835 eager_agg_applicable =
false;
850 if (eager_agg_applicable)
852 root->agg_clause_list = agg_clause_list;
853 root->tlist_vars = tlist_vars;
882 foreach(lc,
root->processed_groupClause)
931 forthree(lc1, exprs, lc2, sortgrouprefs, lc3, ecs)
969 &opfamily, &opcintype, &cmptype))
970 elog(
ERROR,
"operator %u is not a valid ordering operator",
987 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
991 elog(
ERROR,
"could not find opfamilies for equality operator %u",
1032 if (!
root->hasLateralRTEs)
1038 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1140 newvars =
lappend(newvars, node);
1181 if (!
root->hasLateralRTEs)
1185 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1216 bool found_laterals =
false;
1221 if (!
root->hasLateralRTEs)
1230 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1245 lateral_relids = NULL;
1256 found_laterals =
true;
1265 found_laterals =
true;
1291 foreach(lc,
root->placeholder_list)
1301 found_laterals =
true;
1344 if (!found_laterals)
1346 root->hasLateralRTEs =
false;
1361 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1364 Relids outer_lateral_relids;
1372 if (outer_lateral_relids == NULL)
1376 for (rti2 = 1; rti2 <
root->simple_rel_array_size; rti2++)
1386 outer_lateral_relids);
1395 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1465 root->placeholdersFrozen =
true;
1476 root->all_baserels = NULL;
1477 root->outer_join_rels = NULL;
1491 foreach(lc, item_list)
1502 if (
root->join_info_list)
1504 foreach(lc, item_list)
1557 jtitem->
jdomain = parent_domain;
1573 jtitem->
jdomain = parent_domain;
1602 if (sub_members <= 1 ||
1606 joinlist =
lappend(joinlist, sub_joinlist);
1629 switch (
j->jointype)
1633 jtitem->
jdomain = parent_domain;
1660 jtitem->
jdomain = child_domain;
1679 if (
j->rtindex != 0)
1699 jtitem->
jdomain = parent_domain;
1773 elog(
ERROR,
"unrecognized join type: %d",
1775 leftjoinlist = rightjoinlist =
NIL;
1792 joinlist =
list_concat(leftjoinlist, rightjoinlist);
1804 leftpart = (
Node *) leftjoinlist;
1808 rightpart = (
Node *) rightjoinlist;
1814 elog(
ERROR,
"unrecognized node type: %d",
1820 *item_list =
lappend(*item_list, jtitem);
1842 if (
root->qual_security_level > 0)
1858 root->qual_security_level,
1870 root->qual_security_level,
1882 List **postponed_oj_qual_list;
1946 postponed_oj_qual_list = NULL;
1952 root->qual_security_level,
1958 postponed_oj_qual_list);
1966 elog(
ERROR,
"unrecognized node type: %d",
1989 Index security_level = 0;
1998 foreach(lc, rte->securityQuals)
2023 Assert(security_level <= root->qual_security_level);
2045 if (relid ==
root->group_rtindex)
2114 foreach(l,
root->parse->rowMarks)
2121 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2124 errmsg(
"%s cannot be applied to the nullable side of an outer join",
2185 commute_below_l = commute_below_r = NULL;
2186 foreach(l,
root->join_info_list)
2189 bool have_unsafe_phvs;
2233 have_unsafe_phvs =
false;
2256 (have_unsafe_phvs ||
2342 foreach(l,
root->placeholder_list)
2388 if (commute_below_l || commute_below_r)
2393 foreach(l,
root->join_info_list)
2419 List *semi_operators;
2420 List *semi_rhs_exprs;
2461 semi_operators =
NIL;
2462 semi_rhs_exprs =
NIL;
2504 all_varnos =
bms_union(left_varnos, right_varnos);
2535 right_expr = left_expr;
2557 if (!(all_btree || all_hash))
2561 semi_operators =
lappend_oid(semi_operators, opno);
2566 if (semi_rhs_exprs ==
NIL)
2622 Relids incompatible_joins;
2625 int save_last_rinfo_serial;
2661 incompatible_joins =
bms_union(joins_below, joins_above);
2673 save_last_rinfo_serial =
root->last_rinfo_serial;
2675 joins_so_far = NULL;
2676 foreach(lc, jtitems)
2680 bool below_sjinfo =
false;
2681 bool above_sjinfo =
false;
2684 bool allow_equivalence,
2688 if (othersj == NULL)
2694 below_sjinfo =
true;
2696 else if (othersj ==
sjinfo)
2704 above_sjinfo =
true;
2713 root->last_rinfo_serial = save_last_rinfo_serial;
2740 this_ojscope =
bms_union(ojscope, joins_so_far);
2768 allow_equivalence = (joins_so_far == NULL);
2769 has_clone = allow_equivalence;
2770 is_clone = !has_clone;
2775 root->qual_security_level,
2813 root->qual_security_level,
2839 Index security_level,
2842 Relids outerjoin_nonnullable,
2843 Relids incompatible_relids,
2844 bool allow_equivalence,
2847 List **postponed_oj_qual_list)
2851 foreach(lc, clauses)
2861 outerjoin_nonnullable,
2862 incompatible_relids,
2866 postponed_oj_qual_list);
2917 Index security_level,
2920 Relids outerjoin_nonnullable,
2921 Relids incompatible_relids,
2922 bool allow_equivalence,
2925 List **postponed_oj_qual_list)
2928 bool is_pushed_down;
2929 bool pseudoconstant =
false;
2930 bool maybe_equivalence;
2931 bool maybe_outer_join;
2972 elog(
ERROR,
"failed to postpone qual containing lateral reference");
2980 elog(
ERROR,
"JOIN qualification cannot refer to other relations");
3032 pseudoconstant =
true;
3034 root->hasPseudoConstantQuals =
true;
3079 if (postponed_oj_qual_list != NULL)
3081 *postponed_oj_qual_list =
lappend(*postponed_oj_qual_list, clause);
3092 is_pushed_down =
false;
3093 maybe_equivalence =
false;
3094 maybe_outer_join =
true;
3113 is_pushed_down =
true;
3125 maybe_equivalence = allow_equivalence;
3131 maybe_outer_join =
false;
3145 incompatible_relids,
3146 outerjoin_nonnullable);
3180 where_needed = relids;
3224 if (restrictinfo->mergeopfamilies)
3226 if (maybe_equivalence)
3231 if (restrictinfo->mergeopfamilies)
3235 else if (maybe_outer_join && restrictinfo->can_join)
3242 outerjoin_nonnullable) &&
3244 outerjoin_nonnullable))
3249 ojcinfo->
rinfo = restrictinfo;
3256 outerjoin_nonnullable) &&
3258 outerjoin_nonnullable))
3263 ojcinfo->
rinfo = restrictinfo;
3274 ojcinfo->
rinfo = restrictinfo;
3306 Var *forced_null_var;
3311 if (forced_null_var == NULL)
3320 if (forced_null_var->varnullingrels == NULL)
3323 foreach(lc,
root->join_info_list)
3372 if (!rte->
inh || rte->relkind == RELKIND_PARTITIONED_TABLE)
3391 int save_last_rinfo_serial =
root->last_rinfo_serial;
3398 restrictinfo->pseudoconstant,
3404 root->last_rinfo_serial = save_last_rinfo_serial;
3465 if (nulltest->argisrow)
3482 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
3530 if (nulltest->argisrow)
3552 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
3625 elog(
ERROR,
"cannot cope with variable-free clause");
3667 Index security_level,
3673 bool pseudoconstant =
false;
3698 if (!cclause->constisnull &&
DatumGetBool(cclause->constvalue))
3724 pseudoconstant =
true;
3726 root->hasPseudoConstantQuals =
true;
3788 return restrictinfo;
3811 Index security_level)
3847 return restrictinfo;
3884 foreach(lc,
root->join_info_list)
3922 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
3956 where_needed = relids;
3985 foreach(lc,
root->fkey_list)
4002 if (con_rel == NULL)
4005 if (ref_rel == NULL)
4024 for (colno = 0; colno < fkinfo->
nkeys; colno++)
4046 con_attno = fkinfo->conkey[colno];
4047 ref_attno = fkinfo->confkey[colno];
4067 if (!(leftvar &&
IsA(leftvar,
Var)))
4071 if (!(rightvar &&
IsA(rightvar,
Var)))
4075 if (fkinfo->
ref_relid == leftvar->varno &&
4076 ref_attno == leftvar->varattno &&
4078 con_attno == rightvar->varattno)
4081 if (clause->
opno == fkinfo->conpfeqop[colno])
4088 else if (fkinfo->
ref_relid == rightvar->varno &&
4089 ref_attno == rightvar->varattno &&
4091 con_attno == leftvar->varattno)
4102 if (clause->
opno == fpeqop)
4111 if (fkinfo->
rinfos[colno])
4122 newlist =
lappend(newlist, fkinfo);
4125 root->fkey_list = newlist;
4151 if (restrictinfo->pseudoconstant)
4158 opno = ((
OpExpr *) clause)->opno;
4188 if (restrictinfo->pseudoconstant)
4195 opno = ((
OpExpr *) clause)->opno;
4200 restrictinfo->hashjoinoperator = opno;
4217 if (restrictinfo->pseudoconstant)
4230 restrictinfo->left_hasheqoperator = typentry->
eq_opr;
4238 if (lefttype != righttype)
4243 restrictinfo->right_hasheqoperator = typentry->
eq_opr;
bool enable_eager_aggregate
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 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)
bool var_is_nonnullable(PlannerInfo *root, Var *var, bool use_rel_info)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
EquivalenceClass * get_eclass_for_sort_expr(PlannerInfo *root, Expr *expr, List *opfamilies, Oid opcintype, Oid collation, Index sortref, Relids rel, bool create_it)
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)
Datum OidFunctionCall1Coll(Oid functionId, Oid collation, Datum arg1)
Assert(PointerIsAligned(start, uint64))
void expand_inherited_rtentry(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, Index rti)
static void check_hashjoinable(RestrictInfo *restrictinfo)
static void create_grouping_expr_infos(PlannerInfo *root)
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)
void setup_eager_aggregation(PlannerInfo *root)
static bool expr_is_nonnullable(PlannerInfo *root, Expr *expr)
static EquivalenceClass * get_eclass_for_sortgroupclause(PlannerInfo *root, SortGroupClause *sgc, 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 bool is_partial_agg_memory_risky(PlannerInfo *root)
static void create_agg_clause_infos(PlannerInfo *root)
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_append_unique(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
void list_free_deep(List *list)
bool get_ordering_op_properties(Oid opno, Oid *opfamily, Oid *opcintype, CompareType *cmptype)
Oid get_opfamily_member_for_cmptype(Oid opfamily, Oid lefttype, Oid righttype, CompareType cmptype)
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
bool op_hashjoinable(Oid opno, Oid inputtype)
bool get_func_leakproof(Oid funcid)
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)
#define BTEQUALIMAGE_PROC
Oid exprType(const Node *expr)
Oid exprCollation(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 castNode(_type_, nodeptr)
#define PVC_RECURSE_AGGREGATES
#define PVC_RECURSE_PLACEHOLDERS
#define PVC_RECURSE_WINDOWFUNCS
#define PVC_INCLUDE_PLACEHOLDERS
#define PVC_INCLUDE_AGGREGATES
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 forthree(cell1, list1, cell2, list2, cell3, list3)
#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 Datum ObjectIdGetDatum(Oid 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_BTREE_OPFAMILY
#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)