38 #ifdef OPTIMIZER_DEBUG
78 #define EXPRKIND_QUAL 0
79 #define EXPRKIND_TARGET 1
80 #define EXPRKIND_RTFUNC 2
81 #define EXPRKIND_RTFUNC_LATERAL 3
82 #define EXPRKIND_VALUES 4
83 #define EXPRKIND_VALUES_LATERAL 5
84 #define EXPRKIND_LIMIT 6
85 #define EXPRKIND_APPINFO 7
86 #define EXPRKIND_PHV 8
87 #define EXPRKIND_TABLESAMPLE 9
88 #define EXPRKIND_ARBITER_ELEM 10
89 #define EXPRKIND_TABLEFUNC 11
90 #define EXPRKIND_TABLEFUNC_LATERAL 12
134 int *tleref_to_colnum_map);
137 double tuple_fraction,
138 int64 *offset_est, int64 *count_est);
151 bool target_parallel_safe,
158 PathTarget *target,
bool target_parallel_safe,
179 bool output_target_parallel_safe,
181 List *activeWindows);
188 List *activeWindows);
202 bool target_parallel_safe,
203 double limit_tuples);
215 List *activeWindows);
220 bool *have_postponed_srfs);
222 List *targets,
List *targets_contain_srfs);
235 bool force_rel_creation);
240 List *scanjoin_targets,
241 List *scanjoin_targets_contain_srfs,
242 bool scanjoin_target_parallel_safe,
280 result = (*planner_hook) (
parse, query_string, cursorOptions, boundParams);
292 double tuple_fraction;
308 glob->boundParams = boundParams;
311 glob->subroots =
NIL;
351 !
parse->hasModifyingCTE &&
403 if (tuple_fraction >= 1.0)
404 tuple_fraction = 0.0;
405 else if (tuple_fraction <= 0.0)
406 tuple_fraction = 1
e-10;
411 tuple_fraction = 0.0;
452 bool unsafe_initplans;
490 &initplan_cost, &unsafe_initplans);
495 root->glob->parallelModeNeeded =
true;
497 top_plan = &gather->
plan;
588 if (glob->partition_directory != NULL)
629 bool hasRecursion,
double tuple_fraction,
633 List *newWithCheckOptions;
645 root->parent_root = parent_root;
647 root->outer_params = NULL;
654 root->ec_merging_done =
false;
655 root->last_rinfo_serial = 0;
656 root->all_result_relids =
658 root->leaf_result_relids = NULL;
662 memset(
root->upper_rels, 0,
sizeof(
root->upper_rels));
663 memset(
root->upper_targets, 0,
sizeof(
root->upper_targets));
664 root->processed_groupClause =
NIL;
665 root->processed_distinctClause =
NIL;
668 root->grouping_map = NULL;
670 root->qual_security_level = 0;
671 root->hasPseudoConstantQuals =
false;
672 root->hasAlternativeSubPlans =
false;
673 root->placeholdersFrozen =
false;
674 root->hasRecursion = hasRecursion;
678 root->wt_param_id = -1;
679 root->non_recursive_path = NULL;
680 root->partColsUpdated =
false;
713 if (
parse->hasSubLinks)
736 if (
parse->setOperations)
749 root->hasJoinRTEs =
false;
750 root->hasLateralRTEs =
false;
751 hasOuterJoins =
false;
752 hasResultRTEs =
false;
753 foreach(l,
parse->rtable)
777 root->hasJoinRTEs =
true;
779 hasOuterJoins =
true;
782 hasResultRTEs =
true;
790 root->hasLateralRTEs =
true;
798 if (rte->securityQuals)
799 root->qual_security_level =
Max(
root->qual_security_level,
807 if (
parse->resultRelation)
812 root->leaf_result_relids =
827 root->hasHavingQual = (
parse->havingQual != NULL);
840 if (
parse->hasTargetSRFs)
843 newWithCheckOptions =
NIL;
844 foreach(l,
parse->withCheckOptions)
850 if (wco->
qual != NULL)
851 newWithCheckOptions =
lappend(newWithCheckOptions, wco);
853 parse->withCheckOptions = newWithCheckOptions;
864 foreach(l,
parse->windowClause)
880 if (
parse->onConflict)
882 parse->onConflict->arbiterElems = (
List *)
884 (
Node *)
parse->onConflict->arbiterElems,
886 parse->onConflict->arbiterWhere =
888 parse->onConflict->arbiterWhere,
890 parse->onConflict->onConflictSet = (
List *)
892 (
Node *)
parse->onConflict->onConflictSet,
894 parse->onConflict->onConflictWhere =
896 parse->onConflict->onConflictWhere,
901 foreach(l,
parse->mergeActionList)
915 parse->mergeJoinCondition =
923 foreach(l,
parse->rtable)
946 if (rte->lateral &&
root->hasJoinRTEs)
979 foreach(lcsq, rte->securityQuals)
998 if (
root->hasJoinRTEs)
1000 foreach(l,
parse->rtable)
1004 rte->joinaliasvars =
NIL;
1044 if ((
parse->groupClause &&
parse->groupingSets) ||
1050 newHaving =
lappend(newHaving, havingclause);
1052 else if (
parse->groupClause && !
parse->groupingSets)
1064 newHaving =
lappend(newHaving, havingclause);
1083 if (hasResultRTEs || hasOuterJoins)
1142 if (
root->hasJoinRTEs &&
1178 #ifdef OPTIMIZER_DEBUG
1179 printf(
"After canonicalize_qual()\n");
1195 if (
root->parse->hasSubLinks)
1204 if (
root->query_level > 1)
1253 elog(
ERROR,
"unrecognized node type: %d",
1306 int64 offset_est = 0;
1307 int64 count_est = 0;
1308 double limit_tuples = -1.0;
1309 bool have_postponed_srfs =
false;
1311 List *final_targets;
1312 List *final_targets_contain_srfs;
1313 bool final_target_parallel_safe;
1323 &offset_est, &count_est);
1329 if (count_est > 0 && offset_est >= 0)
1330 limit_tuples = (double) count_est + (
double) offset_est;
1334 root->tuple_fraction = tuple_fraction;
1336 if (
parse->setOperations)
1356 root->processed_tlist =
1364 final_target_parallel_safe =
1369 final_targets = final_targets_contain_srfs =
NIL;
1375 if (
parse->rowMarks)
1377 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1380 errmsg(
"%s is not allowed with UNION/INTERSECT/EXCEPT",
1382 parse->rowMarks)->strength))));
1390 root->processed_tlist);
1396 List *sort_input_targets;
1397 List *sort_input_targets_contain_srfs;
1398 bool sort_input_target_parallel_safe;
1400 List *grouping_targets;
1401 List *grouping_targets_contain_srfs;
1402 bool grouping_target_parallel_safe;
1404 List *scanjoin_targets;
1405 List *scanjoin_targets_contain_srfs;
1406 bool scanjoin_target_parallel_safe;
1407 bool scanjoin_target_same_exprs;
1418 if (
parse->groupingSets)
1422 else if (
parse->groupClause)
1458 if (
parse->hasWindowFuncs)
1474 parse->hasWindowFuncs =
false;
1492 if (
parse->groupClause ||
1493 parse->groupingSets ||
1494 parse->distinctClause ||
1496 parse->hasWindowFuncs ||
1497 parse->hasTargetSRFs ||
1498 root->hasHavingQual)
1499 root->limit_tuples = -1.0;
1501 root->limit_tuples = limit_tuples;
1511 qp_extra.
setop = setops;
1532 final_target_parallel_safe =
1540 if (
parse->sortClause)
1544 &have_postponed_srfs);
1545 sort_input_target_parallel_safe =
1550 sort_input_target = final_target;
1551 sort_input_target_parallel_safe = final_target_parallel_safe;
1564 grouping_target_parallel_safe =
1569 grouping_target = sort_input_target;
1570 grouping_target_parallel_safe = sort_input_target_parallel_safe;
1578 have_grouping = (
parse->groupClause ||
parse->groupingSets ||
1583 scanjoin_target_parallel_safe =
1588 scanjoin_target = grouping_target;
1589 scanjoin_target_parallel_safe = grouping_target_parallel_safe;
1598 if (
parse->hasTargetSRFs)
1603 &final_targets_contain_srfs);
1608 &sort_input_targets,
1609 &sort_input_targets_contain_srfs);
1615 &grouping_targets_contain_srfs);
1621 &scanjoin_targets_contain_srfs);
1628 final_targets = final_targets_contain_srfs =
NIL;
1629 sort_input_targets = sort_input_targets_contain_srfs =
NIL;
1630 grouping_targets = grouping_targets_contain_srfs =
NIL;
1631 scanjoin_targets =
list_make1(scanjoin_target);
1632 scanjoin_targets_contain_srfs =
NIL;
1636 scanjoin_target_same_exprs =
list_length(scanjoin_targets) == 1
1639 scanjoin_targets_contain_srfs,
1640 scanjoin_target_parallel_safe,
1641 scanjoin_target_same_exprs);
1667 grouping_target_parallel_safe,
1670 if (
parse->hasTargetSRFs)
1673 grouping_targets_contain_srfs);
1686 sort_input_target_parallel_safe,
1690 if (
parse->hasTargetSRFs)
1693 sort_input_targets_contain_srfs);
1700 if (
parse->distinctClause)
1715 if (
parse->sortClause)
1720 final_target_parallel_safe,
1721 have_postponed_srfs ? -1.0 :
1724 if (
parse->hasTargetSRFs)
1727 final_targets_contain_srfs);
1753 final_rel->fdwroutine = current_rel->fdwroutine;
1770 if (
parse->rowMarks)
1786 offset_est, count_est);
1796 List *updateColnosLists =
NIL;
1797 List *withCheckOptionLists =
NIL;
1800 List *mergeJoinConditions =
NIL;
1807 parse->resultRelation);
1808 int resultRelation = -1;
1811 rootRelation =
parse->resultRelation;
1815 resultRelation)) >= 0)
1833 List *update_colnos =
root->update_colnos;
1835 if (this_result_rel != top_result_rel)
1839 this_result_rel->
relid,
1840 top_result_rel->
relid);
1841 updateColnosLists =
lappend(updateColnosLists,
1844 if (
parse->withCheckOptions)
1846 List *withCheckOptions =
parse->withCheckOptions;
1848 if (this_result_rel != top_result_rel)
1849 withCheckOptions = (
List *)
1851 (
Node *) withCheckOptions,
1854 withCheckOptionLists =
lappend(withCheckOptionLists,
1857 if (
parse->returningList)
1859 List *returningList =
parse->returningList;
1861 if (this_result_rel != top_result_rel)
1862 returningList = (
List *)
1864 (
Node *) returningList,
1867 returningLists =
lappend(returningLists,
1870 if (
parse->mergeActionList)
1879 foreach(l,
parse->mergeActionList)
1889 leaf_action->targetList = (
List *)
1895 leaf_action->updateColnos =
1898 this_result_rel->
relid,
1899 top_result_rel->
relid);
1900 mergeActionList =
lappend(mergeActionList,
1904 mergeActionLists =
lappend(mergeActionLists,
1909 Node *mergeJoinCondition =
parse->mergeJoinCondition;
1911 if (this_result_rel != top_result_rel)
1912 mergeJoinCondition =
1917 mergeJoinConditions =
lappend(mergeJoinConditions,
1918 mergeJoinCondition);
1922 if (resultRelations ==
NIL)
1938 if (
parse->withCheckOptions)
1940 if (
parse->returningList)
1942 if (
parse->mergeActionList)
1955 if (
parse->withCheckOptions)
1957 if (
parse->returningList)
1959 if (
parse->mergeActionList)
1970 if (
parse->rowMarks)
1973 rowMarks =
root->rowMarks;
1980 parse->resultRelation,
1982 root->partColsUpdated,
1985 withCheckOptionLists,
1990 mergeJoinConditions,
2023 if (final_rel->fdwroutine &&
2024 final_rel->fdwroutine->GetForeignUpperPaths)
2026 current_rel, final_rel,
2032 current_rel, final_rel, &extra);
2063 root->processed_groupClause =
parse->groupClause;
2065 if (
parse->groupClause)
2069 foreach(lc,
parse->groupClause)
2099 foreach(lc,
parse->groupingSets)
2120 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2121 errmsg(
"could not implement GROUP BY"),
2122 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
2125 sortable_sets =
lappend(sortable_sets, gset);
2136 foreach(lc_set, sets)
2227 int *tleref_to_colnum_map)
2233 foreach(lc, groupClause)
2246 foreach(lc2, gs->
set)
2251 result =
lappend(result, set);
2270 if (
parse->rowMarks)
2279 parse->rowMarks)->strength);
2299 if (
parse->resultRelation)
2306 foreach(l,
parse->rowMarks)
2339 prowmarks =
lappend(prowmarks, newrc);
2346 foreach(l,
parse->rtable)
2364 prowmarks =
lappend(prowmarks, newrc);
2367 root->rowMarks = prowmarks;
2381 else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2417 elog(
ERROR,
"unrecognized LockClauseStrength %d", (
int) strength);
2441 int64 *offset_est, int64 *count_est)
2445 double limit_fraction;
2454 if (
parse->limitCount)
2459 if (((
Const *) est)->constisnull)
2467 if (*count_est <= 0)
2477 if (
parse->limitOffset)
2482 if (((
Const *) est)->constisnull)
2490 if (*offset_est < 0)
2500 if (*count_est != 0)
2507 if (*count_est < 0 || *offset_est < 0)
2510 limit_fraction = 0.10;
2515 limit_fraction = (double) *count_est + (
double) *offset_est;
2525 if (tuple_fraction >= 1.0)
2527 if (limit_fraction >= 1.0)
2530 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2537 else if (tuple_fraction > 0.0)
2539 if (limit_fraction >= 1.0)
2542 tuple_fraction = limit_fraction;
2547 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2553 tuple_fraction = limit_fraction;
2556 else if (*offset_est != 0 && tuple_fraction > 0.0)
2567 if (*offset_est < 0)
2568 limit_fraction = 0.10;
2570 limit_fraction = (double) *offset_est;
2578 if (tuple_fraction >= 1.0)
2580 if (limit_fraction >= 1.0)
2583 tuple_fraction += limit_fraction;
2588 tuple_fraction = limit_fraction;
2593 if (limit_fraction >= 1.0)
2600 tuple_fraction += limit_fraction;
2601 if (tuple_fraction >= 1.0)
2602 tuple_fraction = 0.0;
2607 return tuple_fraction;
2629 node =
parse->limitCount;
2635 if (!((
Const *) node)->constisnull)
2642 node =
parse->limitOffset;
2648 if (!((
Const *) node)->constisnull)
2697 if (
parse->groupingSets)
2707 foreach(lc,
root->processed_groupClause)
2740 foreach(lc,
parse->rtable)
2758 if (rte->
inh && rte->relkind != RELKIND_PARTITIONED_TABLE)
2762 relattnos = groupbyattnos[relid];
2771 if (pkattnos == NULL)
2784 if (surplusvars == NULL)
2798 if (surplusvars != NULL)
2802 foreach(lc,
root->processed_groupClause)
2815 surplusvars[var->
varno]))
2816 new_groupby =
lappend(new_groupby, sgc);
2819 root->processed_groupClause = new_groupby;
2866 new_groupclause =
lappend(new_groupclause, cl);
2869 return new_groupclause;
2882 foreach(sl,
parse->sortClause)
2886 foreach(gl,
parse->groupClause)
2892 new_groupclause =
lappend(new_groupclause, gc);
2902 if (new_groupclause ==
NIL)
2911 foreach(gl,
parse->groupClause)
2919 new_groupclause =
lappend(new_groupclause, gc);
2924 return new_groupclause;
2959 short *adjacency_buf;
2975 lc1 =
lnext(groupingSets, lc1);
3000 orig_sets =
palloc0((num_sets_raw + 1) *
sizeof(
List *));
3002 adjacency =
palloc0((num_sets_raw + 1) *
sizeof(
short *));
3003 adjacency_buf =
palloc((num_sets_raw + 1) *
sizeof(
short));
3016 foreach(lc2, candidate)
3026 for (k =
j; k <
i; ++k)
3028 if (
bms_equal(set_masks[k], candidate_set))
3043 orig_sets[dup_of] =
lappend(orig_sets[dup_of], candidate);
3052 set_masks[
i] = candidate_set;
3056 for (k =
j - 1; k > 0; --k)
3059 adjacency_buf[++n_adj] = k;
3064 adjacency_buf[0] = n_adj;
3065 adjacency[
i] =
palloc((n_adj + 1) *
sizeof(
short));
3066 memcpy(adjacency[
i], adjacency_buf, (n_adj + 1) *
sizeof(
short));
3069 adjacency[
i] = NULL;
3088 chains =
palloc0((num_sets + 1) *
sizeof(
int));
3090 for (
i = 1;
i <= num_sets; ++
i)
3092 int u =
state->pair_vu[
i];
3093 int v =
state->pair_uv[
i];
3096 chains[
i] = chains[u];
3097 else if (v > 0 && v <
i)
3098 chains[
i] = chains[v];
3100 chains[
i] = ++num_chains;
3104 results =
palloc0((num_chains + 1) *
sizeof(
List *));
3106 for (
i = 1;
i <= num_sets; ++
i)
3116 while (num_empty-- > 0)
3117 results[1] =
lcons(
NIL, results[1]);
3120 for (
i = 1;
i <= num_chains; ++
i)
3121 result =
lappend(result, results[
i]);
3132 for (
i = 1;
i <= num_sets; ++
i)
3136 pfree(adjacency_buf);
3138 for (
i = 1;
i <= num_sets; ++
i)
3165 foreach(lc, groupingSets)
3193 result =
lcons(gs, result);
3215 if (pathkey->pk_eclass->ec_has_volatile)
3254 List *grouppathkeys =
root->group_pathkeys;
3274 unprocessed_aggs = NULL;
3275 foreach(lc,
root->agginfos)
3280 if (AGGKIND_IS_ORDERED_SET(aggref->aggkind))
3341 if (currpathkeys ==
NIL)
3343 currpathkeys = pathkeys;
3346 if (grouppathkeys !=
NIL)
3358 if (grouppathkeys !=
NIL)
3367 currpathkeys = pathkeys;
3394 bestaggs = aggindexes;
3395 bestpathkeys = currpathkeys;
3404 if (bestpathkeys !=
NIL)
3405 root->group_pathkeys = bestpathkeys;
3424 aggref->aggpresorted =
true;
3437 List *tlist =
root->processed_tlist;
3465 root->num_groupby_pathkeys = 0;
3468 else if (
parse->groupClause ||
root->numOrderedAggs > 0)
3484 root->group_pathkeys =
3486 &
root->processed_groupClause,
3495 root->num_groupby_pathkeys = 0;
3501 if (
root->numOrderedAggs > 0)
3508 root->num_groupby_pathkeys = 0;
3512 if (activeWindows !=
NIL)
3529 if (
parse->distinctClause)
3535 root->distinct_pathkeys =
3537 &
root->processed_distinctClause,
3543 root->distinct_pathkeys =
NIL;
3546 root->distinct_pathkeys =
NIL;
3548 root->sort_pathkeys =
3554 if (qp_extra->
setop != NULL &&
3562 root->setop_pathkeys =
3595 if (
root->group_pathkeys)
3596 root->query_pathkeys =
root->group_pathkeys;
3597 else if (
root->window_pathkeys)
3598 root->query_pathkeys =
root->window_pathkeys;
3601 root->query_pathkeys =
root->distinct_pathkeys;
3602 else if (
root->sort_pathkeys)
3603 root->query_pathkeys =
root->sort_pathkeys;
3604 else if (
root->setop_pathkeys !=
NIL)
3605 root->query_pathkeys =
root->setop_pathkeys;
3630 if (
parse->groupClause)
3634 if (
parse->groupingSets)
3707 else if (
parse->groupingSets)
3712 else if (
parse->hasAggs ||
root->hasHavingQual)
3747 bool target_parallel_safe,
3763 target_parallel_safe,
parse->havingQual);
3812 root->numOrderedAggs == 0 &&
3822 extra.
flags = flags;
3840 &agg_costs, gd, &extra,
3841 &partially_grouped_rel);
3858 PathTarget *target,
bool target_parallel_safe,
3897 grouped_rel->fdwroutine = input_rel->fdwroutine;
3914 return (
root->hasHavingQual ||
parse->groupingSets) &&
3950 while (--nrows >= 0)
4030 root->parse->groupClause))
4045 bool force_rel_creation;
4054 partially_grouped_rel =
4060 force_rel_creation);
4064 *partially_grouped_rel_p = partially_grouped_rel;
4069 partially_grouped_rel, agg_costs,
4075 Assert(partially_grouped_rel);
4077 if (partially_grouped_rel->
pathlist)
4094 cheapest_path->
rows,
4100 partially_grouped_rel, agg_costs, gd,
4106 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4107 errmsg(
"could not implement GROUP BY"),
4108 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4114 if (grouped_rel->fdwroutine &&
4115 grouped_rel->fdwroutine->GetForeignUpperPaths)
4117 input_rel, grouped_rel,
4123 input_rel, grouped_rel,
4168 double exclude_groups = 0.0;
4192 if (l_start != NULL &&
4196 exclude_groups = unhashed_rollup->
numGroups;
4203 dNumGroups - exclude_groups);
4210 if (hashsize > hash_mem_limit && gd->
rollups)
4239 foreach(lc, sets_data)
4248 empty_sets_data =
lappend(empty_sets_data, gs);
4263 new_rollups =
lappend(new_rollups, rollup);
4271 if (new_rollups ==
NIL)
4278 Assert(!unhashed_rollup || !empty_sets);
4280 if (unhashed_rollup)
4282 new_rollups =
lappend(new_rollups, unhashed_rollup);
4285 else if (empty_sets)
4291 rollup->
gsets = empty_sets;
4295 new_rollups =
lappend(new_rollups, rollup);
4328 double availspace = hash_mem_limit;
4344 int *k_weights =
palloc(num_rollups *
sizeof(
int));
4370 scale =
Max(availspace / (20.0 * num_rollups), 1.0);
4371 k_capacity = (int) floor(availspace /
scale);
4395 k_weights[
i] = (int)
Min(floor(sz /
scale),
4425 rollups =
lappend(rollups, rollup);
4429 rollups =
lappend(rollups, rollup);
4434 if (!rollups && hash_sets)
4437 foreach(lc, hash_sets)
4452 rollups =
lcons(rollup, rollups);
4500 bool output_target_parallel_safe,
4502 List *activeWindows)
4525 window_rel->fdwroutine = input_rel->fdwroutine;
4554 if (window_rel->fdwroutine &&
4555 window_rel->fdwroutine->GetForeignUpperPaths)
4557 input_rel, window_rel,
4563 input_rel, window_rel, NULL);
4589 List *activeWindows)
4610 window_target = input_target;
4612 foreach(l, activeWindows)
4615 List *window_pathkeys;
4624 root->processed_tlist);
4657 if (
lnext(activeWindows, l))
4667 int64 tuple_width = window_target->
width;
4682 window_target = output_target;
4697 foreach(lc3, wfunc->runCondition)
4722 wfuncrc->inputcollid);
4724 runcondition =
lappend(runcondition, opexpr);
4727 topqual =
lappend(topqual, opexpr);
4735 topwindow ? topqual :
NIL, topwindow);
4776 distinct_rel->fdwroutine = input_rel->fdwroutine;
4787 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4788 errmsg(
"could not implement DISTINCT"),
4789 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4795 if (distinct_rel->fdwroutine &&
4796 distinct_rel->fdwroutine->GetForeignUpperPaths)
4797 distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4806 distinct_rel, NULL);
4811 return distinct_rel;
4829 List *distinctExprs;
4830 double numDistinctRows;
4831 Path *cheapest_partial_path;
4841 if (
parse->hasDistinctOn)
4846 partial_distinct_rel->
reltarget = target;
4855 partial_distinct_rel->fdwroutine = input_rel->fdwroutine;
4864 cheapest_partial_path->
rows,
4885 sorted_path = input_path;
4895 if (input_path != cheapest_partial_path &&
4906 partial_distinct_rel,
4908 root->distinct_pathkeys,
4912 partial_distinct_rel,
4914 root->distinct_pathkeys,
4923 if (
root->distinct_pathkeys ==
NIL)
4971 partial_distinct_rel,
4972 cheapest_partial_path,
4973 cheapest_partial_path->pathtarget,
4976 root->processed_distinctClause,
4986 if (partial_distinct_rel->fdwroutine &&
4987 partial_distinct_rel->fdwroutine->GetForeignUpperPaths)
4988 partial_distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4991 partial_distinct_rel,
4997 input_rel, partial_distinct_rel, NULL);
5010 final_distinct_rel);
5027 double numDistinctRows;
5032 root->hasHavingQual)
5039 numDistinctRows = cheapest_input_path->
rows;
5046 List *distinctExprs;
5051 cheapest_input_path->
rows,
5074 List *needed_pathkeys;
5076 double limittuples =
root->distinct_pathkeys ==
NIL ? 1.0 : -1.0;
5078 if (
parse->hasDistinctOn &&
5081 needed_pathkeys =
root->sort_pathkeys;
5083 needed_pathkeys =
root->distinct_pathkeys;
5097 sorted_path = input_path;
5107 if (input_path != cheapest_input_path &&
5143 if (
root->distinct_pathkeys ==
NIL)
5198 cheapest_input_path,
5199 cheapest_input_path->pathtarget,
5202 root->processed_distinctClause,
5208 return distinct_rel;
5232 bool target_parallel_safe,
5233 double limit_tuples)
5256 ordered_rel->fdwroutine = input_rel->fdwroutine;
5266 input_path->
pathkeys, &presorted_keys);
5269 sorted_path = input_path;
5279 if (input_path != cheapest_input_path &&
5292 root->sort_pathkeys,
5298 root->sort_pathkeys,
5304 if (sorted_path->pathtarget != target)
5306 sorted_path, target);
5308 add_path(ordered_rel, sorted_path);
5325 Path *cheapest_partial_path;
5335 double total_groups;
5351 if (input_path != cheapest_partial_path &&
5364 root->sort_pathkeys,
5370 root->sort_pathkeys,
5374 sorted_path = (
Path *)
5377 sorted_path->pathtarget,
5378 root->sort_pathkeys, NULL,
5382 if (sorted_path->pathtarget != target)
5384 sorted_path, target);
5386 add_path(ordered_rel, sorted_path);
5394 if (ordered_rel->fdwroutine &&
5395 ordered_rel->fdwroutine->GetForeignUpperPaths)
5397 input_rel, ordered_rel,
5403 input_rel, ordered_rel, NULL);
5447 List *non_group_cols;
5448 List *non_group_vars;
5457 non_group_cols =
NIL;
5460 foreach(lc, final_target->
exprs)
5465 if (sgref &&
root->processed_groupClause &&
5467 root->processed_groupClause) != NULL)
5480 non_group_cols =
lappend(non_group_cols, expr);
5489 if (
parse->havingQual)
5490 non_group_cols =
lappend(non_group_cols,
parse->havingQual);
5536 List *non_group_cols;
5537 List *non_group_exprs;
5542 non_group_cols =
NIL;
5545 foreach(lc, grouping_target->
exprs)
5550 if (sgref &&
root->processed_groupClause &&
5552 root->processed_groupClause) != NULL)
5566 non_group_cols =
lappend(non_group_cols, expr);
5576 non_group_cols =
lappend(non_group_cols, havingQual);
5597 foreach(lc, partial_target->
exprs)
5610 memcpy(newaggref, aggref,
sizeof(
Aggref));
5642 agg->aggsplit = aggsplit;
5652 agg->aggtype = BYTEAOID;
5654 agg->aggtype = agg->aggtranstype;
5674 foreach(l, new_tlist)
5680 if (new_tle->resjunk)
5683 Assert(orig_tlist_item != NULL);
5685 orig_tlist_item =
lnext(orig_tlist, orig_tlist_item);
5686 if (orig_tle->resjunk)
5687 elog(
ERROR,
"resjunk output columns are not implemented");
5691 if (orig_tlist_item != NULL)
5692 elog(
ERROR,
"resjunk output columns are not implemented");
5708 List *windowClause =
root->parse->windowClause;
5711 foreach(lc, windowClause)
5715 int optimizedFrameOptions = 0;
5736 req.
type = T_SupportRequestOptimizeWindowClause;
5758 optimizedFrameOptions =
res->frameOptions;
5765 else if (optimizedFrameOptions !=
res->frameOptions)
5770 if (lc2 == NULL && wc->
frameOptions != optimizedFrameOptions)
5790 foreach(lc3, windowClause)
5795 if (existing_wc == wc)
5848 List *windowClause =
root->parse->windowClause;
5856 foreach(lc, windowClause)
5865 actives[nActive].
wc = wc;
5909 for (
int i = 0;
i < nActive;
i++)
5910 result =
lappend(result, actives[
i].wc);
6005 List *activeWindows)
6009 List *flattenable_cols;
6010 List *flattenable_vars;
6021 foreach(lc, activeWindows)
6041 foreach(lc,
root->processed_groupClause)
6053 flattenable_cols =
NIL;
6056 foreach(lc, final_target->
exprs)
6080 flattenable_cols =
lappend(flattenable_cols, expr);
6131 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6132 errmsg(
"could not implement window PARTITION BY"),
6133 errdetail(
"Window partitioning columns must be of sortable datatypes.")));
6136 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6137 errmsg(
"could not implement window ORDER BY"),
6138 errdetail(
"Window ordering columns must be of sortable datatypes.")));
6167 List *orderby_pathkeys;
6174 if (window_pathkeys !=
NIL)
6177 window_pathkeys = orderby_pathkeys;
6180 return window_pathkeys;
6252 bool *have_postponed_srfs)
6261 bool have_expensive;
6262 bool have_srf_sortcols;
6264 List *postponable_cols;
6265 List *postponable_vars;
6272 *have_postponed_srfs =
false;
6276 col_is_srf = (
bool *)
palloc0(ncols *
sizeof(
bool));
6277 postpone_col = (
bool *)
palloc0(ncols *
sizeof(
bool));
6278 have_srf = have_volatile = have_expensive = have_srf_sortcols =
false;
6281 foreach(lc, final_target->
exprs)
6299 if (
parse->hasTargetSRFs &&
6303 col_is_srf[
i] =
true;
6309 postpone_col[
i] =
true;
6310 have_volatile =
true;
6330 postpone_col[
i] =
true;
6331 have_expensive =
true;
6338 if (!have_srf_sortcols &&
6339 parse->hasTargetSRFs &&
6341 have_srf_sortcols =
true;
6350 postpone_srfs = (have_srf && !have_srf_sortcols);
6355 if (!(postpone_srfs || have_volatile ||
6357 (
parse->limitCount ||
root->tuple_fraction > 0))))
6358 return final_target;
6366 *have_postponed_srfs = postpone_srfs;
6374 postponable_cols =
NIL;
6377 foreach(lc, final_target->
exprs)
6381 if (postpone_col[
i] || (postpone_srfs && col_is_srf[
i]))
6382 postponable_cols =
lappend(postponable_cols, expr);
6427 if (tuple_fraction <= 0.0)
6431 if (tuple_fraction >= 1.0 && best_path->
rows > 0)
6432 tuple_fraction /= best_path->
rows;
6465 List *targets,
List *targets_contain_srfs)
6494 forboth(lc1, targets, lc2, targets_contain_srfs)
6527 forboth(lc1, targets, lc2, targets_contain_srfs)
6593 return (
Expr *) result;
6608 List **relationOids,
6616 MemSet(&glob, 0,
sizeof(glob));
6617 glob.type = T_PlannerGlobal;
6622 root.type = T_PlannerInfo;
6644 return (
Expr *) result;
6669 Cost comparisonCost;
6671 Path seqScanAndSortPath;
6686 root->parse = query;
6688 root->query_level = 1;
6690 root->wt_param_id = -1;
6696 rte->
relid = tableOid;
6697 rte->relkind = RELKIND_RELATION;
6699 rte->lateral =
false;
6701 rte->inFromCl =
true;
6716 if (indexInfo->
indexoid == indexOid)
6789 int parallel_workers;
6808 root->parse = query;
6810 root->query_level = 1;
6812 root->wt_param_id = -1;
6825 rte->
relid = tableOid;
6826 rte->relkind = RELKIND_RELATION;
6828 rte->lateral =
false;
6830 rte->inFromCl =
true;
6851 if (heap->
rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
6855 parallel_workers = 0;
6896 while (parallel_workers > 0 &&
6904 return parallel_workers;
6915 Path *cheapest_path,
List *pathkeys)
6932 if (path != cheapest_path &&
6991 Path *path_save = path;
6992 List *pathkey_orderings =
NIL;
6999 foreach(lc2, pathkey_orderings)
7015 if (
parse->groupingSets)
7018 path,
true, can_hash,
7019 gd, agg_costs, dNumGroups);
7021 else if (
parse->hasAggs)
7039 else if (
parse->groupClause)
7065 if (partially_grouped_rel != NULL)
7067 foreach(lc, partially_grouped_rel->
pathlist)
7071 Path *path_save = path;
7072 List *pathkey_orderings =
NIL;
7080 foreach(lc2, pathkey_orderings)
7124 if (
parse->groupingSets)
7130 cheapest_path,
false,
true,
7131 gd, agg_costs, dNumGroups);
7145 root->processed_groupClause,
7155 if (partially_grouped_rel && partially_grouped_rel->
pathlist)
7166 root->processed_groupClause,
7205 bool force_rel_creation)
7211 Path *cheapest_partial_path = NULL;
7212 Path *cheapest_total_path = NULL;
7213 double dNumPartialGroups = 0;
7214 double dNumPartialPartialGroups = 0;
7243 if (cheapest_total_path == NULL &&
7244 cheapest_partial_path == NULL &&
7245 !force_rel_creation)
7261 partially_grouped_rel->fdwroutine = grouped_rel->fdwroutine;
7296 if (cheapest_total_path != NULL)
7299 cheapest_total_path->
rows,
7302 if (cheapest_partial_path != NULL)
7303 dNumPartialPartialGroups =
7305 cheapest_partial_path->
rows,
7309 if (can_sort && cheapest_total_path != NULL)
7322 Path *path_save = path;
7323 List *pathkey_orderings =
NIL;
7331 foreach(lc2, pathkey_orderings)
7339 partially_grouped_rel,
7341 cheapest_total_path,
7350 partially_grouped_rel,
7358 dNumPartialGroups));
7362 partially_grouped_rel,
7366 dNumPartialGroups));
7371 if (can_sort && cheapest_partial_path != NULL)
7378 Path *path_save = path;
7379 List *pathkey_orderings =
NIL;
7387 foreach(lc2, pathkey_orderings)
7396 partially_grouped_rel,
7398 cheapest_partial_path,
7407 partially_grouped_rel,
7415 dNumPartialPartialGroups));
7419 partially_grouped_rel,
7423 dNumPartialPartialGroups));
7431 if (can_hash && cheapest_total_path != NULL)
7438 partially_grouped_rel,
7439 cheapest_total_path,
7443 root->processed_groupClause,
7446 dNumPartialGroups));
7452 if (can_hash && cheapest_partial_path != NULL)
7456 partially_grouped_rel,
7457 cheapest_partial_path,
7461 root->processed_groupClause,
7464 dNumPartialPartialGroups));
7471 if (partially_grouped_rel->fdwroutine &&
7472 partially_grouped_rel->fdwroutine->GetForeignUpperPaths)
7474 FdwRoutine *fdwroutine = partially_grouped_rel->fdwroutine;
7478 input_rel, partially_grouped_rel,
7482 return partially_grouped_rel;
7502 Path *cheapest_partial_path;
7503 List *groupby_pathkeys;
7511 root->num_groupby_pathkeys);
7513 groupby_pathkeys =
root->group_pathkeys;
7526 double total_groups;
7541 if (path != cheapest_partial_path &&
7594 else if (
parse->groupingSets)
7599 else if (
root->hasNonPartialAggs ||
root->hasNonSerialAggs)
7626 List *scanjoin_targets,
7627 List *scanjoin_targets_contain_srfs,
7628 bool scanjoin_target_parallel_safe,
7657 if (rel_is_partitioned)
7664 if (!scanjoin_target_parallel_safe)
7683 if (rel_is_partitioned)
7706 subpath->pathtarget->sortgrouprefs =
7707 scanjoin_target->sortgrouprefs;
7727 subpath->pathtarget->sortgrouprefs =
7728 scanjoin_target->sortgrouprefs;
7745 if (
root->parse->hasTargetSRFs)
7748 scanjoin_targets_contain_srfs);
7770 if (rel_is_partitioned)
7782 List *child_scanjoin_targets =
NIL;
7784 Assert(child_rel != NULL);
7793 foreach(lc, scanjoin_targets)
7801 nappinfos, appinfos);
7802 child_scanjoin_targets =
lappend(child_scanjoin_targets,
7809 child_scanjoin_targets,
7810 scanjoin_targets_contain_srfs,
7811 scanjoin_target_parallel_safe,
7816 live_children =
lappend(live_children, child_rel);
7868 List *grouped_live_children =
NIL;
7869 List *partially_grouped_live_children =
NIL;
7871 bool partial_grouping_valid =
true;
7876 partially_grouped_rel != NULL);
7882 RelOptInfo *child_input_rel = input_rel->part_rels[
i];
7890 Assert(child_input_rel != NULL);
7902 memcpy(&child_extra, extra,
sizeof(child_extra));
7910 nappinfos, appinfos);
7916 nappinfos, appinfos);
7920 nappinfos, appinfos);
7927 child_extra.
patype = patype;
7941 agg_costs, gd, &child_extra,
7942 &child_partially_grouped_rel);
7944 if (child_partially_grouped_rel)
7946 partially_grouped_live_children =
7947 lappend(partially_grouped_live_children,
7948 child_partially_grouped_rel);
7951 partial_grouping_valid =
false;
7956 grouped_live_children =
lappend(grouped_live_children,
7972 if (partially_grouped_rel && partial_grouping_valid)
7974 Assert(partially_grouped_live_children !=
NIL);
7977 partially_grouped_live_children);
7983 if (partially_grouped_rel->
pathlist)
8012 Assert(input_rel->part_scheme);
8015 if (!input_rel->partexprs)
8018 partnatts = input_rel->part_scheme->partnatts;
8020 for (cnt = 0; cnt < partnatts; cnt++)
8022 List *partexprs = input_rel->partexprs[cnt];
8026 foreach(lc, partexprs)
8067 foreach(lt, targetlist)
8079 lg =
lnext(grouplist, lg);
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)
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, RelOptInfo *childrel, RelOptInfo *parentrel)
List * adjust_inherited_attnums_multilevel(PlannerInfo *root, List *attnums, Index child_relid, Index top_parent_relid)
void pprint(const void *obj)
void BipartiteMatchFree(BipartiteMatchState *state)
BipartiteMatchState * BipartiteMatch(int u_size, int v_size, short **adjacency)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
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_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
BMS_Membership bms_membership(const Bitmapset *a)
bool bms_overlap_list(const Bitmapset *a, const List *b)
#define Assert(condition)
#define MemSet(start, val, len)
#define OidIsValid(objectId)
WindowFuncLists * find_window_functions(Node *clause, Index maxWinRef)
bool contain_agg_clause(Node *clause)
void convert_saop_to_hashed_saop(Node *node)
char max_parallel_hazard(Query *parse)
bool is_parallel_safe(PlannerInfo *root, Node *node)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
bool contain_subplans(Node *clause)
bool contain_volatile_functions(Node *clause)
Node * estimate_expression_value(PlannerInfo *root, Node *node)
bool enable_partitionwise_aggregate
int max_parallel_workers_per_gather
double parallel_setup_cost
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
double parallel_tuple_cost
double compute_gather_rows(Path *path)
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
bool enable_presorted_aggregate
int32 clamp_width_est(int64 tuple_width)
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
bool enable_incremental_sort
Plan * create_plan(PlannerInfo *root, Path *best_path)
Plan * materialize_finished_plan(Plan *subplan)
static void PGresult * res
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
bool ExecSupportsBackwardScan(Plan *node)
Datum Int64GetDatum(int64 X)
#define OidFunctionCall1(functionId, arg1)
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
int max_parallel_maintenance_workers
#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 * list_delete_int(List *list, int datum)
List * list_concat_unique(List *list1, const List *list2)
List * lappend(List *list, void *datum)
List * list_difference_int(const List *list1, const List *list2)
List * list_copy_head(const List *oldlist, int len)
List * lappend_int(List *list, int datum)
List * list_copy(const List *oldlist)
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_concat(List *list1, const List *list2)
bool list_member(const List *list, const void *datum)
List * lcons(void *datum, List *list)
RegProcedure get_func_support(Oid funcid)
int32 get_typavgwidth(Oid typid, int32 typmod)
Datum subpath(PG_FUNCTION_ARGS)
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
List * make_ands_implicit(Expr *clause)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
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 PVC_RECURSE_AGGREGATES
#define PVC_RECURSE_WINDOWFUNCS
#define PVC_INCLUDE_WINDOWFUNCS
#define PVC_INCLUDE_PLACEHOLDERS
#define PVC_INCLUDE_AGGREGATES
int assign_special_exec_param(PlannerInfo *root)
List * expand_grouping_sets(List *groupingSets, bool groupDistinct, int limit)
Index assignSortGroupRef(TargetEntry *tle, List *tlist)
RTEPermissionInfo * addRTEPermissionInfo(List **rteperminfos, RangeTblEntry *rte)
#define CURSOR_OPT_SCROLL
#define CURSOR_OPT_FAST_PLAN
#define CURSOR_OPT_PARALLEL_OK
void CheckSelectLocking(Query *qry, LockClauseStrength strength)
const char * LCS_asString(LockClauseStrength strength)
#define rt_fetch(rangetable_index, rangetable)
void DestroyPartitionDirectory(PartitionDirectory pdir)
List * get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
List * append_pathkeys(List *target, List *source)
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 *sortable, bool set_ec_sortref)
bool pathkeys_contained_in(List *keys1, List *keys2)
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
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)
SortPath * create_sort_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
GroupResultPath * create_group_result_path(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *havingqual)
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)
LimitPath * create_limit_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, Node *limitOffset, Node *limitCount, LimitOption limitOption, int64 offset_est, int64 count_est)
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
GatherMergePath * create_gather_merge_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *pathkeys, Relids required_outer, double *rows)
UpperUniquePath * create_upper_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, int numCols, double numGroups)
LockRowsPath * create_lockrows_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *rowMarks, int epqParam)
void set_cheapest(RelOptInfo *parent_rel)
ProjectSetPath * create_set_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
GroupPath * create_group_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *groupClause, List *qual, double numGroups)
GroupingSetsPath * create_groupingsets_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *having_qual, AggStrategy aggstrategy, List *rollups, const AggClauseCosts *agg_costs)
IncrementalSortPath * create_incremental_sort_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, int presorted_keys, double limit_tuples)
WindowAggPath * create_windowagg_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *windowFuncs, List *runCondition, WindowClause *winclause, List *qual, bool topwindow)
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)
void add_path(RelOptInfo *parent_rel, Path *new_path)
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)
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)
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)
Bitmapset * get_primary_key_attnos(Oid relid, bool deferrableOk, Oid *constraintOid)
bool has_subclass(Oid relationId)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_current_index(var_or_cell)
#define for_each_cell(cell, lst, initcell)
static ListCell * list_head(const List *l)
#define for_each_from(cell, lst, N)
static void * list_nth(const List *list, int n)
#define list_nth_node(type, list, n)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make1_int(x1)
#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)
Expr * expression_planner(Expr *expr)
static PathTarget * make_partial_grouping_target(PlannerInfo *root, PathTarget *grouping_target, Node *havingQual)
static void gather_grouping_paths(PlannerInfo *root, RelOptInfo *rel)
static void preprocess_rowmarks(PlannerInfo *root)
#define EXPRKIND_TABLESAMPLE
PlannerInfo * subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction, SetOperationStmt *setops)
static void create_degenerate_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *grouped_rel)
planner_hook_type planner_hook
double cursor_tuple_fraction
static bool is_degenerate_grouping(PlannerInfo *root)
static void remove_useless_groupby_columns(PlannerInfo *root)
bool plan_cluster_use_sort(Oid tableOid, Oid indexOid)
static void preprocess_qual_conditions(PlannerInfo *root, Node *jtnode)
int plan_create_index_workers(Oid tableOid, Oid indexOid)
#define EXPRKIND_RTFUNC_LATERAL
#define EXPRKIND_VALUES_LATERAL
static void create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel, RelOptInfo *grouped_rel, const AggClauseCosts *agg_costs, grouping_sets_data *gd, GroupPathExtraData *extra, RelOptInfo **partially_grouped_rel_p)
static bool can_partial_agg(PlannerInfo *root)
static double preprocess_limit(PlannerInfo *root, double tuple_fraction, int64 *offset_est, int64 *count_est)
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)
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 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)
PlannedStmt * planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
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)
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 * preprocess_phv_expression(PlannerInfo *root, Expr *expr)
bool limit_needed(Query *parse)
create_upper_paths_hook_type create_upper_paths_hook
#define EXPRKIND_TABLEFUNC
static void consider_groupingsets_paths(PlannerInfo *root, RelOptInfo *grouped_rel, Path *path, bool is_sorted, bool can_hash, grouping_sets_data *gd, const AggClauseCosts *agg_costs, double dNumGroups)
Expr * expression_planner_with_deps(Expr *expr, List **relationOids, List **invalItems)
static Path * make_ordered_path(PlannerInfo *root, RelOptInfo *rel, Path *path, Path *cheapest_path, List *pathkeys)
PlannedStmt * standard_planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
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)
Path * get_cheapest_fractional_path(RelOptInfo *rel, double tuple_fraction)
#define EXPRKIND_ARBITER_ELEM
static bool group_by_has_partkey(RelOptInfo *input_rel, List *targetList, List *groupClause)
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)
void check_stack_depth(void)
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)
void reduce_outer_joins(PlannerInfo *root)
Expr * canonicalize_qual(Expr *qual, bool is_check)
void preprocess_targetlist(PlannerInfo *root)
bool set_operation_ordered_results_useful(SetOperationStmt *setop)
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)
void setup_simple_rel_arrays(PlannerInfo *root)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids 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)
GetForeignRowMarkType_function GetForeignRowMarkType
GetForeignUpperPaths_function GetForeignUpperPaths
LockClauseStrength strength
LockWaitPolicy waitPolicy
Bitmapset * rewindPlanIDs
Bitmapset * rewindPlanIDs
struct TableSampleClause * tablesample
struct PathTarget * reltarget
struct Path * cheapest_startup_path
struct Path * cheapest_total_path
LockClauseStrength strength
LockWaitPolicy waitPolicy
struct WindowClause * window_clause
int * tleref_to_colnum_map
Bitmapset * unhashable_refs
Bitmapset * unsortable_refs
grouping_sets_data * gset_data
void SS_process_ctes(PlannerInfo *root)
void SS_identify_outer_params(PlannerInfo *root)
void SS_finalize_plan(PlannerInfo *root, Plan *plan)
Node * SS_replace_correlation_vars(PlannerInfo *root, Node *expr)
Node * SS_process_sublinks(PlannerInfo *root, Node *expr, bool isQual)
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)
#define FirstLowInvalidHeapAttributeNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
List * get_sortgrouplist_exprs(List *sgClauses, List *targetList)
bool tlist_same_exprs(List *tlist1, List *tlist2)
PathTarget * copy_pathtarget(PathTarget *src)
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
bool grouping_is_sortable(List *groupClause)
void add_new_columns_to_pathtarget(PathTarget *target, List *exprs)
PathTarget * create_empty_pathtarget(void)
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
SortGroupClause * get_sortgroupref_clause(Index sortref, List *clauses)
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)
List * pull_var_clause(Node *node, int flags)
Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)