54 Relids nominal_join_relids,
56 Relids nominal_inner_relids,
59 Oid lefttype,
Oid righttype);
140 Assert(restrictinfo->left_ec == NULL);
141 Assert(restrictinfo->right_ec == NULL);
149 opno = ((
OpExpr *) clause)->opno;
150 collation = ((
OpExpr *) clause)->inputcollid;
153 item1_relids = restrictinfo->left_relids;
154 item2_relids = restrictinfo->right_relids;
173 if (
equal(item1, item2))
192 ntest->argisrow =
false;
201 restrictinfo->pseudoconstant,
220 opfamilies = restrictinfo->mergeopfamilies;
243 foreach(lc1,
root->eq_classes)
319 restrictinfo->left_ec = ec1;
320 restrictinfo->right_ec = ec1;
322 restrictinfo->left_em = em1;
323 restrictinfo->right_em = em2;
333 if (
root->ec_merging_done)
334 elog(
ERROR,
"too late to merge equivalence classes");
366 restrictinfo->left_ec = ec1;
367 restrictinfo->right_ec = ec1;
369 restrictinfo->left_em = em1;
370 restrictinfo->right_em = em2;
376 jdomain, NULL, item2_type);
383 restrictinfo->left_ec = ec1;
384 restrictinfo->right_ec = ec1;
386 restrictinfo->left_em = em1;
387 restrictinfo->right_em = em2;
393 jdomain, NULL, item1_type);
400 restrictinfo->left_ec = ec2;
401 restrictinfo->right_ec = ec2;
403 restrictinfo->left_em = em1;
404 restrictinfo->right_em = em2;
425 jdomain, NULL, item1_type);
427 jdomain, NULL, item2_type);
432 restrictinfo->left_ec = ec;
433 restrictinfo->right_ec = ec;
435 restrictinfo->left_em = em1;
436 restrictinfo->right_em = em2;
479 if (IsPolymorphicType(req_type) || req_type == RECORDOID)
480 req_type = expr_type;
485 if (expr_type != req_type ||
495 if (expr_type != req_type)
505 req_type, req_typmod, req_collation,
527 em->em_parent = parent;
616 foreach(lc1,
root->eq_classes)
626 (sortref == 0 || sortref != cur_ec->
ec_sortref))
685 elog(
ERROR,
"volatile EquivalenceClass has no sortref");
693 jdomain, NULL, opcintype);
719 if (
root->ec_merging_done)
729 if (
i ==
root->group_rtindex)
799 if (
equal(emexpr, expr))
841 bool require_parallel_safe)
897 if (require_parallel_safe &&
937 foreach(lc, target->
exprs)
958 if (require_parallel_safe &&
969 require_parallel_safe);
1044 root->ec_merging_done =
true;
1047 foreach(lc,
root->eq_classes)
1050 bool can_generate_joinclause =
false;
1073 can_generate_joinclause =
1090 if (
i ==
root->group_rtindex)
1104 if (can_generate_joinclause)
1155 Assert(const_em != NULL);
1165 if (cur_em == const_em)
1196 if (rinfo && rinfo->mergeopfamilies)
1199 rinfo->left_ec = rinfo->right_ec = ec;
1200 rinfo->left_em = cur_em;
1201 rinfo->right_em = const_em;
1236 Assert(relid < root->simple_rel_array_size);
1238 if (prev_ems[relid] != NULL)
1272 if (rinfo && rinfo->mergeopfamilies)
1275 rinfo->left_ec = rinfo->right_ec = ec;
1276 rinfo->left_em = prev_em;
1277 rinfo->right_em = cur_em;
1280 prev_ems[relid] = cur_em;
1393 Relids nominal_inner_relids;
1394 Relids nominal_join_relids;
1406 nominal_join_relids =
bms_union(outer_relids, nominal_inner_relids);
1408 nominal_join_relids,
1414 nominal_inner_relids = inner_relids;
1415 nominal_join_relids = join_relids;
1431 if (sjinfo && sjinfo->
ojrelid != 0)
1465 nominal_join_relids,
1467 nominal_inner_relids,
1493 Relids nominal_inner_relids;
1494 Relids nominal_join_relids;
1505 nominal_join_relids =
bms_union(outer_relids, nominal_inner_relids);
1509 nominal_inner_relids = inner_relids;
1510 nominal_join_relids = join_relids;
1513 foreach(lc, eclasses)
1541 nominal_join_relids,
1543 nominal_inner_relids,
1590 outer_members =
lappend(outer_members, cur_em);
1592 inner_members =
lappend(inner_members, cur_em);
1594 new_members =
lappend(new_members, cur_em);
1606 if (outer_members && inner_members)
1611 int best_score = -1;
1614 foreach(lc1, outer_members)
1619 foreach(lc2, inner_members)
1642 if (score > best_score)
1644 best_outer_em = outer_em;
1645 best_inner_em = inner_em;
1648 if (best_score == 3)
1652 if (best_score == 3)
1667 best_outer_em, best_inner_em,
1670 result =
lappend(result, rinfo);
1692 foreach(lc1, new_members)
1696 if (prev_em != NULL)
1714 result =
lappend(result, rinfo);
1734 Relids nominal_join_relids,
1736 Relids nominal_inner_relids,
1750 result =
lappend(result, restrictinfo);
1768 inner_rel->top_parent);
1840 if (rinfo->left_em == leftem &&
1841 rinfo->right_em == rightem &&
1842 rinfo->parent_ec == parent_ec)
1844 if (rinfo->left_em == rightem &&
1845 rinfo->right_em == leftem &&
1846 rinfo->parent_ec == parent_ec)
1853 if (rinfo->left_em == leftem &&
1854 rinfo->right_em == rightem &&
1855 rinfo->parent_ec == parent_ec)
1857 if (rinfo->left_em == rightem &&
1858 rinfo->right_em == leftem &&
1859 rinfo->parent_ec == parent_ec)
1912 rinfo->parent_ec = parent_ec;
1918 rinfo->left_ec = ec;
1919 rinfo->right_ec = ec;
1922 rinfo->left_em = leftem;
1923 rinfo->right_em = rightem;
2012 foreach(cell,
root->left_join_clauses)
2022 root->left_join_clauses =
2040 foreach(cell,
root->right_join_clauses)
2050 root->right_join_clauses =
2068 foreach(cell,
root->full_join_clauses)
2078 root->full_join_clauses =
2097 foreach(cell,
root->left_join_clauses)
2103 foreach(cell,
root->right_join_clauses)
2109 foreach(cell,
root->full_join_clauses)
2148 inner_datatype = right_type;
2149 inner_relids = rinfo->right_relids;
2155 inner_datatype = left_type;
2156 inner_relids = rinfo->left_relids;
2160 foreach(lc1,
root->eq_classes)
2268 left_relids = rinfo->left_relids;
2269 right_relids = rinfo->right_relids;
2271 foreach(lc1,
root->eq_classes)
2334 if (
equal(leftvar, cfirst) &&
equal(rightvar, csecond))
2351 matchleft = matchright =
false;
2404 if (matchleft && matchright)
2435 foreach(lc,
root->eq_classes)
2471 foreach(lc,
root->join_domains)
2478 elog(
ERROR,
"failed to find appropriate JoinDomain");
2502 foreach(lc1,
root->eq_classes)
2505 bool item1member =
false;
2506 bool item2member =
false;
2535 if (item1member && item2member)
2564 AttrNumber var1attno = fkinfo->conkey[colno];
2566 AttrNumber var2attno = fkinfo->confkey[colno];
2567 Oid eqop = fkinfo->conpfeqop[colno];
2607 if (!(var &&
IsA(var,
Var)))
2613 else if (var->
varno == var2varno && var->
varattno == var2attno)
2617 if (item1_em && item2_em)
2624 if (opfamilies ==
NIL)
2628 fkinfo->
eclass[colno] = ec;
2665 if (rinfo->left_em == em)
2729 for (
int pos = 0; pos < num_members; pos++)
2765 child_expr = (
Expr *)
2773 child_expr = (
Expr *)
2777 child_rel->top_parent);
2861 for (
int pos = 0; pos < num_members; pos++)
2892 child_expr = (
Expr *)
2895 nappinfos, appinfos);
2901 child_expr = (
Expr *)
2905 child_joinrel->top_parent);
2943 List *child_tlist,
List *setop_pathkeys)
2948 foreach(lc, child_tlist)
2958 elog(
ERROR,
"too few pathkeys for set operation");
2961 parent_em =
linitial(pk->pk_eclass->ec_members);
2976 lc2 =
lnext(setop_pathkeys, lc2);
3035 parent_relids = NULL;
3091 if (other_em == cur_em ||
3118 result =
lappend(result, rinfo);
3302 foreach(lc,
eclass->ec_members)
3330 if (parent_ec == NULL)
3333 foreach(lc, clauselist)
3337 if (otherrinfo->parent_ec == parent_ec)
3356 foreach(lc, indexclauses)
3366 if (rinfo == otherrinfo)
3369 if (parent_ec && otherrinfo->parent_ec == parent_ec)
3400 if (
i ==
root->group_rtindex)
3434 rel2ecs =
root->simple_rel_array[relid]->eclass_indexes;
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, RelOptInfo *childrel, RelOptInfo *parentrel)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
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_difference(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_int_members(Bitmapset *a, const Bitmapset *b)
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)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
#define Assert(condition)
#define OidIsValid(objectId)
bool contain_agg_clause(Node *clause)
bool contain_window_function(Node *clause)
bool is_parallel_safe(PlannerInfo *root, Node *node)
bool contain_volatile_functions(Node *clause)
bool equal(const void *a, const void *b)
void rebuild_eclass_attr_needed(PlannerInfo *root)
EquivalenceMember * find_ec_member_matching_expr(EquivalenceClass *ec, Expr *expr, Relids relids)
void add_child_rel_equivalences(PlannerInfo *root, AppendRelInfo *appinfo, RelOptInfo *parent_rel, RelOptInfo *child_rel)
bool is_redundant_with_indexclauses(RestrictInfo *rinfo, List *indexclauses)
void generate_base_implied_equalities(PlannerInfo *root)
bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2, Oid opfamily)
RestrictInfo * find_derived_clause_for_ec_member(EquivalenceClass *ec, EquivalenceMember *em)
static List * generate_join_implied_equalities_normal(PlannerInfo *root, EquivalenceClass *ec, Relids join_relids, Relids outer_relids, Relids inner_relids)
Expr * canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation)
static JoinDomain * find_join_domain(PlannerInfo *root, Relids relids)
bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, bool require_parallel_safe)
static void generate_base_implied_equalities_broken(PlannerInfo *root, EquivalenceClass *ec)
bool process_equivalence(PlannerInfo *root, RestrictInfo **p_restrictinfo, JoinDomain *jdomain)
List * generate_join_implied_equalities_for_ecs(PlannerInfo *root, List *eclasses, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
static EquivalenceMember * add_eq_member(EquivalenceClass *ec, Expr *expr, Relids relids, JoinDomain *jdomain, EquivalenceMember *parent, Oid datatype)
EquivalenceClass * get_eclass_for_sort_expr(PlannerInfo *root, Expr *expr, List *opfamilies, Oid opcintype, Oid collation, Index sortref, Relids rel, bool create_it)
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo)
bool have_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
static Bitmapset * get_common_eclass_indexes(PlannerInfo *root, Relids relids1, Relids relids2)
List * generate_implied_equalities_for_column(PlannerInfo *root, RelOptInfo *rel, ec_matches_callback_type callback, void *callback_arg, Relids prohibited_rels)
void add_setop_child_rel_equivalences(PlannerInfo *root, RelOptInfo *child_rel, List *child_tlist, List *setop_pathkeys)
void reconsider_outer_join_clauses(PlannerInfo *root)
bool eclass_useful_for_merging(PlannerInfo *root, EquivalenceClass *eclass, RelOptInfo *rel)
void add_child_join_rel_equivalences(PlannerInfo *root, int nappinfos, AppendRelInfo **appinfos, RelOptInfo *parent_joinrel, RelOptInfo *child_joinrel)
static RestrictInfo * create_join_clause(PlannerInfo *root, EquivalenceClass *ec, Oid opno, EquivalenceMember *leftem, EquivalenceMember *rightem, EquivalenceClass *parent_ec)
EquivalenceClass * match_eclasses_to_foreign_key_col(PlannerInfo *root, ForeignKeyOptInfo *fkinfo, int colno)
static Bitmapset * get_eclass_indexes_for_relids(PlannerInfo *root, Relids relids)
bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist)
static void generate_base_implied_equalities_no_const(PlannerInfo *root, EquivalenceClass *ec)
static void generate_base_implied_equalities_const(PlannerInfo *root, EquivalenceClass *ec)
static Oid select_equality_operator(EquivalenceClass *ec, Oid lefttype, Oid righttype)
static bool reconsider_outer_join_clause(PlannerInfo *root, OuterJoinClauseInfo *ojcinfo, bool outer_on_left)
EquivalenceMember * find_computable_ec_member(PlannerInfo *root, EquivalenceClass *ec, List *exprs, Relids relids, bool require_parallel_safe)
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
static bool reconsider_full_join_clause(PlannerInfo *root, OuterJoinClauseInfo *ojcinfo)
static List * generate_join_implied_equalities_broken(PlannerInfo *root, EquivalenceClass *ec, Relids nominal_join_relids, Relids outer_relids, Relids nominal_inner_relids, RelOptInfo *inner_rel)
void distribute_restrictinfo_to_rels(PlannerInfo *root, RestrictInfo *restrictinfo)
void add_vars_to_targetlist(PlannerInfo *root, List *vars, Relids where_needed)
RestrictInfo * build_implied_join_equality(PlannerInfo *root, Oid opno, Oid collation, Expr *item1, Expr *item2, Relids qualscope, Index security_level)
RestrictInfo * process_implied_equality(PlannerInfo *root, Oid opno, Oid collation, Expr *item1, Expr *item2, Relids qualscope, Index security_level, bool both_const)
void add_vars_to_attr_needed(PlannerInfo *root, List *vars, Relids where_needed)
if(TABLE==NULL||TABLE_index==NULL)
Relids add_outer_joins_to_relids(PlannerInfo *root, Relids input_relids, SpecialJoinInfo *sjinfo, List **pushed_down_joins)
List * lappend(List *list, void *datum)
List * list_copy(const List *oldlist)
List * list_delete_nth_cell(List *list, int n)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
bool list_member(const List *list, const void *datum)
List * get_mergejoin_opfamilies(Oid opno)
bool op_hashjoinable(Oid opno, Oid inputtype)
RegProcedure get_opcode(Oid opno)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
bool func_strict(Oid funcid)
bool get_func_leakproof(Oid funcid)
void op_input_types(Oid opno, Oid *lefttype, Oid *righttype)
Node * makeBoolConst(bool value, bool isnull)
void pfree(void *pointer)
void * palloc0(Size size)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
bool expression_returns_set(Node *clause)
void set_opfuncid(OpExpr *opexpr)
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_WINDOWFUNCS
#define PVC_INCLUDE_PLACEHOLDERS
#define PVC_INCLUDE_AGGREGATES
#define IS_SIMPLE_REL(rel)
@ RELOPT_OTHER_MEMBER_REL
#define IS_OTHER_REL(rel)
bool(* ec_matches_callback_type)(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define foreach_current_index(var_or_cell)
#define foreach_delete_current(lst, var_or_cell)
static ListCell * list_head(const List *l)
static void * list_nth(const List *list, int n)
static ListCell * lnext(const List *l, const ListCell *c)
MemoryContextSwitchTo(old_ctx)
static struct cvec * eclass(struct vars *v, chr c, int cases)
Relids find_childrel_parents(PlannerInfo *root, RelOptInfo *rel)
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)
#define BTEqualStrategyNumber
struct EquivalenceClass * ec_merged
struct EquivalenceClass * eclass[INDEX_MAX_KEYS]
struct EquivalenceMember * fk_eclass_member[INDEX_MAX_KEYS]
struct RestrictInfo * rinfo
NullTestType nulltesttype
struct PathTarget * reltarget
Bitmapset * eclass_indexes
Relids incompatible_relids
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
List * pull_var_clause(Node *node, int flags)
Relids pull_varnos(PlannerInfo *root, Node *node)