38 #ifdef OPTIMIZER_DEBUG
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
87 #define EXPRKIND_PHV 8
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,
140 int64 *offset_est, int64 *count_est);
153 bool target_parallel_safe,
160 PathTarget *target,
bool target_parallel_safe,
181 bool output_target_parallel_safe,
183 List *activeWindows);
190 List *activeWindows);
204 bool target_parallel_safe,
205 double limit_tuples);
217 List *activeWindows);
222 bool *have_postponed_srfs);
224 List *targets,
List *targets_contain_srfs);
237 bool force_rel_creation);
242 List *scanjoin_targets,
243 List *scanjoin_targets_contain_srfs,
244 bool scanjoin_target_parallel_safe,
282 result = (*planner_hook) (
parse, query_string, cursorOptions, boundParams);
294 double tuple_fraction;
310 glob->boundParams = boundParams;
313 glob->subroots =
NIL;
353 !
parse->hasModifyingCTE &&
405 if (tuple_fraction >= 1.0)
406 tuple_fraction = 0.0;
407 else if (tuple_fraction <= 0.0)
408 tuple_fraction = 1
e-10;
413 tuple_fraction = 0.0;
454 bool unsafe_initplans;
492 &initplan_cost, &unsafe_initplans);
497 root->glob->parallelModeNeeded =
true;
499 top_plan = &gather->
plan;
590 if (glob->partition_directory != NULL)
631 bool hasRecursion,
double tuple_fraction,
635 List *newWithCheckOptions;
647 root->parent_root = parent_root;
649 root->outer_params = NULL;
656 root->ec_merging_done =
false;
657 root->last_rinfo_serial = 0;
658 root->all_result_relids =
660 root->leaf_result_relids = NULL;
664 memset(
root->upper_rels, 0,
sizeof(
root->upper_rels));
665 memset(
root->upper_targets, 0,
sizeof(
root->upper_targets));
666 root->processed_groupClause =
NIL;
667 root->processed_distinctClause =
NIL;
670 root->grouping_map = NULL;
672 root->qual_security_level = 0;
673 root->hasPseudoConstantQuals =
false;
674 root->hasAlternativeSubPlans =
false;
675 root->placeholdersFrozen =
false;
676 root->hasRecursion = hasRecursion;
680 root->wt_param_id = -1;
681 root->non_recursive_path = NULL;
682 root->partColsUpdated =
false;
715 if (
parse->hasSubLinks)
738 if (
parse->setOperations)
751 root->hasJoinRTEs =
false;
752 root->hasLateralRTEs =
false;
753 root->group_rtindex = 0;
754 hasOuterJoins =
false;
755 hasResultRTEs =
false;
756 foreach(l,
parse->rtable)
780 root->hasJoinRTEs =
true;
782 hasOuterJoins =
true;
785 hasResultRTEs =
true;
797 root->hasLateralRTEs =
true;
805 if (rte->securityQuals)
806 root->qual_security_level =
Max(
root->qual_security_level,
814 if (
parse->resultRelation)
819 root->leaf_result_relids =
834 root->hasHavingQual = (
parse->havingQual != NULL);
846 newWithCheckOptions =
NIL;
847 foreach(l,
parse->withCheckOptions)
853 if (wco->
qual != NULL)
854 newWithCheckOptions =
lappend(newWithCheckOptions, wco);
856 parse->withCheckOptions = newWithCheckOptions;
867 foreach(l,
parse->windowClause)
883 if (
parse->onConflict)
885 parse->onConflict->arbiterElems = (
List *)
887 (
Node *)
parse->onConflict->arbiterElems,
889 parse->onConflict->arbiterWhere =
891 parse->onConflict->arbiterWhere,
893 parse->onConflict->onConflictSet = (
List *)
895 (
Node *)
parse->onConflict->onConflictSet,
897 parse->onConflict->onConflictWhere =
899 parse->onConflict->onConflictWhere,
904 foreach(l,
parse->mergeActionList)
918 parse->mergeJoinCondition =
926 foreach(l,
parse->rtable)
949 if (rte->lateral &&
root->hasJoinRTEs)
978 rte->groupexprs = (
List *)
989 foreach(lcsq, rte->securityQuals)
1008 if (
root->hasJoinRTEs)
1010 foreach(l,
parse->rtable)
1014 rte->joinaliasvars =
NIL;
1027 if (
parse->hasGroupRTE)
1036 if (
parse->hasTargetSRFs)
1085 if ((
parse->groupClause &&
parse->groupingSets) ||
1091 newHaving =
lappend(newHaving, havingclause);
1093 else if (
parse->groupClause && !
parse->groupingSets)
1103 (
List *) whereclause);
1115 (
List *) whereclause);
1117 newHaving =
lappend(newHaving, havingclause);
1136 if (hasResultRTEs || hasOuterJoins)
1195 if (
root->hasJoinRTEs &&
1231 #ifdef OPTIMIZER_DEBUG
1232 printf(
"After canonicalize_qual()\n");
1248 if (
root->parse->hasSubLinks)
1257 if (
root->query_level > 1)
1306 elog(
ERROR,
"unrecognized node type: %d",
1359 int64 offset_est = 0;
1360 int64 count_est = 0;
1361 double limit_tuples = -1.0;
1362 bool have_postponed_srfs =
false;
1364 List *final_targets;
1365 List *final_targets_contain_srfs;
1366 bool final_target_parallel_safe;
1376 &offset_est, &count_est);
1382 if (count_est > 0 && offset_est >= 0)
1383 limit_tuples = (double) count_est + (
double) offset_est;
1387 root->tuple_fraction = tuple_fraction;
1389 if (
parse->setOperations)
1409 root->processed_tlist =
1417 final_target_parallel_safe =
1422 final_targets = final_targets_contain_srfs =
NIL;
1428 if (
parse->rowMarks)
1430 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1433 errmsg(
"%s is not allowed with UNION/INTERSECT/EXCEPT",
1435 parse->rowMarks)->strength))));
1443 root->processed_tlist);
1449 List *sort_input_targets;
1450 List *sort_input_targets_contain_srfs;
1451 bool sort_input_target_parallel_safe;
1453 List *grouping_targets;
1454 List *grouping_targets_contain_srfs;
1455 bool grouping_target_parallel_safe;
1457 List *scanjoin_targets;
1458 List *scanjoin_targets_contain_srfs;
1459 bool scanjoin_target_parallel_safe;
1460 bool scanjoin_target_same_exprs;
1471 if (
parse->groupingSets)
1475 else if (
parse->groupClause)
1511 if (
parse->hasWindowFuncs)
1527 parse->hasWindowFuncs =
false;
1545 if (
parse->groupClause ||
1546 parse->groupingSets ||
1547 parse->distinctClause ||
1549 parse->hasWindowFuncs ||
1550 parse->hasTargetSRFs ||
1551 root->hasHavingQual)
1552 root->limit_tuples = -1.0;
1554 root->limit_tuples = limit_tuples;
1564 qp_extra.
setop = setops;
1585 final_target_parallel_safe =
1593 if (
parse->sortClause)
1597 &have_postponed_srfs);
1598 sort_input_target_parallel_safe =
1603 sort_input_target = final_target;
1604 sort_input_target_parallel_safe = final_target_parallel_safe;
1617 grouping_target_parallel_safe =
1622 grouping_target = sort_input_target;
1623 grouping_target_parallel_safe = sort_input_target_parallel_safe;
1631 have_grouping = (
parse->groupClause ||
parse->groupingSets ||
1636 scanjoin_target_parallel_safe =
1641 scanjoin_target = grouping_target;
1642 scanjoin_target_parallel_safe = grouping_target_parallel_safe;
1651 if (
parse->hasTargetSRFs)
1656 &final_targets_contain_srfs);
1661 &sort_input_targets,
1662 &sort_input_targets_contain_srfs);
1668 &grouping_targets_contain_srfs);
1674 &scanjoin_targets_contain_srfs);
1681 final_targets = final_targets_contain_srfs =
NIL;
1682 sort_input_targets = sort_input_targets_contain_srfs =
NIL;
1683 grouping_targets = grouping_targets_contain_srfs =
NIL;
1684 scanjoin_targets =
list_make1(scanjoin_target);
1685 scanjoin_targets_contain_srfs =
NIL;
1689 scanjoin_target_same_exprs =
list_length(scanjoin_targets) == 1
1692 scanjoin_targets_contain_srfs,
1693 scanjoin_target_parallel_safe,
1694 scanjoin_target_same_exprs);
1720 grouping_target_parallel_safe,
1723 if (
parse->hasTargetSRFs)
1726 grouping_targets_contain_srfs);
1739 sort_input_target_parallel_safe,
1743 if (
parse->hasTargetSRFs)
1746 sort_input_targets_contain_srfs);
1753 if (
parse->distinctClause)
1768 if (
parse->sortClause)
1773 final_target_parallel_safe,
1774 have_postponed_srfs ? -1.0 :
1777 if (
parse->hasTargetSRFs)
1780 final_targets_contain_srfs);
1806 final_rel->fdwroutine = current_rel->fdwroutine;
1823 if (
parse->rowMarks)
1839 offset_est, count_est);
1849 List *updateColnosLists =
NIL;
1850 List *withCheckOptionLists =
NIL;
1853 List *mergeJoinConditions =
NIL;
1860 parse->resultRelation);
1861 int resultRelation = -1;
1864 rootRelation =
parse->resultRelation;
1868 resultRelation)) >= 0)
1886 List *update_colnos =
root->update_colnos;
1888 if (this_result_rel != top_result_rel)
1892 this_result_rel->
relid,
1893 top_result_rel->
relid);
1894 updateColnosLists =
lappend(updateColnosLists,
1897 if (
parse->withCheckOptions)
1899 List *withCheckOptions =
parse->withCheckOptions;
1901 if (this_result_rel != top_result_rel)
1902 withCheckOptions = (
List *)
1904 (
Node *) withCheckOptions,
1907 withCheckOptionLists =
lappend(withCheckOptionLists,
1910 if (
parse->returningList)
1912 List *returningList =
parse->returningList;
1914 if (this_result_rel != top_result_rel)
1915 returningList = (
List *)
1917 (
Node *) returningList,
1920 returningLists =
lappend(returningLists,
1923 if (
parse->mergeActionList)
1932 foreach(l,
parse->mergeActionList)
1942 leaf_action->targetList = (
List *)
1948 leaf_action->updateColnos =
1951 this_result_rel->
relid,
1952 top_result_rel->
relid);
1953 mergeActionList =
lappend(mergeActionList,
1957 mergeActionLists =
lappend(mergeActionLists,
1962 Node *mergeJoinCondition =
parse->mergeJoinCondition;
1964 if (this_result_rel != top_result_rel)
1965 mergeJoinCondition =
1970 mergeJoinConditions =
lappend(mergeJoinConditions,
1971 mergeJoinCondition);
1975 if (resultRelations ==
NIL)
1991 if (
parse->withCheckOptions)
1993 if (
parse->returningList)
1995 if (
parse->mergeActionList)
2008 if (
parse->withCheckOptions)
2010 if (
parse->returningList)
2012 if (
parse->mergeActionList)
2023 if (
parse->rowMarks)
2026 rowMarks =
root->rowMarks;
2033 parse->resultRelation,
2035 root->partColsUpdated,
2038 withCheckOptionLists,
2043 mergeJoinConditions,
2076 if (final_rel->fdwroutine &&
2077 final_rel->fdwroutine->GetForeignUpperPaths)
2079 current_rel, final_rel,
2085 current_rel, final_rel, &extra);
2116 root->processed_groupClause =
parse->groupClause;
2118 if (
parse->groupClause)
2122 foreach(lc,
parse->groupClause)
2152 foreach(lc,
parse->groupingSets)
2173 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2174 errmsg(
"could not implement GROUP BY"),
2175 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
2178 sortable_sets =
lappend(sortable_sets, gset);
2189 foreach(lc_set, sets)
2280 int *tleref_to_colnum_map)
2286 foreach(lc, groupClause)
2299 foreach(lc2, gs->
set)
2304 result =
lappend(result, set);
2323 if (
parse->rowMarks)
2332 parse->rowMarks)->strength);
2352 if (
parse->resultRelation)
2359 foreach(l,
parse->rowMarks)
2392 prowmarks =
lappend(prowmarks, newrc);
2399 foreach(l,
parse->rtable)
2417 prowmarks =
lappend(prowmarks, newrc);
2420 root->rowMarks = prowmarks;
2434 else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2470 elog(
ERROR,
"unrecognized LockClauseStrength %d", (
int) strength);
2494 int64 *offset_est, int64 *count_est)
2498 double limit_fraction;
2507 if (
parse->limitCount)
2512 if (((
Const *) est)->constisnull)
2520 if (*count_est <= 0)
2530 if (
parse->limitOffset)
2535 if (((
Const *) est)->constisnull)
2543 if (*offset_est < 0)
2553 if (*count_est != 0)
2560 if (*count_est < 0 || *offset_est < 0)
2563 limit_fraction = 0.10;
2568 limit_fraction = (double) *count_est + (
double) *offset_est;
2578 if (tuple_fraction >= 1.0)
2580 if (limit_fraction >= 1.0)
2583 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2590 else if (tuple_fraction > 0.0)
2592 if (limit_fraction >= 1.0)
2595 tuple_fraction = limit_fraction;
2600 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2606 tuple_fraction = limit_fraction;
2609 else if (*offset_est != 0 && tuple_fraction > 0.0)
2620 if (*offset_est < 0)
2621 limit_fraction = 0.10;
2623 limit_fraction = (double) *offset_est;
2631 if (tuple_fraction >= 1.0)
2633 if (limit_fraction >= 1.0)
2636 tuple_fraction += limit_fraction;
2641 tuple_fraction = limit_fraction;
2646 if (limit_fraction >= 1.0)
2653 tuple_fraction += limit_fraction;
2654 if (tuple_fraction >= 1.0)
2655 tuple_fraction = 0.0;
2660 return tuple_fraction;
2682 node =
parse->limitCount;
2688 if (!((
Const *) node)->constisnull)
2695 node =
parse->limitOffset;
2701 if (!((
Const *) node)->constisnull)
2750 if (
parse->groupingSets)
2760 foreach(lc,
root->processed_groupClause)
2793 foreach(lc,
parse->rtable)
2811 if (rte->
inh && rte->relkind != RELKIND_PARTITIONED_TABLE)
2815 relattnos = groupbyattnos[relid];
2824 if (pkattnos == NULL)
2837 if (surplusvars == NULL)
2851 if (surplusvars != NULL)
2855 foreach(lc,
root->processed_groupClause)
2868 surplusvars[var->
varno]))
2869 new_groupby =
lappend(new_groupby, sgc);
2872 root->processed_groupClause = new_groupby;
2919 new_groupclause =
lappend(new_groupclause, cl);
2922 return new_groupclause;
2935 foreach(sl,
parse->sortClause)
2939 foreach(gl,
parse->groupClause)
2945 new_groupclause =
lappend(new_groupclause, gc);
2955 if (new_groupclause ==
NIL)
2964 foreach(gl,
parse->groupClause)
2972 new_groupclause =
lappend(new_groupclause, gc);
2977 return new_groupclause;
3012 short *adjacency_buf;
3028 lc1 =
lnext(groupingSets, lc1);
3053 orig_sets =
palloc0((num_sets_raw + 1) *
sizeof(
List *));
3055 adjacency =
palloc0((num_sets_raw + 1) *
sizeof(
short *));
3056 adjacency_buf =
palloc((num_sets_raw + 1) *
sizeof(
short));
3069 foreach(lc2, candidate)
3079 for (k =
j; k <
i; ++k)
3081 if (
bms_equal(set_masks[k], candidate_set))
3096 orig_sets[dup_of] =
lappend(orig_sets[dup_of], candidate);
3105 set_masks[
i] = candidate_set;
3109 for (k =
j - 1; k > 0; --k)
3112 adjacency_buf[++n_adj] = k;
3117 adjacency_buf[0] = n_adj;
3118 adjacency[
i] =
palloc((n_adj + 1) *
sizeof(
short));
3119 memcpy(adjacency[
i], adjacency_buf, (n_adj + 1) *
sizeof(
short));
3122 adjacency[
i] = NULL;
3141 chains =
palloc0((num_sets + 1) *
sizeof(
int));
3143 for (
i = 1;
i <= num_sets; ++
i)
3145 int u =
state->pair_vu[
i];
3146 int v =
state->pair_uv[
i];
3149 chains[
i] = chains[u];
3150 else if (v > 0 && v <
i)
3151 chains[
i] = chains[v];
3153 chains[
i] = ++num_chains;
3157 results =
palloc0((num_chains + 1) *
sizeof(
List *));
3159 for (
i = 1;
i <= num_sets; ++
i)
3169 while (num_empty-- > 0)
3170 results[1] =
lcons(
NIL, results[1]);
3173 for (
i = 1;
i <= num_chains; ++
i)
3174 result =
lappend(result, results[
i]);
3185 for (
i = 1;
i <= num_sets; ++
i)
3189 pfree(adjacency_buf);
3191 for (
i = 1;
i <= num_sets; ++
i)
3218 foreach(lc, groupingSets)
3246 result =
lcons(gs, result);
3268 if (pathkey->pk_eclass->ec_has_volatile)
3307 List *grouppathkeys =
root->group_pathkeys;
3327 unprocessed_aggs = NULL;
3328 foreach(lc,
root->agginfos)
3333 if (AGGKIND_IS_ORDERED_SET(aggref->aggkind))
3394 if (currpathkeys ==
NIL)
3396 currpathkeys = pathkeys;
3399 if (grouppathkeys !=
NIL)
3411 if (grouppathkeys !=
NIL)
3420 currpathkeys = pathkeys;
3447 bestaggs = aggindexes;
3448 bestpathkeys = currpathkeys;
3457 if (bestpathkeys !=
NIL)
3458 root->group_pathkeys = bestpathkeys;
3477 aggref->aggpresorted =
true;
3490 List *tlist =
root->processed_tlist;
3518 root->group_pathkeys =
3532 root->num_groupby_pathkeys = 0;
3535 else if (
parse->groupClause ||
root->numOrderedAggs > 0)
3551 root->group_pathkeys =
3553 &
root->processed_groupClause,
3563 root->num_groupby_pathkeys = 0;
3569 if (
root->numOrderedAggs > 0)
3576 root->num_groupby_pathkeys = 0;
3580 if (activeWindows !=
NIL)
3597 if (
parse->distinctClause)
3603 root->distinct_pathkeys =
3605 &
root->processed_distinctClause,
3612 root->distinct_pathkeys =
NIL;
3615 root->distinct_pathkeys =
NIL;
3617 root->sort_pathkeys =
3623 if (qp_extra->
setop != NULL &&
3631 root->setop_pathkeys =
3665 if (
root->group_pathkeys)
3666 root->query_pathkeys =
root->group_pathkeys;
3667 else if (
root->window_pathkeys)
3668 root->query_pathkeys =
root->window_pathkeys;
3671 root->query_pathkeys =
root->distinct_pathkeys;
3672 else if (
root->sort_pathkeys)
3673 root->query_pathkeys =
root->sort_pathkeys;
3674 else if (
root->setop_pathkeys !=
NIL)
3675 root->query_pathkeys =
root->setop_pathkeys;
3700 if (
parse->groupClause)
3704 if (
parse->groupingSets)
3777 else if (
parse->groupingSets)
3782 else if (
parse->hasAggs ||
root->hasHavingQual)
3817 bool target_parallel_safe,
3833 target_parallel_safe,
parse->havingQual);
3882 root->numOrderedAggs == 0 &&
3892 extra.
flags = flags;
3910 &agg_costs, gd, &extra,
3911 &partially_grouped_rel);
3928 PathTarget *target,
bool target_parallel_safe,
3967 grouped_rel->fdwroutine = input_rel->fdwroutine;
3984 return (
root->hasHavingQual ||
parse->groupingSets) &&
4020 while (--nrows >= 0)
4100 root->parse->groupClause))
4115 bool force_rel_creation;
4124 partially_grouped_rel =
4130 force_rel_creation);
4134 *partially_grouped_rel_p = partially_grouped_rel;
4139 partially_grouped_rel, agg_costs,
4145 Assert(partially_grouped_rel);
4147 if (partially_grouped_rel->
pathlist)
4164 cheapest_path->
rows,
4170 partially_grouped_rel, agg_costs, gd,
4176 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4177 errmsg(
"could not implement GROUP BY"),
4178 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4184 if (grouped_rel->fdwroutine &&
4185 grouped_rel->fdwroutine->GetForeignUpperPaths)
4187 input_rel, grouped_rel,
4193 input_rel, grouped_rel,
4238 double exclude_groups = 0.0;
4262 if (l_start != NULL &&
4266 exclude_groups = unhashed_rollup->
numGroups;
4273 dNumGroups - exclude_groups);
4280 if (hashsize > hash_mem_limit && gd->
rollups)
4309 foreach(lc, sets_data)
4318 empty_sets_data =
lappend(empty_sets_data, gs);
4333 new_rollups =
lappend(new_rollups, rollup);
4341 if (new_rollups ==
NIL)
4348 Assert(!unhashed_rollup || !empty_sets);
4350 if (unhashed_rollup)
4352 new_rollups =
lappend(new_rollups, unhashed_rollup);
4355 else if (empty_sets)
4361 rollup->
gsets = empty_sets;
4365 new_rollups =
lappend(new_rollups, rollup);
4398 double availspace = hash_mem_limit;
4414 int *k_weights =
palloc(num_rollups *
sizeof(
int));
4440 scale =
Max(availspace / (20.0 * num_rollups), 1.0);
4441 k_capacity = (int) floor(availspace /
scale);
4465 k_weights[
i] = (int)
Min(floor(sz /
scale),
4495 rollups =
lappend(rollups, rollup);
4499 rollups =
lappend(rollups, rollup);
4504 if (!rollups && hash_sets)
4507 foreach(lc, hash_sets)
4522 rollups =
lcons(rollup, rollups);
4570 bool output_target_parallel_safe,
4572 List *activeWindows)
4595 window_rel->fdwroutine = input_rel->fdwroutine;
4624 if (window_rel->fdwroutine &&
4625 window_rel->fdwroutine->GetForeignUpperPaths)
4627 input_rel, window_rel,
4633 input_rel, window_rel, NULL);
4659 List *activeWindows)
4680 window_target = input_target;
4682 foreach(l, activeWindows)
4685 List *window_pathkeys;
4694 root->processed_tlist);
4727 if (
lnext(activeWindows, l))
4737 int64 tuple_width = window_target->
width;
4752 window_target = output_target;
4767 foreach(lc3, wfunc->runCondition)
4792 wfuncrc->inputcollid);
4794 runcondition =
lappend(runcondition, opexpr);
4797 topqual =
lappend(topqual, opexpr);
4805 topwindow ? topqual :
NIL, topwindow);
4846 distinct_rel->fdwroutine = input_rel->fdwroutine;
4857 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4858 errmsg(
"could not implement DISTINCT"),
4859 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4865 if (distinct_rel->fdwroutine &&
4866 distinct_rel->fdwroutine->GetForeignUpperPaths)
4867 distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4876 distinct_rel, NULL);
4881 return distinct_rel;
4899 List *distinctExprs;
4900 double numDistinctRows;
4901 Path *cheapest_partial_path;
4911 if (
parse->hasDistinctOn)
4916 partial_distinct_rel->
reltarget = target;
4925 partial_distinct_rel->fdwroutine = input_rel->fdwroutine;
4934 cheapest_partial_path->
rows,
4955 sorted_path = input_path;
4965 if (input_path != cheapest_partial_path &&
4976 partial_distinct_rel,
4978 root->distinct_pathkeys,
4982 partial_distinct_rel,
4984 root->distinct_pathkeys,
4993 if (
root->distinct_pathkeys ==
NIL)
5041 partial_distinct_rel,
5042 cheapest_partial_path,
5043 cheapest_partial_path->pathtarget,
5046 root->processed_distinctClause,
5056 if (partial_distinct_rel->fdwroutine &&
5057 partial_distinct_rel->fdwroutine->GetForeignUpperPaths)
5058 partial_distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
5061 partial_distinct_rel,
5067 input_rel, partial_distinct_rel, NULL);
5080 final_distinct_rel);
5097 double numDistinctRows;
5102 root->hasHavingQual)
5109 numDistinctRows = cheapest_input_path->
rows;
5116 List *distinctExprs;
5121 cheapest_input_path->
rows,
5144 List *needed_pathkeys;
5146 double limittuples =
root->distinct_pathkeys ==
NIL ? 1.0 : -1.0;
5148 if (
parse->hasDistinctOn &&
5151 needed_pathkeys =
root->sort_pathkeys;
5153 needed_pathkeys =
root->distinct_pathkeys;
5167 sorted_path = input_path;
5177 if (input_path != cheapest_input_path &&
5213 if (
root->distinct_pathkeys ==
NIL)
5268 cheapest_input_path,
5269 cheapest_input_path->pathtarget,
5272 root->processed_distinctClause,
5278 return distinct_rel;
5302 bool target_parallel_safe,
5303 double limit_tuples)
5326 ordered_rel->fdwroutine = input_rel->fdwroutine;
5336 input_path->
pathkeys, &presorted_keys);
5339 sorted_path = input_path;
5349 if (input_path != cheapest_input_path &&
5362 root->sort_pathkeys,
5368 root->sort_pathkeys,
5377 if (!
equal(sorted_path->pathtarget->exprs, target->
exprs))
5379 sorted_path, target);
5381 add_path(ordered_rel, sorted_path);
5398 Path *cheapest_partial_path;
5408 double total_groups;
5424 if (input_path != cheapest_partial_path &&
5437 root->sort_pathkeys,
5443 root->sort_pathkeys,
5447 sorted_path = (
Path *)
5450 sorted_path->pathtarget,
5451 root->sort_pathkeys, NULL,
5458 if (!
equal(sorted_path->pathtarget->exprs, target->
exprs))
5460 sorted_path, target);
5462 add_path(ordered_rel, sorted_path);
5470 if (ordered_rel->fdwroutine &&
5471 ordered_rel->fdwroutine->GetForeignUpperPaths)
5473 input_rel, ordered_rel,
5479 input_rel, ordered_rel, NULL);
5523 List *non_group_cols;
5524 List *non_group_vars;
5533 non_group_cols =
NIL;
5536 foreach(lc, final_target->
exprs)
5541 if (sgref &&
root->processed_groupClause &&
5543 root->processed_groupClause) != NULL)
5568 non_group_cols =
lappend(non_group_cols, expr);
5577 if (
parse->havingQual)
5578 non_group_cols =
lappend(non_group_cols,
parse->havingQual);
5599 non_group_vars = (
List *)
5636 List *non_group_cols;
5637 List *non_group_exprs;
5642 non_group_cols =
NIL;
5645 foreach(lc, grouping_target->
exprs)
5650 if (sgref &&
root->processed_groupClause &&
5652 root->processed_groupClause) != NULL)
5666 non_group_cols =
lappend(non_group_cols, expr);
5676 non_group_cols =
lappend(non_group_cols, havingQual);
5697 foreach(lc, partial_target->
exprs)
5710 memcpy(newaggref, aggref,
sizeof(
Aggref));