81#define EXPRKIND_QUAL 0
82#define EXPRKIND_TARGET 1
83#define EXPRKIND_RTFUNC 2
84#define EXPRKIND_RTFUNC_LATERAL 3
85#define EXPRKIND_VALUES 4
86#define EXPRKIND_VALUES_LATERAL 5
87#define EXPRKIND_LIMIT 6
88#define EXPRKIND_APPINFO 7
90#define EXPRKIND_TABLESAMPLE 9
91#define EXPRKIND_ARBITER_ELEM 10
92#define EXPRKIND_TABLEFUNC 11
93#define EXPRKIND_TABLEFUNC_LATERAL 12
94#define EXPRKIND_GROUPEXPR 13
138 int *tleref_to_colnum_map);
141 double tuple_fraction,
154 bool target_parallel_safe,
161 PathTarget *target,
bool target_parallel_safe,
182 bool output_target_parallel_safe,
184 List *activeWindows);
191 List *activeWindows);
203 List *needed_pathkeys,
204 List *path_pathkeys);
208 bool target_parallel_safe,
209 double limit_tuples);
222 List *activeWindows);
227 bool *have_postponed_srfs);
229 List *targets,
List *targets_contain_srfs);
242 bool force_rel_creation);
248 double limit_tuples);
253 List *scanjoin_targets,
254 List *scanjoin_targets_contain_srfs,
255 bool scanjoin_target_parallel_safe,
272 List *sortPathkeys,
List *groupClause,
275 List *sortPathkeys,
List *groupClause,
299 result = (*planner_hook) (
parse, query_string, cursorOptions, boundParams);
314 double tuple_fraction;
330 glob->boundParams = boundParams;
333 glob->subroots =
NIL;
351 glob->partition_directory = NULL;
352 glob->rel_notnullatts_hash = NULL;
378 !
parse->hasModifyingCTE &&
430 if (tuple_fraction >= 1.0)
431 tuple_fraction = 0.0;
432 else if (tuple_fraction <= 0.0)
433 tuple_fraction = 1
e-10;
438 tuple_fraction = 0.0;
479 bool unsafe_initplans;
517 &initplan_cost, &unsafe_initplans);
522 root->glob->parallelModeNeeded =
true;
524 top_plan = &gather->
plan;
619 if (glob->partition_directory != NULL)
660 bool hasRecursion,
double tuple_fraction,
664 List *newWithCheckOptions;
676 root->parent_root = parent_root;
678 root->outer_params = NULL;
685 root->ec_merging_done =
false;
686 root->last_rinfo_serial = 0;
687 root->all_result_relids =
689 root->leaf_result_relids = NULL;
693 memset(
root->upper_rels, 0,
sizeof(
root->upper_rels));
694 memset(
root->upper_targets, 0,
sizeof(
root->upper_targets));
695 root->processed_groupClause =
NIL;
696 root->processed_distinctClause =
NIL;
699 root->grouping_map = NULL;
701 root->qual_security_level = 0;
702 root->hasPseudoConstantQuals =
false;
703 root->hasAlternativeSubPlans =
false;
704 root->placeholdersFrozen =
false;
705 root->hasRecursion = hasRecursion;
709 root->wt_param_id = -1;
710 root->non_recursive_path = NULL;
711 root->partColsUpdated =
false;
756 if (
parse->hasSubLinks)
779 if (
parse->setOperations)
792 root->hasJoinRTEs =
false;
793 root->hasLateralRTEs =
false;
794 root->group_rtindex = 0;
795 hasOuterJoins =
false;
796 hasResultRTEs =
false;
797 foreach(l,
parse->rtable)
804 root->hasJoinRTEs =
true;
806 hasOuterJoins =
true;
809 hasResultRTEs =
true;
821 root->hasLateralRTEs =
true;
829 if (rte->securityQuals)
830 root->qual_security_level =
Max(
root->qual_security_level,
838 if (
parse->resultRelation)
843 root->leaf_result_relids =
861 foreach(l,
parse->rtable)
865 if (rte->perminfoindex != 0 &&
866 rte->relkind == RELKIND_VIEW)
890 root->hasHavingQual = (
parse->havingQual != NULL);
902 newWithCheckOptions =
NIL;
903 foreach(l,
parse->withCheckOptions)
909 if (wco->
qual != NULL)
910 newWithCheckOptions =
lappend(newWithCheckOptions, wco);
912 parse->withCheckOptions = newWithCheckOptions;
923 foreach(l,
parse->windowClause)
939 if (
parse->onConflict)
941 parse->onConflict->arbiterElems = (
List *)
943 (
Node *)
parse->onConflict->arbiterElems,
945 parse->onConflict->arbiterWhere =
947 parse->onConflict->arbiterWhere,
949 parse->onConflict->onConflictSet = (
List *)
951 (
Node *)
parse->onConflict->onConflictSet,
953 parse->onConflict->onConflictWhere =
955 parse->onConflict->onConflictWhere,
960 foreach(l,
parse->mergeActionList)
974 parse->mergeJoinCondition =
982 foreach(l,
parse->rtable)
1005 if (rte->lateral &&
root->hasJoinRTEs)
1034 rte->groupexprs = (
List *)
1045 foreach(lcsq, rte->securityQuals)
1064 if (
root->hasJoinRTEs)
1066 foreach(l,
parse->rtable)
1070 rte->joinaliasvars =
NIL;
1083 if (
parse->hasGroupRTE)
1092 if (
parse->hasTargetSRFs)
1144 (
parse->groupClause &&
parse->groupingSets &&
1148 newHaving =
lappend(newHaving, havingclause);
1150 else if (
parse->groupClause)
1160 (
List *) whereclause);
1172 (
List *) whereclause);
1174 newHaving =
lappend(newHaving, havingclause);
1193 if (hasResultRTEs || hasOuterJoins)
1252 if (
root->hasJoinRTEs &&
1288#ifdef OPTIMIZER_DEBUG
1289 printf(
"After canonicalize_qual()\n");
1305 if (
root->parse->hasSubLinks)
1314 if (
root->query_level > 1)
1363 elog(
ERROR,
"unrecognized node type: %d",
1416 int64 offset_est = 0;
1417 int64 count_est = 0;
1418 double limit_tuples = -1.0;
1419 bool have_postponed_srfs =
false;
1421 List *final_targets;
1422 List *final_targets_contain_srfs;
1423 bool final_target_parallel_safe;
1433 &offset_est, &count_est);
1439 if (count_est > 0 && offset_est >= 0)
1440 limit_tuples = (double) count_est + (
double) offset_est;
1444 root->tuple_fraction = tuple_fraction;
1446 if (
parse->setOperations)
1466 root->processed_tlist =
1474 final_target_parallel_safe =
1479 final_targets = final_targets_contain_srfs =
NIL;
1485 if (
parse->rowMarks)
1487 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1490 errmsg(
"%s is not allowed with UNION/INTERSECT/EXCEPT",
1492 parse->rowMarks)->strength))));
1500 root->processed_tlist);
1506 List *sort_input_targets;
1507 List *sort_input_targets_contain_srfs;
1508 bool sort_input_target_parallel_safe;
1510 List *grouping_targets;
1511 List *grouping_targets_contain_srfs;
1512 bool grouping_target_parallel_safe;
1514 List *scanjoin_targets;
1515 List *scanjoin_targets_contain_srfs;
1516 bool scanjoin_target_parallel_safe;
1517 bool scanjoin_target_same_exprs;
1528 if (
parse->groupingSets)
1532 else if (
parse->groupClause)
1566 if (
parse->hasWindowFuncs)
1586 parse->hasWindowFuncs =
false;
1604 if (
parse->groupClause ||
1605 parse->groupingSets ||
1606 parse->distinctClause ||
1608 parse->hasWindowFuncs ||
1609 parse->hasTargetSRFs ||
1610 root->hasHavingQual)
1611 root->limit_tuples = -1.0;
1613 root->limit_tuples = limit_tuples;
1623 qp_extra.
setop = setops;
1644 final_target_parallel_safe =
1652 if (
parse->sortClause)
1656 &have_postponed_srfs);
1657 sort_input_target_parallel_safe =
1662 sort_input_target = final_target;
1663 sort_input_target_parallel_safe = final_target_parallel_safe;
1676 grouping_target_parallel_safe =
1681 grouping_target = sort_input_target;
1682 grouping_target_parallel_safe = sort_input_target_parallel_safe;
1690 have_grouping = (
parse->groupClause ||
parse->groupingSets ||
1695 scanjoin_target_parallel_safe =
1700 scanjoin_target = grouping_target;
1701 scanjoin_target_parallel_safe = grouping_target_parallel_safe;
1710 if (
parse->hasTargetSRFs)
1715 &final_targets_contain_srfs);
1720 &sort_input_targets,
1721 &sort_input_targets_contain_srfs);
1727 &grouping_targets_contain_srfs);
1733 &scanjoin_targets_contain_srfs);
1740 final_targets = final_targets_contain_srfs =
NIL;
1741 sort_input_targets = sort_input_targets_contain_srfs =
NIL;
1742 grouping_targets = grouping_targets_contain_srfs =
NIL;
1743 scanjoin_targets =
list_make1(scanjoin_target);
1744 scanjoin_targets_contain_srfs =
NIL;
1748 scanjoin_target_same_exprs =
list_length(scanjoin_targets) == 1
1751 scanjoin_targets_contain_srfs,
1752 scanjoin_target_parallel_safe,
1753 scanjoin_target_same_exprs);
1779 grouping_target_parallel_safe,
1782 if (
parse->hasTargetSRFs)
1785 grouping_targets_contain_srfs);
1798 sort_input_target_parallel_safe,
1802 if (
parse->hasTargetSRFs)
1805 sort_input_targets_contain_srfs);
1812 if (
parse->distinctClause)
1827 if (
parse->sortClause)
1832 final_target_parallel_safe,
1833 have_postponed_srfs ? -1.0 :
1836 if (
parse->hasTargetSRFs)
1839 final_targets_contain_srfs);
1865 final_rel->fdwroutine = current_rel->fdwroutine;
1882 if (
parse->rowMarks)
1898 offset_est, count_est);
1908 List *updateColnosLists =
NIL;
1909 List *withCheckOptionLists =
NIL;
1912 List *mergeJoinConditions =
NIL;
1919 parse->resultRelation);
1920 int resultRelation = -1;
1923 rootRelation =
parse->resultRelation;
1927 resultRelation)) >= 0)
1945 List *update_colnos =
root->update_colnos;
1947 if (this_result_rel != top_result_rel)
1951 this_result_rel->
relid,
1952 top_result_rel->
relid);
1953 updateColnosLists =
lappend(updateColnosLists,
1956 if (
parse->withCheckOptions)
1958 List *withCheckOptions =
parse->withCheckOptions;
1960 if (this_result_rel != top_result_rel)
1961 withCheckOptions = (
List *)
1963 (
Node *) withCheckOptions,
1966 withCheckOptionLists =
lappend(withCheckOptionLists,
1969 if (
parse->returningList)
1971 List *returningList =
parse->returningList;
1973 if (this_result_rel != top_result_rel)
1974 returningList = (
List *)
1976 (
Node *) returningList,
1979 returningLists =
lappend(returningLists,
1982 if (
parse->mergeActionList)
1991 foreach(l,
parse->mergeActionList)
2001 leaf_action->targetList = (
List *)
2007 leaf_action->updateColnos =
2010 this_result_rel->
relid,
2011 top_result_rel->
relid);
2012 mergeActionList =
lappend(mergeActionList,
2016 mergeActionLists =
lappend(mergeActionLists,
2021 Node *mergeJoinCondition =
parse->mergeJoinCondition;
2023 if (this_result_rel != top_result_rel)
2024 mergeJoinCondition =
2029 mergeJoinConditions =
lappend(mergeJoinConditions,
2030 mergeJoinCondition);
2034 if (resultRelations ==
NIL)
2050 if (
parse->withCheckOptions)
2052 if (
parse->returningList)
2054 if (
parse->mergeActionList)
2067 if (
parse->withCheckOptions)
2069 if (
parse->returningList)
2071 if (
parse->mergeActionList)
2082 if (
parse->rowMarks)
2085 rowMarks =
root->rowMarks;
2092 parse->resultRelation,
2094 root->partColsUpdated,
2097 withCheckOptionLists,
2102 mergeJoinConditions,
2135 if (final_rel->fdwroutine &&
2136 final_rel->fdwroutine->GetForeignUpperPaths)
2138 current_rel, final_rel,
2144 current_rel, final_rel, &extra);
2175 root->processed_groupClause =
parse->groupClause;
2177 if (
parse->groupClause)
2181 foreach(lc,
parse->groupClause)
2211 foreach(lc,
parse->groupingSets)
2232 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2233 errmsg(
"could not implement GROUP BY"),
2234 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
2237 sortable_sets =
lappend(sortable_sets, gset);
2248 foreach(lc_set, sets)
2339 int *tleref_to_colnum_map)
2345 foreach(lc, groupClause)
2358 foreach(lc2, gs->
set)
2363 result =
lappend(result, set);
2382 if (
parse->rowMarks)
2391 parse->rowMarks)->strength);
2411 if (
parse->resultRelation)
2418 foreach(l,
parse->rowMarks)
2451 prowmarks =
lappend(prowmarks, newrc);
2458 foreach(l,
parse->rtable)
2476 prowmarks =
lappend(prowmarks, newrc);
2479 root->rowMarks = prowmarks;
2493 else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2529 elog(
ERROR,
"unrecognized LockClauseStrength %d", (
int) strength);
2557 double limit_fraction;
2566 if (
parse->limitCount)
2571 if (((
Const *) est)->constisnull)
2579 if (*count_est <= 0)
2589 if (
parse->limitOffset)
2594 if (((
Const *) est)->constisnull)
2602 if (*offset_est < 0)
2612 if (*count_est != 0)
2619 if (*count_est < 0 || *offset_est < 0)
2622 limit_fraction = 0.10;
2627 limit_fraction = (double) *count_est + (
double) *offset_est;
2637 if (tuple_fraction >= 1.0)
2639 if (limit_fraction >= 1.0)
2642 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2649 else if (tuple_fraction > 0.0)
2651 if (limit_fraction >= 1.0)
2654 tuple_fraction = limit_fraction;
2659 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2665 tuple_fraction = limit_fraction;
2668 else if (*offset_est != 0 && tuple_fraction > 0.0)
2679 if (*offset_est < 0)
2680 limit_fraction = 0.10;
2682 limit_fraction = (double) *offset_est;
2690 if (tuple_fraction >= 1.0)
2692 if (limit_fraction >= 1.0)
2695 tuple_fraction += limit_fraction;
2700 tuple_fraction = limit_fraction;
2705 if (limit_fraction >= 1.0)
2712 tuple_fraction += limit_fraction;
2713 if (tuple_fraction >= 1.0)
2714 tuple_fraction = 0.0;
2719 return tuple_fraction;
2741 node =
parse->limitCount;
2747 if (!((
Const *) node)->constisnull)
2754 node =
parse->limitOffset;
2760 if (!((
Const *) node)->constisnull)
2818 new_groupclause =
lappend(new_groupclause, cl);
2821 return new_groupclause;
2834 foreach(sl,
parse->sortClause)
2838 foreach(gl,
parse->groupClause)
2844 new_groupclause =
lappend(new_groupclause, gc);
2854 if (new_groupclause ==
NIL)
2863 foreach(gl,
parse->groupClause)
2871 new_groupclause =
lappend(new_groupclause, gc);
2876 return new_groupclause;
2911 short *adjacency_buf;
2927 lc1 =
lnext(groupingSets, lc1);
2952 orig_sets =
palloc0((num_sets_raw + 1) *
sizeof(
List *));
2954 adjacency =
palloc0((num_sets_raw + 1) *
sizeof(
short *));
2955 adjacency_buf =
palloc((num_sets_raw + 1) *
sizeof(
short));
2968 foreach(lc2, candidate)
2978 for (k =
j; k <
i; ++k)
2980 if (
bms_equal(set_masks[k], candidate_set))
2995 orig_sets[dup_of] =
lappend(orig_sets[dup_of], candidate);
3004 set_masks[
i] = candidate_set;
3008 for (k =
j - 1; k > 0; --k)
3011 adjacency_buf[++n_adj] = k;
3016 adjacency_buf[0] = n_adj;
3017 adjacency[
i] =
palloc((n_adj + 1) *
sizeof(
short));
3018 memcpy(adjacency[
i], adjacency_buf, (n_adj + 1) *
sizeof(
short));
3021 adjacency[
i] = NULL;
3040 chains =
palloc0((num_sets + 1) *
sizeof(
int));
3042 for (
i = 1;
i <= num_sets; ++
i)
3044 int u =
state->pair_vu[
i];
3045 int v =
state->pair_uv[
i];
3048 chains[
i] = chains[u];
3049 else if (v > 0 && v <
i)
3050 chains[
i] = chains[v];
3052 chains[
i] = ++num_chains;
3056 results =
palloc0((num_chains + 1) *
sizeof(
List *));
3058 for (
i = 1;
i <= num_sets; ++
i)
3068 while (num_empty-- > 0)
3069 results[1] =
lcons(
NIL, results[1]);
3072 for (
i = 1;
i <= num_chains; ++
i)
3073 result =
lappend(result, results[
i]);
3084 for (
i = 1;
i <= num_sets; ++
i)
3088 pfree(adjacency_buf);
3090 for (
i = 1;
i <= num_sets; ++
i)
3117 foreach(lc, groupingSets)
3145 result =
lcons(gs, result);
3167 if (pathkey->pk_eclass->ec_has_volatile)
3206 List *grouppathkeys =
root->group_pathkeys;
3226 unprocessed_aggs = NULL;
3227 foreach(lc,
root->agginfos)
3232 if (AGGKIND_IS_ORDERED_SET(aggref->aggkind))
3243 bool allow_presort =
true;
3258 foreach(lc2, aggref->
args)
3271 allow_presort =
false;
3336 if (currpathkeys ==
NIL)
3338 currpathkeys = pathkeys;
3341 if (grouppathkeys !=
NIL)
3353 if (grouppathkeys !=
NIL)
3362 currpathkeys = pathkeys;
3389 bestaggs = aggindexes;
3390 bestpathkeys = currpathkeys;
3399 if (bestpathkeys !=
NIL)
3400 root->group_pathkeys = bestpathkeys;
3419 aggref->aggpresorted =
true;
3432 List *tlist =
root->processed_tlist;
3460 root->group_pathkeys =
3474 root->num_groupby_pathkeys = 0;
3477 else if (
parse->groupClause ||
root->numOrderedAggs > 0)
3493 root->group_pathkeys =
3495 &
root->processed_groupClause,
3505 root->num_groupby_pathkeys = 0;
3511 if (
root->numOrderedAggs > 0)
3518 root->num_groupby_pathkeys = 0;
3522 if (activeWindows !=
NIL)
3539 if (
parse->distinctClause)
3545 root->distinct_pathkeys =
3547 &
root->processed_distinctClause,
3554 root->distinct_pathkeys =
NIL;
3557 root->distinct_pathkeys =
NIL;
3559 root->sort_pathkeys =
3565 if (qp_extra->
setop != NULL)
3572 root->setop_pathkeys =
3606 if (
root->group_pathkeys)
3607 root->query_pathkeys =
root->group_pathkeys;
3608 else if (
root->window_pathkeys)
3609 root->query_pathkeys =
root->window_pathkeys;
3612 root->query_pathkeys =
root->distinct_pathkeys;
3613 else if (
root->sort_pathkeys)
3614 root->query_pathkeys =
root->sort_pathkeys;
3615 else if (
root->setop_pathkeys !=
NIL)
3616 root->query_pathkeys =
root->setop_pathkeys;
3641 if (
parse->groupClause)
3645 if (
parse->groupingSets)
3718 else if (
parse->groupingSets)
3723 else if (
parse->hasAggs ||
root->hasHavingQual)
3758 bool target_parallel_safe,
3774 target_parallel_safe,
parse->havingQual);
3823 root->numOrderedAggs == 0 &&
3833 extra.
flags = flags;
3851 &agg_costs, gd, &extra,
3852 &partially_grouped_rel);
3869 PathTarget *target,
bool target_parallel_safe,
3908 grouped_rel->fdwroutine = input_rel->fdwroutine;
3925 return (
root->hasHavingQual ||
parse->groupingSets) &&
3961 while (--nrows >= 0)
4042 root->parse->groupClause))
4057 bool force_rel_creation;
4066 partially_grouped_rel =
4072 force_rel_creation);
4076 *partially_grouped_rel_p = partially_grouped_rel;
4081 partially_grouped_rel, agg_costs,
4087 Assert(partially_grouped_rel);
4089 if (partially_grouped_rel->
pathlist)
4106 cheapest_path->
rows,
4112 partially_grouped_rel, agg_costs, gd,
4118 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4119 errmsg(
"could not implement GROUP BY"),
4120 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4126 if (grouped_rel->fdwroutine &&
4127 grouped_rel->fdwroutine->GetForeignUpperPaths)
4129 input_rel, grouped_rel,
4135 input_rel, grouped_rel,
4180 double exclude_groups = 0.0;
4204 if (l_start != NULL &&
4208 exclude_groups = unhashed_rollup->
numGroups;
4215 dNumGroups - exclude_groups);
4222 if (hashsize > hash_mem_limit && gd->
rollups)
4251 foreach(lc, sets_data)
4260 empty_sets_data =
lappend(empty_sets_data, gs);
4275 new_rollups =
lappend(new_rollups, rollup);
4283 if (new_rollups ==
NIL)
4290 Assert(!unhashed_rollup || !empty_sets);
4292 if (unhashed_rollup)
4294 new_rollups =
lappend(new_rollups, unhashed_rollup);
4297 else if (empty_sets)
4303 rollup->
gsets = empty_sets;
4307 new_rollups =
lappend(new_rollups, rollup);
4340 double availspace = hash_mem_limit;
4356 int *k_weights =
palloc(num_rollups *
sizeof(
int));
4382 scale =
Max(availspace / (20.0 * num_rollups), 1.0);
4383 k_capacity = (int) floor(availspace /
scale);
4407 k_weights[
i] = (int)
Min(floor(sz /
scale),
4437 rollups =
lappend(rollups, rollup);
4441 rollups =
lappend(rollups, rollup);
4446 if (!rollups && hash_sets)
4449 foreach(lc, hash_sets)
4464 rollups =
lcons(rollup, rollups);
4512 bool output_target_parallel_safe,
4514 List *activeWindows)
4537 window_rel->fdwroutine = input_rel->fdwroutine;
4566 if (window_rel->fdwroutine &&
4567 window_rel->fdwroutine->GetForeignUpperPaths)
4569 input_rel, window_rel,
4575 input_rel, window_rel, NULL);
4601 List *activeWindows)
4622 window_target = input_target;
4624 foreach(l, activeWindows)
4627 List *window_pathkeys;
4636 root->processed_tlist);
4669 if (
lnext(activeWindows, l))
4694 window_target = output_target;
4709 foreach(lc3, wfunc->runCondition)
4734 wfuncrc->inputcollid);
4736 runcondition =
lappend(runcondition, opexpr);
4739 topqual =
lappend(topqual, opexpr);
4747 topwindow ? topqual :
NIL, topwindow);
4788 distinct_rel->fdwroutine = input_rel->fdwroutine;
4799 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4800 errmsg(
"could not implement DISTINCT"),
4801 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4807 if (distinct_rel->fdwroutine &&
4808 distinct_rel->fdwroutine->GetForeignUpperPaths)
4809 distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4818 distinct_rel, NULL);
4823 return distinct_rel;
4841 List *distinctExprs;
4842 double numDistinctRows;
4843 Path *cheapest_partial_path;
4853 if (
parse->hasDistinctOn)
4858 partial_distinct_rel->
reltarget = target;
4867 partial_distinct_rel->fdwroutine = input_rel->fdwroutine;
4876 cheapest_partial_path->
rows,
4892 List *useful_pathkeys_list =
NIL;
4894 useful_pathkeys_list =
4896 root->distinct_pathkeys,
4903 partial_distinct_rel,
4905 cheapest_partial_path,
4909 if (sorted_path == NULL)
4917 if (
root->distinct_pathkeys ==
NIL)
4967 partial_distinct_rel,
4968 cheapest_partial_path,
4969 cheapest_partial_path->pathtarget,
4972 root->processed_distinctClause,
4982 if (partial_distinct_rel->fdwroutine &&
4983 partial_distinct_rel->fdwroutine->GetForeignUpperPaths)
4984 partial_distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4987 partial_distinct_rel,
4993 input_rel, partial_distinct_rel, NULL);
5006 final_distinct_rel);
5023 double numDistinctRows;
5028 root->hasHavingQual)
5035 numDistinctRows = cheapest_input_path->
rows;
5042 List *distinctExprs;
5047 cheapest_input_path->
rows,
5072 List *needed_pathkeys;
5074 double limittuples =
root->distinct_pathkeys ==
NIL ? 1.0 : -1.0;
5076 if (
parse->hasDistinctOn &&
5079 needed_pathkeys =
root->sort_pathkeys;
5081 needed_pathkeys =
root->distinct_pathkeys;
5087 List *useful_pathkeys_list =
NIL;
5089 useful_pathkeys_list =
5100 cheapest_input_path,
5104 if (sorted_path == NULL)
5120 if (
root->distinct_pathkeys ==
NIL)
5176 cheapest_input_path,
5177 cheapest_input_path->pathtarget,
5180 root->processed_distinctClause,
5186 return distinct_rel;
5199 List *path_pathkeys)
5201 List *useful_pathkeys_list =
NIL;
5205 useful_pathkeys_list =
lappend(useful_pathkeys_list,
5209 return useful_pathkeys_list;
5228 if (
root->parse->hasDistinctOn &&
5232 useful_pathkeys =
lappend(useful_pathkeys, pathkey);
5236 if (useful_pathkeys ==
NIL)
5237 return useful_pathkeys_list;
5245 return useful_pathkeys_list;
5257 return useful_pathkeys_list;
5259 useful_pathkeys_list =
lappend(useful_pathkeys_list,
5262 return useful_pathkeys_list;
5286 bool target_parallel_safe,
5287 double limit_tuples)
5310 ordered_rel->fdwroutine = input_rel->fdwroutine;
5320 input_path->
pathkeys, &presorted_keys);
5323 sorted_path = input_path;
5333 if (input_path != cheapest_input_path &&
5346 root->sort_pathkeys,
5352 root->sort_pathkeys,
5361 if (!
equal(sorted_path->pathtarget->exprs, target->
exprs))
5363 sorted_path, target);
5365 add_path(ordered_rel, sorted_path);
5382 Path *cheapest_partial_path;
5392 double total_groups;
5408 if (input_path != cheapest_partial_path &&
5421 root->sort_pathkeys,
5427 root->sort_pathkeys,
5431 sorted_path = (
Path *)
5434 sorted_path->pathtarget,
5435 root->sort_pathkeys, NULL,
5442 if (!
equal(sorted_path->pathtarget->exprs, target->
exprs))
5444 sorted_path, target);
5446 add_path(ordered_rel, sorted_path);
5454 if (ordered_rel->fdwroutine &&
5455 ordered_rel->fdwroutine->GetForeignUpperPaths)
5457 input_rel, ordered_rel,
5463 input_rel, ordered_rel, NULL);
5507 List *non_group_cols;
5508 List *non_group_vars;
5517 non_group_cols =
NIL;
5520 foreach(lc, final_target->
exprs)
5525 if (sgref &&
root->processed_groupClause &&
5527 root->processed_groupClause) != NULL)
5552 non_group_cols =
lappend(non_group_cols, expr);
5561 if (
parse->havingQual)
5562 non_group_cols =
lappend(non_group_cols,
parse->havingQual);
5583 non_group_vars = (
List *)
5620 List *non_group_cols;
5621 List *non_group_exprs;
5626 non_group_cols =
NIL;
5629 foreach(lc, grouping_target->
exprs)
5634 if (sgref &&
root->processed_groupClause &&
5636 root->processed_groupClause) != NULL)
5650 non_group_cols =
lappend(non_group_cols, expr);
5660 non_group_cols =
lappend(non_group_cols, havingQual);
5681 foreach(lc, partial_target->
exprs)
5694 memcpy(newaggref, aggref,
sizeof(
Aggref));
5726 agg->aggsplit = aggsplit;
5736 agg->aggtype = BYTEAOID;
5738 agg->aggtype = agg->aggtranstype;
5758 foreach(l, new_tlist)
5764 if (new_tle->resjunk)
5767 Assert(orig_tlist_item != NULL);
5769 orig_tlist_item =
lnext(orig_tlist, orig_tlist_item);
5770 if (orig_tle->resjunk)
5771 elog(
ERROR,
"resjunk output columns are not implemented");
5775 if (orig_tlist_item != NULL)
5776 elog(
ERROR,
"resjunk output columns are not implemented");
5792 List *windowClause =
root->parse->windowClause;
5795 foreach(lc, windowClause)
5799 int optimizedFrameOptions = 0;
5820 req.
type = T_SupportRequestOptimizeWindowClause;
5854 if (lc2 == NULL && wc->
frameOptions != optimizedFrameOptions)
5874 foreach(lc3, windowClause)
5879 if (existing_wc == wc)
5932 List *windowClause =
root->parse->windowClause;
5940 foreach(lc, windowClause)
5949 actives[nActive].
wc = wc;
5993 for (
int i = 0;
i < nActive;
i++)
5994 result =
lappend(result, actives[
i].wc);
6019 foreach(lc, activeWindows)
6032 snprintf(newname,
sizeof(newname),
"w%d", next_n++);
6033 foreach(lc2, activeWindows)
6037 if (wc2->name && strcmp(wc2->name, newname) == 0)
6135 List *activeWindows)
6139 List *flattenable_cols;
6140 List *flattenable_vars;
6151 foreach(lc, activeWindows)
6171 foreach(lc,
root->processed_groupClause)
6183 flattenable_cols =
NIL;
6186 foreach(lc, final_target->
exprs)
6210 flattenable_cols =
lappend(flattenable_cols, expr);
6261 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6262 errmsg(
"could not implement window PARTITION BY"),
6263 errdetail(
"Window partitioning columns must be of sortable datatypes.")));
6266 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6267 errmsg(
"could not implement window ORDER BY"),
6268 errdetail(
"Window ordering columns must be of sortable datatypes.")));
6298 List *orderby_pathkeys;
6305 if (window_pathkeys !=
NIL)
6308 window_pathkeys = orderby_pathkeys;
6311 return window_pathkeys;
6383 bool *have_postponed_srfs)
6392 bool have_expensive;
6393 bool have_srf_sortcols;
6395 List *postponable_cols;
6396 List *postponable_vars;
6403 *have_postponed_srfs =
false;
6407 col_is_srf = (
bool *)
palloc0(ncols *
sizeof(
bool));
6408 postpone_col = (
bool *)
palloc0(ncols *
sizeof(
bool));
6409 have_srf = have_volatile = have_expensive = have_srf_sortcols =
false;
6412 foreach(lc, final_target->
exprs)
6430 if (
parse->hasTargetSRFs &&
6434 col_is_srf[
i] =
true;
6440 postpone_col[
i] =
true;
6441 have_volatile =
true;
6461 postpone_col[
i] =
true;
6462 have_expensive =
true;
6469 if (!have_srf_sortcols &&
6470 parse->hasTargetSRFs &&
6472 have_srf_sortcols =
true;
6481 postpone_srfs = (have_srf && !have_srf_sortcols);
6486 if (!(postpone_srfs || have_volatile ||
6488 (
parse->limitCount ||
root->tuple_fraction > 0))))
6489 return final_target;
6497 *have_postponed_srfs = postpone_srfs;
6505 postponable_cols =
NIL;
6508 foreach(lc, final_target->
exprs)
6512 if (postpone_col[
i] || (postpone_srfs && col_is_srf[
i]))
6513 postponable_cols =
lappend(postponable_cols, expr);
6563 if (tuple_fraction <= 0.0)
6567 if (tuple_fraction >= 1.0 && best_path->
rows > 0)
6568 tuple_fraction /= best_path->
rows;
6574 if (path->param_info)
6604 List *targets,
List *targets_contain_srfs)
6633 forboth(lc1, targets, lc2, targets_contain_srfs)
6666 forboth(lc1, targets, lc2, targets_contain_srfs)
6732 return (
Expr *) result;
6747 List **relationOids,
6755 MemSet(&glob, 0,
sizeof(glob));
6756 glob.type = T_PlannerGlobal;
6761 root.type = T_PlannerInfo;
6783 return (
Expr *) result;
6808 Cost comparisonCost;
6810 Path seqScanAndSortPath;
6825 root->parse = query;
6827 root->query_level = 1;
6829 root->wt_param_id = -1;
6835 rte->relid = tableOid;
6836 rte->relkind = RELKIND_RELATION;
6838 rte->lateral =
false;
6840 rte->inFromCl =
true;
6855 if (indexInfo->
indexoid == indexOid)
6930 int parallel_workers;
6949 root->parse = query;
6951 root->query_level = 1;
6953 root->wt_param_id = -1;
6966 rte->relid = tableOid;
6967 rte->relkind = RELKIND_RELATION;
6969 rte->lateral =
false;
6971 rte->inFromCl =
true;
6992 if (heap->
rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
6996 parallel_workers = 0;
7037 while (parallel_workers > 0 &&
7045 return parallel_workers;
7080 Path *path_save = path;
7081 List *pathkey_orderings =
NIL;
7088 foreach(lc2, pathkey_orderings)
7105 if (
parse->groupingSets)
7108 path,
true, can_hash,
7109 gd, agg_costs, dNumGroups);
7111 else if (
parse->hasAggs)
7129 else if (
parse->groupClause)
7155 if (partially_grouped_rel != NULL)
7157 foreach(lc, partially_grouped_rel->
pathlist)
7161 Path *path_save = path;
7162 List *pathkey_orderings =
NIL;
7170 foreach(lc2, pathkey_orderings)
7215 if (
parse->groupingSets)
7221 cheapest_path,
false,
true,
7222 gd, agg_costs, dNumGroups);
7236 root->processed_groupClause,
7246 if (partially_grouped_rel && partially_grouped_rel->
pathlist)
7257 root->processed_groupClause,
7296 bool force_rel_creation)
7302 Path *cheapest_partial_path = NULL;
7303 Path *cheapest_total_path = NULL;
7304 double dNumPartialGroups = 0;
7305 double dNumPartialPartialGroups = 0;
7334 if (cheapest_total_path == NULL &&
7335 cheapest_partial_path == NULL &&
7336 !force_rel_creation)
7352 partially_grouped_rel->fdwroutine = grouped_rel->fdwroutine;
7387 if (cheapest_total_path != NULL)
7390 cheapest_total_path->
rows,
7393 if (cheapest_partial_path != NULL)
7394 dNumPartialPartialGroups =
7396 cheapest_partial_path->
rows,
7400 if (can_sort && cheapest_total_path != NULL)
7413 Path *path_save = path;
7414 List *pathkey_orderings =
NIL;
7422 foreach(lc2, pathkey_orderings)
7430 partially_grouped_rel,
7432 cheapest_total_path,
7442 partially_grouped_rel,
7450 dNumPartialGroups));
7454 partially_grouped_rel,
7458 dNumPartialGroups));
7463 if (can_sort && cheapest_partial_path != NULL)
7470 Path *path_save = path;
7471 List *pathkey_orderings =
NIL;
7479 foreach(lc2, pathkey_orderings)
7488 partially_grouped_rel,
7490 cheapest_partial_path,
7500 partially_grouped_rel,
7508 dNumPartialPartialGroups));
7512 partially_grouped_rel,
7516 dNumPartialPartialGroups));
7524 if (can_hash && cheapest_total_path != NULL)
7531 partially_grouped_rel,
7532 cheapest_total_path,
7536 root->processed_groupClause,
7539 dNumPartialGroups));
7545 if (can_hash && cheapest_partial_path != NULL)
7549 partially_grouped_rel,
7550 cheapest_partial_path,
7554 root->processed_groupClause,
7557 dNumPartialPartialGroups));
7564 if (partially_grouped_rel->fdwroutine &&
7565 partially_grouped_rel->fdwroutine->GetForeignUpperPaths)
7567 FdwRoutine *fdwroutine = partially_grouped_rel->fdwroutine;
7571 input_rel, partially_grouped_rel,
7575 return partially_grouped_rel;
7586 Path *cheapest_path,
List *pathkeys,
double limit_tuples)
7603 if (path != cheapest_path &&
7647 Path *cheapest_partial_path;
7648 List *groupby_pathkeys;
7656 root->num_groupby_pathkeys);
7658 groupby_pathkeys =
root->group_pathkeys;
7671 double total_groups;
7686 if (path != cheapest_partial_path &&
7739 else if (
parse->groupingSets)
7744 else if (
root->hasNonPartialAggs ||
root->hasNonSerialAggs)
7771 List *scanjoin_targets,
7772 List *scanjoin_targets_contain_srfs,
7773 bool scanjoin_target_parallel_safe,
7802 if (rel_is_partitioned)
7809 if (!scanjoin_target_parallel_safe)
7828 if (rel_is_partitioned)
7851 subpath->pathtarget->sortgrouprefs =
7852 scanjoin_target->sortgrouprefs;
7872 subpath->pathtarget->sortgrouprefs =
7873 scanjoin_target->sortgrouprefs;
7890 if (
root->parse->hasTargetSRFs)
7893 scanjoin_targets_contain_srfs);
7915 if (rel_is_partitioned)
7927 List *child_scanjoin_targets =
NIL;
7929 Assert(child_rel != NULL);
7938 foreach(lc, scanjoin_targets)
7946 nappinfos, appinfos);
7947 child_scanjoin_targets =
lappend(child_scanjoin_targets,
7954 child_scanjoin_targets,
7955 scanjoin_targets_contain_srfs,
7956 scanjoin_target_parallel_safe,
7961 live_children =
lappend(live_children, child_rel);
8013 List *grouped_live_children =
NIL;
8014 List *partially_grouped_live_children =
NIL;
8016 bool partial_grouping_valid =
true;
8021 partially_grouped_rel != NULL);
8027 RelOptInfo *child_input_rel = input_rel->part_rels[
i];
8035 Assert(child_input_rel != NULL);
8047 memcpy(&child_extra, extra,
sizeof(child_extra));
8055 nappinfos, appinfos);
8061 nappinfos, appinfos);
8065 nappinfos, appinfos);
8072 child_extra.
patype = patype;
8086 agg_costs, gd, &child_extra,
8087 &child_partially_grouped_rel);
8089 if (child_partially_grouped_rel)
8091 partially_grouped_live_children =
8092 lappend(partially_grouped_live_children,
8093 child_partially_grouped_rel);
8096 partial_grouping_valid =
false;
8101 grouped_live_children =
lappend(grouped_live_children,
8117 if (partially_grouped_rel && partial_grouping_valid)
8119 Assert(partially_grouped_live_children !=
NIL);
8122 partially_grouped_live_children);
8128 if (partially_grouped_rel->
pathlist)
8157 Assert(input_rel->part_scheme);
8160 if (!input_rel->partexprs)
8163 partnatts = input_rel->part_scheme->partnatts;
8165 for (cnt = 0; cnt < partnatts; cnt++)
8167 List *partexprs = input_rel->partexprs[cnt];
8171 foreach(lc, partexprs)
8175 Oid partcoll = input_rel->part_scheme->partcollation[cnt];
8177 foreach(lg, groupexprs)
8190 if (
equal(groupexpr, partexpr))
8197 partcoll != groupcoll)
8244 foreach(lt, targetlist)
8267 lg =
lnext(grouplist, lg);
8268 ct =
lnext(op->colTypes, ct);
8369 unique_rel->
reltarget = child_unique_target;
8405 bool made_tle =
false;
8414 newtlist =
lappend(newtlist, tle);
8439 elog(
ERROR,
"could not find equality operator for ordering operator %u",
8444 sortcl->
eqop = eqop;
8448 sortcl->hashable =
false;
8449 sortList =
lappend(sortList, sortcl);
8474 elog(
ERROR,
"could not find ordering operator for equality operator %u",
8491 elog(
ERROR,
"could not find compatible hash operator for operator %u",
8496 groupcl->
eqop = eq_oper;
8497 groupcl->
sortop = sortop;
8500 groupcl->hashable =
true;
8501 groupClause =
lappend(groupClause, groupcl);
8518 if (sortPathkeys ==
NIL && groupClause ==
NIL)
8530 sjinfo, unique_rel);
8534 sjinfo, unique_rel);
8561 List *sortPathkeys,
List *groupClause,
8569 cheapest_input_path->
rows,
8597 if (input_path->param_info &&
8598 input_path != cheapest_input_path)
8610 if (!is_sorted && input_path != cheapest_input_path &&
8662 cheapest_input_path,
8668 cheapest_input_path->pathtarget,
8686 List *sortPathkeys,
List *groupClause,
8690 Path *cheapest_partial_path;
8706 memcpy(partial_unique_rel, input_rel,
sizeof(
RelOptInfo));
8721 cheapest_partial_path->
rows,
8752 if (!is_sorted && input_path != cheapest_partial_path &&
8788 partial_unique_rel->
rows);
8804 cheapest_partial_path,
8810 cheapest_partial_path->pathtarget,
8816 partial_unique_rel->
rows);
8832 sortPathkeys, groupClause,
8833 sjinfo, unique_rel);
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
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(int64 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)
bool ExecCheckOneRelPerms(RTEPermissionInfo *perminfo)
#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)
List * list_delete_last(List *list)
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)
char * get_rel_name(Oid relid)
bool get_compatible_hash_operators(Oid opno, Oid *lhs_opno, Oid *rhs_opno)
RegProcedure get_func_support(Oid funcid)
Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse)
Oid get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type)
int32 get_typavgwidth(Oid typid, int32 typmod)
Datum subpath(PG_FUNCTION_ARGS)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
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
MemoryContext GetMemoryChunkContext(void *pointer)
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
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
int assign_special_exec_param(PlannerInfo *root)
List * expand_grouping_sets(List *groupingSets, bool groupDistinct, int limit)
Index assignSortGroupRef(TargetEntry *tle, List *tlist)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
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)
UniquePath * create_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)
#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)
RelOptInfo * create_unique_paths(PlannerInfo *root, RelOptInfo *rel, SpecialJoinInfo *sjinfo)
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 void create_final_unique_paths(PlannerInfo *root, RelOptInfo *input_rel, List *sortPathkeys, List *groupClause, SpecialJoinInfo *sjinfo, RelOptInfo *unique_rel)
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)
static void create_partial_unique_paths(PlannerInfo *root, RelOptInfo *input_rel, List *sortPathkeys, List *groupClause, SpecialJoinInfo *sjinfo, RelOptInfo *unique_rel)
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 Datum Int64GetDatum(int64 X)
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)
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)
Query * preprocess_relation_rtes(PlannerInfo *root)
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
PlannedStmtOrigin planOrigin
Bitmapset * unprunableRelids
Bitmapset * prunableRelids
Bitmapset * rewindPlanIDs
struct TableSampleClause * tablesample
struct PathTarget * reltarget
List * cheapest_parameterized_paths
struct Path * cheapest_startup_path
struct Path * cheapest_total_path
List * unique_groupclause
struct RelOptInfo * unique_rel
LockClauseStrength strength
LockWaitPolicy waitPolicy
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)
TargetEntry * tlist_member(Expr *node, List *targetlist)
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)
List * make_tlist_from_pathtarget(PathTarget *target)
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)