70#define CP_EXACT_TLIST 0x0001
71#define CP_SMALL_TLIST 0x0002
72#define CP_LABEL_TLIST 0x0004
73#define CP_IGNORE_TLIST 0x0008
128 List *tlist,
List *scan_clauses,
bool indexonly);
169 List **stripped_indexquals_p,
170 List **fixed_indexquals_p);
181 double limit_tuples);
183 List *pathkeys,
double limit_tuples);
189 List *indexorderby,
List *indexorderbyorig,
190 List *indexorderbyops,
200 List *indexqualorig);
204 List *bitmapqualorig,
221 Index scanrelid,
int ctePlanId,
int cteParam);
223 Index scanrelid,
char *enrname);
225 Index scanrelid,
int wtParam);
235 List *joinclauses,
List *otherclauses,
List *nestParams,
237 JoinType jointype,
bool inner_unique);
239 List *joinclauses,
List *otherclauses,
241 List *hashoperators,
List *hashcollations,
244 JoinType jointype,
bool inner_unique);
251 List *joinclauses,
List *otherclauses,
254 Oid *mergecollations,
255 bool *mergereversals,
256 bool *mergenullsfirst,
258 JoinType jointype,
bool inner_unique,
259 bool skip_mark_restore);
262 Oid *collations,
bool *nullsFirst);
264 int numCols,
int nPresortedCols,
266 Oid *collations,
bool *nullsFirst);
270 bool adjust_tlist_in_place,
273 Oid **p_sortOperators,
275 bool **p_nullsFirst);
279 List *pathkeys,
Relids relids,
int nPresortedCols);
285 Oid *collations,
List *param_exprs,
286 bool singlerow,
bool binary_mode,
289 int partNumCols,
AttrNumber *partColIdx,
Oid *partOperators,
Oid *partCollations,
290 int ordNumCols,
AttrNumber *ordColIdx,
Oid *ordOperators,
Oid *ordCollations,
291 int frameOptions,
Node *startOffset,
Node *endOffset,
292 Oid startInRangeFunc,
Oid endInRangeFunc,
293 Oid inRangeColl,
bool inRangeAsc,
bool inRangeNullsFirst,
294 List *runCondition,
List *qual,
bool topWindow,
301 List *pathkeys,
int numCols);
303 int nworkers,
int rescan_param,
bool single_copy,
Plan *subplan);
306 List *groupList,
long numGroups);
311 CmdType operation,
bool canSetTag,
313 bool partColsUpdated,
314 List *resultRelations,
315 List *updateColnosLists,
316 List *withCheckOptionLists,
List *returningLists,
318 List *mergeActionLists,
List *mergeJoinConditions,
348 root->curOuterRels = NULL;
374 if (
root->curOuterParams !=
NIL)
375 elog(
ERROR,
"failed to assign all NestLoopParams to plan nodes");
403 case T_IndexOnlyScan:
404 case T_BitmapHeapScan:
409 case T_TableFuncScan:
412 case T_WorkTableScan:
413 case T_NamedTuplestoreScan:
496 case T_IncrementalSort:
525 case T_RecursiveUnion:
548 elog(
ERROR,
"unrecognized node type: %d",
549 (
int) best_path->pathtype);
566 List *gating_clauses;
585 case T_IndexOnlyScan:
599 if (best_path->param_info)
601 best_path->param_info->ppi_clauses);
618 best_path->
pathtype == T_CustomScan);
619 if (best_path->
pathtype == T_ForeignScan)
620 join_clauses = ((
ForeignPath *) best_path)->fdw_restrictinfo;
622 join_clauses = ((
CustomPath *) best_path)->custom_restrictinfo;
647 if (best_path->
pathtype == T_IndexOnlyScan)
704 case T_IndexOnlyScan:
712 case T_BitmapHeapScan:
747 case T_TableFuncScan:
768 case T_NamedTuplestoreScan:
782 case T_WorkTableScan:
804 elog(
ERROR,
"unrecognized node type: %d",
831 Index *sortgrouprefs = path->pathtarget->sortgrouprefs;
835 foreach(v, path->pathtarget->exprs)
846 if (path->param_info)
915 path->pathtarget->exprs ==
NIL)
933 foreach(lc,
root->placeholder_list)
947 if (path->
pathtype == T_IndexOnlyScan)
953 if (!indexinfo->canreturn[
i])
972 foreach(lc, path->pathtarget->exprs)
976 if (path->pathtarget->sortgrouprefs[
i])
978 if (expr &&
IsA(expr,
Var))
980 int attno = ((
Var *) expr)->varattno;
1008 if (!
root->hasPseudoConstantQuals)
1055 (
Node *) gating_quals,
1087 List *gating_clauses;
1089 switch (best_path->path.pathtype)
1104 elog(
ERROR,
"unrecognized node type: %d",
1105 (
int) best_path->path.pathtype);
1127 if (get_loc_restrictinfo(best_path) !=
NIL)
1147 case T_SubqueryScanPath:
1170 FdwRoutine *fdwroutine = path->parent->fdwroutine;
1179 Assert(fdwroutine != NULL);
1185 case T_ProjectionPath:
1206 plan->async_capable =
true;
1224 bool tlist_was_changed =
false;
1228 int nasyncplans = 0;
1231 int nodenumsortkeys = 0;
1233 Oid *nodeSortOperators = NULL;
1234 Oid *nodeCollations = NULL;
1235 bool *nodeNullsFirst = NULL;
1236 bool consider_async =
false;
1274 plan->plan.targetlist = tlist;
1276 plan->plan.lefttree = NULL;
1277 plan->plan.righttree = NULL;
1280 if (pathkeys !=
NIL)
1289 best_path->
path.parent->relids,
1297 tlist_was_changed = (orig_tlist_length !=
list_length(
plan->plan.targetlist));
1306 foreach(subpaths, best_path->
subpaths)
1318 if (pathkeys !=
NIL)
1348 Assert(numsortkeys == nodenumsortkeys);
1349 if (memcmp(sortColIdx, nodeSortColIdx,
1351 elog(
ERROR,
"Append child's targetlist doesn't match Append");
1352 Assert(memcmp(sortOperators, nodeSortOperators,
1353 numsortkeys *
sizeof(
Oid)) == 0);
1354 Assert(memcmp(collations, nodeCollations,
1355 numsortkeys *
sizeof(
Oid)) == 0);
1356 Assert(memcmp(nullsFirst, nodeNullsFirst,
1357 numsortkeys *
sizeof(
bool)) == 0);
1363 sortColIdx, sortOperators,
1364 collations, nullsFirst);
1378 subplans =
lappend(subplans, subplan);
1392 if (best_path->
path.param_info)
1394 List *prmquals = best_path->
path.param_info->ppi_clauses;
1403 if (prunequal !=
NIL)
1410 plan->appendplans = subplans;
1411 plan->nasyncplans = nasyncplans;
1413 plan->part_prune_info = partpruneinfo;
1426 plan->plan.parallel_safe);
1447 bool tlist_was_changed;
1461 plan->targetlist = tlist;
1463 plan->lefttree = NULL;
1464 plan->righttree = NULL;
1474 best_path->
path.parent->relids,
1479 &node->sortOperators,
1482 tlist_was_changed = (orig_tlist_length !=
list_length(
plan->targetlist));
1489 foreach(subpaths, best_path->
subpaths)
1521 if (memcmp(sortColIdx, node->sortColIdx,
1523 elog(
ERROR,
"MergeAppend child's targetlist doesn't match MergeAppend");
1524 Assert(memcmp(sortOperators, node->sortOperators,
1525 numsortkeys *
sizeof(
Oid)) == 0);
1526 Assert(memcmp(collations, node->collations,
1527 numsortkeys *
sizeof(
Oid)) == 0);
1528 Assert(memcmp(nullsFirst, node->nullsFirst,
1529 numsortkeys *
sizeof(
bool)) == 0);
1535 sortColIdx, sortOperators,
1536 collations, nullsFirst);
1542 subplans =
lappend(subplans, subplan);
1559 if (prunequal !=
NIL)
1690 operators =
palloc(nkeys *
sizeof(
Oid));
1691 collations =
palloc(nkeys *
sizeof(
Oid));
1699 operators[
i] = opno;
1734 Oid *groupCollations;
1769 foreach(l, uniq_exprs)
1781 newtlist =
lappend(newtlist, tle);
1801 groupCollations = (
Oid *)
palloc(numGroupCols *
sizeof(
Oid));
1804 foreach(l, uniq_exprs)
1811 elog(
ERROR,
"failed to find unique expression in subplan tlist");
1812 groupColIdx[groupColPos] = tle->
resno;
1819 Oid *groupOperators;
1827 groupOperators = (
Oid *)
palloc(numGroupCols *
sizeof(
Oid));
1829 foreach(l, in_operators)
1835 elog(
ERROR,
"could not find compatible hash operator for operator %u",
1837 groupOperators[groupColPos++] = eq_oper;
1866 foreach(l, in_operators)
1876 elog(
ERROR,
"could not find ordering operator for equality operator %u",
1887 elog(
ERROR,
"could not find equality operator for ordering operator %u",
1891 groupColIdx[groupColPos]);
1897 sortcl->
eqop = eqop;
1901 sortcl->hashable =
false;
1902 sortList =
lappend(sortList, sortcl);
1949 root->glob->parallelModeNeeded =
true;
1985 best_path->
subpath->parent->relids,
1986 gm_plan->sortColIdx,
1989 &gm_plan->sortColIdx,
1990 &gm_plan->sortOperators,
1991 &gm_plan->collations,
1992 &gm_plan->nullsFirst);
2004 root->glob->parallelModeNeeded =
true;
2022 bool needs_result_node =
false;
2048 best_path->
path.pathtarget);
2082 if (!needs_result_node)
2086 plan->targetlist = tlist;
2092 plan->plan_width = best_path->
path.pathtarget->width;
2133 plan->parallel_safe = parallel_safe;
2162 tlist_parallel_safe);
2200 best_path->
path.parent->relids : NULL);
2225 best_path->
spath.
path.parent->relids : NULL,
2365 foreach(lc, groupClause)
2372 return new_grpColIdx;
2417 foreach(lc,
root->processed_groupClause)
2428 foreach(lc,
root->processed_groupClause)
2441 root->grouping_map = grouping_map;
2458 Plan *sort_plan = NULL;
2464 if (!rollup->
is_hashed && !is_first_sort)
2466 sort_plan = (
Plan *)
2473 is_first_sort =
false;
2505 chain =
lappend(chain, agg_plan);
2575 0, NULL, NULL, NULL);
2581 plan->plan_rows = 1;
2582 plan->plan_width = mminfo->
path->pathtarget->width;
2583 plan->parallel_aware =
false;
2627 Oid *partCollations;
2651 partCollations = (
Oid *)
palloc(
sizeof(
Oid) * numPart);
2660 partColIdx[partNumCols] = tle->
resno;
2661 partOperators[partNumCols] = sgc->
eqop;
2668 ordCollations = (
Oid *)
palloc(
sizeof(
Oid) * numOrder);
2677 ordColIdx[ordNumCols] = tle->
resno;
2678 ordOperators[ordNumCols] = sgc->
eqop;
2697 wc->startInRangeFunc,
2701 wc->inRangeNullsFirst,
2863 int numUniqkeys = 0;
2865 Oid *uniqOperators = NULL;
2866 Oid *uniqCollations = NULL;
2879 uniqOperators = (
Oid *)
palloc(numUniqkeys *
sizeof(
Oid));
2880 uniqCollations = (
Oid *)
palloc(numUniqkeys *
sizeof(
Oid));
2883 foreach(l,
parse->sortClause)
2888 uniqColIdx[numUniqkeys] = tle->
resno;
2889 uniqOperators[numUniqkeys] = sortcl->
eqop;
2899 numUniqkeys, uniqColIdx, uniqOperators, uniqCollations);
2924 Index scan_relid = best_path->parent->relid;
2937 if (best_path->param_info)
2939 scan_clauses = (
List *)
2962 Index scan_relid = best_path->parent->relid;
2980 if (best_path->param_info)
2982 scan_clauses = (
List *)
3018 Index baserelid = best_path->
path.parent->relid;
3022 List *stripped_indexquals;
3023 List *fixed_indexquals;
3024 List *fixed_indexorderbys;
3042 &stripped_indexquals,
3079 foreach(l, scan_clauses)
3083 if (rinfo->pseudoconstant)
3091 qpqual =
lappend(qpqual, rinfo);
3109 if (best_path->
path.param_info)
3111 stripped_indexquals = (
List *)
3115 indexorderbys = (
List *)
3147 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
3149 indexorderbyops =
lappend_oid(indexorderbyops, sortop);
3166 indextle->resjunk = !indexinfo->canreturn[
i];
3178 stripped_indexquals,
3179 fixed_indexorderbys,
3188 stripped_indexquals,
3189 fixed_indexorderbys,
3210 Index baserelid = best_path->
path.parent->relid;
3211 Plan *bitmapqualplan;
3212 List *bitmapqualorig;
3225 &bitmapqualorig, &indexquals,
3258 foreach(l, scan_clauses)
3263 if (rinfo->pseudoconstant)
3272 qpqual =
lappend(qpqual, rinfo);
3294 if (best_path->
path.param_info)
3298 bitmapqualorig = (
List *)
3364 &subqual, &subindexqual,
3366 subplans =
lappend(subplans, subplan);
3370 subindexECs =
list_concat(subindexECs, subindexEC);
3377 plan->plan_width = 0;
3378 plan->parallel_aware =
false;
3381 *indexqual = subindexquals;
3382 *indexECs = subindexECs;
3390 bool const_true_subqual =
false;
3391 bool const_true_subindexqual =
false;
3411 &subqual, &subindexqual,
3413 subplans =
lappend(subplans, subplan);
3415 const_true_subqual =
true;
3416 else if (!const_true_subqual)
3419 if (subindexqual ==
NIL)
3420 const_true_subindexqual =
true;
3421 else if (!const_true_subindexqual)
3422 subindexquals =
lappend(subindexquals,
3441 plan->plan_width = 0;
3442 plan->parallel_aware =
false;
3451 if (const_true_subqual)
3457 if (const_true_subindexqual)
3460 *indexqual = subindexquals;
3470 List *subindexquals;
3484 plan->startup_cost = 0.0;
3488 plan->plan_width = 0;
3489 plan->parallel_aware =
false;
3493 subindexquals =
NIL;
3500 Assert(!rinfo->pseudoconstant);
3504 if (rinfo->parent_ec)
3505 subindexECs =
lappend(subindexECs, rinfo->parent_ec);
3520 subquals =
lappend(subquals, pred);
3521 subindexquals =
lappend(subindexquals, pred);
3525 *indexqual = subindexquals;
3526 *indexECs = subindexECs;
3547 Index scan_relid = best_path->
path.parent->relid;
3578 foreach(l, scan_clauses)
3582 if (rinfo->pseudoconstant)
3588 qpqual =
lappend(qpqual, rinfo);
3590 scan_clauses = qpqual;
3616 if (best_path->
path.param_info)
3620 scan_clauses = (
List *)
3644 Index scan_relid = best_path->
path.parent->relid;
3660 foreach(l, scan_clauses)
3664 if (rinfo->pseudoconstant)
3668 qpqual =
lappend(qpqual, rinfo);
3670 scan_clauses = qpqual;
3681 if (best_path->
path.param_info)
3683 tidrangequals = (
List *)
3685 scan_clauses = (
List *)
3740 if (best_path->
path.param_info)
3744 scan_clauses = (
List *)
3768 Index scan_relid = best_path->parent->relid;
3785 if (best_path->param_info)
3787 scan_clauses = (
List *)
3811 Index scan_relid = best_path->parent->relid;
3828 if (best_path->param_info)
3830 scan_clauses = (
List *)
3854 Index scan_relid = best_path->parent->relid;
3871 if (best_path->param_info)
3873 scan_clauses = (
List *)
3876 values_lists = (
List *)
3898 Index scan_relid = best_path->parent->relid;
3911 Assert(!rte->self_reference);
3918 while (levelsup-- > 0)
3920 cteroot = cteroot->parent_root;
3949 if (ctesplan->
plan_id == plan_id)
3968 if (best_path->param_info)
3970 scan_clauses = (
List *)
3974 scan_plan =
make_ctescan(tlist, scan_clauses, scan_relid,
3975 plan_id, cte_param_id);
3993 Index scan_relid = best_path->parent->relid;
4007 if (best_path->param_info)
4009 scan_clauses = (
List *)
4032 Index scan_relid = best_path->parent->relid;
4046 if (best_path->param_info)
4048 scan_clauses = (
List *)
4069 Index scan_relid = best_path->parent->relid;
4077 Assert(rte->self_reference);
4089 while (levelsup-- > 0)
4091 cteroot = cteroot->parent_root;
4105 if (best_path->param_info)
4107 scan_clauses = (
List *)
4132 Plan *outer_plan = NULL;
4134 Assert(rel->fdwroutine != NULL);
4152 rel_oid = rte->
relid;
4168 scan_plan = rel->fdwroutine->GetForeignPlan(
root, rel, rel_oid,
4170 tlist, scan_clauses,
4198 root->outer_join_rels);
4206 root->glob->dependsOnRole =
true;
4216 if (best_path->
path.param_info)
4218 scan_plan->
scan.plan.qual = (
List *)
4332 if (best_path->
path.param_info)
4392 root->curOuterRels = saveOuterRels;
4402 best_path->
jpath.path.parent->relids,
4403 &joinclauses, &otherclauses);
4413 if (best_path->
jpath.path.param_info)
4415 joinclauses = (
List *)
4417 otherclauses = (
List *)
4453 List *outerpathkeys;
4454 List *innerpathkeys;
4457 Oid *mergecollations;
4458 bool *mergereversals;
4459 bool *mergenullsfirst;
4490 best_path->
jpath.path.parent->relids,
4491 &joinclauses, &otherclauses);
4511 if (best_path->
jpath.path.param_info)
4513 joinclauses = (
List *)
4515 otherclauses = (
List *)
4532 Relids outer_relids = outer_path->parent->relids;
4534 bool use_incremental_sort =
false;
4550 if (presorted_keys > 0)
4551 use_incremental_sort =
true;
4554 if (!use_incremental_sort)
4556 sort_plan = (
Plan *)
4565 sort_plan = (
Plan *)
4577 outer_plan = sort_plan;
4590 Relids inner_relids = inner_path->parent->relids;
4618 inner_plan = matplan;
4630 mergefamilies = (
Oid *)
palloc(nClauses *
sizeof(
Oid));
4631 mergecollations = (
Oid *)
palloc(nClauses *
sizeof(
Oid));
4632 mergereversals = (
bool *)
palloc(nClauses *
sizeof(
bool));
4633 mergenullsfirst = (
bool *)
palloc(nClauses *
sizeof(
bool));
4647 bool first_inner_match =
false;
4650 if (rinfo->outer_is_left)
4652 oeclass = rinfo->left_ec;
4653 ieclass = rinfo->right_ec;
4657 oeclass = rinfo->right_ec;
4658 ieclass = rinfo->left_ec;
4678 if (oeclass != opeclass)
4682 elog(
ERROR,
"outer pathkeys do not match mergeclauses");
4684 opeclass = opathkey->pk_eclass;
4685 lop =
lnext(outerpathkeys, lop);
4686 if (oeclass != opeclass)
4687 elog(
ERROR,
"outer pathkeys do not match mergeclauses");
4708 ipeclass = ipathkey->pk_eclass;
4709 if (ieclass == ipeclass)
4712 lip =
lnext(innerpathkeys, lip);
4713 first_inner_match =
true;
4716 if (!first_inner_match)
4721 foreach(l2, innerpathkeys)
4726 ipeclass = ipathkey->pk_eclass;
4727 if (ieclass == ipeclass)
4730 if (ieclass != ipeclass)
4731 elog(
ERROR,
"inner pathkeys do not match mergeclauses");
4749 opathkey->pk_eclass->ec_collation != ipathkey->pk_eclass->ec_collation)
4750 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
4751 if (first_inner_match &&
4754 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
4758 mergecollations[
i] = opathkey->pk_eclass->ec_collation;
4811 bool skewInherit =
false;
4836 best_path->
jpath.path.parent->relids,
4837 &joinclauses, &otherclauses);
4857 if (best_path->
jpath.path.param_info)
4859 joinclauses = (
List *)
4861 otherclauses = (
List *)
4894 rte =
root->simple_rte_array[var->
varno];
4897 skewTable = rte->
relid;
4899 skewInherit = rte->
inh;
4912 foreach(lc, hashclauses)
4917 hashcollations =
lappend_oid(hashcollations, hclause->inputcollid);
4943 if (best_path->
jpath.path.parallel_aware)
5016 root->curOuterRels))
5036 newphv->phexpr = (
Expr *)
5039 return (
Node *) newphv;
5069 List **stripped_indexquals_p,
List **fixed_indexquals_p)
5072 List *stripped_indexquals;
5073 List *fixed_indexquals;
5076 stripped_indexquals = fixed_indexquals =
NIL;
5089 stripped_indexquals =
lappend(stripped_indexquals, clause);
5092 fixed_indexquals =
lappend(fixed_indexquals, clause);
5096 *stripped_indexquals_p = stripped_indexquals;
5097 *fixed_indexquals_p = fixed_indexquals;