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)
874 (
Node *) wc->runCondition,
883 if (
parse->onConflict)
885 parse->onConflict->arbiterElems = (
List *)
887 (
Node *)
parse->onConflict->arbiterElems,
889 parse->onConflict->arbiterWhere =
891 parse->onConflict->arbiterWhere,
893 parse->onConflict->onConflictSet = (
List *)
895 (
Node *)
parse->onConflict->onConflictSet,
897 parse->onConflict->onConflictWhere =
899 parse->onConflict->onConflictWhere,
904 foreach(l,
parse->mergeActionList)
918 parse->mergeJoinCondition =
926 foreach(l,
parse->rtable)
949 if (rte->lateral &&
root->hasJoinRTEs)
982 foreach(lcsq, rte->securityQuals)
1001 if (
root->hasJoinRTEs)
1003 foreach(l,
parse->rtable)
1007 rte->joinaliasvars =
NIL;
1047 if ((
parse->groupClause &&
parse->groupingSets) ||
1053 newHaving =
lappend(newHaving, havingclause);
1055 else if (
parse->groupClause && !
parse->groupingSets)
1067 newHaving =
lappend(newHaving, havingclause);
1086 if (hasResultRTEs || hasOuterJoins)
1145 if (
root->hasJoinRTEs &&
1181 #ifdef OPTIMIZER_DEBUG
1182 printf(
"After canonicalize_qual()\n");
1198 if (
root->parse->hasSubLinks)
1207 if (
root->query_level > 1)
1256 elog(
ERROR,
"unrecognized node type: %d",
1309 int64 offset_est = 0;
1310 int64 count_est = 0;
1311 double limit_tuples = -1.0;
1312 bool have_postponed_srfs =
false;
1314 List *final_targets;
1315 List *final_targets_contain_srfs;
1316 bool final_target_parallel_safe;
1326 &offset_est, &count_est);
1332 if (count_est > 0 && offset_est >= 0)
1333 limit_tuples = (double) count_est + (
double) offset_est;
1337 root->tuple_fraction = tuple_fraction;
1339 if (
parse->setOperations)
1359 root->processed_tlist =
1367 final_target_parallel_safe =
1372 final_targets = final_targets_contain_srfs =
NIL;
1378 if (
parse->rowMarks)
1380 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1383 errmsg(
"%s is not allowed with UNION/INTERSECT/EXCEPT",
1385 parse->rowMarks)->strength))));
1393 root->processed_tlist);
1399 List *sort_input_targets;
1400 List *sort_input_targets_contain_srfs;
1401 bool sort_input_target_parallel_safe;
1403 List *grouping_targets;
1404 List *grouping_targets_contain_srfs;
1405 bool grouping_target_parallel_safe;
1407 List *scanjoin_targets;
1408 List *scanjoin_targets_contain_srfs;
1409 bool scanjoin_target_parallel_safe;
1410 bool scanjoin_target_same_exprs;
1421 if (
parse->groupingSets)
1425 else if (
parse->groupClause)
1461 if (
parse->hasWindowFuncs)
1477 parse->hasWindowFuncs =
false;
1495 if (
parse->groupClause ||
1496 parse->groupingSets ||
1497 parse->distinctClause ||
1499 parse->hasWindowFuncs ||
1500 parse->hasTargetSRFs ||
1501 root->hasHavingQual)
1502 root->limit_tuples = -1.0;
1504 root->limit_tuples = limit_tuples;
1514 qp_extra.
setop = setops;
1535 final_target_parallel_safe =
1543 if (
parse->sortClause)
1547 &have_postponed_srfs);
1548 sort_input_target_parallel_safe =
1553 sort_input_target = final_target;
1554 sort_input_target_parallel_safe = final_target_parallel_safe;
1567 grouping_target_parallel_safe =
1572 grouping_target = sort_input_target;
1573 grouping_target_parallel_safe = sort_input_target_parallel_safe;
1581 have_grouping = (
parse->groupClause ||
parse->groupingSets ||
1586 scanjoin_target_parallel_safe =
1591 scanjoin_target = grouping_target;
1592 scanjoin_target_parallel_safe = grouping_target_parallel_safe;
1601 if (
parse->hasTargetSRFs)
1606 &final_targets_contain_srfs);
1611 &sort_input_targets,
1612 &sort_input_targets_contain_srfs);
1618 &grouping_targets_contain_srfs);
1624 &scanjoin_targets_contain_srfs);
1631 final_targets = final_targets_contain_srfs =
NIL;
1632 sort_input_targets = sort_input_targets_contain_srfs =
NIL;
1633 grouping_targets = grouping_targets_contain_srfs =
NIL;
1634 scanjoin_targets =
list_make1(scanjoin_target);
1635 scanjoin_targets_contain_srfs =
NIL;
1639 scanjoin_target_same_exprs =
list_length(scanjoin_targets) == 1
1642 scanjoin_targets_contain_srfs,
1643 scanjoin_target_parallel_safe,
1644 scanjoin_target_same_exprs);
1670 grouping_target_parallel_safe,
1673 if (
parse->hasTargetSRFs)
1676 grouping_targets_contain_srfs);
1689 sort_input_target_parallel_safe,
1693 if (
parse->hasTargetSRFs)
1696 sort_input_targets_contain_srfs);
1703 if (
parse->distinctClause)
1718 if (
parse->sortClause)
1723 final_target_parallel_safe,
1724 have_postponed_srfs ? -1.0 :
1727 if (
parse->hasTargetSRFs)
1730 final_targets_contain_srfs);
1756 final_rel->fdwroutine = current_rel->fdwroutine;
1773 if (
parse->rowMarks)
1789 offset_est, count_est);
1799 List *updateColnosLists =
NIL;
1800 List *withCheckOptionLists =
NIL;
1803 List *mergeJoinConditions =
NIL;
1810 parse->resultRelation);
1811 int resultRelation = -1;
1814 rootRelation =
parse->resultRelation;
1818 resultRelation)) >= 0)
1836 List *update_colnos =
root->update_colnos;
1838 if (this_result_rel != top_result_rel)
1842 this_result_rel->
relid,
1843 top_result_rel->
relid);
1844 updateColnosLists =
lappend(updateColnosLists,
1847 if (
parse->withCheckOptions)
1849 List *withCheckOptions =
parse->withCheckOptions;
1851 if (this_result_rel != top_result_rel)
1852 withCheckOptions = (
List *)
1854 (
Node *) withCheckOptions,
1857 withCheckOptionLists =
lappend(withCheckOptionLists,
1860 if (
parse->returningList)
1862 List *returningList =
parse->returningList;
1864 if (this_result_rel != top_result_rel)
1865 returningList = (
List *)
1867 (
Node *) returningList,
1870 returningLists =
lappend(returningLists,
1873 if (
parse->mergeActionList)
1882 foreach(l,
parse->mergeActionList)
1892 leaf_action->targetList = (
List *)
1898 leaf_action->updateColnos =
1901 this_result_rel->
relid,
1902 top_result_rel->
relid);
1903 mergeActionList =
lappend(mergeActionList,
1907 mergeActionLists =
lappend(mergeActionLists,
1912 Node *mergeJoinCondition =
parse->mergeJoinCondition;
1914 if (this_result_rel != top_result_rel)
1915 mergeJoinCondition =
1920 mergeJoinConditions =
lappend(mergeJoinConditions,
1921 mergeJoinCondition);
1925 if (resultRelations ==
NIL)
1941 if (
parse->withCheckOptions)
1943 if (
parse->returningList)
1945 if (
parse->mergeActionList)
1958 if (
parse->withCheckOptions)
1960 if (
parse->returningList)
1962 if (
parse->mergeActionList)
1973 if (
parse->rowMarks)
1976 rowMarks =
root->rowMarks;
1983 parse->resultRelation,
1985 root->partColsUpdated,
1988 withCheckOptionLists,
1993 mergeJoinConditions,
2026 if (final_rel->fdwroutine &&
2027 final_rel->fdwroutine->GetForeignUpperPaths)
2029 current_rel, final_rel,
2035 current_rel, final_rel, &extra);
2066 root->processed_groupClause =
parse->groupClause;
2068 if (
parse->groupClause)
2072 foreach(lc,
parse->groupClause)
2102 foreach(lc,
parse->groupingSets)
2123 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2124 errmsg(
"could not implement GROUP BY"),
2125 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
2128 sortable_sets =
lappend(sortable_sets, gset);
2139 foreach(lc_set, sets)
2230 int *tleref_to_colnum_map)
2236 foreach(lc, groupClause)
2249 foreach(lc2, gs->
set)
2254 result =
lappend(result, set);
2273 if (
parse->rowMarks)
2282 parse->rowMarks)->strength);
2302 if (
parse->resultRelation)
2309 foreach(l,
parse->rowMarks)
2342 prowmarks =
lappend(prowmarks, newrc);
2349 foreach(l,
parse->rtable)
2367 prowmarks =
lappend(prowmarks, newrc);
2370 root->rowMarks = prowmarks;
2384 else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2420 elog(
ERROR,
"unrecognized LockClauseStrength %d", (
int) strength);
2444 int64 *offset_est, int64 *count_est)
2448 double limit_fraction;
2457 if (
parse->limitCount)
2462 if (((
Const *) est)->constisnull)
2470 if (*count_est <= 0)
2480 if (
parse->limitOffset)
2485 if (((
Const *) est)->constisnull)
2493 if (*offset_est < 0)
2503 if (*count_est != 0)
2510 if (*count_est < 0 || *offset_est < 0)
2513 limit_fraction = 0.10;
2518 limit_fraction = (double) *count_est + (
double) *offset_est;
2528 if (tuple_fraction >= 1.0)
2530 if (limit_fraction >= 1.0)
2533 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2540 else if (tuple_fraction > 0.0)
2542 if (limit_fraction >= 1.0)
2545 tuple_fraction = limit_fraction;
2550 tuple_fraction =
Min(tuple_fraction, limit_fraction);
2556 tuple_fraction = limit_fraction;
2559 else if (*offset_est != 0 && tuple_fraction > 0.0)
2570 if (*offset_est < 0)
2571 limit_fraction = 0.10;
2573 limit_fraction = (double) *offset_est;
2581 if (tuple_fraction >= 1.0)
2583 if (limit_fraction >= 1.0)
2586 tuple_fraction += limit_fraction;
2591 tuple_fraction = limit_fraction;
2596 if (limit_fraction >= 1.0)
2603 tuple_fraction += limit_fraction;
2604 if (tuple_fraction >= 1.0)
2605 tuple_fraction = 0.0;
2610 return tuple_fraction;
2632 node =
parse->limitCount;
2638 if (!((
Const *) node)->constisnull)
2645 node =
parse->limitOffset;
2651 if (!((
Const *) node)->constisnull)
2700 if (
parse->groupingSets)
2710 foreach(lc,
root->processed_groupClause)
2743 foreach(lc,
parse->rtable)
2761 if (rte->
inh && rte->relkind != RELKIND_PARTITIONED_TABLE)
2765 relattnos = groupbyattnos[relid];
2774 if (pkattnos == NULL)
2787 if (surplusvars == NULL)
2801 if (surplusvars != NULL)
2805 foreach(lc,
root->processed_groupClause)
2818 surplusvars[var->
varno]))
2819 new_groupby =
lappend(new_groupby, sgc);
2822 root->processed_groupClause = new_groupby;
2843 new_groupclause =
lappend(new_groupclause, cl);
2845 return new_groupclause;
2880 short *adjacency_buf;
2896 lc1 =
lnext(groupingSets, lc1);
2921 orig_sets =
palloc0((num_sets_raw + 1) *
sizeof(
List *));
2923 adjacency =
palloc0((num_sets_raw + 1) *
sizeof(
short *));
2924 adjacency_buf =
palloc((num_sets_raw + 1) *
sizeof(
short));
2937 foreach(lc2, candidate)
2947 for (k =
j; k <
i; ++k)
2949 if (
bms_equal(set_masks[k], candidate_set))
2964 orig_sets[dup_of] =
lappend(orig_sets[dup_of], candidate);
2973 set_masks[
i] = candidate_set;
2977 for (k =
j - 1; k > 0; --k)
2980 adjacency_buf[++n_adj] = k;
2985 adjacency_buf[0] = n_adj;
2986 adjacency[
i] =
palloc((n_adj + 1) *
sizeof(
short));
2987 memcpy(adjacency[
i], adjacency_buf, (n_adj + 1) *
sizeof(
short));
2990 adjacency[
i] = NULL;
3009 chains =
palloc0((num_sets + 1) *
sizeof(
int));
3011 for (
i = 1;
i <= num_sets; ++
i)
3013 int u =
state->pair_vu[
i];
3014 int v =
state->pair_uv[
i];
3017 chains[
i] = chains[u];
3018 else if (v > 0 && v <
i)
3019 chains[
i] = chains[v];
3021 chains[
i] = ++num_chains;
3025 results =
palloc0((num_chains + 1) *
sizeof(
List *));
3027 for (
i = 1;
i <= num_sets; ++
i)
3037 while (num_empty-- > 0)
3038 results[1] =
lcons(
NIL, results[1]);
3041 for (
i = 1;
i <= num_chains; ++
i)
3042 result =
lappend(result, results[
i]);
3053 for (
i = 1;
i <= num_sets; ++
i)
3057 pfree(adjacency_buf);
3059 for (
i = 1;
i <= num_sets; ++
i)
3086 foreach(lc, groupingSets)
3114 result =
lcons(gs, result);
3136 if (pathkey->pk_eclass->ec_has_volatile)
3175 List *grouppathkeys =
root->group_pathkeys;
3195 unprocessed_aggs = NULL;
3196 foreach(lc,
root->agginfos)
3201 if (AGGKIND_IS_ORDERED_SET(aggref->aggkind))
3262 if (currpathkeys ==
NIL)
3264 currpathkeys = pathkeys;
3267 if (grouppathkeys !=
NIL)
3279 if (grouppathkeys !=
NIL)
3288 currpathkeys = pathkeys;
3315 bestaggs = aggindexes;
3316 bestpathkeys = currpathkeys;
3325 if (bestpathkeys !=
NIL)
3326 root->group_pathkeys = bestpathkeys;
3345 aggref->aggpresorted =
true;
3358 List *tlist =
root->processed_tlist;
3386 root->num_groupby_pathkeys = 0;
3389 else if (
parse->groupClause ||
root->numOrderedAggs > 0)
3401 root->group_pathkeys =
3403 &
root->processed_groupClause,
3411 root->num_groupby_pathkeys = 0;
3417 if (
root->numOrderedAggs > 0)
3424 root->num_groupby_pathkeys = 0;
3428 if (activeWindows !=
NIL)
3445 if (
parse->distinctClause)
3451 root->distinct_pathkeys =
3453 &
root->processed_distinctClause,
3458 root->distinct_pathkeys =
NIL;
3461 root->distinct_pathkeys =
NIL;
3463 root->sort_pathkeys =
3469 if (qp_extra->
setop != NULL &&
3477 root->setop_pathkeys =
3509 if (
root->group_pathkeys)
3510 root->query_pathkeys =
root->group_pathkeys;
3511 else if (
root->window_pathkeys)
3512 root->query_pathkeys =
root->window_pathkeys;
3515 root->query_pathkeys =
root->distinct_pathkeys;
3516 else if (
root->sort_pathkeys)
3517 root->query_pathkeys =
root->sort_pathkeys;
3518 else if (
root->setop_pathkeys !=
NIL)
3519 root->query_pathkeys =
root->setop_pathkeys;
3544 if (
parse->groupClause)
3548 if (
parse->groupingSets)
3621 else if (
parse->groupingSets)
3626 else if (
parse->hasAggs ||
root->hasHavingQual)
3661 bool target_parallel_safe,
3677 target_parallel_safe,
parse->havingQual);
3726 root->numOrderedAggs == 0 &&
3736 extra.
flags = flags;
3754 &agg_costs, gd, &extra,
3755 &partially_grouped_rel);
3772 PathTarget *target,
bool target_parallel_safe,
3811 grouped_rel->fdwroutine = input_rel->fdwroutine;
3828 return (
root->hasHavingQual ||
parse->groupingSets) &&
3864 while (--nrows >= 0)
3944 root->parse->groupClause))
3959 bool force_rel_creation;
3968 partially_grouped_rel =
3974 force_rel_creation);
3978 *partially_grouped_rel_p = partially_grouped_rel;
3983 partially_grouped_rel, agg_costs,
3989 Assert(partially_grouped_rel);
3991 if (partially_grouped_rel->
pathlist)
4008 cheapest_path->
rows,
4014 partially_grouped_rel, agg_costs, gd,
4020 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4021 errmsg(
"could not implement GROUP BY"),
4022 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4028 if (grouped_rel->fdwroutine &&
4029 grouped_rel->fdwroutine->GetForeignUpperPaths)
4031 input_rel, grouped_rel,
4037 input_rel, grouped_rel,
4082 double exclude_groups = 0.0;
4106 if (l_start != NULL &&
4110 exclude_groups = unhashed_rollup->
numGroups;
4117 dNumGroups - exclude_groups);
4124 if (hashsize > hash_mem_limit && gd->
rollups)
4153 foreach(lc, sets_data)
4162 empty_sets_data =
lappend(empty_sets_data, gs);
4177 new_rollups =
lappend(new_rollups, rollup);
4185 if (new_rollups ==
NIL)
4192 Assert(!unhashed_rollup || !empty_sets);
4194 if (unhashed_rollup)
4196 new_rollups =
lappend(new_rollups, unhashed_rollup);
4199 else if (empty_sets)
4205 rollup->
gsets = empty_sets;
4209 new_rollups =
lappend(new_rollups, rollup);
4242 double availspace = hash_mem_limit;
4258 int *k_weights =
palloc(num_rollups *
sizeof(
int));
4284 scale =
Max(availspace / (20.0 * num_rollups), 1.0);
4285 k_capacity = (int) floor(availspace /
scale);
4309 k_weights[
i] = (int)
Min(floor(sz /
scale),
4339 rollups =
lappend(rollups, rollup);
4343 rollups =
lappend(rollups, rollup);
4348 if (!rollups && hash_sets)
4351 foreach(lc, hash_sets)
4366 rollups =
lcons(rollup, rollups);
4414 bool output_target_parallel_safe,
4416 List *activeWindows)
4439 window_rel->fdwroutine = input_rel->fdwroutine;
4468 if (window_rel->fdwroutine &&
4469 window_rel->fdwroutine->GetForeignUpperPaths)
4471 input_rel, window_rel,
4477 input_rel, window_rel, NULL);
4503 List *activeWindows)
4524 window_target = input_target;
4526 foreach(l, activeWindows)
4529 List *window_pathkeys;
4536 root->processed_tlist);
4569 if (
lnext(activeWindows, l))
4579 int64 tuple_width = window_target->
width;
4595 window_target = output_target;
4612 wc, topwindow ? topqual :
NIL, topwindow);
4653 distinct_rel->fdwroutine = input_rel->fdwroutine;
4664 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4665 errmsg(
"could not implement DISTINCT"),
4666 errdetail(
"Some of the datatypes only support hashing, while others only support sorting.")));
4672 if (distinct_rel->fdwroutine &&
4673 distinct_rel->fdwroutine->GetForeignUpperPaths)
4674 distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4683 distinct_rel, NULL);
4688 return distinct_rel;
4706 List *distinctExprs;
4707 double numDistinctRows;
4708 Path *cheapest_partial_path;
4718 if (
parse->hasDistinctOn)
4723 partial_distinct_rel->
reltarget = target;
4732 partial_distinct_rel->fdwroutine = input_rel->fdwroutine;
4741 cheapest_partial_path->
rows,
4762 sorted_path = input_path;
4772 if (input_path != cheapest_partial_path &&
4783 partial_distinct_rel,
4785 root->distinct_pathkeys,
4789 partial_distinct_rel,
4791 root->distinct_pathkeys,
4800 if (
root->distinct_pathkeys ==
NIL)
4848 partial_distinct_rel,
4849 cheapest_partial_path,
4850 cheapest_partial_path->pathtarget,
4853 root->processed_distinctClause,
4863 if (partial_distinct_rel->fdwroutine &&
4864 partial_distinct_rel->fdwroutine->GetForeignUpperPaths)
4865 partial_distinct_rel->fdwroutine->GetForeignUpperPaths(
root,
4868 partial_distinct_rel,
4874 input_rel, partial_distinct_rel, NULL);
4887 final_distinct_rel);
4904 double numDistinctRows;
4909 root->hasHavingQual)
4916 numDistinctRows = cheapest_input_path->
rows;
4923 List *distinctExprs;
4928 cheapest_input_path->
rows,
4951 List *needed_pathkeys;
4953 double limittuples =
root->distinct_pathkeys ==
NIL ? 1.0 : -1.0;
4955 if (
parse->hasDistinctOn &&
4958 needed_pathkeys =
root->sort_pathkeys;
4960 needed_pathkeys =
root->distinct_pathkeys;
4974 sorted_path = input_path;
4984 if (input_path != cheapest_input_path &&
5020 if (
root->distinct_pathkeys ==
NIL)
5075 cheapest_input_path,
5076 cheapest_input_path->pathtarget,
5079 root->processed_distinctClause,
5085 return distinct_rel;
5109 bool target_parallel_safe,
5110 double limit_tuples)
5133 ordered_rel->fdwroutine = input_rel->fdwroutine;
5143 input_path->
pathkeys, &presorted_keys);
5146 sorted_path = input_path;
5156 if (input_path != cheapest_input_path &&
5169 root->sort_pathkeys,
5175 root->sort_pathkeys,
5181 if (sorted_path->pathtarget != target)
5183 sorted_path, target);
5185 add_path(ordered_rel, sorted_path);
5202 Path *cheapest_partial_path;
5212 double total_groups;
5228 if (input_path != cheapest_partial_path &&
5241 root->sort_pathkeys,
5247 root->sort_pathkeys,
5250 total_groups = input_path->
rows *
5252 sorted_path = (
Path *)
5255 sorted_path->pathtarget,
5256 root->sort_pathkeys, NULL,
5260 if (sorted_path->pathtarget != target)
5262 sorted_path, target);
5264 add_path(ordered_rel, sorted_path);
5272 if (ordered_rel->fdwroutine &&
5273 ordered_rel->fdwroutine->GetForeignUpperPaths)
5275 input_rel, ordered_rel,
5281 input_rel, ordered_rel, NULL);
5325 List *non_group_cols;
5326 List *non_group_vars;
5335 non_group_cols =
NIL;
5338 foreach(lc, final_target->
exprs)
5343 if (sgref &&
root->processed_groupClause &&
5345 root->processed_groupClause) != NULL)
5358 non_group_cols =
lappend(non_group_cols, expr);
5367 if (
parse->havingQual)
5368 non_group_cols =
lappend(non_group_cols,
parse->havingQual);
5414 List *non_group_cols;
5415 List *non_group_exprs;
5420 non_group_cols =
NIL;
5423 foreach(lc, grouping_target->
exprs)
5428 if (sgref &&
root->processed_groupClause &&
5430 root->processed_groupClause) != NULL)
5444 non_group_cols =
lappend(non_group_cols, expr);
5454 non_group_cols =
lappend(non_group_cols, havingQual);
5475 foreach(lc, partial_target->
exprs)
5488 memcpy(newaggref, aggref,
sizeof(
Aggref));
5520 agg->aggsplit = aggsplit;
5530 agg->aggtype = BYTEAOID;
5532 agg->aggtype = agg->aggtranstype;
5552 foreach(l, new_tlist)
5558 if (new_tle->resjunk)
5561 Assert(orig_tlist_item != NULL);
5563 orig_tlist_item =
lnext(orig_tlist, orig_tlist_item);
5564 if (orig_tle->resjunk)
5565 elog(
ERROR,
"resjunk output columns are not implemented");
5569 if (orig_tlist_item != NULL)
5570 elog(
ERROR,
"resjunk output columns are not implemented");
5586 List *windowClause =
root->parse->windowClause;
5589 foreach(lc, windowClause)
5593 int optimizedFrameOptions = 0;
5614 req.
type = T_SupportRequestOptimizeWindowClause;
5636 optimizedFrameOptions =
res->frameOptions;
5643 else if (optimizedFrameOptions !=
res->frameOptions)
5648 if (lc2 == NULL && wc->
frameOptions != optimizedFrameOptions)
5668 foreach(lc3, windowClause)
5673 if (existing_wc == wc)
5726 List *windowClause =
root->parse->windowClause;
5734 foreach(lc, windowClause)
5743 actives[nActive].
wc = wc;
5787 for (
int i = 0;
i < nActive;
i++)
5788 result =
lappend(result, actives[
i].wc);
5883 List *activeWindows)
5887 List *flattenable_cols;
5888 List *flattenable_vars;
5899 foreach(lc, activeWindows)
5919 foreach(lc,
root->processed_groupClause)
5931 flattenable_cols =
NIL;
5934 foreach(lc, final_target->
exprs)
5958 flattenable_cols =
lappend(flattenable_cols, expr);
6009 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6010 errmsg(
"could not implement window PARTITION BY"),
6011 errdetail(
"Window partitioning columns must be of sortable datatypes.")));
6014 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
6015 errmsg(
"could not implement window ORDER BY"),
6016 errdetail(
"Window ordering columns must be of sortable datatypes.")));
6044 List *orderby_pathkeys;
6051 if (window_pathkeys !=
NIL)
6054 window_pathkeys = orderby_pathkeys;
6057 return window_pathkeys;
6129 bool *have_postponed_srfs)
6138 bool have_expensive;
6139 bool have_srf_sortcols;
6141 List *postponable_cols;
6142 List *postponable_vars;
6149 *have_postponed_srfs =
false;
6153 col_is_srf = (
bool *)
palloc0(ncols *
sizeof(
bool));
6154 postpone_col = (
bool *)
palloc0(ncols *
sizeof(
bool));
6155 have_srf = have_volatile = have_expensive = have_srf_sortcols =
false;
6158 foreach(lc, final_target->
exprs)
6176 if (
parse->hasTargetSRFs &&
6180 col_is_srf[
i] =
true;
6186 postpone_col[
i] =
true;
6187 have_volatile =
true;
6207 postpone_col[
i] =
true;
6208 have_expensive =
true;
6215 if (!have_srf_sortcols &&
6216 parse->hasTargetSRFs &&
6218 have_srf_sortcols =
true;
6227 postpone_srfs = (have_srf && !have_srf_sortcols);
6232 if (!(postpone_srfs || have_volatile ||
6234 (
parse->limitCount ||
root->tuple_fraction > 0))))
6235 return final_target;
6243 *have_postponed_srfs = postpone_srfs;
6251 postponable_cols =
NIL;
6254 foreach(lc, final_target->
exprs)
6258 if (postpone_col[
i] || (postpone_srfs && col_is_srf[
i]))
6259 postponable_cols =
lappend(postponable_cols, expr);
6304 if (tuple_fraction <= 0.0)
6308 if (tuple_fraction >= 1.0 && best_path->
rows > 0)
6309 tuple_fraction /= best_path->
rows;
6342 List *targets,
List *targets_contain_srfs)
6371 forboth(lc1, targets, lc2, targets_contain_srfs)
6404 forboth(lc1, targets, lc2, targets_contain_srfs)
6470 return (
Expr *) result;
6485 List **relationOids,
6493 MemSet(&glob, 0,
sizeof(glob));
6494 glob.type = T_PlannerGlobal;
6499 root.type = T_PlannerInfo;
6521 return (
Expr *) result;
6546 Cost comparisonCost;
6548 Path seqScanAndSortPath;
6563 root->parse = query;
6565 root->query_level = 1;
6567 root->wt_param_id = -1;
6573 rte->
relid = tableOid;
6574 rte->relkind = RELKIND_RELATION;
6576 rte->lateral =
false;
6578 rte->inFromCl =
true;
6593 if (indexInfo->
indexoid == indexOid)
6666 int parallel_workers;
6685 root->parse = query;
6687 root->query_level = 1;
6689 root->wt_param_id = -1;
6702 rte->
relid = tableOid;
6703 rte->relkind = RELKIND_RELATION;
6705 rte->lateral =
false;
6707 rte->inFromCl =
true;
6728 if (heap->
rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
6732 parallel_workers = 0;
6773 while (parallel_workers > 0 &&
6781 return parallel_workers;
6792 Path *cheapest_path,
List *pathkeys)
6809 if (path != cheapest_path &&
6868 Path *path_save = path;
6869 List *pathkey_orderings =
NIL;
6876 foreach(lc2, pathkey_orderings)
6892 if (
parse->groupingSets)
6895 path,
true, can_hash,
6896 gd, agg_costs, dNumGroups);
6898 else if (
parse->hasAggs)
6916 else if (
parse->groupClause)
6942 if (partially_grouped_rel != NULL)
6944 foreach(lc, partially_grouped_rel->
pathlist)
6948 Path *path_save = path;
6949 List *pathkey_orderings =
NIL;
6957 foreach(lc2, pathkey_orderings)
7001 if (
parse->groupingSets)
7007 cheapest_path,
false,
true,
7008 gd, agg_costs, dNumGroups);
7022 root->processed_groupClause,
7032 if (partially_grouped_rel && partially_grouped_rel->
pathlist)
7043 root->processed_groupClause,
7082 bool force_rel_creation)
7088 Path *cheapest_partial_path = NULL;
7089 Path *cheapest_total_path = NULL;
7090 double dNumPartialGroups = 0;
7091 double dNumPartialPartialGroups = 0;
7120 if (cheapest_total_path == NULL &&
7121 cheapest_partial_path == NULL &&
7122 !force_rel_creation)
7138 partially_grouped_rel->fdwroutine = grouped_rel->fdwroutine;
7173 if (cheapest_total_path != NULL)
7176 cheapest_total_path->
rows,
7179 if (cheapest_partial_path != NULL)
7180 dNumPartialPartialGroups =
7182 cheapest_partial_path->
rows,
7186 if (can_sort && cheapest_total_path != NULL)
7199 Path *path_save = path;
7200 List *pathkey_orderings =
NIL;
7208 foreach(lc2, pathkey_orderings)
7216 partially_grouped_rel,
7218 cheapest_total_path,
7227 partially_grouped_rel,
7235 dNumPartialGroups));
7239 partially_grouped_rel,
7243 dNumPartialGroups));
7248 if (can_sort && cheapest_partial_path != NULL)
7255 Path *path_save = path;
7256 List *pathkey_orderings =
NIL;
7264 foreach(lc2, pathkey_orderings)
7273 partially_grouped_rel,
7275 cheapest_partial_path,
7284 partially_grouped_rel,
7292 dNumPartialPartialGroups));
7296 partially_grouped_rel,
7300 dNumPartialPartialGroups));
7308 if (can_hash && cheapest_total_path != NULL)
7315 partially_grouped_rel,
7316 cheapest_total_path,
7320 root->processed_groupClause,
7323 dNumPartialGroups));
7329 if (can_hash && cheapest_partial_path != NULL)
7333 partially_grouped_rel,
7334 cheapest_partial_path,
7338 root->processed_groupClause,
7341 dNumPartialPartialGroups));
7348 if (partially_grouped_rel->fdwroutine &&
7349 partially_grouped_rel->fdwroutine->GetForeignUpperPaths)
7351 FdwRoutine *fdwroutine = partially_grouped_rel->fdwroutine;
7355 input_rel, partially_grouped_rel,
7359 return partially_grouped_rel;
7379 Path *cheapest_partial_path;
7380 List *groupby_pathkeys;
7388 root->num_groupby_pathkeys);
7390 groupby_pathkeys =
root->group_pathkeys;
7403 double total_groups;
7418 if (path != cheapest_partial_path &&
7473 else if (
parse->groupingSets)
7478 else if (
root->hasNonPartialAggs ||
root->hasNonSerialAggs)
7505 List *scanjoin_targets,
7506 List *scanjoin_targets_contain_srfs,
7507 bool scanjoin_target_parallel_safe,
7536 if (rel_is_partitioned)
7543 if (!scanjoin_target_parallel_safe)
7562 if (rel_is_partitioned)
7585 subpath->pathtarget->sortgrouprefs =
7586 scanjoin_target->sortgrouprefs;
7606 subpath->pathtarget->sortgrouprefs =
7607 scanjoin_target->sortgrouprefs;
7624 if (
root->parse->hasTargetSRFs)
7627 scanjoin_targets_contain_srfs);
7649 if (rel_is_partitioned)
7661 List *child_scanjoin_targets =
NIL;
7663 Assert(child_rel != NULL);
7672 foreach(lc, scanjoin_targets)
7680 nappinfos, appinfos);
7681 child_scanjoin_targets =
lappend(child_scanjoin_targets,
7688 child_scanjoin_targets,
7689 scanjoin_targets_contain_srfs,
7690 scanjoin_target_parallel_safe,
7695 live_children =
lappend(live_children, child_rel);
7747 List *grouped_live_children =
NIL;
7748 List *partially_grouped_live_children =
NIL;
7750 bool partial_grouping_valid =
true;
7755 partially_grouped_rel != NULL);
7761 RelOptInfo *child_input_rel = input_rel->part_rels[
i];
7769 Assert(child_input_rel != NULL);
7781 memcpy(&child_extra, extra,
sizeof(child_extra));
7789 nappinfos, appinfos);
7795 nappinfos, appinfos);
7799 nappinfos, appinfos);
7806 child_extra.
patype = patype;
7820 agg_costs, gd, &child_extra,
7821 &child_partially_grouped_rel);
7823 if (child_partially_grouped_rel)
7825 partially_grouped_live_children =
7826 lappend(partially_grouped_live_children,
7827 child_partially_grouped_rel);
7830 partial_grouping_valid =
false;
7835 grouped_live_children =
lappend(grouped_live_children,
7851 if (partially_grouped_rel && partial_grouping_valid)
7853 Assert(partially_grouped_live_children !=
NIL);
7856 partially_grouped_live_children);
7862 if (partially_grouped_rel->
pathlist)
7891 Assert(input_rel->part_scheme);
7894 if (!input_rel->partexprs)
7897 partnatts = input_rel->part_scheme->partnatts;
7899 for (cnt = 0; cnt < partnatts; cnt++)
7901 List *partexprs = input_rel->partexprs[cnt];
7905 foreach(lc, partexprs)
7946 foreach(lt, targetlist)
7958 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
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)
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)
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_extended(PlannerInfo *root, List **sortclauses, List *tlist, bool remove_redundant, bool *sortable)
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
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)
WindowAggPath * create_windowagg_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *windowFuncs, WindowClause *winclause, List *qual, bool topwindow)
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)
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
static List * groupclause_apply_groupingset(PlannerInfo *root, List *force)
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 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)