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)
442 foreach(lc,
root->processed_groupClause)
489 foreach(lc,
parse->rtable)
508 if (rte->
inh && rte->relkind != RELKIND_PARTITIONED_TABLE)
512 relattnos = groupbyattnos[relid];
516 rel =
root->simple_rel_array[relid];
541 nulls_check_ok =
true;
542 for (
int i = 0;
i <
index->nkeycolumns;
i++)
552 if (!
index->nullsnotdistinct &&
556 nulls_check_ok =
false;
584 if (
index->nkeycolumns < best_nkeycolumns)
586 best_keycolumns = ind_attnos;
587 best_nkeycolumns =
index->nkeycolumns;
598 if (surplusvars == NULL)
611 if (surplusvars != NULL)
615 foreach(lc,
root->processed_groupClause)
628 surplusvars[var->
varno]))
629 new_groupby =
lappend(new_groupby, sgc);
632 root->processed_groupClause = new_groupby;
654 if (!
root->processed_groupClause)
660 if (
root->parse->groupingSets)
666 if (
root->numOrderedAggs > 0)
674 if (
root->hasNonPartialAggs ||
root->hasNonSerialAggs)
681 if (
root->parse->hasTargetSRFs)
708 if (
root->agg_clause_list ==
NIL)
733 foreach(lc,
root->aggtransinfos)
755 Relids aggregate_relids = NULL;
756 bool eager_agg_applicable =
true;
772 if (
root->parse->havingQual != NULL)
779 if (having_exprs !=
NIL)
781 tlist_exprs =
list_concat(tlist_exprs, having_exprs);
786 foreach(lc, tlist_exprs)
796 eager_agg_applicable =
false;
817 if (
root->qual_security_level > 0 &&
820 eager_agg_applicable =
false;
833 eager_agg_applicable =
false;
848 if (eager_agg_applicable)
850 root->agg_clause_list = agg_clause_list;
851 root->tlist_vars = tlist_vars;
880 foreach(lc,
root->processed_groupClause)
929 forthree(lc1, exprs, lc2, sortgrouprefs, lc3, ecs)
967 &opfamily, &opcintype, &cmptype))
968 elog(
ERROR,
"operator %u is not a valid ordering operator",
985 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
989 elog(
ERROR,
"could not find opfamilies for equality operator %u",
1030 if (!
root->hasLateralRTEs)
1036 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1138 newvars =
lappend(newvars, node);
1179 if (!
root->hasLateralRTEs)
1183 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1214 bool found_laterals =
false;
1219 if (!
root->hasLateralRTEs)
1228 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1243 lateral_relids = NULL;
1254 found_laterals =
true;
1263 found_laterals =
true;
1289 foreach(lc,
root->placeholder_list)
1299 found_laterals =
true;
1342 if (!found_laterals)
1344 root->hasLateralRTEs =
false;
1359 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1362 Relids outer_lateral_relids;
1370 if (outer_lateral_relids == NULL)
1374 for (rti2 = 1; rti2 <
root->simple_rel_array_size; rti2++)
1384 outer_lateral_relids);
1393 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
1463 root->placeholdersFrozen =
true;
1474 root->all_baserels = NULL;
1475 root->outer_join_rels = NULL;
1489 foreach(lc, item_list)
1500 if (
root->join_info_list)
1502 foreach(lc, item_list)
1555 jtitem->
jdomain = parent_domain;
1571 jtitem->
jdomain = parent_domain;
1600 if (sub_members <= 1 ||
1604 joinlist =
lappend(joinlist, sub_joinlist);
1627 switch (
j->jointype)
1631 jtitem->
jdomain = parent_domain;
1658 jtitem->
jdomain = child_domain;
1677 if (
j->rtindex != 0)
1697 jtitem->
jdomain = parent_domain;
1771 elog(
ERROR,
"unrecognized join type: %d",
1773 leftjoinlist = rightjoinlist =
NIL;
1790 joinlist =
list_concat(leftjoinlist, rightjoinlist);
1802 leftpart = (
Node *) leftjoinlist;
1806 rightpart = (
Node *) rightjoinlist;
1812 elog(
ERROR,
"unrecognized node type: %d",
1818 *item_list =
lappend(*item_list, jtitem);
1840 if (
root->qual_security_level > 0)
1856 root->qual_security_level,
1868 root->qual_security_level,
1880 List **postponed_oj_qual_list;
1944 postponed_oj_qual_list = NULL;
1950 root->qual_security_level,
1956 postponed_oj_qual_list);
1964 elog(
ERROR,
"unrecognized node type: %d",
1987 Index security_level = 0;
1996 foreach(lc, rte->securityQuals)
2021 Assert(security_level <= root->qual_security_level);
2043 if (relid ==
root->group_rtindex)
2112 foreach(l,
root->parse->rowMarks)
2119 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2122 errmsg(
"%s cannot be applied to the nullable side of an outer join",
2183 commute_below_l = commute_below_r = NULL;
2184 foreach(l,
root->join_info_list)
2187 bool have_unsafe_phvs;
2231 have_unsafe_phvs =
false;
2254 (have_unsafe_phvs ||
2340 foreach(l,
root->placeholder_list)
2386 if (commute_below_l || commute_below_r)
2391 foreach(l,
root->join_info_list)
2417 List *semi_operators;
2418 List *semi_rhs_exprs;
2459 semi_operators =
NIL;
2460 semi_rhs_exprs =
NIL;
2502 all_varnos =
bms_union(left_varnos, right_varnos);
2533 right_expr = left_expr;
2555 if (!(all_btree || all_hash))
2559 semi_operators =
lappend_oid(semi_operators, opno);
2564 if (semi_rhs_exprs ==
NIL)
2620 Relids incompatible_joins;
2623 int save_last_rinfo_serial;
2659 incompatible_joins =
bms_union(joins_below, joins_above);
2671 save_last_rinfo_serial =
root->last_rinfo_serial;
2673 joins_so_far = NULL;
2674 foreach(lc, jtitems)
2678 bool below_sjinfo =
false;
2679 bool above_sjinfo =
false;
2682 bool allow_equivalence,
2686 if (othersj == NULL)
2692 below_sjinfo =
true;
2694 else if (othersj ==
sjinfo)
2702 above_sjinfo =
true;
2711 root->last_rinfo_serial = save_last_rinfo_serial;
2738 this_ojscope =
bms_union(ojscope, joins_so_far);
2766 allow_equivalence = (joins_so_far == NULL);
2767 has_clone = allow_equivalence;
2768 is_clone = !has_clone;
2773 root->qual_security_level,
2811 root->qual_security_level,
2837 Index security_level,
2840 Relids outerjoin_nonnullable,
2841 Relids incompatible_relids,
2842 bool allow_equivalence,
2845 List **postponed_oj_qual_list)
2849 foreach(lc, clauses)
2859 outerjoin_nonnullable,
2860 incompatible_relids,
2864 postponed_oj_qual_list);
2915 Index security_level,
2918 Relids outerjoin_nonnullable,
2919 Relids incompatible_relids,
2920 bool allow_equivalence,
2923 List **postponed_oj_qual_list)
2926 bool is_pushed_down;
2927 bool pseudoconstant =
false;
2928 bool maybe_equivalence;
2929 bool maybe_outer_join;
2970 elog(
ERROR,
"failed to postpone qual containing lateral reference");
2978 elog(
ERROR,
"JOIN qualification cannot refer to other relations");
3030 pseudoconstant =
true;
3032 root->hasPseudoConstantQuals =
true;
3077 if (postponed_oj_qual_list != NULL)
3079 *postponed_oj_qual_list =
lappend(*postponed_oj_qual_list, clause);
3090 is_pushed_down =
false;
3091 maybe_equivalence =
false;
3092 maybe_outer_join =
true;
3111 is_pushed_down =
true;
3123 maybe_equivalence = allow_equivalence;
3129 maybe_outer_join =
false;
3143 incompatible_relids,
3144 outerjoin_nonnullable);
3178 where_needed = relids;
3222 if (restrictinfo->mergeopfamilies)
3224 if (maybe_equivalence)
3229 if (restrictinfo->mergeopfamilies)
3233 else if (maybe_outer_join && restrictinfo->can_join)
3240 outerjoin_nonnullable) &&
3242 outerjoin_nonnullable))
3247 ojcinfo->
rinfo = restrictinfo;
3254 outerjoin_nonnullable) &&
3256 outerjoin_nonnullable))
3261 ojcinfo->
rinfo = restrictinfo;
3272 ojcinfo->
rinfo = restrictinfo;
3304 Var *forced_null_var;
3309 if (forced_null_var == NULL)
3318 if (forced_null_var->varnullingrels == NULL)
3321 foreach(lc,
root->join_info_list)
3370 if (!rte->
inh || rte->relkind == RELKIND_PARTITIONED_TABLE)
3389 int save_last_rinfo_serial =
root->last_rinfo_serial;
3396 restrictinfo->pseudoconstant,
3402 root->last_rinfo_serial = save_last_rinfo_serial;
3447 if (nulltest->argisrow)
3464 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
3512 if (nulltest->argisrow)
3534 foreach(lc, ((
BoolExpr *) restrictinfo->orclause)->args)
3607 elog(
ERROR,
"cannot cope with variable-free clause");
3649 Index security_level,
3655 bool pseudoconstant =
false;
3680 if (!cclause->constisnull &&
DatumGetBool(cclause->constvalue))
3706 pseudoconstant =
true;
3708 root->hasPseudoConstantQuals =
true;
3770 return restrictinfo;
3793 Index security_level)
3829 return restrictinfo;
3866 foreach(lc,
root->join_info_list)
3904 for (rti = 1; rti <
root->simple_rel_array_size; rti++)
3938 where_needed = relids;
3967 foreach(lc,
root->fkey_list)
3984 if (con_rel == NULL)
3987 if (ref_rel == NULL)
4006 for (colno = 0; colno < fkinfo->
nkeys; colno++)
4028 con_attno = fkinfo->conkey[colno];
4029 ref_attno = fkinfo->confkey[colno];
4049 if (!(leftvar &&
IsA(leftvar,
Var)))
4053 if (!(rightvar &&
IsA(rightvar,
Var)))
4057 if (fkinfo->
ref_relid == leftvar->varno &&
4058 ref_attno == leftvar->varattno &&
4060 con_attno == rightvar->varattno)
4063 if (clause->
opno == fkinfo->conpfeqop[colno])
4070 else if (fkinfo->
ref_relid == rightvar->varno &&
4071 ref_attno == rightvar->varattno &&
4073 con_attno == leftvar->varattno)
4084 if (clause->
opno == fpeqop)
4093 if (fkinfo->
rinfos[colno])
4104 newlist =
lappend(newlist, fkinfo);
4107 root->fkey_list = newlist;
4133 if (restrictinfo->pseudoconstant)
4140 opno = ((
OpExpr *) clause)->opno;
4170 if (restrictinfo->pseudoconstant)
4177 opno = ((
OpExpr *) clause)->opno;
4182 restrictinfo->hashjoinoperator = opno;
4199 if (restrictinfo->pseudoconstant)
4212 restrictinfo->left_hasheqoperator = typentry->
eq_opr;
4220 if (lefttype != righttype)
4225 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 expr_is_nonnullable(PlannerInfo *root, Expr *expr, bool use_rel_info)
bool contain_volatile_functions(Node *clause)
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_array(type, count)
#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 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)
#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)