37 bool only_pushed_down);
44 List *parent_restrictlist);
74 List **joinrels =
root->join_rel_level;
81 root->join_cur_level = level;
90 foreach(r, joinrels[level - 1])
149 int other_level = level - k;
158 foreach(r, joinrels[k])
173 if (k == other_level)
218 if (joinrels[level] ==
NIL)
224 foreach(r, joinrels[level - 1])
251 if (joinrels[level] ==
NIL &&
253 !
root->hasLateralRTEs)
254 elog(
ERROR,
"failed to build any %d-way joins", level);
319 foreach(l, other_rels)
356 bool must_be_leftjoin;
373 unique_ified =
false;
374 must_be_leftjoin =
false;
376 foreach(l,
root->join_info_list)
433 match_sjinfo = sjinfo;
441 match_sjinfo = sjinfo;
473 match_sjinfo = sjinfo;
485 match_sjinfo = sjinfo;
528 must_be_leftjoin =
true;
541 if (must_be_leftjoin &&
542 (match_sjinfo == NULL ||
550 if (
root->hasLateralRTEs)
573 if (lateral_fwd && lateral_rev)
590 else if (lateral_rev)
621 if (join_lateral_rels)
629 foreach(l,
root->join_info_list)
652 *sjinfo_p = match_sjinfo;
653 *reversed_p = reversed;
672 sjinfo->type = T_SpecialJoinInfo;
752 sjinfo = &sjinfo_data;
761 sjinfo, pushed_down_joins,
803 List **pushed_down_joins)
806 if (sjinfo == NULL || sjinfo->
ojrelid == 0)
848 foreach(lc,
root->join_info_list)
852 if (othersj == sjinfo ||
867 if (pushed_down_joins != NULL)
868 *pushed_down_joins =
lappend(*pushed_down_joins, othersj);
971 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
972 errmsg(
"FULL JOIN is only supported with merge-joinable or hash-joinable join conditions")));
1077 bool result =
false;
1095 foreach(l,
root->placeholder_list)
1112 foreach(l,
root->join_info_list)
1194 foreach(l,
root->placeholder_list)
1203 foreach(l,
root->join_info_list)
1247 foreach(lc,
root->initial_rels)
1265 &sjinfo, &reversed))
1312 foreach(lc,
root->placeholder_list)
1429 bool only_pushed_down)
1439 foreach(lc, restrictlist)
1451 if (con->constisnull)
1483 List *parent_restrictlist)
1497 if (joinrel->part_scheme == NULL || joinrel->
nparts == 0)
1520 Assert(joinrel->part_scheme == rel1->part_scheme &&
1521 joinrel->part_scheme == rel2->part_scheme);
1539 for (cnt_parts = 0; cnt_parts < joinrel->
nparts; cnt_parts++)
1546 List *child_restrictlist;
1556 lcr1 =
lnext(parts1, lcr1);
1557 lcr2 =
lnext(parts2, lcr2);
1561 child_rel1 = rel1->part_rels[cnt_parts];
1562 child_rel2 = rel2->part_rels[cnt_parts];
1565 rel1_empty = (child_rel1 == NULL ||
IS_DUMMY_REL(child_rel1));
1566 rel2_empty = (child_rel2 == NULL ||
IS_DUMMY_REL(child_rel2));
1579 if (rel1_empty || rel2_empty)
1588 if (rel1_empty && rel2_empty)
1593 elog(
ERROR,
"unrecognized join type: %d",
1603 if (child_rel1 == NULL || child_rel2 == NULL)
1654 child_restrictlist =
1656 (
Node *) parent_restrictlist,
1657 nappinfos, appinfos);
1660 child_joinrel = joinrel->part_rels[cnt_parts];
1664 joinrel, child_restrictlist,
1665 child_sjinfo, nappinfos, appinfos);
1666 joinrel->part_rels[cnt_parts] = child_joinrel;
1675 nappinfos, appinfos)));
1679 child_joinrel, child_sjinfo,
1680 child_restrictlist);
1710 int right_nappinfos;
1727 left_nappinfos, left_appinfos);
1732 left_nappinfos, left_appinfos);
1742 pfree(left_appinfos);
1743 pfree(right_appinfos);
1793 if (joinrel->
nparts == -1)
1799 Assert(joinrel->boundinfo == NULL);
1800 Assert(joinrel->part_rels == NULL);
1818 rel1->boundinfo, rel2->boundinfo))
1820 boundinfo = rel1->boundinfo;
1832 if (boundinfo == NULL)
1842 joinrel->boundinfo = boundinfo;
1843 joinrel->
nparts = nparts;
1844 joinrel->part_rels =
1850 Assert(joinrel->boundinfo);
1851 Assert(joinrel->part_rels);
1886 for (cnt_parts = 0; cnt_parts < joinrel->
nparts; cnt_parts++)
1888 RelOptInfo *child_joinrel = joinrel->part_rels[cnt_parts];
1904 *parts1 =
lappend(*parts1, NULL);
1905 *parts2 =
lappend(*parts2, NULL);
1962 *parts1 =
lappend(*parts1, child_rel1);
1963 *parts2 =
lappend(*parts2, child_rel2);
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Relids adjust_child_relids(Relids relids, int nappinfos, AppendRelInfo **appinfos)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
int bms_singleton_member(const Bitmapset *a)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
#define Assert(condition)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
if(TABLE==NULL||TABLE_index==NULL)
bool have_relevant_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist)
static void populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *joinrel, SpecialJoinInfo *sjinfo, List *restrictlist)
static void try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *joinrel, SpecialJoinInfo *parent_sjinfo, List *parent_restrictlist)
static void make_rels_by_clauseless_joins(PlannerInfo *root, RelOptInfo *old_rel, List *other_rels)
bool is_dummy_rel(RelOptInfo *rel)
void join_search_one_level(PlannerInfo *root, int level)
static bool restriction_is_constant_false(List *restrictlist, RelOptInfo *joinrel, bool only_pushed_down)
static void get_matching_part_pairs(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *rel1, RelOptInfo *rel2, List **parts1, List **parts2)
static bool has_legal_joinclause(PlannerInfo *root, RelOptInfo *rel)
static void compute_partition_bounds(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *joinrel, SpecialJoinInfo *parent_sjinfo, List **parts1, List **parts2)
Relids add_outer_joins_to_relids(PlannerInfo *root, Relids input_relids, SpecialJoinInfo *sjinfo, List **pushed_down_joins)
static SpecialJoinInfo * build_child_join_sjinfo(PlannerInfo *root, SpecialJoinInfo *parent_sjinfo, Relids left_relids, Relids right_relids)
RelOptInfo * make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
void mark_dummy_rel(RelOptInfo *rel)
bool have_dangerous_phv(PlannerInfo *root, Relids outer_relids, Relids inner_params)
bool have_join_order_restriction(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
static bool has_join_restriction(PlannerInfo *root, RelOptInfo *rel)
void init_dummy_sjinfo(SpecialJoinInfo *sjinfo, Relids left_relids, Relids right_relids)
static bool join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, Relids joinrelids, SpecialJoinInfo **sjinfo_p, bool *reversed_p)
static void free_child_join_sjinfo(SpecialJoinInfo *sjinfo)
static void make_rels_by_clause_joins(PlannerInfo *root, RelOptInfo *old_rel, List *other_rels, int first_rel_idx)
List * lappend(List *list, void *datum)
Datum subpath(PG_FUNCTION_ARGS)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext GetMemoryChunkContext(void *pointer)
#define IsA(nodeptr, _type_)
bool partition_bounds_equal(int partnatts, int16 *parttyplen, bool *parttypbyval, PartitionBoundInfo b1, PartitionBoundInfo b2)
PartitionBoundInfo partition_bounds_merge(int partnatts, FmgrInfo *partsupfunc, Oid *partcollation, RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinType jointype, List **outer_parts, List **inner_parts)
AppendPath * create_append_path(PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *partial_subpaths, List *pathkeys, Relids required_outer, int parallel_workers, bool parallel_aware, double rows)
UniquePath * create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
void set_cheapest(RelOptInfo *parent_rel)
void add_path(RelOptInfo *parent_rel, Path *new_path)
#define IS_DUMMY_APPEND(p)
#define RINFO_IS_PUSHED_DOWN(rinfo, joinrelids)
#define IS_SIMPLE_REL(rel)
#define IS_PARTITIONED_REL(rel)
#define REL_HAS_ALL_PART_PROPS(rel)
@ RELOPT_OTHER_MEMBER_REL
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define foreach_current_index(var_or_cell)
static ListCell * list_head(const List *l)
#define for_each_from(cell, lst, N)
static ListCell * lnext(const List *l, const ListCell *c)
void check_stack_depth(void)
static bool DatumGetBool(Datum X)
MemoryContextSwitchTo(old_ctx)
RelOptInfo * build_join_rel(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *pushed_down_joins, List **restrictlist_ptr)
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
RelOptInfo * build_child_join_rel(PlannerInfo *root, RelOptInfo *outer_rel, RelOptInfo *inner_rel, RelOptInfo *parent_joinrel, List *restrictlist, SpecialJoinInfo *sjinfo, int nappinfos, AppendRelInfo **appinfos)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
struct FmgrInfo * partsupfunc
Relids lateral_referencers
struct Path * cheapest_total_path
Relids direct_lateral_relids
bool consider_partitionwise_join