47 List *pushed_down_joins,
61 List *new_restrictlist);
115 foreach(lc,
root->parse->rtable)
119 root->simple_rte_array[rti++] = rte;
123 if (
root->append_rel_list ==
NIL)
125 root->append_rel_array = NULL;
138 foreach(lc,
root->append_rel_list)
146 if (
root->append_rel_array[child_relid])
147 elog(
ERROR,
"child relation already exists");
149 root->append_rel_array[child_relid] = appinfo;
171 root->simple_rel_array =
174 root->simple_rte_array =
177 if (
root->append_rel_array)
178 root->append_rel_array =
181 root->append_rel_array =
184 root->simple_rel_array_size = new_size;
198 Assert(relid > 0 && relid < root->simple_rel_array_size);
199 if (
root->simple_rel_array[relid] != NULL)
200 elog(
ERROR,
"rel %d already exists", relid);
203 rte =
root->simple_rte_array[relid];
268 rel->fdwroutine = NULL;
269 rel->fdw_private = NULL;
279 rel->part_scheme = NULL;
281 rel->boundinfo = NULL;
284 rel->part_rels = NULL;
287 rel->partexprs = NULL;
288 rel->nullable_partexprs = NULL;
296 rel->parent = parent;
297 rel->top_parent = parent->top_parent ? parent->top_parent : parent;
327 rel->top_parent = NULL;
357 rel->attr_needed = (
Relids *)
359 rel->attr_widths = (
int32 *)
366 rel->attr_needed = NULL;
367 rel->attr_widths = NULL;
380 root->simple_rel_array[relid] = rel;
421 rel =
root->simple_rel_array[relid];
426 elog(
ERROR,
"no relation entry for relid %d", relid);
440 return root->simple_rel_array[relid];
462 rel =
root->simple_rel_array[relid];
471 rte =
root->simple_rte_array[relid];
476 elog(
ERROR,
"no relation entry for relid %d", relid);
504 foreach(l,
root->join_rel_list)
518 root->join_rel_hash = hashtab;
544 if (
root->join_rel_hash)
560 foreach(l,
root->join_rel_list)
600 joinrel->fdwroutine = outer_rel->fdwroutine;
608 joinrel->fdwroutine = outer_rel->fdwroutine;
616 joinrel->fdwroutine = outer_rel->fdwroutine;
633 if (
root->join_rel_hash)
670 List *pushed_down_joins,
671 List **restrictlist_ptr)
690 if (restrictlist_ptr)
723 outer_rel, inner_rel);
728 joinrel->attr_needed = NULL;
729 joinrel->attr_widths = NULL;
747 joinrel->fdwroutine = NULL;
748 joinrel->fdw_private = NULL;
758 joinrel->parent = NULL;
759 joinrel->top_parent = NULL;
761 joinrel->part_scheme = NULL;
763 joinrel->boundinfo = NULL;
766 joinrel->part_rels = NULL;
769 joinrel->partexprs = NULL;
770 joinrel->nullable_partexprs = NULL;
806 outer_rel, inner_rel,
808 if (restrictlist_ptr)
809 *restrictlist_ptr = restrictlist;
826 sjinfo, restrictlist);
856 if (
root->join_rel_level)
860 root->join_rel_level[
root->join_cur_level] =
897 nappinfos, appinfos);
917 joinrel->attr_needed = NULL;
918 joinrel->attr_widths = NULL;
934 joinrel->fdwroutine = NULL;
935 joinrel->fdw_private = NULL;
942 joinrel->parent = parent_joinrel;
943 joinrel->top_parent = parent_joinrel->top_parent ? parent_joinrel->top_parent : parent_joinrel;
945 joinrel->part_scheme = NULL;
947 joinrel->boundinfo = NULL;
950 joinrel->part_rels = NULL;
953 joinrel->partexprs = NULL;
954 joinrel->nullable_partexprs = NULL;
961 nappinfos, appinfos);
991 sjinfo, restrictlist);
1007 nappinfos, appinfos,
1008 parent_joinrel, joinrel);
1103 List *pushed_down_joins,
1142 foreach(lc, pushed_down_joins)
1171 elog(
ERROR,
"unexpected node type in rel targetlist: %d",
1197 tuple_width += baserel->attr_widths[ndx];
1217 foreach(lc, pushed_down_joins)
1226 var->varnullingrels =
1292 Relids both_input_relids;
1302 both_input_relids,
NIL);
1304 both_input_relids, result);
1343 Relids both_input_relids,
1344 List *new_restrictlist)
1382 both_input_relids));
1402 return new_restrictlist;
1407 List *joininfo_list,
1415 foreach(l, joininfo_list)
1440 return new_joininfo;
1471 foreach(lc,
root->upper_rels[kind])
1582 pclauses =
lappend(pclauses, rinfo);
1595 #ifdef USE_ASSERT_CHECKING
1596 foreach(lc, eqclauses)
1609 foreach(lc, pclauses)
1664 List **restrict_clauses)
1695 if (outer_path->param_info)
1696 outer_and_req =
bms_union(outer_path->parent->relids,
1699 outer_and_req = NULL;
1700 if (inner_path->param_info)
1701 inner_and_req =
bms_union(inner_path->parent->relids,
1704 inner_and_req = NULL;
1715 outer_path->parent->relids,
1718 inner_path->parent->relids,
1720 pclauses =
lappend(pclauses, rinfo);
1731 foreach(lc, eclauses)
1739 outer_path->parent->relids,
1743 inner_path->parent->relids,
1747 Assert(rinfo->left_ec == rinfo->right_ec);
1748 dropped_ecs =
lappend(dropped_ecs, rinfo->left_ec);
1751 pclauses =
lappend(pclauses, rinfo);
1786 Relids real_outer_and_req;
1788 real_outer_and_req =
bms_union(outer_path->parent->relids,
1795 outer_path->parent);
1796 foreach(lc, eclauses)
1801 outer_path->parent->relids,
1802 real_outer_and_req));
1804 outer_path->parent->relids,
1806 pclauses =
lappend(pclauses, rinfo);
1815 *restrict_clauses =
list_concat(pclauses, *restrict_clauses);
1912 if (path->param_info == NULL)
1994 return path->param_info->ppi_serials;
2030 if (outer_rel->part_scheme == NULL || inner_rel->part_scheme == NULL ||
2033 outer_rel->part_scheme != inner_rel->part_scheme ||
2041 part_scheme = outer_rel->part_scheme;
2047 Assert(!joinrel->part_scheme && !joinrel->partexprs &&
2048 !joinrel->nullable_partexprs && !joinrel->part_rels &&
2049 !joinrel->boundinfo);
2058 joinrel->part_scheme = part_scheme;
2091 Assert(rel1->part_scheme == rel2->part_scheme);
2095 memset(pk_known_equal, 0,
sizeof(pk_known_equal));
2100 foreach(lc, restrictlist)
2116 if (!rinfo->can_join)
2120 if (!rinfo->mergeopfamilies && !
OidIsValid(rinfo->hashjoinoperator))
2158 root->outer_join_rels,
2162 root->outer_join_rels,
2185 if (pk_known_equal[ipk1])
2204 pk_known_equal[ipk1] =
true;
2207 if (++num_equal_pks == part_scheme->
partnatts)
2218 for (
int ipk = 0; ipk < part_scheme->
partnatts; ipk++)
2223 if (pk_known_equal[ipk])
2236 List *eq_opfamilies;
2245 if (eq_opfamilies ==
NIL)
2257 foreach(lc, rel1->partexprs[ipk])
2262 foreach(lc2, rel2->partexprs[ipk])
2268 pk_known_equal[ipk] =
true;
2272 if (pk_known_equal[ipk])
2276 if (pk_known_equal[ipk])
2279 if (++num_equal_pks == part_scheme->
partnatts)
2306 Assert(rel->part_scheme);
2308 Assert(rel->nullable_partexprs);
2314 for (cnt = 0; cnt < rel->part_scheme->partnatts; cnt++)
2319 foreach(lc, rel->partexprs[cnt])
2335 foreach(lc, rel->nullable_partexprs[cnt])
2358 joinrel->nullable_partexprs =
2367 for (
int cnt = 0; cnt < partnatts; cnt++)
2370 const List *outer_expr = outer_rel->partexprs[cnt];
2371 const List *outer_null_expr = outer_rel->nullable_partexprs[cnt];
2372 const List *inner_expr = inner_rel->partexprs[cnt];
2373 const List *inner_null_expr = inner_rel->nullable_partexprs[cnt];
2375 List *nullable_partexpr =
NIL;
2405 nullable_partexpr =
list_copy(outer_null_expr);
2419 nullable_partexpr =
list_concat(nullable_partexpr,
2432 nullable_partexpr =
list_concat(nullable_partexpr,
2434 nullable_partexpr =
list_concat(nullable_partexpr,
2475 nullable_partexpr =
lappend(nullable_partexpr,
c);
2481 elog(
ERROR,
"unrecognized join type: %d", (
int) jointype);
2484 joinrel->partexprs[cnt] = partexpr;
2485 joinrel->nullable_partexprs[cnt] = nullable_partexpr;
2504 nappinfos, appinfos);
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Relids adjust_child_relids(Relids relids, int nappinfos, AppendRelInfo **appinfos)
uint32 bitmap_hash(const void *key, Size keysize)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
int bms_num_members(const Bitmapset *a)
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_intersect(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
int bitmap_match(const void *key1, const void *key2, Size keysize)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)
#define Assert(condition)
#define OidIsValid(objectId)
bool is_parallel_safe(PlannerInfo *root, Node *node)
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
bool enable_partitionwise_join
int32 clamp_width_est(int64 tuple_width)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
bool equal(const void *a, const void *b)
bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2, Oid opfamily)
List * generate_join_implied_equalities_for_ecs(PlannerInfo *root, List *eclasses, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo)
void add_child_join_rel_equivalences(PlannerInfo *root, int nappinfos, AppendRelInfo **appinfos, RelOptInfo *parent_joinrel, RelOptInfo *child_joinrel)
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
#define palloc0_array(type, count)
bool apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *childrel, RangeTblEntry *childRTE, AppendRelInfo *appinfo)
void mark_dummy_rel(RelOptInfo *rel)
List * lappend(List *list, void *datum)
List * list_copy(const List *oldlist)
bool list_member_oid(const List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
List * list_append_unique_ptr(List *list, void *datum)
List * list_concat_copy(const List *list1, const List *list2)
List * get_mergejoin_opfamilies(Oid opno)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
bool op_in_opfamily(Oid opno, Oid opfamily)
Datum subpath(PG_FUNCTION_ARGS)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
Oid exprType(const Node *expr)
Oid exprCollation(const Node *expr)
#define IsA(nodeptr, _type_)
#define IS_OUTER_JOIN(jointype)
#define castNode(_type_, nodeptr)
#define repalloc0_array(pointer, type, oldcount, count)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
@ PARTITION_STRATEGY_HASH
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
#define RINFO_IS_PUSHED_DOWN(rinfo, joinrelids)
#define IS_PARTITIONED_REL(rel)
#define PATH_REQ_OUTER(path)
@ RELOPT_OTHER_MEMBER_REL
#define IS_OTHER_REL(rel)
#define PARTITION_MAX_KEYS
#define lfirst_node(type, lc)
static int list_length(const List *l)
static ListCell * list_head(const List *l)
static void * list_nth(const List *list, int n)
#define list_make2(x1, x2)
PlaceHolderInfo * find_placeholder_info(PlannerInfo *root, PlaceHolderVar *phv)
void add_placeholders_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo)
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
static void build_joinrel_partition_info(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
void setup_simple_rel_arrays(PlannerInfo *root)
static void set_joinrel_partition_key_exprs(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinType jointype)
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel, SpecialJoinInfo *sjinfo, List *pushed_down_joins, bool can_null)
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
RelOptInfo * build_join_rel(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *pushed_down_joins, List **restrictlist_ptr)
static bool have_partkey_equi_join(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *rel1, RelOptInfo *rel2, JoinType jointype, List *restrictlist)
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
static void build_join_rel_hash(PlannerInfo *root)
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)
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
Relids find_childrel_parents(PlannerInfo *root, RelOptInfo *rel)
void expand_planner_arrays(PlannerInfo *root, int add_size)
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
RelOptInfo * find_base_rel_ignore_join(PlannerInfo *root, int relid)
static void build_child_join_reltarget(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *childrel, int nappinfos, AppendRelInfo **appinfos)
RelOptInfo * find_base_rel_noerr(PlannerInfo *root, int relid)
static List * build_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo)
static int match_expr_to_partition_keys(Expr *expr, RelOptInfo *rel, bool strict_op)
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
struct JoinHashEntry JoinHashEntry
static void build_joinrel_joinlist(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
ParamPathInfo * find_param_path_info(RelOptInfo *rel, Relids required_outer)
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
static List * subbuild_joinrel_joinlist(RelOptInfo *joinrel, List *joininfo_list, List *new_joininfo)
static List * subbuild_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel, Relids both_input_relids, List *new_restrictlist)
Bitmapset * get_param_path_clause_serials(Path *path)
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Node * remove_nulling_relids(Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
Size add_size(Size s1, Size s2)
static pg_noinline void Size size
#define HTEqualStrategyNumber
bool consider_param_startup
Bitmapset * notnullattnums
struct PathTarget * reltarget
List * cheapest_parameterized_paths
struct Path * cheapest_unique_path
Relids lateral_referencers
struct Path * cheapest_startup_path
QualCost baserestrictcost
struct Path * cheapest_total_path
List * non_unique_for_rels
Bitmapset * eclass_indexes
Relids direct_lateral_relids
bool consider_partitionwise_join
Index baserestrict_min_security
Relids incompatible_relids
PathTarget * create_empty_pathtarget(void)