80#define EXPRKIND_QUAL 0
81#define EXPRKIND_TARGET 1
82#define EXPRKIND_RTFUNC 2
83#define EXPRKIND_RTFUNC_LATERAL 3
84#define EXPRKIND_VALUES 4
85#define EXPRKIND_VALUES_LATERAL 5
86#define EXPRKIND_LIMIT 6
87#define EXPRKIND_APPINFO 7
89#define EXPRKIND_TABLESAMPLE 9
90#define EXPRKIND_ARBITER_ELEM 10
91#define EXPRKIND_TABLEFUNC 11
92#define EXPRKIND_TABLEFUNC_LATERAL 12
93#define EXPRKIND_GROUPEXPR 13
137 int *tleref_to_colnum_map);
140 double tuple_fraction,
153 bool target_parallel_safe,
160 PathTarget *target,
bool target_parallel_safe,
181 bool output_target_parallel_safe,
183 List *activeWindows);
190 List *activeWindows);
202 List *needed_pathkeys,
203 List *path_pathkeys);
207 bool target_parallel_safe,
208 double limit_tuples);
221 List *activeWindows);
226 bool *have_postponed_srfs);
228 List *targets,
List *targets_contain_srfs);
241 bool force_rel_creation);
247 double limit_tuples);
252 List *scanjoin_targets,
253 List *scanjoin_targets_contain_srfs,
254 bool scanjoin_target_parallel_safe,
292 result = (*planner_hook) (
parse, query_string, cursorOptions, boundParams);
307 double tuple_fraction;
323 glob->boundParams = boundParams;
326 glob->subroots =
NIL;
345 glob->partition_directory = NULL;
371 !
parse->hasModifyingCTE &&
423 if (tuple_fraction >= 1.0)
424 tuple_fraction = 0.0;
425 else if (tuple_fraction <= 0.0)
426 tuple_fraction = 1
e-10;
431 tuple_fraction = 0.0;
472 bool unsafe_initplans;
510 &initplan_cost, &unsafe_initplans);
515 root->glob->parallelModeNeeded =
true;
517 top_plan = &gather->
plan;
612 if (glob->partition_directory != NULL)
653 bool hasRecursion,
double tuple_fraction,
657 List *newWithCheckOptions;
669 root->parent_root = parent_root;
671 root->outer_params = NULL;
678 root->ec_merging_done =
false;
679 root->last_rinfo_serial = 0;
680 root->all_result_relids =
682 root->leaf_result_relids = NULL;
686 memset(
root->upper_rels, 0,
sizeof(
root->upper_rels));
687 memset(
root->upper_targets, 0,
sizeof(
root->upper_targets));
688 root->processed_groupClause =
NIL;
689 root->processed_distinctClause =
NIL;
692 root->grouping_map = NULL;
694 root->qual_security_level = 0;
695 root->hasPseudoConstantQuals =
false;
696 root->hasAlternativeSubPlans =
false;
697 root->placeholdersFrozen =
false;
698 root->hasRecursion = hasRecursion;
702 root->wt_param_id = -1;
703 root->non_recursive_path = NULL;
704 root->partColsUpdated =
false;
737 if (
parse->hasSubLinks)
768 if (
parse->setOperations)
781 root->hasJoinRTEs =
false;
782 root->hasLateralRTEs =
false;
783 root->group_rtindex = 0;
784 hasOuterJoins =
false;
785 hasResultRTEs =
false;
786 foreach(l,
parse->rtable)
810 root->hasJoinRTEs =
true;
812 hasOuterJoins =
true;
815 hasResultRTEs =
true;
827 root->hasLateralRTEs =
true;
835 if (rte->securityQuals)
836 root->qual_security_level =
Max(
root->qual_security_level,
844 if (
parse->resultRelation)
849 root->leaf_result_relids =
864 root->hasHavingQual = (
parse->havingQual != NULL);
876 newWithCheckOptions =
NIL;
877 foreach(l,
parse->withCheckOptions)
883 if (wco->
qual != NULL)
884 newWithCheckOptions =
lappend(newWithCheckOptions, wco);
886 parse->withCheckOptions = newWithCheckOptions;
897 foreach(l,
parse->windowClause)
913 if (
parse->onConflict)
915 parse->onConflict->arbiterElems = (
List *)
917 (
Node *)
parse->onConflict->arbiterElems,
919 parse->onConflict->arbiterWhere =
921 parse->onConflict->arbiterWhere,
923 parse->onConflict->onConflictSet = (
List *)
925 (
Node *)
parse->onConflict->onConflictSet,
927 parse->onConflict->onConflictWhere =
929 parse->onConflict->onConflictWhere,
934 foreach(l,
parse->mergeActionList)
948 parse->mergeJoinCondition =
956 foreach(l,
parse->rtable)
979 if (rte->lateral &&
root->hasJoinRTEs)
1008 rte->groupexprs = (
List *)
1019 foreach(lcsq, rte->securityQuals)
1038 if (
root->hasJoinRTEs)
1040 foreach(l,
parse->rtable)
1044 rte->joinaliasvars =
NIL;
1057 if (
parse->hasGroupRTE)
1066 if (
parse->hasTargetSRFs)
1118 (
parse->groupClause &&
parse->groupingSets &&
1122 newHaving =
lappend(newHaving, havingclause);
1124 else if (
parse->groupClause)
1134 (
List *) whereclause);
1146 (
List *) whereclause);
1148 newHaving =
lappend(newHaving, havingclause);
1167 if (hasResultRTEs || hasOuterJoins)
1226 if (
root->hasJoinRTEs &&
1262#ifdef OPTIMIZER_DEBUG
1263 printf(
"After canonicalize_qual()\n");
1279 if (
root->parse->hasSubLinks)
1288 if (
root->query_level > 1)
1337 elog(
ERROR,
"unrecognized node type: %d",
1390 int64 offset_est = 0;
1391 int64 count_est = 0;
1392 double limit_tuples = -1.0;
1393 bool have_postponed_srfs =
false;
1395 List *final_targets;
1396 List *final_targets_contain_srfs;
1397 bool final_target_parallel_safe;
1407 &offset_est, &count_est);
1413 if (count_est > 0 && offset_est >= 0)
1414 limit_tuples = (double) count_est + (
double) offset_est;
1418 root->tuple_fraction = tuple_fraction;
1420 if (
parse->setOperations)
1440 root->processed_tlist =
1448 final_target_parallel_safe =
1453 final_targets = final_targets_contain_srfs =
NIL;
1459 if (
parse->rowMarks)
1461 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1464 errmsg(
"%s is not allowed with UNION/INTERSECT/EXCEPT",
1466 parse->rowMarks)->strength))));
1474 root->processed_tlist);
1480 List *sort_input_targets;
1481 List *sort_input_targets_contain_srfs;
1482 bool sort_input_target_parallel_safe;
1484 List *grouping_targets;
1485 List *grouping_targets_contain_srfs;
1486 bool grouping_target_parallel_safe;
1488 List *scanjoin_targets;
1489 List *scanjoin_targets_contain_srfs;
1490 bool scanjoin_target_parallel_safe;
1491 bool scanjoin_target_same_exprs;
1502 if (
parse->groupingSets)
1506 else if (
parse->groupClause)
1540 if (
parse->hasWindowFuncs)
1560 parse->hasWindowFuncs =
false;
1578 if (
parse->groupClause ||
1579 parse->groupingSets ||
1580 parse->distinctClause ||
1582 parse->hasWindowFuncs ||
1583 parse->hasTargetSRFs ||
1584 root->hasHavingQual)
1585 root->limit_tuples = -1.0;
1587 root->limit_tuples = limit_tuples;
1597 qp_extra.
setop = setops;
1618 final_target_parallel_safe =
1626 if (
parse->sortClause)
1630 &have_postponed_srfs);
1631 sort_input_target_parallel_safe =
1636 sort_input_target = final_target;
1637 sort_input_target_parallel_safe = final_target_parallel_safe;
1650 grouping_target_parallel_safe =
1655 grouping_target = sort_input_target;
1656 grouping_target_parallel_safe = sort_input_target_parallel_safe;
1664 have_grouping = (
parse->groupClause ||
parse->groupingSets ||
1669 scanjoin_target_parallel_safe =
1674 scanjoin_target = grouping_target;
1675 scanjoin_target_parallel_safe = grouping_target_parallel_safe;
1684 if (
parse->hasTargetSRFs)
1689 &final_targets_contain_srfs);
1694 &sort_input_targets,
1695 &sort_input_targets_contain_srfs);
1701 &grouping_targets_contain_srfs);
1707 &scanjoin_targets_contain_srfs);
1714 final_targets = final_targets_contain_srfs =
NIL;
1715 sort_input_targets = sort_input_targets_contain_srfs =
NIL;
1716 grouping_targets = grouping_targets_contain_srfs =
NIL;
1717 scanjoin_targets =
list_make1(scanjoin_target);
1718 scanjoin_targets_contain_srfs =
NIL;
1722 scanjoin_target_same_exprs =
list_length(scanjoin_targets) == 1
1725 scanjoin_targets_contain_srfs,
1726 scanjoin_target_parallel_safe,
1727 scanjoin_target_same_exprs);
1753 grouping_target_parallel_safe,
1756 if (
parse->hasTargetSRFs)
1759 grouping_targets_contain_srfs);
1772 sort_input_target_parallel_safe,
1776 if (
parse->hasTargetSRFs)
1779 sort_input_targets_contain_srfs);
1786 if (
parse->distinctClause)
1801 if (
parse->sortClause)
1806 final_target_parallel_safe,
1807 have_postponed_srfs ? -1.0 :
1810 if (
parse->hasTargetSRFs)
1813 final_targets_contain_srfs);
1839 final_rel->fdwroutine = current_rel->fdwroutine;
1856 if (
parse->rowMarks)
1872 offset_est, count_est);
1882 List *updateColnosLists =
NIL;
1883 List *withCheckOptionLists =
NIL;
1886 List *mergeJoinConditions =
NIL;
1893 parse->resultRelation);
1894 int resultRelation = -1;
1897 rootRelation =
parse->resultRelation;
1901 resultRelation)) >= 0)
1919 List *update_colnos =
root->update_colnos;
1921 if (this_result_rel != top_result_rel)
1925 this_result_rel->
relid,
1926 top_result_rel->
relid);
1927 updateColnosLists =
lappend(updateColnosLists,
1930 if (
parse->withCheckOptions)
1932 List *withCheckOptions =
parse->withCheckOptions;
1934 if (this_result_rel != top_result_rel)
1935 withCheckOptions = (
List *)
1937 (
Node *) withCheckOptions,
1940 withCheckOptionLists =
lappend(withCheckOptionLists,
1943 if (
parse->returningList)
1945 List *returningList =
parse->returningList;
1947 if (this_result_rel != top_result_rel)
1948 returningList = (
List *)
1950 (
Node *) returningList,
1953 returningLists =
lappend(returningLists,
1956 if (
parse->mergeActionList)
1965 foreach(l,
parse->mergeActionList)
1975 leaf_action->targetList = (
List *)
1981 leaf_action->updateColnos =
1984 this_result_rel->
relid,
1985 top_result_rel->
relid);
1986 mergeActionList =
lappend(mergeActionList,
1990 mergeActionLists =
lappend(mergeActionLists,
1995 Node *mergeJoinCondition =
parse->mergeJoinCondition;
1997 if (this_result_rel != top_result_rel)
1998 mergeJoinCondition =
2003 mergeJoinConditions =
lappend(mergeJoinConditions,
2004 mergeJoinCondition);
2008 if (resultRelations ==
NIL)
2024 if (
parse->withCheckOptions)
2026 if (
parse->returningList)
2028 if (
parse->mergeActionList)
2041 if (
parse->withCheckOptions)
2043 if (
parse->returningList)
2045 if (
parse->mergeActionList)
2056 if (
parse->rowMarks)
2059 rowMarks =
root->rowMarks;
2066 parse->resultRelation,
2068 root->partColsUpdated,
2071 withCheckOptionLists,
2076 mergeJoinConditions,
2109 if (final_rel->fdwroutine &&
2110 final_rel->fdwroutine->GetForeignUpperPaths)
2112 current_rel, final_rel,
2118 current_rel, final_rel, &extra);
2149 root->processed_groupClause =
parse->groupClause;
2151 if (
parse->groupClause)
2155 foreach(lc,
parse->groupClause)
2185 foreach(lc,
parse->groupingSets)
2206 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2207 errmsg(
"could not implement GROUP BY"),
2208 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
2211 sortable_sets =
lappend(sortable_sets, gset);
2222 foreach(lc_set, sets)
2313 int *tleref_to_colnum_map)
2319 foreach(lc, groupClause)
2332 foreach(lc2, gs->
set)
2337 result =
lappend(result, set);
2356 if (
parse->rowMarks)
2365 parse->rowMarks)->strength);
2385 if (
parse->resultRelation)
2392 foreach(l,
parse->rowMarks)
2425 prowmarks =
lappend(prowmarks, newrc);
2432 foreach(l,
parse->rtable)
2450 prowmarks =
lappend(prowmarks, newrc);
2453 root->rowMarks = prowmarks;
2467 else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2503 elog(
ERROR,
"unrecognized LockClauseStrength %d", (
int) strength);
2531 double limit_fraction;
2540 if (
parse->limitCount)
2545 if (((
Const *) est)->constisnull)
2553 if (*count_est <= 0)
2563 if (
parse->limitOffset)
2568 if (((
Const *) est)->constisnull)
2576 if (*offset_est < 0)
2586 if (*count_est != 0)
2593 if (*count_est < 0 || *offset_est < 0)
2596 limit_fraction = 0.10;
2601 limit_fraction = (double) *count_est + (
double) *offset_est;
2611 if (tuple_fraction >= 1.0)
2613 if (limit_fraction >= 1.0)
2616 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2623 else if (tuple_fraction > 0.0)
2625 if (limit_fraction >= 1.0)
2628 tuple_fraction = limit_fraction;
2633 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2639 tuple_fraction = limit_fraction;
2642 else if (*offset_est != 0 && tuple_fraction > 0.0)
2653 if (*offset_est < 0)
2654 limit_fraction = 0.10;
2656 limit_fraction = (double) *offset_est;
2664 if (tuple_fraction >= 1.0)
2666 if (limit_fraction >= 1.0)
2669 tuple_fraction += limit_fraction;
2674 tuple_fraction = limit_fraction;
2679 if (limit_fraction >= 1.0)
2686 tuple_fraction += limit_fraction;
2687 if (tuple_fraction >= 1.0)
2688 tuple_fraction = 0.0;
2693 return tuple_fraction;
2715 node =
parse->limitCount;
2721 if (!((
Const *) node)->constisnull)
2728 node =
parse->limitOffset;
2734 if (!((
Const *) node)->constisnull)
2792 new_groupclause =
lappend(new_groupclause, cl);
2795 return new_groupclause;
2808 foreach(sl,
parse->sortClause)
2812 foreach(gl,
parse->groupClause)
2818 new_groupclause =
lappend(new_groupclause, gc);
2828 if (new_groupclause ==
NIL)
2837 foreach(gl,
parse->groupClause)
2845 new_groupclause =
lappend(new_groupclause, gc);
2850 return new_groupclause;
2885 short *adjacency_buf;
2901 lc1 =
lnext(groupingSets, lc1);
2926 orig_sets =
palloc0((num_sets_raw + 1) *
sizeof(
List *));
2928 adjacency =
palloc0((num_sets_raw + 1) *
sizeof(
short *));
2929 adjacency_buf =
palloc((num_sets_raw + 1) *
sizeof(
short));
2942 foreach(lc2, candidate)
2952 for (k =
j; k <
i; ++k)
2954 if (
bms_equal(set_masks[k], candidate_set))
2969 orig_sets[dup_of] =
lappend(orig_sets[dup_of], candidate);
2978 set_masks[
i] = candidate_set;
2982 for (k =
j - 1; k > 0; --k)
2985 adjacency_buf[++n_adj] = k;
2990 adjacency_buf[0] = n_adj;
2991 adjacency[
i] =
palloc((n_adj + 1) *
sizeof(
short));
2992 memcpy(adjacency[
i], adjacency_buf, (n_adj + 1) *
sizeof(
short));
2995 adjacency[
i] = NULL;
3014 chains =
palloc0((num_sets + 1) *
sizeof(
int));
3016 for (
i = 1;
i <= num_sets; ++
i)
3018 int u =
state->pair_vu[
i];
3019 int v =
state->pair_uv[
i];
3022 chains[
i] = chains[u];
3023 else if (v > 0 && v <
i)
3024 chains[
i] = chains[v];
3026 chains[
i] = ++num_chains;
3030 results =
palloc0((num_chains + 1) *
sizeof(
List *));
3032 for (
i = 1;
i <= num_sets; ++
i)
3042 while (num_empty-- > 0)
3043 results[1] =
lcons(
NIL, results[1]);
3046 for (
i = 1;
i <= num_chains; ++
i)
3047 result =
lappend(result, results[
i]);
3058 for (
i = 1;
i <= num_sets; ++
i)
3062 pfree(adjacency_buf);
3064 for (
i = 1;
i <= num_sets; ++
i)
3091 foreach(lc, groupingSets)
3119 result =
lcons(gs, result);
3141 if (pathkey->pk_eclass->ec_has_volatile)
3180 List *grouppathkeys =
root->group_pathkeys;
3200 unprocessed_aggs = NULL;
3201 foreach(lc,
root->agginfos)
3206 if (AGGKIND_IS_ORDERED_SET(aggref->aggkind))
3217 bool allow_presort =
true;
3232 foreach(lc2, aggref->
args)
3245 allow_presort =
false;
3310 if (currpathkeys ==
NIL)
3312 currpathkeys = pathkeys;
3315 if (grouppathkeys !=
NIL)
3327 if (grouppathkeys !=
NIL)
3336 currpathkeys = pathkeys;
3363 bestaggs = aggindexes;
3364 bestpathkeys = currpathkeys;
3373 if (bestpathkeys !=
NIL)
3374 root->group_pathkeys = bestpathkeys;
3393 aggref->aggpresorted =
true;
3406 List *tlist =
root->processed_tlist;
3434 root->group_pathkeys =
3448 root->num_groupby_pathkeys = 0;
3451 else if (
parse->groupClause ||
root->numOrderedAggs > 0)
3467 root->group_pathkeys =
3469 &
root->processed_groupClause,
3479 root->num_groupby_pathkeys = 0;
3485 if (
root->numOrderedAggs > 0)
3492 root->num_groupby_pathkeys = 0;
3496 if (activeWindows !=
NIL)
3513 if (
parse->distinctClause)
3519 root->distinct_pathkeys =
3521 &
root->processed_distinctClause,
3528 root->distinct_pathkeys =
NIL;
3531 root->distinct_pathkeys =
NIL;
3533 root->sort_pathkeys =
3539 if (qp_extra->
setop != NULL)
3546 root->setop_pathkeys =
3580 if (
root->group_pathkeys)
3581 root->query_pathkeys =
root->group_pathkeys;
3582 else if (
root->window_pathkeys)
3583 root->query_pathkeys =
root->window_pathkeys;
3586 root->query_pathkeys =
root->distinct_pathkeys;
3587 else if (
root->sort_pathkeys)
3588 root->query_pathkeys =
root->sort_pathkeys;
3589 else if (
root->setop_pathkeys !=
NIL)
3590 root->query_pathkeys =
root->setop_pathkeys;
3615 if (
parse->groupClause)
3619 if (
parse->groupingSets)
3692 else if (
parse->groupingSets)
3697 else if (
parse->hasAggs ||
root->hasHavingQual)
3732 bool target_parallel_safe,
3748 target_parallel_safe,
parse->havingQual);
3797 root->numOrderedAggs == 0 &&
3807 extra.
flags = flags;
3825 &agg_costs, gd, &extra,
3826 &partially_grouped_rel);
3843 PathTarget *target,
bool target_parallel_safe,
3882 grouped_rel->fdwroutine = input_rel->fdwroutine;
3899 return (
root->hasHavingQual ||
parse->groupingSets) &&
3935 while (--nrows >= 0)
4016 root->parse->groupClause))
4031 bool force_rel_creation;
4040 partially_grouped_rel =
4046 force_rel_creation);
4050 *partially_grouped_rel_p = partially_grouped_rel;
4055 partially_grouped_rel, agg_costs,
4061 Assert(partially_grouped_rel);
4063 if (partially_grouped_rel->
pathlist)
4080 cheapest_path->
rows,
4086 partially_grouped_rel, agg_costs, gd,
4092 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4093 errmsg(
"could not implement GROUP BY"),
4094 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4100 if (grouped_rel->fdwroutine &&
4101 grouped_rel->fdwroutine->GetForeignUpperPaths)
4103 input_rel, grouped_rel,
4109 input_rel, grouped_rel,
4154 double exclude_groups = 0.0;
4178 if (l_start != NULL &&
4182 exclude_groups = unhashed_rollup->
numGroups;
4189 dNumGroups - exclude_groups);
4196 if (hashsize > hash_mem_limit && gd->
rollups)
4225 foreach(lc, sets_data)
4234 empty_sets_data =
lappend(empty_sets_data, gs);
4249 new_rollups =
lappend(new_rollups, rollup);
4257 if (new_rollups ==
NIL)
4264 Assert(!unhashed_rollup || !empty_sets);
4266 if (unhashed_rollup)
4268 new_rollups =
lappend(new_rollups, unhashed_rollup);
4271 else if (empty_sets)
4277 rollup->
gsets = empty_sets;
4281 new_rollups =
lappend(new_rollups, rollup);
4314 double availspace = hash_mem_limit;
4330 int *k_weights =
palloc(num_rollups *
sizeof(
int));
4356 scale =
Max(availspace / (20.0 * num_rollups), 1.0);
4357 k_capacity = (int) floor(availspace /
scale);
4381 k_weights[
i] = (int)
Min(floor(sz /
scale),
4411 rollups =
lappend(rollups, rollup);
4415 rollups =
lappend(rollups, rollup);
4420 if (!rollups && hash_sets)
4423 foreach(lc, hash_sets)
4438 rollups =
lcons(rollup, rollups);
4486 bool output_target_parallel_safe,
4488 List *activeWindows)
4511 window_rel->fdwroutine = input_rel->fdwroutine;
4540 if (window_rel->fdwroutine &&
4541 window_rel->fdwroutine->GetForeignUpperPaths)
4543 input_rel, window_rel,
4549 input_rel, window_rel, NULL);
4575 List *activeWindows)
4596 window_target = input_target;
4598 foreach(l, activeWindows)
4601 List *window_pathkeys;
4610 root->processed_tlist);
4643 if (
lnext(activeWindows, l))
4668 window_target = output_target;
4683 foreach(lc3, wfunc->runCondition)
4708 wfuncrc->inputcollid);
4710 runcondition =
lappend(runcondition, opexpr);
4713 topqual =
lappend(topqual, opexpr);
4721 topwindow ? topqual :
NIL, topwindow);
4762 distinct_rel->fdwroutine = input_rel->fdwroutine;
4773 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4774 errmsg(
"could not implement DISTINCT"),
4775 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4781 if (distinct_rel->fdwroutine &&
4782 distinct_rel->fdwroutine->GetForeignUpperPaths)
4783 distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4792 distinct_rel, NULL);
4797 return distinct_rel;
4815 List *distinctExprs;
4816 double numDistinctRows;
4817 Path *cheapest_partial_path;
4827 if (
parse->hasDistinctOn)
4832 partial_distinct_rel->
reltarget = target;
4841 partial_distinct_rel->fdwroutine = input_rel->fdwroutine;
4850 cheapest_partial_path->
rows,
4866 List *useful_pathkeys_list =
NIL;
4868 useful_pathkeys_list =
4870 root->distinct_pathkeys,
4877 partial_distinct_rel,
4879 cheapest_partial_path,
4883 if (sorted_path == NULL)
4891 if (
root->distinct_pathkeys ==
NIL)
4941 partial_distinct_rel,
4942 cheapest_partial_path,
4943 cheapest_partial_path->pathtarget,
4946 root->processed_distinctClause,
4956 if (partial_distinct_rel->fdwroutine &&
4957 partial_distinct_rel->fdwroutine->GetForeignUpperPaths)
4958 partial_distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4961 partial_distinct_rel,
4967 input_rel, partial_distinct_rel, NULL);
4980 final_distinct_rel);
4997 double numDistinctRows;
5002 root->hasHavingQual)
5009 numDistinctRows = cheapest_input_path->
rows;
5016 List *distinctExprs;
5021 cheapest_input_path->
rows,
5046 List *needed_pathkeys;
5048 double limittuples =
root->distinct_pathkeys ==
NIL ? 1.0 : -1.0;
5050 if (
parse->hasDistinctOn &&
5053 needed_pathkeys =
root->sort_pathkeys;
5055 needed_pathkeys =
root->distinct_pathkeys;
5061 List *useful_pathkeys_list =
NIL;
5063 useful_pathkeys_list =
5074 cheapest_input_path,
5078 if (sorted_path == NULL)
5094 if (
root->distinct_pathkeys ==
NIL)
5150 cheapest_input_path,
5151 cheapest_input_path->pathtarget,
5154 root->processed_distinctClause,
5160 return distinct_rel;
5173 List *path_pathkeys)
5175 List *useful_pathkeys_list =
NIL;
5179 useful_pathkeys_list =
lappend(useful_pathkeys_list,
5183 return useful_pathkeys_list;
5202 if (
root->parse->hasDistinctOn &&
5206 useful_pathkeys =
lappend(useful_pathkeys, pathkey);
5210 if (useful_pathkeys ==
NIL)
5211 return useful_pathkeys_list;
5219 return useful_pathkeys_list;
5231 return useful_pathkeys_list;
5233 useful_pathkeys_list =
lappend(useful_pathkeys_list,
5236 return useful_pathkeys_list;
5260 bool target_parallel_safe,
5261 double limit_tuples)
5284 ordered_rel->fdwroutine = input_rel->fdwroutine;
5294 input_path->
pathkeys, &presorted_keys);
5297 sorted_path = input_path;
5307 if (input_path != cheapest_input_path &&
5320 root->sort_pathkeys,
5326 root->sort_pathkeys,
5335 if (!
equal(sorted_path->pathtarget->exprs, target->
exprs))
5337 sorted_path, target);
5339 add_path(ordered_rel, sorted_path);
5356 Path *cheapest_partial_path;
5366 double total_groups;
5382 if (input_path != cheapest_partial_path &&
5395 root->sort_pathkeys,
5401 root->sort_pathkeys,
5405 sorted_path = (
Path *)
5408 sorted_path->pathtarget,
5409 root->sort_pathkeys, NULL,
5416 if (!
equal(sorted_path->pathtarget->exprs, target->
exprs))
5418 sorted_path, target);
5420 add_path(ordered_rel, sorted_path);
5428 if (ordered_rel->fdwroutine &&
5429 ordered_rel->fdwroutine->GetForeignUpperPaths)
5431 input_rel, ordered_rel,
5437 input_rel, ordered_rel, NULL);
5481 List *non_group_cols;
5482 List *non_group_vars;
5491 non_group_cols =
NIL;
5494 foreach(lc, final_target->
exprs)
5499 if (sgref &&
root->processed_groupClause &&
5501 root->processed_groupClause) != NULL)
5526 non_group_cols =
lappend(non_group_cols, expr);
5535 if (
parse->havingQual)
5536 non_group_cols =
lappend(non_group_cols,
parse->havingQual);
5557 non_group_vars = (
List *)
5594 List *non_group_cols;
5595 List *non_group_exprs;
5600 non_group_cols =
NIL;
5603 foreach(lc, grouping_target->
exprs)
5608 if (sgref &&
root->processed_groupClause &&
5610 root->processed_groupClause) != NULL)
5624 non_group_cols =
lappend(non_group_cols, expr);
5634 non_group_cols =
lappend(non_group_cols, havingQual);
5655 foreach(lc, partial_target->
exprs)
5668 memcpy(newaggref, aggref,
sizeof(
Aggref));
5700 agg->aggsplit = aggsplit;
5710 agg->aggtype = BYTEAOID;
5712 agg->aggtype = agg->aggtranstype;
5732 foreach(l, new_tlist)
5738 if (new_tle->resjunk)
5741 Assert(orig_tlist_item != NULL);
5743 orig_tlist_item =
lnext(orig_tlist, orig_tlist_item);
5744 if (orig_tle->resjunk)
5745 elog(
ERROR,
"resjunk output columns are not implemented");
5749 if (orig_tlist_item != NULL)
5750 elog(
ERROR,
"resjunk output columns are not implemented");
5766 List *windowClause =
root->parse->windowClause;
5769 foreach(lc, windowClause)
5773 int optimizedFrameOptions = 0;
5794 req.
type = T_SupportRequestOptimizeWindowClause;
5828 if (lc2 == NULL && wc->
frameOptions != optimizedFrameOptions)
5848 foreach(lc3, windowClause)
5853 if (existing_wc == wc)
5906 List *windowClause =
root->parse->windowClause;
5914 foreach(lc, windowClause)
5923 actives[nActive].
wc = wc;
5967 for (
int i = 0;
i < nActive;
i++)
5968 result =
lappend(result, actives[
i].wc);
5993 foreach(lc, activeWindows)
6006 snprintf(newname,
sizeof(newname),
"w%d", next_n++);
6007 foreach(lc2, activeWindows)
6011 if (wc2->name && strcmp(wc2->name, newname) == 0)
6109 List *activeWindows)
6113 List *flattenable_cols;
6114 List *flattenable_vars;
6125 foreach(lc, activeWindows)
6145 foreach(lc,
root->processed_groupClause)
6157 flattenable_cols =
NIL;
6160 foreach(lc, final_target->
exprs)
6184 flattenable_cols =
lappend(flattenable_cols, expr);
6235 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6236 errmsg(
"could not implement window PARTITION BY"),
6237 errdetail(
"Window partitioning columns must be of sortable datatypes.")));
6240 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6241 errmsg(
"could not implement window ORDER BY"),
6242 errdetail(
"Window ordering columns must be of sortable datatypes.")));
6272 List *orderby_pathkeys;
6279 if (window_pathkeys !=
NIL)
6282 window_pathkeys = orderby_pathkeys;
6285 return window_pathkeys;
6357 bool *have_postponed_srfs)
6366 bool have_expensive;
6367 bool have_srf_sortcols;
6369 List *postponable_cols;
6370 List *postponable_vars;
6377 *have_postponed_srfs =
false;
6381 col_is_srf = (
bool *)
palloc0(ncols *
sizeof(
bool));
6382 postpone_col = (
bool *)
palloc0(ncols *
sizeof(
bool));
6383 have_srf = have_volatile = have_expensive = have_srf_sortcols =
false;
6386 foreach(lc, final_target->
exprs)
6404 if (
parse->hasTargetSRFs &&
6408 col_is_srf[
i] =
true;
6414 postpone_col[
i] =
true;
6415 have_volatile =
true;
6435 postpone_col[
i] =
true;
6436 have_expensive =
true;
6443 if (!have_srf_sortcols &&
6444 parse->hasTargetSRFs &&
6446 have_srf_sortcols =
true;
6455 postpone_srfs = (have_srf && !have_srf_sortcols);
6460 if (!(postpone_srfs || have_volatile ||
6462 (
parse->limitCount ||
root->tuple_fraction > 0))))
6463 return final_target;
6471 *have_postponed_srfs = postpone_srfs;
6479 postponable_cols =
NIL;
6482 foreach(lc, final_target->
exprs)
6486 if (postpone_col[
i] || (postpone_srfs && col_is_srf[
i]))
6487 postponable_cols =
lappend(postponable_cols, expr);
6537 if (tuple_fraction <= 0.0)
6541 if (tuple_fraction >= 1.0 && best_path->
rows > 0)
6542 tuple_fraction /= best_path->
rows;
6548 if (path->param_info)
6578 List *targets,
List *targets_contain_srfs)
6607 forboth(lc1, targets, lc2, targets_contain_srfs)
6640 forboth(lc1, targets, lc2, targets_contain_srfs)
6706 return (
Expr *) result;
6721 List **relationOids,
6729 MemSet(&glob, 0,
sizeof(glob));
6730 glob.type = T_PlannerGlobal;
6735 root.type = T_PlannerInfo;
6757 return (
Expr *) result;
6782 Cost comparisonCost;
6784 Path seqScanAndSortPath;
6799 root->parse = query;
6801 root->query_level = 1;
6803 root->wt_param_id = -1;
6809 rte->relid = tableOid;
6810 rte->relkind = RELKIND_RELATION;
6812 rte->lateral =
false;
6814 rte->inFromCl =
true;
6829 if (indexInfo->
indexoid == indexOid)
6904 int parallel_workers;
6923 root->parse = query;
6925 root->query_level = 1;
6927 root->wt_param_id = -1;
6940 rte->relid = tableOid;
6941 rte->relkind = RELKIND_RELATION;
6943 rte->lateral =
false;
6945 rte->inFromCl =
true;
6966 if (heap->
rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
6970 parallel_workers = 0;
7011 while (parallel_workers > 0 &&
7019 return parallel_workers;
7054 Path *path_save = path;
7055 List *pathkey_orderings =
NIL;
7062 foreach(lc2, pathkey_orderings)
7079 if (
parse->groupingSets)
7082 path,
true, can_hash,
7083 gd, agg_costs, dNumGroups);
7085 else if (
parse->hasAggs)
7103 else if (
parse->groupClause)
7129 if (partially_grouped_rel != NULL)
7131 foreach(lc, partially_grouped_rel->
pathlist)
7135 Path *path_save = path;
7136 List *pathkey_orderings =
NIL;
7144 foreach(lc2, pathkey_orderings)
7189 if (
parse->groupingSets)
7195 cheapest_path,
false,
true,
7196 gd, agg_costs, dNumGroups);
7210 root->processed_groupClause,
7220 if (partially_grouped_rel && partially_grouped_rel->
pathlist)
7231 root->processed_groupClause,
7270 bool force_rel_creation)
7276 Path *cheapest_partial_path = NULL;
7277 Path *cheapest_total_path = NULL;
7278 double dNumPartialGroups = 0;
7279 double dNumPartialPartialGroups = 0;
7308 if (cheapest_total_path == NULL &&
7309 cheapest_partial_path == NULL &&
7310 !force_rel_creation)
7326 partially_grouped_rel->fdwroutine = grouped_rel->fdwroutine;
7361 if (cheapest_total_path != NULL)
7364 cheapest_total_path->
rows,
7367 if (cheapest_partial_path != NULL)
7368 dNumPartialPartialGroups =
7370 cheapest_partial_path->
rows,
7374 if (can_sort && cheapest_total_path != NULL)
7387 Path *path_save = path;
7388 List *pathkey_orderings =
NIL;
7396 foreach(lc2, pathkey_orderings)
7404 partially_grouped_rel,
7406 cheapest_total_path,
7416 partially_grouped_rel,
7424 dNumPartialGroups));
7428 partially_grouped_rel,
7432 dNumPartialGroups));
7437 if (can_sort && cheapest_partial_path != NULL)
7444 Path *path_save = path;
7445 List *pathkey_orderings =
NIL;
7453 foreach(lc2, pathkey_orderings)
7462 partially_grouped_rel,
7464 cheapest_partial_path,
7474 partially_grouped_rel,
7482 dNumPartialPartialGroups));
7486 partially_grouped_rel,
7490 dNumPartialPartialGroups));
7498 if (can_hash && cheapest_total_path != NULL)
7505 partially_grouped_rel,
7506 cheapest_total_path,
7510 root->processed_groupClause,
7513 dNumPartialGroups));
7519 if (can_hash && cheapest_partial_path != NULL)
7523 partially_grouped_rel,
7524 cheapest_partial_path,
7528 root->processed_groupClause,
7531 dNumPartialPartialGroups));
7538 if (partially_grouped_rel->fdwroutine &&
7539 partially_grouped_rel->fdwroutine->GetForeignUpperPaths)
7541 FdwRoutine *fdwroutine = partially_grouped_rel->fdwroutine;
7545 input_rel, partially_grouped_rel,
7549 return partially_grouped_rel;
7560 Path *cheapest_path,
List *pathkeys,
double limit_tuples)
7577 if (path != cheapest_path &&
7621 Path *cheapest_partial_path;
7622 List *groupby_pathkeys;
7630 root->num_groupby_pathkeys);
7632 groupby_pathkeys =
root->group_pathkeys;
7645 double total_groups;
7660 if (path != cheapest_partial_path &&
7713 else if (
parse->groupingSets)
7718 else if (
root->hasNonPartialAggs ||
root->hasNonSerialAggs)
7745 List *scanjoin_targets,
7746 List *scanjoin_targets_contain_srfs,
7747 bool scanjoin_target_parallel_safe,
7776 if (rel_is_partitioned)
7783 if (!scanjoin_target_parallel_safe)
7802 if (rel_is_partitioned)
7825 subpath->pathtarget->sortgrouprefs =
7826 scanjoin_target->sortgrouprefs;
7846 subpath->pathtarget->sortgrouprefs =
7847 scanjoin_target->sortgrouprefs;
7864 if (
root->parse->hasTargetSRFs)
7867 scanjoin_targets_contain_srfs);
7889 if (rel_is_partitioned)
7901 List *child_scanjoin_targets =
NIL;
7903 Assert(child_rel != NULL);
7912 foreach(lc, scanjoin_targets)
7920 nappinfos, appinfos);
7921 child_scanjoin_targets =
lappend(child_scanjoin_targets,
7928 child_scanjoin_targets,
7929 scanjoin_targets_contain_srfs,
7930 scanjoin_target_parallel_safe,
7935 live_children =
lappend(live_children, child_rel);
7987 List *grouped_live_children =
NIL;
7988 List *partially_grouped_live_children =
NIL;
7990 bool partial_grouping_valid =
true;
7995 partially_grouped_rel != NULL);
8001 RelOptInfo *child_input_rel = input_rel->part_rels[
i];
8009 Assert(child_input_rel != NULL);
8021 memcpy(&child_extra, extra,
sizeof(child_extra));
8029 nappinfos, appinfos);
8035 nappinfos, appinfos);
8039 nappinfos, appinfos);
8046 child_extra.
patype = patype;
8060 agg_costs, gd, &child_extra,
8061 &child_partially_grouped_rel);
8063 if (child_partially_grouped_rel)
8065 partially_grouped_live_children =
8066 lappend(partially_grouped_live_children,
8067 child_partially_grouped_rel);
8070 partial_grouping_valid =
false;
8075 grouped_live_children =
lappend(grouped_live_children,
8091 if (partially_grouped_rel && partial_grouping_valid)
8093 Assert(partially_grouped_live_children !=
NIL);
8096 partially_grouped_live_children);
8102 if (partially_grouped_rel->
pathlist)
8131 Assert(input_rel->part_scheme);
8134 if (!input_rel->partexprs)
8137 partnatts = input_rel->part_scheme->partnatts;
8139 for (cnt = 0; cnt < partnatts; cnt++)
8141 List *partexprs = input_rel->partexprs[cnt];
8145 foreach(lc, partexprs)
8149 Oid partcoll = input_rel->part_scheme->partcollation[cnt];
8151 foreach(lg, groupexprs)
8164 if (
equal(groupexpr, partexpr))
8171 partcoll != groupcoll)
8218 foreach(lt, targetlist)
8241 lg =
lnext(grouplist, lg);
8242 ct =
lnext(op->colTypes, ct);
int compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages, int max_workers)
void generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, List *live_childrels)
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
List * adjust_inherited_attnums_multilevel(PlannerInfo *root, List *attnums, Index child_relid, Index top_parent_relid)
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, RelOptInfo *childrel, RelOptInfo *parentrel)
void pprint(const void *obj)
void pgstat_report_plan_id(uint64 plan_id, bool force)
BipartiteMatchState * BipartiteMatch(int u_size, int v_size, short **adjacency)
void BipartiteMatchFree(BipartiteMatchState *state)
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_make_singleton(int x)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
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)
BMS_Membership bms_membership(const Bitmapset *a)
bool bms_overlap_list(const Bitmapset *a, const List *b)
#define MemSet(start, val, len)
#define OidIsValid(objectId)
bool contain_agg_clause(Node *clause)
Node * estimate_expression_value(PlannerInfo *root, Node *node)
WindowFuncLists * find_window_functions(Node *clause, Index maxWinRef)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
void convert_saop_to_hashed_saop(Node *node)
char max_parallel_hazard(Query *parse)
bool is_parallel_safe(PlannerInfo *root, Node *node)
bool contain_subplans(Node *clause)
bool contain_volatile_functions(Node *clause)
bool enable_partitionwise_aggregate
int max_parallel_workers_per_gather
double parallel_setup_cost
double parallel_tuple_cost
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, int input_disabled_nodes, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
double compute_gather_rows(Path *path)
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
bool enable_presorted_aggregate
int32 clamp_width_est(int64 tuple_width)
bool enable_incremental_sort
Plan * materialize_finished_plan(Plan *subplan)
Plan * create_plan(PlannerInfo *root, Path *best_path)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
bool ExecSupportsBackwardScan(Plan *node)
Datum Int64GetDatum(int64 X)
#define OidFunctionCall1(functionId, arg1)
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
int max_parallel_maintenance_workers
Assert(PointerIsAligned(start, uint64))
#define IsParallelWorker()
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
if(TABLE==NULL||TABLE_index==NULL)
double jit_optimize_above_cost
double jit_inline_above_cost
Bitmapset * DiscreteKnapsack(int max_weight, int num_items, int *item_weights, double *item_values)
List * lappend(List *list, void *datum)
List * list_difference_int(const List *list1, const List *list2)
List * list_concat_unique_ptr(List *list1, const List *list2)
List * list_concat(List *list1, const List *list2)
List * list_copy(const List *oldlist)
List * lappend_int(List *list, int datum)
List * lcons(void *datum, List *list)
List * list_delete_int(List *list, int datum)
bool list_member_ptr(const List *list, const void *datum)
void list_free(List *list)
bool list_member_int(const List *list, int datum)
List * list_copy_head(const List *oldlist, int len)
List * list_concat_unique(List *list1, const List *list2)
RegProcedure get_func_support(Oid funcid)
int32 get_typavgwidth(Oid typid, int32 typmod)
Datum subpath(PG_FUNCTION_ARGS)
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
List * make_ands_implicit(Expr *clause)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
Oid exprType(const Node *expr)
Oid exprCollation(const Node *expr)
bool expression_returns_set(Node *clause)
void fix_opfuncids(Node *node)
size_t get_hash_memory_limit(void)
#define DO_AGGSPLIT_SKIPFINAL(as)
#define IsA(nodeptr, _type_)
#define IS_OUTER_JOIN(jointype)
#define DO_AGGSPLIT_SERIALIZE(as)
@ AGGSPLIT_FINAL_DESERIAL
@ AGGSPLIT_INITIAL_SERIAL
#define castNode(_type_, nodeptr)
#define PVC_RECURSE_AGGREGATES
#define PVC_RECURSE_WINDOWFUNCS
#define PVC_INCLUDE_WINDOWFUNCS
#define PVC_INCLUDE_PLACEHOLDERS
#define PVC_INCLUDE_AGGREGATES
int assign_special_exec_param(PlannerInfo *root)
List * expand_grouping_sets(List *groupingSets, bool groupDistinct, int limit)
Index assignSortGroupRef(TargetEntry *tle, List *tlist)
RTEPermissionInfo * addRTEPermissionInfo(List **rteperminfos, RangeTblEntry *rte)
#define CURSOR_OPT_SCROLL
#define CURSOR_OPT_FAST_PLAN
#define CURSOR_OPT_PARALLEL_OK
void CheckSelectLocking(Query *qry, LockClauseStrength strength)
const char * LCS_asString(LockClauseStrength strength)
#define rt_fetch(rangetable_index, rangetable)
void DestroyPartitionDirectory(PartitionDirectory pdir)
List * append_pathkeys(List *target, List *source)
bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
List * make_pathkeys_for_sortclauses_extended(PlannerInfo *root, List **sortclauses, List *tlist, bool remove_redundant, bool remove_group_rtindex, bool *sortable, bool set_ec_sortref)
bool pathkeys_contained_in(List *keys1, List *keys2)
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
List * get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
IndexPath * create_index_path(PlannerInfo *root, IndexOptInfo *index, List *indexclauses, List *indexorderbys, List *indexorderbycols, List *pathkeys, ScanDirection indexscandir, bool indexonly, Relids required_outer, double loop_count, bool partial_path)
ProjectSetPath * create_set_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
WindowAggPath * create_windowagg_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *windowFuncs, List *runCondition, WindowClause *winclause, List *qual, bool topwindow)
LockRowsPath * create_lockrows_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *rowMarks, int epqParam)
Path * apply_projection_to_path(PlannerInfo *root, RelOptInfo *rel, Path *path, PathTarget *target)
Path * create_seqscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer, int parallel_workers)
GatherMergePath * create_gather_merge_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *pathkeys, Relids required_outer, double *rows)
void set_cheapest(RelOptInfo *parent_rel)
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
LimitPath * create_limit_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, Node *limitOffset, Node *limitCount, LimitOption limitOption, int64 offset_est, int64 count_est)
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)
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
IncrementalSortPath * create_incremental_sort_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, int presorted_keys, double limit_tuples)
GroupingSetsPath * create_groupingsets_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *having_qual, AggStrategy aggstrategy, List *rollups, const AggClauseCosts *agg_costs)
SortPath * create_sort_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
GroupPath * create_group_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *groupClause, List *qual, double numGroups)
void add_path(RelOptInfo *parent_rel, Path *new_path)
UpperUniquePath * create_upper_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, int numCols, double numGroups)
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)
ModifyTablePath * create_modifytable_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, CmdType operation, bool canSetTag, Index nominalRelation, Index rootRelation, bool partColsUpdated, List *resultRelations, List *updateColnosLists, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, List *mergeActionLists, List *mergeJoinConditions, int epqParam)
GroupResultPath * create_group_result_path(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *havingqual)
PartitionwiseAggregateType
@ PARTITIONWISE_AGGREGATE_PARTIAL
@ PARTITIONWISE_AGGREGATE_FULL
@ PARTITIONWISE_AGGREGATE_NONE
#define GROUPING_CAN_USE_HASH
#define get_pathtarget_sortgroupref(target, colno)
#define IS_PARTITIONED_REL(rel)
#define GROUPING_CAN_USE_SORT
#define GROUPING_CAN_PARTIAL_AGG
@ UPPERREL_PARTIAL_GROUP_AGG
@ UPPERREL_PARTIAL_DISTINCT
#define IS_OTHER_REL(rel)
bool has_subclass(Oid relationId)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_current_index(var_or_cell)
#define for_each_cell(cell, lst, initcell)
#define for_each_from(cell, lst, N)
static void * list_nth(const List *list, int n)
#define foreach_node(type, var, lst)
static ListCell * list_head(const List *l)
#define list_nth_node(type, list, n)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make1_int(x1)
static int list_cell_number(const List *l, const ListCell *c)
#define llast_node(type, l)
void preprocess_minmax_aggregates(PlannerInfo *root)
void estimate_rel_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
int32 get_relation_data_width(Oid relid, int32 *attr_widths)
RelOptInfo * query_planner(PlannerInfo *root, query_pathkeys_callback qp_callback, void *qp_extra)
#define DEFAULT_CURSOR_TUPLE_FRACTION
#define EXPRKIND_TABLEFUNC_LATERAL
static RelOptInfo * create_final_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *distinct_rel)
static List * postprocess_setop_tlist(List *new_tlist, List *orig_tlist)
static PathTarget * make_partial_grouping_target(PlannerInfo *root, PathTarget *grouping_target, Node *havingQual)
Expr * expression_planner_with_deps(Expr *expr, List **relationOids, List **invalItems)
static void gather_grouping_paths(PlannerInfo *root, RelOptInfo *rel)
static void preprocess_rowmarks(PlannerInfo *root)
#define EXPRKIND_TABLESAMPLE
PlannedStmt * planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
static void create_degenerate_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *grouped_rel)
#define EXPRKIND_GROUPEXPR
planner_hook_type planner_hook
double cursor_tuple_fraction
static bool is_degenerate_grouping(PlannerInfo *root)
bool plan_cluster_use_sort(Oid tableOid, Oid indexOid)
static void preprocess_qual_conditions(PlannerInfo *root, Node *jtnode)
int plan_create_index_workers(Oid tableOid, Oid indexOid)
#define EXPRKIND_RTFUNC_LATERAL
#define EXPRKIND_VALUES_LATERAL
static void create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *grouped_rel, const AggClauseCosts *agg_costs, grouping_sets_data *gd, GroupPathExtraData *extra, RelOptInfo **partially_grouped_rel_p)
static bool can_partial_agg(PlannerInfo *root)
static double preprocess_limit(PlannerInfo *root, double tuple_fraction, int64 *offset_est, int64 *count_est)
Path * get_cheapest_fractional_path(RelOptInfo *rel, double tuple_fraction)
Expr * preprocess_phv_expression(PlannerInfo *root, Expr *expr)
static List * get_useful_pathkeys_for_distinct(PlannerInfo *root, List *needed_pathkeys, List *path_pathkeys)
bool parallel_leader_participation
static PathTarget * make_window_input_target(PlannerInfo *root, PathTarget *final_target, List *activeWindows)
static void apply_scanjoin_target_to_paths(PlannerInfo *root, RelOptInfo *rel, List *scanjoin_targets, List *scanjoin_targets_contain_srfs, bool scanjoin_target_parallel_safe, bool tlist_same_exprs)
static RelOptInfo * create_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel, PathTarget *target)
static void optimize_window_clauses(PlannerInfo *root, WindowFuncLists *wflists)
RowMarkType select_rowmark_type(RangeTblEntry *rte, LockClauseStrength strength)
PlannerInfo * subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction, SetOperationStmt *setops)
static void adjust_paths_for_srfs(PlannerInfo *root, RelOptInfo *rel, List *targets, List *targets_contain_srfs)
static void create_partial_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *final_distinct_rel, PathTarget *target)
static List * preprocess_groupclause(PlannerInfo *root, List *force)
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
static Path * make_ordered_path(PlannerInfo *root, RelOptInfo *rel, Path *path, Path *cheapest_path, List *pathkeys, double limit_tuples)
static bool has_volatile_pathkey(List *keys)
static RelOptInfo * create_partial_grouping_paths(PlannerInfo *root, RelOptInfo *grouped_rel, RelOptInfo *input_rel, grouping_sets_data *gd, GroupPathExtraData *extra, bool force_rel_creation)
static void name_active_windows(List *activeWindows)
static PathTarget * make_sort_input_target(PlannerInfo *root, PathTarget *final_target, bool *have_postponed_srfs)
static void create_one_window_path(PlannerInfo *root, RelOptInfo *window_rel, Path *path, PathTarget *input_target, PathTarget *output_target, WindowFuncLists *wflists, List *activeWindows)
bool enable_distinct_reordering
void mark_partial_aggref(Aggref *agg, AggSplit aggsplit)
static grouping_sets_data * preprocess_grouping_sets(PlannerInfo *root)
static List * remap_to_groupclause_idx(List *groupClause, List *gsets, int *tleref_to_colnum_map)
static void adjust_group_pathkeys_for_groupagg(PlannerInfo *root)
static PathTarget * make_group_input_target(PlannerInfo *root, PathTarget *final_target)
static List * reorder_grouping_sets(List *groupingSets, List *sortclause)
static int common_prefix_cmp(const void *a, const void *b)
static void grouping_planner(PlannerInfo *root, double tuple_fraction, SetOperationStmt *setops)
static RelOptInfo * make_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel, PathTarget *target, bool target_parallel_safe, Node *havingQual)
static List * generate_setop_child_grouplist(SetOperationStmt *op, List *targetlist)
static List * select_active_windows(PlannerInfo *root, WindowFuncLists *wflists)
Expr * expression_planner(Expr *expr)
bool limit_needed(Query *parse)
create_upper_paths_hook_type create_upper_paths_hook
#define EXPRKIND_TABLEFUNC
static void consider_groupingsets_paths(PlannerInfo *root, RelOptInfo *grouped_rel, Path *path, bool is_sorted, bool can_hash, grouping_sets_data *gd, const AggClauseCosts *agg_costs, double dNumGroups)
static List * make_pathkeys_for_window(PlannerInfo *root, WindowClause *wc, List *tlist)
static void add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *grouped_rel, RelOptInfo *partially_grouped_rel, const AggClauseCosts *agg_costs, grouping_sets_data *gd, double dNumGroups, GroupPathExtraData *extra)
static RelOptInfo * create_ordered_paths(PlannerInfo *root, RelOptInfo *input_rel, PathTarget *target, bool target_parallel_safe, double limit_tuples)
static double get_number_of_groups(PlannerInfo *root, double path_rows, grouping_sets_data *gd, List *target_list)
static List * extract_rollup_sets(List *groupingSets)
static RelOptInfo * create_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel, PathTarget *target, bool target_parallel_safe, grouping_sets_data *gd)
static void create_partitionwise_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *grouped_rel, RelOptInfo *partially_grouped_rel, const AggClauseCosts *agg_costs, grouping_sets_data *gd, PartitionwiseAggregateType patype, GroupPathExtraData *extra)
#define EXPRKIND_ARBITER_ELEM
static bool group_by_has_partkey(RelOptInfo *input_rel, List *targetList, List *groupClause)
PlannedStmt * standard_planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
static void standard_qp_callback(PlannerInfo *root, void *extra)
static RelOptInfo * create_window_paths(PlannerInfo *root, RelOptInfo *input_rel, PathTarget *input_target, PathTarget *output_target, bool output_target_parallel_safe, WindowFuncLists *wflists, List *activeWindows)
PlannedStmt *(* planner_hook_type)(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
void(* create_upper_paths_hook_type)(PlannerInfo *root, UpperRelationKind stage, RelOptInfo *input_rel, RelOptInfo *output_rel, void *extra)
@ ROW_MARK_NOKEYEXCLUSIVE
#define qsort(a, b, c, d)
static int64 DatumGetInt64(Datum X)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
void get_agg_clause_costs(PlannerInfo *root, AggSplit aggsplit, AggClauseCosts *costs)
void preprocess_aggrefs(PlannerInfo *root, Node *clause)
void preprocess_function_rtes(PlannerInfo *root)
void flatten_simple_union_all(PlannerInfo *root)
void transform_MERGE_to_join(Query *parse)
void remove_useless_result_rtes(PlannerInfo *root)
Query * expand_virtual_generated_columns(PlannerInfo *root)
void pull_up_sublinks(PlannerInfo *root)
void replace_empty_jointree(Query *parse)
void pull_up_subqueries(PlannerInfo *root)
Relids get_relids_in_jointree(Node *jtnode, bool include_outer_joins, bool include_inner_joins)
void reduce_outer_joins(PlannerInfo *root)
Expr * canonicalize_qual(Expr *qual, bool is_check)
void preprocess_targetlist(PlannerInfo *root)
RelOptInfo * plan_set_operations(PlannerInfo *root)
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
List * RelationGetIndexPredicate(Relation relation)
List * RelationGetIndexExpressions(Relation relation)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
void setup_simple_rel_arrays(PlannerInfo *root)
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
Node * remove_nulling_relids(Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset, EstimationInfo *estinfo)
double estimate_hashagg_tablesize(PlannerInfo *root, Path *path, const AggClauseCosts *agg_costs, double dNumGroups)
Plan * set_plan_references(PlannerInfo *root, Plan *plan)
bool extract_query_dependencies_walker(Node *node, PlannerInfo *context)
void check_stack_depth(void)
GetForeignRowMarkType_function GetForeignRowMarkType
GetForeignUpperPaths_function GetForeignUpperPaths
LockClauseStrength strength
LockWaitPolicy waitPolicy
Bitmapset * rewindPlanIDs
Bitmapset * unprunableRelids
Bitmapset * prunableRelids
Bitmapset * rewindPlanIDs
struct TableSampleClause * tablesample
struct PathTarget * reltarget
struct Path * cheapest_startup_path
struct Path * cheapest_total_path
LockClauseStrength strength
LockWaitPolicy waitPolicy
struct WindowClause * window_clause
int * tleref_to_colnum_map
Bitmapset * unhashable_refs
Bitmapset * unsortable_refs
grouping_sets_data * gset_data
Node * SS_process_sublinks(PlannerInfo *root, Node *expr, bool isQual)
void SS_process_ctes(PlannerInfo *root)
void SS_identify_outer_params(PlannerInfo *root)
Node * SS_replace_correlation_vars(PlannerInfo *root, Node *expr)
void SS_finalize_plan(PlannerInfo *root, Plan *plan)
void SS_compute_initplan_cost(List *init_plans, Cost *initplan_cost_p, bool *unsafe_initplans_p)
void SS_charge_for_initplans(PlannerInfo *root, RelOptInfo *final_rel)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
bool tlist_same_exprs(List *tlist1, List *tlist2)
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
SortGroupClause * get_sortgroupref_clause(Index sortref, List *clauses)
bool grouping_is_sortable(List *groupClause)
PathTarget * copy_pathtarget(PathTarget *src)
void add_new_columns_to_pathtarget(PathTarget *target, List *exprs)
PathTarget * create_empty_pathtarget(void)
List * get_sortgrouplist_exprs(List *sgClauses, List *targetList)
void split_pathtarget_at_srfs(PlannerInfo *root, PathTarget *target, PathTarget *input_target, List **targets, List **targets_contain_srfs)
bool grouping_is_hashable(List *groupClause)
void add_column_to_pathtarget(PathTarget *target, Expr *expr, Index sortgroupref)
#define create_pathtarget(root, tlist)
Node * flatten_group_exprs(PlannerInfo *root, Query *query, Node *node)
Relids pull_varnos(PlannerInfo *root, Node *node)
List * pull_var_clause(Node *node, int flags)
Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)