79#define EXPRKIND_QUAL 0
80#define EXPRKIND_TARGET 1
81#define EXPRKIND_RTFUNC 2
82#define EXPRKIND_RTFUNC_LATERAL 3
83#define EXPRKIND_VALUES 4
84#define EXPRKIND_VALUES_LATERAL 5
85#define EXPRKIND_LIMIT 6
86#define EXPRKIND_APPINFO 7
88#define EXPRKIND_TABLESAMPLE 9
89#define EXPRKIND_ARBITER_ELEM 10
90#define EXPRKIND_TABLEFUNC 11
91#define EXPRKIND_TABLEFUNC_LATERAL 12
92#define EXPRKIND_GROUPEXPR 13
136 int *tleref_to_colnum_map);
139 double tuple_fraction,
152 bool target_parallel_safe,
159 PathTarget *target,
bool target_parallel_safe,
180 bool output_target_parallel_safe,
182 List *activeWindows);
189 List *activeWindows);
201 List *needed_pathkeys,
202 List *path_pathkeys);
206 bool target_parallel_safe,
207 double limit_tuples);
219 List *activeWindows);
224 bool *have_postponed_srfs);
226 List *targets,
List *targets_contain_srfs);
239 bool force_rel_creation);
245 double limit_tuples);
250 List *scanjoin_targets,
251 List *scanjoin_targets_contain_srfs,
252 bool scanjoin_target_parallel_safe,
290 result = (*planner_hook) (
parse, query_string, cursorOptions, boundParams);
302 double tuple_fraction;
318 glob->boundParams = boundParams;
321 glob->subroots =
NIL;
361 !
parse->hasModifyingCTE &&
413 if (tuple_fraction >= 1.0)
414 tuple_fraction = 0.0;
415 else if (tuple_fraction <= 0.0)
416 tuple_fraction = 1
e-10;
421 tuple_fraction = 0.0;
462 bool unsafe_initplans;
500 &initplan_cost, &unsafe_initplans);
505 root->glob->parallelModeNeeded =
true;
507 top_plan = &gather->
plan;
598 if (glob->partition_directory != NULL)
639 bool hasRecursion,
double tuple_fraction,
643 List *newWithCheckOptions;
655 root->parent_root = parent_root;
657 root->outer_params = NULL;
664 root->ec_merging_done =
false;
665 root->last_rinfo_serial = 0;
666 root->all_result_relids =
668 root->leaf_result_relids = NULL;
672 memset(
root->upper_rels, 0,
sizeof(
root->upper_rels));
673 memset(
root->upper_targets, 0,
sizeof(
root->upper_targets));
674 root->processed_groupClause =
NIL;
675 root->processed_distinctClause =
NIL;
678 root->grouping_map = NULL;
680 root->qual_security_level = 0;
681 root->hasPseudoConstantQuals =
false;
682 root->hasAlternativeSubPlans =
false;
683 root->placeholdersFrozen =
false;
684 root->hasRecursion = hasRecursion;
688 root->wt_param_id = -1;
689 root->non_recursive_path = NULL;
690 root->partColsUpdated =
false;
723 if (
parse->hasSubLinks)
746 if (
parse->setOperations)
759 root->hasJoinRTEs =
false;
760 root->hasLateralRTEs =
false;
761 root->group_rtindex = 0;
762 hasOuterJoins =
false;
763 hasResultRTEs =
false;
764 foreach(l,
parse->rtable)
788 root->hasJoinRTEs =
true;
790 hasOuterJoins =
true;
793 hasResultRTEs =
true;
805 root->hasLateralRTEs =
true;
813 if (rte->securityQuals)
814 root->qual_security_level =
Max(
root->qual_security_level,
822 if (
parse->resultRelation)
827 root->leaf_result_relids =
842 root->hasHavingQual = (
parse->havingQual != NULL);
854 newWithCheckOptions =
NIL;
855 foreach(l,
parse->withCheckOptions)
861 if (wco->
qual != NULL)
862 newWithCheckOptions =
lappend(newWithCheckOptions, wco);
864 parse->withCheckOptions = newWithCheckOptions;
875 foreach(l,
parse->windowClause)
891 if (
parse->onConflict)
893 parse->onConflict->arbiterElems = (
List *)
895 (
Node *)
parse->onConflict->arbiterElems,
897 parse->onConflict->arbiterWhere =
899 parse->onConflict->arbiterWhere,
901 parse->onConflict->onConflictSet = (
List *)
903 (
Node *)
parse->onConflict->onConflictSet,
905 parse->onConflict->onConflictWhere =
907 parse->onConflict->onConflictWhere,
912 foreach(l,
parse->mergeActionList)
926 parse->mergeJoinCondition =
934 foreach(l,
parse->rtable)
957 if (rte->lateral &&
root->hasJoinRTEs)
986 rte->groupexprs = (
List *)
997 foreach(lcsq, rte->securityQuals)
1016 if (
root->hasJoinRTEs)
1018 foreach(l,
parse->rtable)
1022 rte->joinaliasvars =
NIL;
1035 if (
parse->hasGroupRTE)
1044 if (
parse->hasTargetSRFs)
1096 (
parse->groupClause &&
parse->groupingSets &&
1100 newHaving =
lappend(newHaving, havingclause);
1102 else if (
parse->groupClause)
1112 (
List *) whereclause);
1124 (
List *) whereclause);
1126 newHaving =
lappend(newHaving, havingclause);
1145 if (hasResultRTEs || hasOuterJoins)
1204 if (
root->hasJoinRTEs &&
1240#ifdef OPTIMIZER_DEBUG
1241 printf(
"After canonicalize_qual()\n");
1257 if (
root->parse->hasSubLinks)
1266 if (
root->query_level > 1)
1315 elog(
ERROR,
"unrecognized node type: %d",
1368 int64 offset_est = 0;
1369 int64 count_est = 0;
1370 double limit_tuples = -1.0;
1371 bool have_postponed_srfs =
false;
1373 List *final_targets;
1374 List *final_targets_contain_srfs;
1375 bool final_target_parallel_safe;
1385 &offset_est, &count_est);
1391 if (count_est > 0 && offset_est >= 0)
1392 limit_tuples = (double) count_est + (
double) offset_est;
1396 root->tuple_fraction = tuple_fraction;
1398 if (
parse->setOperations)
1418 root->processed_tlist =
1426 final_target_parallel_safe =
1431 final_targets = final_targets_contain_srfs =
NIL;
1437 if (
parse->rowMarks)
1439 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1442 errmsg(
"%s is not allowed with UNION/INTERSECT/EXCEPT",
1444 parse->rowMarks)->strength))));
1452 root->processed_tlist);
1458 List *sort_input_targets;
1459 List *sort_input_targets_contain_srfs;
1460 bool sort_input_target_parallel_safe;
1462 List *grouping_targets;
1463 List *grouping_targets_contain_srfs;
1464 bool grouping_target_parallel_safe;
1466 List *scanjoin_targets;
1467 List *scanjoin_targets_contain_srfs;
1468 bool scanjoin_target_parallel_safe;
1469 bool scanjoin_target_same_exprs;
1480 if (
parse->groupingSets)
1484 else if (
parse->groupClause)
1518 if (
parse->hasWindowFuncs)
1534 parse->hasWindowFuncs =
false;
1552 if (
parse->groupClause ||
1553 parse->groupingSets ||
1554 parse->distinctClause ||
1556 parse->hasWindowFuncs ||
1557 parse->hasTargetSRFs ||
1558 root->hasHavingQual)
1559 root->limit_tuples = -1.0;
1561 root->limit_tuples = limit_tuples;
1571 qp_extra.
setop = setops;
1592 final_target_parallel_safe =
1600 if (
parse->sortClause)
1604 &have_postponed_srfs);
1605 sort_input_target_parallel_safe =
1610 sort_input_target = final_target;
1611 sort_input_target_parallel_safe = final_target_parallel_safe;
1624 grouping_target_parallel_safe =
1629 grouping_target = sort_input_target;
1630 grouping_target_parallel_safe = sort_input_target_parallel_safe;
1638 have_grouping = (
parse->groupClause ||
parse->groupingSets ||
1643 scanjoin_target_parallel_safe =
1648 scanjoin_target = grouping_target;
1649 scanjoin_target_parallel_safe = grouping_target_parallel_safe;
1658 if (
parse->hasTargetSRFs)
1663 &final_targets_contain_srfs);
1668 &sort_input_targets,
1669 &sort_input_targets_contain_srfs);
1675 &grouping_targets_contain_srfs);
1681 &scanjoin_targets_contain_srfs);
1688 final_targets = final_targets_contain_srfs =
NIL;
1689 sort_input_targets = sort_input_targets_contain_srfs =
NIL;
1690 grouping_targets = grouping_targets_contain_srfs =
NIL;
1691 scanjoin_targets =
list_make1(scanjoin_target);
1692 scanjoin_targets_contain_srfs =
NIL;
1696 scanjoin_target_same_exprs =
list_length(scanjoin_targets) == 1
1699 scanjoin_targets_contain_srfs,
1700 scanjoin_target_parallel_safe,
1701 scanjoin_target_same_exprs);
1727 grouping_target_parallel_safe,
1730 if (
parse->hasTargetSRFs)
1733 grouping_targets_contain_srfs);
1746 sort_input_target_parallel_safe,
1750 if (
parse->hasTargetSRFs)
1753 sort_input_targets_contain_srfs);
1760 if (
parse->distinctClause)
1775 if (
parse->sortClause)
1780 final_target_parallel_safe,
1781 have_postponed_srfs ? -1.0 :
1784 if (
parse->hasTargetSRFs)
1787 final_targets_contain_srfs);
1813 final_rel->fdwroutine = current_rel->fdwroutine;
1830 if (
parse->rowMarks)
1846 offset_est, count_est);
1856 List *updateColnosLists =
NIL;
1857 List *withCheckOptionLists =
NIL;
1860 List *mergeJoinConditions =
NIL;
1867 parse->resultRelation);
1868 int resultRelation = -1;
1871 rootRelation =
parse->resultRelation;
1875 resultRelation)) >= 0)
1893 List *update_colnos =
root->update_colnos;
1895 if (this_result_rel != top_result_rel)
1899 this_result_rel->
relid,
1900 top_result_rel->
relid);
1901 updateColnosLists =
lappend(updateColnosLists,
1904 if (
parse->withCheckOptions)
1906 List *withCheckOptions =
parse->withCheckOptions;
1908 if (this_result_rel != top_result_rel)
1909 withCheckOptions = (
List *)
1911 (
Node *) withCheckOptions,
1914 withCheckOptionLists =
lappend(withCheckOptionLists,
1917 if (
parse->returningList)
1919 List *returningList =
parse->returningList;
1921 if (this_result_rel != top_result_rel)
1922 returningList = (
List *)
1924 (
Node *) returningList,
1927 returningLists =
lappend(returningLists,
1930 if (
parse->mergeActionList)
1939 foreach(l,
parse->mergeActionList)
1949 leaf_action->targetList = (
List *)
1955 leaf_action->updateColnos =
1958 this_result_rel->
relid,
1959 top_result_rel->
relid);
1960 mergeActionList =
lappend(mergeActionList,
1964 mergeActionLists =
lappend(mergeActionLists,
1969 Node *mergeJoinCondition =
parse->mergeJoinCondition;
1971 if (this_result_rel != top_result_rel)
1972 mergeJoinCondition =
1977 mergeJoinConditions =
lappend(mergeJoinConditions,
1978 mergeJoinCondition);
1982 if (resultRelations ==
NIL)
1998 if (
parse->withCheckOptions)
2000 if (
parse->returningList)
2002 if (
parse->mergeActionList)
2015 if (
parse->withCheckOptions)
2017 if (
parse->returningList)
2019 if (
parse->mergeActionList)
2030 if (
parse->rowMarks)
2033 rowMarks =
root->rowMarks;
2040 parse->resultRelation,
2042 root->partColsUpdated,
2045 withCheckOptionLists,
2050 mergeJoinConditions,
2083 if (final_rel->fdwroutine &&
2084 final_rel->fdwroutine->GetForeignUpperPaths)
2086 current_rel, final_rel,
2092 current_rel, final_rel, &extra);
2123 root->processed_groupClause =
parse->groupClause;
2125 if (
parse->groupClause)
2129 foreach(lc,
parse->groupClause)
2159 foreach(lc,
parse->groupingSets)
2180 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2181 errmsg(
"could not implement GROUP BY"),
2182 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
2185 sortable_sets =
lappend(sortable_sets, gset);
2196 foreach(lc_set, sets)
2287 int *tleref_to_colnum_map)
2293 foreach(lc, groupClause)
2306 foreach(lc2, gs->
set)
2311 result =
lappend(result, set);
2330 if (
parse->rowMarks)
2339 parse->rowMarks)->strength);
2359 if (
parse->resultRelation)
2366 foreach(l,
parse->rowMarks)
2399 prowmarks =
lappend(prowmarks, newrc);
2406 foreach(l,
parse->rtable)
2424 prowmarks =
lappend(prowmarks, newrc);
2427 root->rowMarks = prowmarks;
2441 else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2477 elog(
ERROR,
"unrecognized LockClauseStrength %d", (
int) strength);
2505 double limit_fraction;
2514 if (
parse->limitCount)
2519 if (((
Const *) est)->constisnull)
2527 if (*count_est <= 0)
2537 if (
parse->limitOffset)
2542 if (((
Const *) est)->constisnull)
2550 if (*offset_est < 0)
2560 if (*count_est != 0)
2567 if (*count_est < 0 || *offset_est < 0)
2570 limit_fraction = 0.10;
2575 limit_fraction = (double) *count_est + (
double) *offset_est;
2585 if (tuple_fraction >= 1.0)
2587 if (limit_fraction >= 1.0)
2590 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2597 else if (tuple_fraction > 0.0)
2599 if (limit_fraction >= 1.0)
2602 tuple_fraction = limit_fraction;
2607 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2613 tuple_fraction = limit_fraction;
2616 else if (*offset_est != 0 && tuple_fraction > 0.0)
2627 if (*offset_est < 0)
2628 limit_fraction = 0.10;
2630 limit_fraction = (double) *offset_est;
2638 if (tuple_fraction >= 1.0)
2640 if (limit_fraction >= 1.0)
2643 tuple_fraction += limit_fraction;
2648 tuple_fraction = limit_fraction;
2653 if (limit_fraction >= 1.0)
2660 tuple_fraction += limit_fraction;
2661 if (tuple_fraction >= 1.0)
2662 tuple_fraction = 0.0;
2667 return tuple_fraction;
2689 node =
parse->limitCount;
2695 if (!((
Const *) node)->constisnull)
2702 node =
parse->limitOffset;
2708 if (!((
Const *) node)->constisnull)
2766 new_groupclause =
lappend(new_groupclause, cl);
2769 return new_groupclause;
2782 foreach(sl,
parse->sortClause)
2786 foreach(gl,
parse->groupClause)
2792 new_groupclause =
lappend(new_groupclause, gc);
2802 if (new_groupclause ==
NIL)
2811 foreach(gl,
parse->groupClause)
2819 new_groupclause =
lappend(new_groupclause, gc);
2824 return new_groupclause;
2859 short *adjacency_buf;
2875 lc1 =
lnext(groupingSets, lc1);
2900 orig_sets =
palloc0((num_sets_raw + 1) *
sizeof(
List *));
2902 adjacency =
palloc0((num_sets_raw + 1) *
sizeof(
short *));
2903 adjacency_buf =
palloc((num_sets_raw + 1) *
sizeof(
short));
2916 foreach(lc2, candidate)
2926 for (k =
j; k <
i; ++k)
2928 if (
bms_equal(set_masks[k], candidate_set))
2943 orig_sets[dup_of] =
lappend(orig_sets[dup_of], candidate);
2952 set_masks[
i] = candidate_set;
2956 for (k =
j - 1; k > 0; --k)
2959 adjacency_buf[++n_adj] = k;
2964 adjacency_buf[0] = n_adj;
2965 adjacency[
i] =
palloc((n_adj + 1) *
sizeof(
short));
2966 memcpy(adjacency[
i], adjacency_buf, (n_adj + 1) *
sizeof(
short));
2969 adjacency[
i] = NULL;
2988 chains =
palloc0((num_sets + 1) *
sizeof(
int));
2990 for (
i = 1;
i <= num_sets; ++
i)
2992 int u =
state->pair_vu[
i];
2993 int v =
state->pair_uv[
i];
2996 chains[
i] = chains[u];
2997 else if (v > 0 && v <
i)
2998 chains[
i] = chains[v];
3000 chains[
i] = ++num_chains;
3004 results =
palloc0((num_chains + 1) *
sizeof(
List *));
3006 for (
i = 1;
i <= num_sets; ++
i)
3016 while (num_empty-- > 0)
3017 results[1] =
lcons(
NIL, results[1]);
3020 for (
i = 1;
i <= num_chains; ++
i)
3021 result =
lappend(result, results[
i]);
3032 for (
i = 1;
i <= num_sets; ++
i)
3036 pfree(adjacency_buf);
3038 for (
i = 1;
i <= num_sets; ++
i)
3065 foreach(lc, groupingSets)
3093 result =
lcons(gs, result);
3115 if (pathkey->pk_eclass->ec_has_volatile)
3154 List *grouppathkeys =
root->group_pathkeys;
3174 unprocessed_aggs = NULL;
3175 foreach(lc,
root->agginfos)
3180 if (AGGKIND_IS_ORDERED_SET(aggref->aggkind))
3241 if (currpathkeys ==
NIL)
3243 currpathkeys = pathkeys;
3246 if (grouppathkeys !=
NIL)
3258 if (grouppathkeys !=
NIL)
3267 currpathkeys = pathkeys;
3294 bestaggs = aggindexes;
3295 bestpathkeys = currpathkeys;
3304 if (bestpathkeys !=
NIL)
3305 root->group_pathkeys = bestpathkeys;
3324 aggref->aggpresorted =
true;
3337 List *tlist =
root->processed_tlist;
3365 root->group_pathkeys =
3379 root->num_groupby_pathkeys = 0;
3382 else if (
parse->groupClause ||
root->numOrderedAggs > 0)
3398 root->group_pathkeys =
3400 &
root->processed_groupClause,
3410 root->num_groupby_pathkeys = 0;
3416 if (
root->numOrderedAggs > 0)
3423 root->num_groupby_pathkeys = 0;
3427 if (activeWindows !=
NIL)
3444 if (
parse->distinctClause)
3450 root->distinct_pathkeys =
3452 &
root->processed_distinctClause,
3459 root->distinct_pathkeys =
NIL;
3462 root->distinct_pathkeys =
NIL;
3464 root->sort_pathkeys =
3470 if (qp_extra->
setop != NULL)
3477 root->setop_pathkeys =
3511 if (
root->group_pathkeys)
3512 root->query_pathkeys =
root->group_pathkeys;
3513 else if (
root->window_pathkeys)
3514 root->query_pathkeys =
root->window_pathkeys;
3517 root->query_pathkeys =
root->distinct_pathkeys;
3518 else if (
root->sort_pathkeys)
3519 root->query_pathkeys =
root->sort_pathkeys;
3520 else if (
root->setop_pathkeys !=
NIL)
3521 root->query_pathkeys =
root->setop_pathkeys;
3546 if (
parse->groupClause)
3550 if (
parse->groupingSets)
3623 else if (
parse->groupingSets)
3628 else if (
parse->hasAggs ||
root->hasHavingQual)
3663 bool target_parallel_safe,
3679 target_parallel_safe,
parse->havingQual);
3728 root->numOrderedAggs == 0 &&
3738 extra.
flags = flags;
3756 &agg_costs, gd, &extra,
3757 &partially_grouped_rel);
3774 PathTarget *target,
bool target_parallel_safe,
3813 grouped_rel->fdwroutine = input_rel->fdwroutine;
3830 return (
root->hasHavingQual ||
parse->groupingSets) &&
3866 while (--nrows >= 0)
3947 root->parse->groupClause))
3962 bool force_rel_creation;
3971 partially_grouped_rel =
3977 force_rel_creation);
3981 *partially_grouped_rel_p = partially_grouped_rel;
3986 partially_grouped_rel, agg_costs,
3992 Assert(partially_grouped_rel);
3994 if (partially_grouped_rel->
pathlist)
4011 cheapest_path->
rows,
4017 partially_grouped_rel, agg_costs, gd,
4023 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4024 errmsg(
"could not implement GROUP BY"),
4025 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4031 if (grouped_rel->fdwroutine &&
4032 grouped_rel->fdwroutine->GetForeignUpperPaths)
4034 input_rel, grouped_rel,
4040 input_rel, grouped_rel,
4085 double exclude_groups = 0.0;
4109 if (l_start != NULL &&
4113 exclude_groups = unhashed_rollup->
numGroups;
4120 dNumGroups - exclude_groups);
4127 if (hashsize > hash_mem_limit && gd->
rollups)
4156 foreach(lc, sets_data)
4165 empty_sets_data =
lappend(empty_sets_data, gs);
4180 new_rollups =
lappend(new_rollups, rollup);
4188 if (new_rollups ==
NIL)
4195 Assert(!unhashed_rollup || !empty_sets);
4197 if (unhashed_rollup)
4199 new_rollups =
lappend(new_rollups, unhashed_rollup);
4202 else if (empty_sets)
4208 rollup->
gsets = empty_sets;
4212 new_rollups =
lappend(new_rollups, rollup);
4245 double availspace = hash_mem_limit;
4261 int *k_weights =
palloc(num_rollups *
sizeof(
int));
4287 scale =
Max(availspace / (20.0 * num_rollups), 1.0);
4288 k_capacity = (int) floor(availspace /
scale);
4312 k_weights[
i] = (int)
Min(floor(sz /
scale),
4342 rollups =
lappend(rollups, rollup);
4346 rollups =
lappend(rollups, rollup);
4351 if (!rollups && hash_sets)
4354 foreach(lc, hash_sets)
4369 rollups =
lcons(rollup, rollups);
4417 bool output_target_parallel_safe,
4419 List *activeWindows)
4442 window_rel->fdwroutine = input_rel->fdwroutine;
4471 if (window_rel->fdwroutine &&
4472 window_rel->fdwroutine->GetForeignUpperPaths)
4474 input_rel, window_rel,
4480 input_rel, window_rel, NULL);
4506 List *activeWindows)
4527 window_target = input_target;
4529 foreach(l, activeWindows)
4532 List *window_pathkeys;
4541 root->processed_tlist);
4574 if (
lnext(activeWindows, l))
4599 window_target = output_target;
4614 foreach(lc3, wfunc->runCondition)
4639 wfuncrc->inputcollid);
4641 runcondition =
lappend(runcondition, opexpr);
4644 topqual =
lappend(topqual, opexpr);
4652 topwindow ? topqual :
NIL, topwindow);
4693 distinct_rel->fdwroutine = input_rel->fdwroutine;
4704 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4705 errmsg(
"could not implement DISTINCT"),
4706 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4712 if (distinct_rel->fdwroutine &&
4713 distinct_rel->fdwroutine->GetForeignUpperPaths)
4714 distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4723 distinct_rel, NULL);
4728 return distinct_rel;
4746 List *distinctExprs;
4747 double numDistinctRows;
4748 Path *cheapest_partial_path;
4758 if (
parse->hasDistinctOn)
4763 partial_distinct_rel->
reltarget = target;
4772 partial_distinct_rel->fdwroutine = input_rel->fdwroutine;
4781 cheapest_partial_path->
rows,
4797 List *useful_pathkeys_list =
NIL;
4799 useful_pathkeys_list =
4801 root->distinct_pathkeys,
4808 partial_distinct_rel,
4810 cheapest_partial_path,
4814 if (sorted_path == NULL)
4822 if (
root->distinct_pathkeys ==
NIL)
4872 partial_distinct_rel,
4873 cheapest_partial_path,
4874 cheapest_partial_path->pathtarget,
4877 root->processed_distinctClause,
4887 if (partial_distinct_rel->fdwroutine &&
4888 partial_distinct_rel->fdwroutine->GetForeignUpperPaths)
4889 partial_distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4892 partial_distinct_rel,
4898 input_rel, partial_distinct_rel, NULL);
4911 final_distinct_rel);
4928 double numDistinctRows;
4933 root->hasHavingQual)
4940 numDistinctRows = cheapest_input_path->
rows;
4947 List *distinctExprs;
4952 cheapest_input_path->
rows,
4977 List *needed_pathkeys;
4979 double limittuples =
root->distinct_pathkeys ==
NIL ? 1.0 : -1.0;
4981 if (
parse->hasDistinctOn &&
4984 needed_pathkeys =
root->sort_pathkeys;
4986 needed_pathkeys =
root->distinct_pathkeys;
4992 List *useful_pathkeys_list =
NIL;
4994 useful_pathkeys_list =
5005 cheapest_input_path,
5009 if (sorted_path == NULL)
5025 if (
root->distinct_pathkeys ==
NIL)
5081 cheapest_input_path,
5082 cheapest_input_path->pathtarget,
5085 root->processed_distinctClause,
5091 return distinct_rel;
5104 List *path_pathkeys)
5106 List *useful_pathkeys_list =
NIL;
5110 useful_pathkeys_list =
lappend(useful_pathkeys_list,
5114 return useful_pathkeys_list;
5133 if (
root->parse->hasDistinctOn &&
5137 useful_pathkeys =
lappend(useful_pathkeys, pathkey);
5141 if (useful_pathkeys ==
NIL)
5142 return useful_pathkeys_list;
5150 return useful_pathkeys_list;
5162 return useful_pathkeys_list;
5164 useful_pathkeys_list =
lappend(useful_pathkeys_list,
5167 return useful_pathkeys_list;
5191 bool target_parallel_safe,
5192 double limit_tuples)
5215 ordered_rel->fdwroutine = input_rel->fdwroutine;
5225 input_path->
pathkeys, &presorted_keys);
5228 sorted_path = input_path;
5238 if (input_path != cheapest_input_path &&
5251 root->sort_pathkeys,
5257 root->sort_pathkeys,
5266 if (!
equal(sorted_path->pathtarget->exprs, target->
exprs))
5268 sorted_path, target);
5270 add_path(ordered_rel, sorted_path);
5287 Path *cheapest_partial_path;
5297 double total_groups;
5313 if (input_path != cheapest_partial_path &&
5326 root->sort_pathkeys,