74 double dNumGroups,
double dNumOutputRows,
75 const char *construct);
81 List *refnames_tlist);
85 List *refnames_tlist);
109 Query *leftmostQuery;
148 leftmostQuery = leftmostRTE->
subquery;
149 Assert(leftmostQuery != NULL);
169 topop->colTypes, topop->colCollations,
208 List *colTypes,
List *colCollations,
249 elog(
ERROR,
"unexpected outer reference in set operation subquery");
261 *pTargetList = tlist;
306 Path *partial_subpath;
310 partial_path = (
Path *)
336 *pNumGroups = subpath->
rows;
358 *pNumGroups = rel->
rows;
419 elog(
ERROR,
"unrecognized node type: %d",
434 List *refnames_tlist,
451 elog(
ERROR,
"only UNION queries can be recursive");
484 *pTargetList = tlist;
507 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
508 errmsg(
"could not implement recursive UNION"),
509 errdetail(
"All column datatypes must be hashable.")));
515 dNumGroups = lpath->
rows + rpath->
rows * 10;
540 List *refnames_tlist,
549 bool partial_paths_valid =
true;
550 bool consider_parallel =
true;
586 tlist_list, refnames_tlist);
588 *pTargetList = tlist;
597 if (consider_parallel)
601 consider_parallel =
false;
602 partial_paths_valid =
false;
605 partial_paths_valid =
false;
607 partial_pathlist =
lappend(partial_pathlist,
623 NIL, NULL, 0,
false,
NIL, -1);
645 if (partial_paths_valid)
649 int parallel_workers = 0;
652 foreach(lc, partial_pathlist)
658 Assert(parallel_workers > 0);
669 parallel_workers =
Max(parallel_workers,
671 parallel_workers =
Min(parallel_workers,
674 Assert(parallel_workers > 0);
700 List *refnames_tlist,
757 tlist_list =
list_make2(lpath_tlist, rpath_tlist);
763 tlist_list =
list_make2(rpath_tlist, lpath_tlist);
777 tlist_list, refnames_tlist);
779 *pTargetList = tlist;
790 NIL, NULL, 0,
false,
NIL, -1);
805 dNumGroups = dLeftGroups;
806 dNumOutputRows = op->
all ? lpath->
rows : dNumGroups;
810 dNumGroups =
Min(dLeftGroups, dRightGroups);
811 dNumOutputRows = op->
all ?
Min(lpath->
rows, rpath->
rows) : dNumGroups;
818 dNumGroups, dNumOutputRows,
821 if (groupList && !use_hash)
842 elog(
ERROR,
"unrecognized set op: %d", (
int) op->
op);
853 use_hash ? firstFlag : -1,
878 List *refnames_tlist,
887 while (pending_rels !=
NIL)
897 if (op->
op == top_union->
op &&
898 (op->
all == top_union->
all || op->
all) &&
902 pending_rels =
lcons(op->
rarg, pending_rels);
903 pending_rels =
lcons(op->
larg, pending_rels);
925 *tlist_list =
lappend(*tlist_list, child_tlist);
952 dNumGroups = path->
rows;
956 dNumGroups, dNumGroups,
1017 double dNumGroups,
double dNumOutputRows,
1018 const char *construct)
1027 double tuple_fraction;
1032 if (can_hash && can_sort)
1042 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1044 errmsg(
"could not implement %s", construct),
1045 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
1057 if (hashentrysize * dNumGroups > hash_mem * 1024L)
1074 numGroupCols, dNumGroups,
1089 cost_group(&sorted_p, root, numGroupCols, dNumGroups,
1099 if (tuple_fraction >= 1.0)
1100 tuple_fraction /= dNumOutputRows;
1103 tuple_fraction) < 0)
1126 bool hack_constants,
1128 List *refnames_tlist)
1139 forfour(ctlc, colTypes, cclc, colCollations,
1140 itlc, input_tlist, rtlc, refnames_tlist)
1188 "UNION/INTERSECT/EXCEPT");
1264 List *refnames_tlist)
1285 foreach(tlistl, input_tlists)
1292 foreach(subtlistl, subtlist)
1298 Assert(curColType != NULL);
1305 colTypmods[colindex] = subtypmod;
1306 else if (subtypmod != colTypmods[colindex])
1307 colTypmods[colindex] = -1;
1312 colTypmods[colindex] = -1;
1314 curColType =
lnext(colTypes, curColType);
1317 Assert(curColType == NULL);
1324 forthree(curColType, colTypes, curColCollation, colCollations,
1325 ref_tl_item, refnames_tlist)
1328 int32 colTypmod = colTypmods[colindex++];
1396 foreach(lt, targetlist)
1414 lg =
lnext(grouplist, lg);
Path * apply_projection_to_path(PlannerInfo *root, RelOptInfo *rel, Path *path, PathTarget *target)
#define list_make2(x1, x2)
RelOptInfo * plan_set_operations(PlannerInfo *root)
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
static RelOptInfo * generate_recursion_path(SetOperationStmt *setOp, PlannerInfo *root, List *refnames_tlist, List **pTargetList)
static List * generate_append_tlist(List *colTypes, List *colCollations, bool flag, List *input_tlists, List *refnames_tlist)
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset)
GatherPath * create_gather_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, Relids required_outer, double *rows)
#define IsA(nodeptr, _type_)
bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)
void add_path(RelOptInfo *parent_rel, Path *new_path)
SubqueryScanPath * create_subqueryscan_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, Relids required_outer)
static void postprocess_setop_rel(PlannerInfo *root, RelOptInfo *rel)
static ListCell * lnext(const List *l, const ListCell *c)
SetOpPath * create_setop_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, SetOpCmd cmd, SetOpStrategy strategy, List *distinctList, AttrNumber flagColIdx, int firstFlag, double numGroups, double outputRows)
bool equal(const void *a, const void *b)
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
static RelOptInfo * generate_nonunion_paths(SetOperationStmt *op, PlannerInfo *root, List *refnames_tlist, List **pTargetList)
UpperUniquePath * create_upper_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, int numCols, double numGroups)
#define castNode(_type_, nodeptr)
static List * generate_setop_grouplist(SetOperationStmt *op, List *targetlist)
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
int32 exprTypmod(const Node *expr)
#define forthree(cell1, list1, cell2, list2, cell3, list3)
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples, double input_width)
char * pstrdup(const char *in)
static Path * make_union_unique(SetOperationStmt *op, Path *path, List *tlist, PlannerInfo *root)
ParamPathInfo * param_info
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
int errcode(int sqlerrcode)
bool enable_parallel_append
static RelOptInfo * recurse_set_operations(Node *setOp, PlannerInfo *root, List *colTypes, List *colCollations, bool junkOK, int flag, List *refnames_tlist, List **pTargetList, double *pNumGroups)
bool grouping_is_hashable(List *groupClause)
create_upper_paths_hook_type create_upper_paths_hook
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
static bool choose_hashed_setop(PlannerInfo *root, List *groupClauses, Path *input_path, double dNumGroups, double dNumOutputRows, const char *construct)
void pfree(void *pointer)
static List * plan_union_children(PlannerInfo *root, SetOperationStmt *top_union, List *refnames_tlist, List **tlist_list)
RecursiveUnionPath * create_recursiveunion_path(PlannerInfo *root, RelOptInfo *rel, Path *leftpath, Path *rightpath, PathTarget *target, List *distinctList, int wtParam, double numGroups)
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
AggPath * create_agg_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, AggStrategy aggstrategy, AggSplit aggsplit, List *groupClause, List *qual, const AggClauseCosts *aggcosts, double numGroups)
struct Path * cheapest_total_path
static RelOptInfo * generate_union_paths(SetOperationStmt *op, PlannerInfo *root, List *refnames_tlist, List **pTargetList)
void check_stack_depth(void)
int errdetail(const char *fmt,...)
static ListCell * list_head(const List *l)
#define create_pathtarget(root, tlist)
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
AppendPath * create_append_path(PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *partial_subpaths, List *pathkeys, Relids required_outer, int parallel_workers, bool parallel_aware, List *partitioned_rels, double rows)
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
List * lappend(List *list, void *datum)
RangeTblEntry ** simple_rte_array
bool bms_is_empty(const Bitmapset *a)
void set_cheapest(RelOptInfo *parent_rel)
#define SizeofMinimalTupleHeader
List * get_tlist_exprs(List *tlist, bool includeJunk)
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
#define ereport(elevel,...)
SortPath * create_sort_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
List * lcons(void *datum, List *list)
#define Assert(condition)
void setup_simple_rel_arrays(PlannerInfo *root)
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
struct Path * non_recursive_path
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Oid exprType(const Node *expr)
static int list_length(const List *l)
Oid exprCollation(const Node *expr)
#define forfour(cell1, list1, cell2, list2, cell3, list3, cell4, list4)
int errmsg(const char *fmt,...)
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
bool grouping_is_sortable(List *groupClause)
bool tlist_same_collations(List *tlist, List *colCollations, bool junkOK)
int max_parallel_workers_per_gather
struct PathTarget * reltarget
PlannerInfo * subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction)
Datum subpath(PG_FUNCTION_ARGS)
Path * get_cheapest_fractional_path(RelOptInfo *rel, double tuple_fraction)
List * list_delete_first(List *list)
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
static List * generate_setop_tlist(List *colTypes, List *colCollations, int flag, Index varno, bool hack_constants, List *input_tlist, List *refnames_tlist)