55 Relids nominal_join_relids,
57 Relids nominal_inner_relids,
60 Oid lefttype,
Oid righttype);
141 Assert(restrictinfo->left_ec == NULL);
142 Assert(restrictinfo->right_ec == NULL);
150 opno = ((
OpExpr *) clause)->opno;
151 collation = ((
OpExpr *) clause)->inputcollid;
154 item1_relids = restrictinfo->left_relids;
155 item2_relids = restrictinfo->right_relids;
174 if (
equal(item1, item2))
193 ntest->argisrow =
false;
202 restrictinfo->pseudoconstant,
221 opfamilies = restrictinfo->mergeopfamilies;
244 foreach(lc1,
root->eq_classes)
320 restrictinfo->left_ec = ec1;
321 restrictinfo->right_ec = ec1;
323 restrictinfo->left_em = em1;
324 restrictinfo->right_em = em2;
334 if (
root->ec_merging_done)
335 elog(
ERROR,
"too late to merge equivalence classes");
367 restrictinfo->left_ec = ec1;
368 restrictinfo->right_ec = ec1;
370 restrictinfo->left_em = em1;
371 restrictinfo->right_em = em2;
377 jdomain, NULL, item2_type);
384 restrictinfo->left_ec = ec1;
385 restrictinfo->right_ec = ec1;
387 restrictinfo->left_em = em1;
388 restrictinfo->right_em = em2;
394 jdomain, NULL, item1_type);
401 restrictinfo->left_ec = ec2;
402 restrictinfo->right_ec = ec2;
404 restrictinfo->left_em = em1;
405 restrictinfo->right_em = em2;
426 jdomain, NULL, item1_type);
428 jdomain, NULL, item2_type);
433 restrictinfo->left_ec = ec;
434 restrictinfo->right_ec = ec;
436 restrictinfo->left_em = em1;
437 restrictinfo->right_em = em2;
480 if (IsPolymorphicType(req_type) || req_type == RECORDOID)
481 req_type = expr_type;
486 if (expr_type != req_type ||
496 if (expr_type != req_type)
506 req_type, req_typmod, req_collation,
528 em->em_parent = parent;
617 foreach(lc1,
root->eq_classes)
627 (sortref == 0 || sortref != cur_ec->
ec_sortref))
686 elog(
ERROR,
"volatile EquivalenceClass has no sortref");
694 jdomain, NULL, opcintype);
720 if (
root->ec_merging_done)
730 if (
i ==
root->group_rtindex)
800 if (
equal(emexpr, expr))
833 bool require_parallel_safe)
864 foreach(lc2, exprvars)
877 if (require_parallel_safe &&
906 if (
equal(node, expr))
942 foreach(lc, target->
exprs)
963 if (require_parallel_safe &&
974 require_parallel_safe);
1049 root->ec_merging_done =
true;
1052 foreach(lc,
root->eq_classes)
1055 bool can_generate_joinclause =
false;
1078 can_generate_joinclause =
1095 if (
i ==
root->group_rtindex)
1109 if (can_generate_joinclause)
1160 Assert(const_em != NULL);
1170 if (cur_em == const_em)
1201 if (rinfo && rinfo->mergeopfamilies)
1204 rinfo->left_ec = rinfo->right_ec = ec;
1205 rinfo->left_em = cur_em;
1206 rinfo->right_em = const_em;
1241 Assert(relid < root->simple_rel_array_size);
1243 if (prev_ems[relid] != NULL)
1277 if (rinfo && rinfo->mergeopfamilies)
1280 rinfo->left_ec = rinfo->right_ec = ec;
1281 rinfo->left_em = prev_em;
1282 rinfo->right_em = cur_em;
1285 prev_ems[relid] = cur_em;
1397 Relids nominal_inner_relids;
1398 Relids nominal_join_relids;
1410 nominal_join_relids =
bms_union(outer_relids, nominal_inner_relids);
1412 nominal_join_relids,
1418 nominal_inner_relids = inner_relids;
1419 nominal_join_relids = join_relids;
1435 if (sjinfo && sjinfo->
ojrelid != 0)
1469 nominal_join_relids,
1471 nominal_inner_relids,
1497 Relids nominal_inner_relids;
1498 Relids nominal_join_relids;
1509 nominal_join_relids =
bms_union(outer_relids, nominal_inner_relids);
1513 nominal_inner_relids = inner_relids;
1514 nominal_join_relids = join_relids;
1517 foreach(lc, eclasses)
1545 nominal_join_relids,
1547 nominal_inner_relids,
1594 outer_members =
lappend(outer_members, cur_em);
1596 inner_members =
lappend(inner_members, cur_em);
1598 new_members =
lappend(new_members, cur_em);
1610 if (outer_members && inner_members)
1615 int best_score = -1;
1618 foreach(lc1, outer_members)
1623 foreach(lc2, inner_members)
1646 if (score > best_score)
1648 best_outer_em = outer_em;
1649 best_inner_em = inner_em;
1652 if (best_score == 3)
1656 if (best_score == 3)
1671 best_outer_em, best_inner_em,
1674 result =
lappend(result, rinfo);
1696 foreach(lc1, new_members)
1700 if (prev_em != NULL)
1718 result =
lappend(result, rinfo);
1738 Relids nominal_join_relids,
1740 Relids nominal_inner_relids,
1754 result =
lappend(result, restrictinfo);
1772 inner_rel->top_parent);
1844 if (rinfo->left_em == leftem &&
1845 rinfo->right_em == rightem &&
1846 rinfo->parent_ec == parent_ec)
1848 if (rinfo->left_em == rightem &&
1849 rinfo->right_em == leftem &&
1850 rinfo->parent_ec == parent_ec)
1857 if (rinfo->left_em == leftem &&
1858 rinfo->right_em == rightem &&
1859 rinfo->parent_ec == parent_ec)
1861 if (rinfo->left_em == rightem &&
1862 rinfo->right_em == leftem &&
1863 rinfo->parent_ec == parent_ec)
1916 rinfo->parent_ec = parent_ec;
1922 rinfo->left_ec = ec;
1923 rinfo->right_ec = ec;
1926 rinfo->left_em = leftem;
1927 rinfo->right_em = rightem;
2016 foreach(cell,
root->left_join_clauses)
2026 root->left_join_clauses =
2044 foreach(cell,
root->right_join_clauses)
2054 root->right_join_clauses =
2072 foreach(cell,
root->full_join_clauses)
2082 root->full_join_clauses =
2101 foreach(cell,
root->left_join_clauses)
2107 foreach(cell,
root->right_join_clauses)
2113 foreach(cell,
root->full_join_clauses)
2152 inner_datatype = right_type;
2153 inner_relids = rinfo->right_relids;
2159 inner_datatype = left_type;
2160 inner_relids = rinfo->left_relids;
2164 foreach(lc1,
root->eq_classes)
2272 left_relids = rinfo->left_relids;
2273 right_relids = rinfo->right_relids;
2275 foreach(lc1,
root->eq_classes)
2338 if (
equal(leftvar, cfirst) &&
equal(rightvar, csecond))
2355 matchleft = matchright =
false;
2408 if (matchleft && matchright)
2437 foreach(lc,
root->join_domains)
2444 elog(
ERROR,
"failed to find appropriate JoinDomain");
2468 foreach(lc1,
root->eq_classes)
2471 bool item1member =
false;
2472 bool item2member =
false;
2501 if (item1member && item2member)
2530 AttrNumber var1attno = fkinfo->conkey[colno];
2532 AttrNumber var2attno = fkinfo->confkey[colno];
2533 Oid eqop = fkinfo->conpfeqop[colno];
2573 if (!(var &&
IsA(var,
Var)))
2579 else if (var->
varno == var2varno && var->
varattno == var2attno)
2583 if (item1_em && item2_em)
2590 if (opfamilies ==
NIL)
2594 fkinfo->
eclass[colno] = ec;
2631 if (rinfo->left_em == em)
2695 for (
int pos = 0; pos < num_members; pos++)
2731 child_expr = (
Expr *)
2739 child_expr = (
Expr *)
2743 child_rel->top_parent);
2827 for (
int pos = 0; pos < num_members; pos++)
2858 child_expr = (
Expr *)
2861 nappinfos, appinfos);
2867 child_expr = (
Expr *)
2871 child_joinrel->top_parent);
2909 List *child_tlist,
List *setop_pathkeys)
2914 foreach(lc, child_tlist)
2924 elog(
ERROR,
"too few pathkeys for set operation");
2927 parent_em =
linitial(pk->pk_eclass->ec_members);
2942 lc2 =
lnext(setop_pathkeys, lc2);
3001 parent_relids = NULL;
3057 if (other_em == cur_em ||
3084 result =
lappend(result, rinfo);
3268 foreach(lc,
eclass->ec_members)
3296 if (parent_ec == NULL)
3299 foreach(lc, clauselist)
3303 if (otherrinfo->parent_ec == parent_ec)
3322 foreach(lc, indexclauses)
3332 if (rinfo == otherrinfo)
3335 if (parent_ec && otherrinfo->parent_ec == parent_ec)
3366 if (
i ==
root->group_rtindex)
3400 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)
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 is_exprlist_member(Expr *node, List *exprs)
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)
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)
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)