68 #define CP_EXACT_TLIST 0x0001
69 #define CP_SMALL_TLIST 0x0002
70 #define CP_LABEL_TLIST 0x0004
71 #define CP_IGNORE_TLIST 0x0008
126 List *tlist,
List *scan_clauses,
bool indexonly);
167 List **stripped_indexquals_p,
168 List **fixed_indexquals_p);
179 double limit_tuples);
185 List *indexorderby,
List *indexorderbyorig,
186 List *indexorderbyops,
196 List *indexqualorig);
200 List *bitmapqualorig,
217 Index scanrelid,
int ctePlanId,
int cteParam);
219 Index scanrelid,
char *enrname);
221 Index scanrelid,
int wtParam);
231 List *joinclauses,
List *otherclauses,
List *nestParams,
233 JoinType jointype,
bool inner_unique);
235 List *joinclauses,
List *otherclauses,
237 List *hashoperators,
List *hashcollations,
240 JoinType jointype,
bool inner_unique);
247 List *joinclauses,
List *otherclauses,
250 Oid *mergecollations,
251 int *mergestrategies,
252 bool *mergenullsfirst,
254 JoinType jointype,
bool inner_unique,
255 bool skip_mark_restore);
258 Oid *collations,
bool *nullsFirst);
260 int numCols,
int nPresortedCols,
262 Oid *collations,
bool *nullsFirst);
266 bool adjust_tlist_in_place,
269 Oid **p_sortOperators,
271 bool **p_nullsFirst);
275 List *pathkeys,
Relids relids,
int nPresortedCols);
281 Oid *collations,
List *param_exprs,
282 bool singlerow,
bool binary_mode,
285 int partNumCols,
AttrNumber *partColIdx,
Oid *partOperators,
Oid *partCollations,
286 int ordNumCols,
AttrNumber *ordColIdx,
Oid *ordOperators,
Oid *ordCollations,
287 int frameOptions,
Node *startOffset,
Node *endOffset,
288 Oid startInRangeFunc,
Oid endInRangeFunc,
289 Oid inRangeColl,
bool inRangeAsc,
bool inRangeNullsFirst,
290 List *runCondition,
List *qual,
bool topWindow,
297 List *pathkeys,
int numCols);
299 int nworkers,
int rescan_param,
bool single_copy,
Plan *subplan);
307 CmdType operation,
bool canSetTag,
309 bool partColsUpdated,
310 List *resultRelations,
311 List *updateColnosLists,
312 List *withCheckOptionLists,
List *returningLists,
314 List *mergeActionLists,
int epqParam);
370 elog(
ERROR,
"failed to assign all NestLoopParams to plan nodes");
398 case T_IndexOnlyScan:
399 case T_BitmapHeapScan:
404 case T_TableFuncScan:
407 case T_WorkTableScan:
408 case T_NamedTuplestoreScan:
491 case T_IncrementalSort:
520 case T_RecursiveUnion:
543 elog(
ERROR,
"unrecognized node type: %d",
544 (
int) best_path->pathtype);
561 List *gating_clauses;
580 case T_IndexOnlyScan:
594 if (best_path->param_info)
596 best_path->param_info->ppi_clauses);
613 best_path->
pathtype == T_CustomScan);
614 if (best_path->
pathtype == T_ForeignScan)
615 join_clauses = ((
ForeignPath *) best_path)->fdw_restrictinfo;
617 join_clauses = ((
CustomPath *) best_path)->custom_restrictinfo;
642 if (best_path->
pathtype == T_IndexOnlyScan)
699 case T_IndexOnlyScan:
707 case T_BitmapHeapScan:
742 case T_TableFuncScan:
763 case T_NamedTuplestoreScan:
777 case T_WorkTableScan:
799 elog(
ERROR,
"unrecognized node type: %d",
826 Index *sortgrouprefs = path->pathtarget->sortgrouprefs;
830 foreach(v, path->pathtarget->exprs)
841 if (path->param_info)
910 path->pathtarget->exprs ==
NIL)
942 if (path->
pathtype == T_IndexOnlyScan)
948 if (!indexinfo->canreturn[
i])
967 foreach(lc, path->pathtarget->exprs)
971 if (path->pathtarget->sortgrouprefs[
i])
973 if (expr &&
IsA(expr,
Var))
975 int attno = ((
Var *) expr)->varattno;
1050 (
Node *) gating_quals,
1082 List *gating_clauses;
1084 switch (best_path->path.pathtype)
1099 elog(
ERROR,
"unrecognized node type: %d",
1100 (
int) best_path->path.pathtype);
1122 if (get_loc_restrictinfo(best_path) !=
NIL)
1142 case T_SubqueryScanPath:
1165 FdwRoutine *fdwroutine = path->parent->fdwroutine;
1174 Assert(fdwroutine != NULL);
1180 case T_ProjectionPath:
1201 plan->async_capable =
true;
1219 bool tlist_was_changed =
false;
1223 int nasyncplans = 0;
1226 int nodenumsortkeys = 0;
1228 Oid *nodeSortOperators = NULL;
1229 Oid *nodeCollations = NULL;
1230 bool *nodeNullsFirst = NULL;
1231 bool consider_async =
false;
1269 plan->plan.targetlist = tlist;
1271 plan->plan.lefttree = NULL;
1272 plan->plan.righttree = NULL;
1275 if (pathkeys !=
NIL)
1284 best_path->
path.parent->relids,
1292 tlist_was_changed = (orig_tlist_length !=
list_length(
plan->plan.targetlist));
1301 foreach(subpaths, best_path->
subpaths)
1313 if (pathkeys !=
NIL)
1343 Assert(numsortkeys == nodenumsortkeys);
1344 if (memcmp(sortColIdx, nodeSortColIdx,
1346 elog(
ERROR,
"Append child's targetlist doesn't match Append");
1347 Assert(memcmp(sortOperators, nodeSortOperators,
1348 numsortkeys *
sizeof(
Oid)) == 0);
1349 Assert(memcmp(collations, nodeCollations,
1350 numsortkeys *
sizeof(
Oid)) == 0);
1351 Assert(memcmp(nullsFirst, nodeNullsFirst,
1352 numsortkeys *
sizeof(
bool)) == 0);
1358 sortColIdx, sortOperators,
1359 collations, nullsFirst);
1373 subplans =
lappend(subplans, subplan);
1387 if (best_path->
path.param_info)
1389 List *prmquals = best_path->
path.param_info->ppi_clauses;
1398 if (prunequal !=
NIL)
1405 plan->appendplans = subplans;
1406 plan->nasyncplans = nasyncplans;
1408 plan->part_prune_info = partpruneinfo;
1421 plan->plan.parallel_safe);
1442 bool tlist_was_changed;
1456 plan->targetlist = tlist;
1458 plan->lefttree = NULL;
1459 plan->righttree = NULL;
1469 best_path->
path.parent->relids,
1474 &node->sortOperators,
1477 tlist_was_changed = (orig_tlist_length !=
list_length(
plan->targetlist));
1484 foreach(subpaths, best_path->
subpaths)
1516 if (memcmp(sortColIdx, node->sortColIdx,
1518 elog(
ERROR,
"MergeAppend child's targetlist doesn't match MergeAppend");
1519 Assert(memcmp(sortOperators, node->sortOperators,
1520 numsortkeys *
sizeof(
Oid)) == 0);
1521 Assert(memcmp(collations, node->collations,
1522 numsortkeys *
sizeof(
Oid)) == 0);
1523 Assert(memcmp(nullsFirst, node->nullsFirst,
1524 numsortkeys *
sizeof(
bool)) == 0);
1530 sortColIdx, sortOperators,
1531 collations, nullsFirst);
1537 subplans =
lappend(subplans, subplan);
1554 if (prunequal !=
NIL)
1685 operators =
palloc(nkeys *
sizeof(
Oid));
1686 collations =
palloc(nkeys *
sizeof(
Oid));
1694 operators[
i] = opno;
1729 Oid *groupCollations;
1764 foreach(l, uniq_exprs)
1776 newtlist =
lappend(newtlist, tle);
1796 groupCollations = (
Oid *)
palloc(numGroupCols *
sizeof(
Oid));
1799 foreach(l, uniq_exprs)
1806 elog(
ERROR,
"failed to find unique expression in subplan tlist");
1807 groupColIdx[groupColPos] = tle->
resno;
1814 Oid *groupOperators;
1822 groupOperators = (
Oid *)
palloc(numGroupCols *
sizeof(
Oid));
1824 foreach(l, in_operators)
1830 elog(
ERROR,
"could not find compatible hash operator for operator %u",
1832 groupOperators[groupColPos++] = eq_oper;
1861 foreach(l, in_operators)
1871 elog(
ERROR,
"could not find ordering operator for equality operator %u",
1882 elog(
ERROR,
"could not find equality operator for ordering operator %u",
1886 groupColIdx[groupColPos]);
1892 sortcl->
eqop = eqop;
1895 sortcl->hashable =
false;
1896 sortList =
lappend(sortList, sortcl);
1979 best_path->
subpath->parent->relids,
1980 gm_plan->sortColIdx,
1983 &gm_plan->sortColIdx,
1984 &gm_plan->sortOperators,
1985 &gm_plan->collations,
1986 &gm_plan->nullsFirst);
1997 elog(
ERROR,
"gather merge input not sufficiently sorted");
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,
2354 AttrNumber *grouping_map = root->grouping_map;
2364 foreach(lc, groupClause)
2371 return new_grpColIdx;
2439 Assert(root->grouping_map == NULL);
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);
2579 plan->plan_rows = 1;
2580 plan->plan_width = mminfo->
path->pathtarget->width;
2581 plan->parallel_aware =
false;
2625 Oid *partCollations;
2649 partCollations = (
Oid *)
palloc(
sizeof(
Oid) * numPart);
2658 partColIdx[partNumCols] = tle->
resno;
2659 partOperators[partNumCols] = sgc->
eqop;
2666 ordCollations = (
Oid *)
palloc(
sizeof(
Oid) * numOrder);
2675 ordColIdx[ordNumCols] = tle->
resno;
2676 ordOperators[ordNumCols] = sgc->
eqop;
2695 wc->startInRangeFunc,
2699 wc->inRangeNullsFirst,
2856 int numUniqkeys = 0;
2858 Oid *uniqOperators = NULL;
2859 Oid *uniqCollations = NULL;
2872 uniqOperators = (
Oid *)
palloc(numUniqkeys *
sizeof(
Oid));
2873 uniqCollations = (
Oid *)
palloc(numUniqkeys *
sizeof(
Oid));
2876 foreach(l,
parse->sortClause)
2881 uniqColIdx[numUniqkeys] = tle->
resno;
2882 uniqOperators[numUniqkeys] = sortcl->
eqop;
2892 numUniqkeys, uniqColIdx, uniqOperators, uniqCollations);
2917 Index scan_relid = best_path->parent->relid;
2930 if (best_path->param_info)
2932 scan_clauses = (
List *)
2955 Index scan_relid = best_path->parent->relid;
2973 if (best_path->param_info)
2975 scan_clauses = (
List *)
3011 Index baserelid = best_path->
path.parent->relid;
3015 List *stripped_indexquals;
3016 List *fixed_indexquals;
3017 List *fixed_indexorderbys;
3035 &stripped_indexquals,
3072 foreach(l, scan_clauses)
3076 if (rinfo->pseudoconstant)
3084 qpqual =
lappend(qpqual, rinfo);
3102 if (best_path->
path.param_info)
3104 stripped_indexquals = (
List *)
3108 indexorderbys = (
List *)
3140 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
3142 indexorderbyops =
lappend_oid(indexorderbyops, sortop);
3159 indextle->resjunk = !indexinfo->canreturn[
i];
3171 stripped_indexquals,
3172 fixed_indexorderbys,
3181 stripped_indexquals,
3182 fixed_indexorderbys,
3203 Index baserelid = best_path->
path.parent->relid;
3204 Plan *bitmapqualplan;
3205 List *bitmapqualorig;
3218 &bitmapqualorig, &indexquals,
3251 foreach(l, scan_clauses)
3256 if (rinfo->pseudoconstant)
3265 qpqual =
lappend(qpqual, rinfo);
3287 if (best_path->
path.param_info)
3291 bitmapqualorig = (
List *)
3357 &subqual, &subindexqual,
3359 subplans =
lappend(subplans, subplan);
3363 subindexECs =
list_concat(subindexECs, subindexEC);
3370 plan->plan_width = 0;
3371 plan->parallel_aware =
false;
3374 *indexqual = subindexquals;
3375 *indexECs = subindexECs;
3383 bool const_true_subqual =
false;
3384 bool const_true_subindexqual =
false;
3404 &subqual, &subindexqual,
3406 subplans =
lappend(subplans, subplan);
3408 const_true_subqual =
true;
3409 else if (!const_true_subqual)
3412 if (subindexqual ==
NIL)
3413 const_true_subindexqual =
true;
3414 else if (!const_true_subindexqual)
3415 subindexquals =
lappend(subindexquals,
3434 plan->plan_width = 0;
3435 plan->parallel_aware =
false;
3444 if (const_true_subqual)
3450 if (const_true_subindexqual)
3453 *indexqual = subindexquals;
3463 List *subindexquals;
3477 plan->startup_cost = 0.0;
3481 plan->plan_width = 0;
3482 plan->parallel_aware =
false;
3486 subindexquals =
NIL;
3493 Assert(!rinfo->pseudoconstant);
3497 if (rinfo->parent_ec)
3498 subindexECs =
lappend(subindexECs, rinfo->parent_ec);
3513 subquals =
lappend(subquals, pred);
3514 subindexquals =
lappend(subindexquals, pred);
3518 *indexqual = subindexquals;
3519 *indexECs = subindexECs;
3540 Index scan_relid = best_path->
path.parent->relid;
3571 foreach(l, scan_clauses)
3575 if (rinfo->pseudoconstant)
3581 qpqual =
lappend(qpqual, rinfo);
3583 scan_clauses = qpqual;
3609 if (best_path->
path.param_info)
3613 scan_clauses = (
List *)
3637 Index scan_relid = best_path->
path.parent->relid;
3653 foreach(l, scan_clauses)
3657 if (rinfo->pseudoconstant)
3661 qpqual =
lappend(qpqual, rinfo);
3663 scan_clauses = qpqual;
3674 if (best_path->
path.param_info)
3676 tidrangequals = (
List *)
3678 scan_clauses = (
List *)
3724 if (best_path->
path.param_info)
3726 scan_clauses = (
List *)
3752 Index scan_relid = best_path->parent->relid;
3769 if (best_path->param_info)
3771 scan_clauses = (
List *)
3795 Index scan_relid = best_path->parent->relid;
3812 if (best_path->param_info)
3814 scan_clauses = (
List *)
3838 Index scan_relid = best_path->parent->relid;
3855 if (best_path->param_info)
3857 scan_clauses = (
List *)
3860 values_lists = (
List *)
3882 Index scan_relid = best_path->parent->relid;
3902 while (levelsup-- > 0)
3904 cteroot = cteroot->parent_root;
3933 if (ctesplan->
plan_id == plan_id)
3952 if (best_path->param_info)
3954 scan_clauses = (
List *)
3958 scan_plan =
make_ctescan(tlist, scan_clauses, scan_relid,
3959 plan_id, cte_param_id);
3977 Index scan_relid = best_path->parent->relid;
3991 if (best_path->param_info)
3993 scan_clauses = (
List *)
4016 Index scan_relid = best_path->parent->relid;
4030 if (best_path->param_info)
4032 scan_clauses = (
List *)
4053 Index scan_relid = best_path->parent->relid;
4073 while (levelsup-- > 0)
4075 cteroot = cteroot->parent_root;
4089 if (best_path->param_info)
4091 scan_clauses = (
List *)
4116 Plan *outer_plan = NULL;
4118 Assert(rel->fdwroutine != NULL);
4136 rel_oid = rte->
relid;
4152 scan_plan = rel->fdwroutine->GetForeignPlan(root, rel, rel_oid,
4154 tlist, scan_clauses,
4200 if (best_path->
path.param_info)
4202 scan_plan->
scan.plan.qual = (
List *)
4316 if (best_path->
path.param_info)
4370 best_path->
jpath.path.parent->relids,
4371 &joinclauses, &otherclauses);
4381 if (best_path->
jpath.path.param_info)
4383 joinclauses = (
List *)
4385 otherclauses = (
List *)
4421 List *outerpathkeys;
4422 List *innerpathkeys;
4425 Oid *mergecollations;
4426 int *mergestrategies;
4427 bool *mergenullsfirst;
4458 best_path->
jpath.path.parent->relids,
4459 &joinclauses, &otherclauses);
4479 if (best_path->
jpath.path.param_info)
4481 joinclauses = (
List *)
4483 otherclauses = (
List *)
4500 Relids outer_relids = outer_path->parent->relids;
4514 Relids inner_relids = inner_path->parent->relids;
4542 inner_plan = matplan;
4554 mergefamilies = (
Oid *)
palloc(nClauses *
sizeof(
Oid));
4555 mergecollations = (
Oid *)
palloc(nClauses *
sizeof(
Oid));
4556 mergestrategies = (
int *)
palloc(nClauses *
sizeof(
int));
4557 mergenullsfirst = (
bool *)
palloc(nClauses *
sizeof(
bool));
4571 bool first_inner_match =
false;
4574 if (rinfo->outer_is_left)
4576 oeclass = rinfo->left_ec;
4577 ieclass = rinfo->right_ec;
4581 oeclass = rinfo->right_ec;
4582 ieclass = rinfo->left_ec;
4602 if (oeclass != opeclass)
4606 elog(
ERROR,
"outer pathkeys do not match mergeclauses");
4608 opeclass = opathkey->pk_eclass;
4609 lop =
lnext(outerpathkeys, lop);
4610 if (oeclass != opeclass)
4611 elog(
ERROR,
"outer pathkeys do not match mergeclauses");
4632 ipeclass = ipathkey->pk_eclass;
4633 if (ieclass == ipeclass)
4636 lip =
lnext(innerpathkeys, lip);
4637 first_inner_match =
true;
4640 if (!first_inner_match)
4645 foreach(l2, innerpathkeys)
4650 ipeclass = ipathkey->pk_eclass;
4651 if (ieclass == ipeclass)
4654 if (ieclass != ipeclass)
4655 elog(
ERROR,
"inner pathkeys do not match mergeclauses");
4673 opathkey->pk_eclass->ec_collation != ipathkey->pk_eclass->ec_collation)
4674 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
4675 if (first_inner_match &&
4678 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
4682 mergecollations[
i] = opathkey->pk_eclass->ec_collation;
4735 bool skewInherit =
false;
4760 best_path->
jpath.path.parent->relids,
4761 &joinclauses, &otherclauses);
4781 if (best_path->
jpath.path.param_info)
4783 joinclauses = (
List *)
4785 otherclauses = (
List *)
4818 rte = root->simple_rte_array[var->
varno];
4821 skewTable = rte->
relid;
4823 skewInherit = rte->
inh;
4836 foreach(lc, hashclauses)
4841 hashcollations =
lappend_oid(hashcollations, hclause->inputcollid);
4867 if (best_path->
jpath.path.parallel_aware)
4960 newphv->phexpr = (
Expr *)
4963 return (
Node *) newphv;
4995 List **stripped_indexquals_p,
List **fixed_indexquals_p)
4998 List *stripped_indexquals;
4999 List *fixed_indexquals;
5002 stripped_indexquals = fixed_indexquals =
NIL;
5015 stripped_indexquals =
lappend(stripped_indexquals, clause);
5018 fixed_indexquals =
lappend(fixed_indexquals, clause);
5022 *stripped_indexquals_p = stripped_indexquals;
5023 *fixed_indexquals_p = fixed_indexquals;
5038 List *fixed_indexorderbys;
5042 fixed_indexorderbys =
NIL;
5050 fixed_indexorderbys =
lappend(fixed_indexorderbys, clause);
5053 return fixed_indexorderbys;
5118 elog(
ERROR,
"unsupported indexqual type: %d",
5147 Assert(indexcol >= 0 && indexcol < index->ncolumns);
5149 if (
index->indexkeys[indexcol] != 0)
5153 ((
Var *) node)->varno ==
index->rel->relid &&
5154 ((
Var *) node)->varattno ==
index->indexkeys[indexcol])
5159 return (
Node *) result;
5162 elog(
ERROR,
"index key does not match expected index column");
5167 for (pos = 0; pos <
index->ncolumns; pos++)
5169 if (
index->indexkeys[pos] == 0)
5171 if (indexpr_item == NULL)
5172 elog(
ERROR,
"too few entries in indexprs list");
5173 if (pos == indexcol)
5180 if (
equal(node, indexkey))
5186 return (
Node *) result;
5189 elog(
ERROR,
"index key does not match expected index column");
5191 indexpr_item =
lnext(
index->indexprs, indexpr_item);
5196 elog(
ERROR,
"index key does not match expected index column");
5232 temp->opresulttype = clause->opresulttype;
5233 temp->opretset = clause->opretset;
5234 temp->opcollid = clause->opcollid;
5235 temp->inputcollid = clause->inputcollid;
5240 t_list =
lappend(t_list, temp);
5241 restrictinfo->outer_is_left =
false;
5246 t_list =
lappend(t_list, clause);
5247 restrictinfo->outer_is_left =
true;
5293 Index security_level;
5309 items = (QualItem *)
palloc(
nitems *
sizeof(QualItem));
5311 foreach(lc, clauses)
5317 items[
i].clause = clause;
5334 items[
i].security_level = 0;
5339 items[
i].security_level = 0;
5350 QualItem newitem = items[
i];
5354 for (
j =
i;
j > 0;
j--)
5356 QualItem *olditem = &items[
j - 1];
5358 if (newitem.security_level > olditem->security_level ||
5359 (newitem.security_level == olditem->security_level &&
5360 newitem.cost >= olditem->cost))
5362 items[
j] = *olditem;
5370 result =
lappend(result, items[
i].clause);
5386 dest->plan_width = src->pathtarget->width;
5403 dest->parallel_aware =
false;
5420 Plan *lefttree =
plan->plan.lefttree;
5440 plan->plan.parallel_aware =
false;
5487 plan->targetlist = qptlist;
5488 plan->qual = qpqual;
5489 plan->lefttree = NULL;
5490 plan->righttree = NULL;
5505 plan->targetlist = qptlist;
5506 plan->qual = qpqual;
5507 plan->lefttree = NULL;
5508 plan->righttree = NULL;
5521 List *indexqualorig,
5523 List *indexorderbyorig,
5524 List *indexorderbyops,
5530 plan->targetlist = qptlist;
5531 plan->qual = qpqual;
5532 plan->lefttree = NULL;
5533 plan->righttree = NULL;
5560 plan->targetlist = qptlist;
5561 plan->qual = qpqual;
5562 plan->lefttree = NULL;
5563 plan->righttree = NULL;
5579 List *indexqualorig)
5586 plan->lefttree = NULL;
5587 plan->righttree = NULL;
5600 List *bitmapqualorig,
5606 plan->targetlist = qptlist;
5607 plan->qual = qpqual;
5608 plan->lefttree = lefttree;
5609 plan->righttree = NULL;