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 int *mergestrategies,
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);
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;
1900 sortcl->hashable =
false;
1901 sortList =
lappend(sortList, sortcl);
1948 root->glob->parallelModeNeeded =
true;
1984 best_path->
subpath->parent->relids,
1985 gm_plan->sortColIdx,
1988 &gm_plan->sortColIdx,
1989 &gm_plan->sortOperators,
1990 &gm_plan->collations,
1991 &gm_plan->nullsFirst);
2003 root->glob->parallelModeNeeded =
true;
2021 bool needs_result_node =
false;
2047 best_path->
path.pathtarget);
2081 if (!needs_result_node)
2085 plan->targetlist = tlist;
2091 plan->plan_width = best_path->
path.pathtarget->width;
2132 plan->parallel_safe = parallel_safe;
2161 tlist_parallel_safe);
2199 best_path->
path.parent->relids : NULL);
2224 best_path->
spath.
path.parent->relids : NULL,
2364 foreach(lc, groupClause)
2371 return new_grpColIdx;
2416 foreach(lc,
root->processed_groupClause)
2427 foreach(lc,
root->processed_groupClause)
2440 root->grouping_map = grouping_map;
2457 Plan *sort_plan = NULL;
2463 if (!rollup->
is_hashed && !is_first_sort)
2465 sort_plan = (
Plan *)
2472 is_first_sort =
false;
2504 chain =
lappend(chain, agg_plan);
2574 0, NULL, NULL, NULL);
2580 plan->plan_rows = 1;
2581 plan->plan_width = mminfo->
path->pathtarget->width;
2582 plan->parallel_aware =
false;
2626 Oid *partCollations;
2650 partCollations = (
Oid *)
palloc(
sizeof(
Oid) * numPart);
2659 partColIdx[partNumCols] = tle->
resno;
2660 partOperators[partNumCols] = sgc->
eqop;
2667 ordCollations = (
Oid *)
palloc(
sizeof(
Oid) * numOrder);
2676 ordColIdx[ordNumCols] = tle->
resno;
2677 ordOperators[ordNumCols] = sgc->
eqop;
2696 wc->startInRangeFunc,
2700 wc->inRangeNullsFirst,
2858 int numUniqkeys = 0;
2860 Oid *uniqOperators = NULL;
2861 Oid *uniqCollations = NULL;
2874 uniqOperators = (
Oid *)
palloc(numUniqkeys *
sizeof(
Oid));
2875 uniqCollations = (
Oid *)
palloc(numUniqkeys *
sizeof(
Oid));
2878 foreach(l,
parse->sortClause)
2883 uniqColIdx[numUniqkeys] = tle->
resno;
2884 uniqOperators[numUniqkeys] = sortcl->
eqop;
2894 numUniqkeys, uniqColIdx, uniqOperators, uniqCollations);
2919 Index scan_relid = best_path->parent->relid;
2932 if (best_path->param_info)
2934 scan_clauses = (
List *)
2957 Index scan_relid = best_path->parent->relid;
2975 if (best_path->param_info)
2977 scan_clauses = (
List *)
3013 Index baserelid = best_path->
path.parent->relid;
3017 List *stripped_indexquals;
3018 List *fixed_indexquals;
3019 List *fixed_indexorderbys;
3037 &stripped_indexquals,
3074 foreach(l, scan_clauses)
3078 if (rinfo->pseudoconstant)
3086 qpqual =
lappend(qpqual, rinfo);
3104 if (best_path->
path.param_info)
3106 stripped_indexquals = (
List *)
3110 indexorderbys = (
List *)
3142 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
3144 indexorderbyops =
lappend_oid(indexorderbyops, sortop);
3161 indextle->resjunk = !indexinfo->canreturn[
i];
3173 stripped_indexquals,
3174 fixed_indexorderbys,
3183 stripped_indexquals,
3184 fixed_indexorderbys,
3205 Index baserelid = best_path->
path.parent->relid;
3206 Plan *bitmapqualplan;
3207 List *bitmapqualorig;
3220 &bitmapqualorig, &indexquals,
3253 foreach(l, scan_clauses)
3258 if (rinfo->pseudoconstant)
3267 qpqual =
lappend(qpqual, rinfo);
3289 if (best_path->
path.param_info)
3293 bitmapqualorig = (
List *)
3359 &subqual, &subindexqual,
3361 subplans =
lappend(subplans, subplan);
3365 subindexECs =
list_concat(subindexECs, subindexEC);
3372 plan->plan_width = 0;
3373 plan->parallel_aware =
false;
3376 *indexqual = subindexquals;
3377 *indexECs = subindexECs;
3385 bool const_true_subqual =
false;
3386 bool const_true_subindexqual =
false;
3406 &subqual, &subindexqual,
3408 subplans =
lappend(subplans, subplan);
3410 const_true_subqual =
true;
3411 else if (!const_true_subqual)
3414 if (subindexqual ==
NIL)
3415 const_true_subindexqual =
true;
3416 else if (!const_true_subindexqual)
3417 subindexquals =
lappend(subindexquals,
3436 plan->plan_width = 0;
3437 plan->parallel_aware =
false;
3446 if (const_true_subqual)
3452 if (const_true_subindexqual)
3455 *indexqual = subindexquals;
3465 List *subindexquals;
3479 plan->startup_cost = 0.0;
3483 plan->plan_width = 0;
3484 plan->parallel_aware =
false;
3488 subindexquals =
NIL;
3495 Assert(!rinfo->pseudoconstant);
3499 if (rinfo->parent_ec)
3500 subindexECs =
lappend(subindexECs, rinfo->parent_ec);
3515 subquals =
lappend(subquals, pred);
3516 subindexquals =
lappend(subindexquals, pred);
3520 *indexqual = subindexquals;
3521 *indexECs = subindexECs;
3542 Index scan_relid = best_path->
path.parent->relid;
3573 foreach(l, scan_clauses)
3577 if (rinfo->pseudoconstant)
3583 qpqual =
lappend(qpqual, rinfo);
3585 scan_clauses = qpqual;
3611 if (best_path->
path.param_info)
3615 scan_clauses = (
List *)
3639 Index scan_relid = best_path->
path.parent->relid;
3655 foreach(l, scan_clauses)
3659 if (rinfo->pseudoconstant)
3663 qpqual =
lappend(qpqual, rinfo);
3665 scan_clauses = qpqual;
3676 if (best_path->
path.param_info)
3678 tidrangequals = (
List *)
3680 scan_clauses = (
List *)
3735 if (best_path->
path.param_info)
3739 scan_clauses = (
List *)
3763 Index scan_relid = best_path->parent->relid;
3780 if (best_path->param_info)
3782 scan_clauses = (
List *)
3806 Index scan_relid = best_path->parent->relid;
3823 if (best_path->param_info)
3825 scan_clauses = (
List *)
3849 Index scan_relid = best_path->parent->relid;
3866 if (best_path->param_info)
3868 scan_clauses = (
List *)
3871 values_lists = (
List *)
3893 Index scan_relid = best_path->parent->relid;
3906 Assert(!rte->self_reference);
3913 while (levelsup-- > 0)
3915 cteroot = cteroot->parent_root;
3944 if (ctesplan->
plan_id == plan_id)
3963 if (best_path->param_info)
3965 scan_clauses = (
List *)
3969 scan_plan =
make_ctescan(tlist, scan_clauses, scan_relid,
3970 plan_id, cte_param_id);
3988 Index scan_relid = best_path->parent->relid;
4002 if (best_path->param_info)
4004 scan_clauses = (
List *)
4027 Index scan_relid = best_path->parent->relid;
4041 if (best_path->param_info)
4043 scan_clauses = (
List *)
4064 Index scan_relid = best_path->parent->relid;
4072 Assert(rte->self_reference);
4084 while (levelsup-- > 0)
4086 cteroot = cteroot->parent_root;
4100 if (best_path->param_info)
4102 scan_clauses = (
List *)
4127 Plan *outer_plan = NULL;
4129 Assert(rel->fdwroutine != NULL);
4147 rel_oid = rte->
relid;
4163 scan_plan = rel->fdwroutine->GetForeignPlan(
root, rel, rel_oid,
4165 tlist, scan_clauses,
4193 root->outer_join_rels);
4201 root->glob->dependsOnRole =
true;
4211 if (best_path->
path.param_info)
4213 scan_plan->
scan.plan.qual = (
List *)
4327 if (best_path->
path.param_info)
4387 root->curOuterRels = saveOuterRels;
4397 best_path->
jpath.path.parent->relids,
4398 &joinclauses, &otherclauses);
4408 if (best_path->
jpath.path.param_info)
4410 joinclauses = (
List *)
4412 otherclauses = (
List *)
4448 List *outerpathkeys;
4449 List *innerpathkeys;
4452 Oid *mergecollations;
4453 int *mergestrategies;
4454 bool *mergenullsfirst;
4485 best_path->
jpath.path.parent->relids,
4486 &joinclauses, &otherclauses);
4506 if (best_path->
jpath.path.param_info)
4508 joinclauses = (
List *)
4510 otherclauses = (
List *)
4527 Relids outer_relids = outer_path->parent->relids;
4529 bool use_incremental_sort =
false;
4545 if (presorted_keys > 0)
4546 use_incremental_sort =
true;
4549 if (!use_incremental_sort)
4551 sort_plan = (
Plan *)
4560 sort_plan = (
Plan *)
4572 outer_plan = sort_plan;
4585 Relids inner_relids = inner_path->parent->relids;
4613 inner_plan = matplan;
4625 mergefamilies = (
Oid *)
palloc(nClauses *
sizeof(
Oid));
4626 mergecollations = (
Oid *)
palloc(nClauses *
sizeof(
Oid));
4627 mergestrategies = (
int *)
palloc(nClauses *
sizeof(
int));
4628 mergenullsfirst = (
bool *)
palloc(nClauses *
sizeof(
bool));
4642 bool first_inner_match =
false;
4645 if (rinfo->outer_is_left)
4647 oeclass = rinfo->left_ec;
4648 ieclass = rinfo->right_ec;
4652 oeclass = rinfo->right_ec;
4653 ieclass = rinfo->left_ec;
4673 if (oeclass != opeclass)
4677 elog(
ERROR,
"outer pathkeys do not match mergeclauses");
4679 opeclass = opathkey->pk_eclass;
4680 lop =
lnext(outerpathkeys, lop);
4681 if (oeclass != opeclass)
4682 elog(
ERROR,
"outer pathkeys do not match mergeclauses");
4703 ipeclass = ipathkey->pk_eclass;
4704 if (ieclass == ipeclass)
4707 lip =
lnext(innerpathkeys, lip);
4708 first_inner_match =
true;
4711 if (!first_inner_match)
4716 foreach(l2, innerpathkeys)
4721 ipeclass = ipathkey->pk_eclass;
4722 if (ieclass == ipeclass)
4725 if (ieclass != ipeclass)
4726 elog(
ERROR,
"inner pathkeys do not match mergeclauses");
4744 opathkey->pk_eclass->ec_collation != ipathkey->pk_eclass->ec_collation)
4745 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
4746 if (first_inner_match &&
4749 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
4753 mergecollations[
i] = opathkey->pk_eclass->ec_collation;
4806 bool skewInherit =
false;
4831 best_path->
jpath.path.parent->relids,
4832 &joinclauses, &otherclauses);
4852 if (best_path->
jpath.path.param_info)
4854 joinclauses = (
List *)
4856 otherclauses = (
List *)
4889 rte =
root->simple_rte_array[var->
varno];
4892 skewTable = rte->
relid;
4894 skewInherit = rte->
inh;
4907 foreach(lc, hashclauses)
4912 hashcollations =
lappend_oid(hashcollations, hclause->inputcollid);
4938 if (best_path->
jpath.path.parallel_aware)
5011 root->curOuterRels))
5031 newphv->phexpr = (
Expr *)
5034 return (
Node *) newphv;
5066 List **stripped_indexquals_p,
List **fixed_indexquals_p)
5069 List *stripped_indexquals;
5070 List *fixed_indexquals;
5073 stripped_indexquals = fixed_indexquals =
NIL;
5086 stripped_indexquals =
lappend(stripped_indexquals, clause);
5089 fixed_indexquals =
lappend(fixed_indexquals, clause);
5093 *stripped_indexquals_p = stripped_indexquals;
5094 *fixed_indexquals_p = fixed_indexquals;
5109 List *fixed_indexorderbys;
5113 fixed_indexorderbys =
NIL;
5121 fixed_indexorderbys =
lappend(fixed_indexorderbys, clause);
5124 return fixed_indexorderbys;
5189 elog(
ERROR,
"unsupported indexqual type: %d",
5218 Assert(indexcol >= 0 && indexcol < index->ncolumns);
5220 if (
index->indexkeys[indexcol] != 0)
5224 ((
Var *) node)->varno ==
index->rel->relid &&
5225 ((
Var *) node)->varattno ==
index->indexkeys[indexcol])
5230 return (
Node *) result;
5233 elog(
ERROR,
"index key does not match expected index column");
5238 for (pos = 0; pos <
index->ncolumns; pos++)
5240 if (
index->indexkeys[pos] == 0)
5242 if (indexpr_item == NULL)
5243 elog(
ERROR,
"too few entries in indexprs list");
5244 if (pos == indexcol)
5251 if (
equal(node, indexkey))
5257 return (
Node *) result;
5260 elog(
ERROR,
"index key does not match expected index column");
5262 indexpr_item =
lnext(
index->indexprs, indexpr_item);
5267 elog(
ERROR,
"index key does not match expected index column");
5303 temp->opresulttype = clause->opresulttype;
5304 temp->opretset = clause->opretset;
5305 temp->opcollid = clause->opcollid;
5306 temp->inputcollid = clause->inputcollid;
5311 t_list =
lappend(t_list, temp);
5312 restrictinfo->outer_is_left =
false;
5317 t_list =
lappend(t_list, clause);
5318 restrictinfo->outer_is_left =
true;
5364 Index security_level;
5382 foreach(lc, clauses)
5388 items[
i].clause = clause;
5405 items[
i].security_level = 0;
5410 items[
i].security_level = 0;
5421 QualItem newitem =
items[
i];
5425 for (
j =
i;
j > 0;
j--)
5427 QualItem *olditem = &
items[
j - 1];
5429 if (newitem.security_level > olditem->security_level ||
5430 (newitem.security_level == olditem->security_level &&
5431 newitem.cost >= olditem->cost))
5458 dest->plan_width = src->pathtarget->width;
5476 dest->parallel_aware =
false;