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);
623 if (best_path->
pathtype == T_IndexOnlyScan)
680 case T_IndexOnlyScan:
688 case T_BitmapHeapScan:
723 case T_TableFuncScan:
744 case T_NamedTuplestoreScan:
758 case T_WorkTableScan:
780 elog(
ERROR,
"unrecognized node type: %d",
807 Index *sortgrouprefs = path->pathtarget->sortgrouprefs;
811 foreach(v, path->pathtarget->exprs)
822 if (path->param_info)
891 path->pathtarget->exprs ==
NIL)
923 if (path->
pathtype == T_IndexOnlyScan)
929 if (!indexinfo->canreturn[
i])
948 foreach(lc, path->pathtarget->exprs)
952 if (path->pathtarget->sortgrouprefs[
i])
954 if (expr &&
IsA(expr,
Var))
956 int attno = ((
Var *) expr)->varattno;
1031 (
Node *) gating_quals,
1063 List *gating_clauses;
1065 switch (best_path->path.pathtype)
1080 elog(
ERROR,
"unrecognized node type: %d",
1081 (
int) best_path->path.pathtype);
1103 if (get_loc_restrictinfo(best_path) !=
NIL)
1104 set_qpqual((
Plan) plan,
1123 case T_SubqueryScanPath:
1146 FdwRoutine *fdwroutine = path->parent->fdwroutine;
1155 Assert(fdwroutine != NULL);
1161 case T_ProjectionPath:
1200 bool tlist_was_changed =
false;
1204 int nasyncplans = 0;
1206 int nodenumsortkeys = 0;
1208 Oid *nodeSortOperators = NULL;
1209 Oid *nodeCollations = NULL;
1210 bool *nodeNullsFirst = NULL;
1211 bool consider_async =
false;
1255 if (pathkeys !=
NIL)
1264 best_path->
path.parent->relids,
1281 foreach(subpaths, best_path->
subpaths)
1293 if (pathkeys !=
NIL)
1323 Assert(numsortkeys == nodenumsortkeys);
1324 if (memcmp(sortColIdx, nodeSortColIdx,
1326 elog(
ERROR,
"Append child's targetlist doesn't match Append");
1327 Assert(memcmp(sortOperators, nodeSortOperators,
1328 numsortkeys *
sizeof(
Oid)) == 0);
1329 Assert(memcmp(collations, nodeCollations,
1330 numsortkeys *
sizeof(
Oid)) == 0);
1331 Assert(memcmp(nullsFirst, nodeNullsFirst,
1332 numsortkeys *
sizeof(
bool)) == 0);
1338 sortColIdx, sortOperators,
1339 collations, nullsFirst);
1353 subplans =
lappend(subplans, subplan);
1370 if (best_path->
path.param_info)
1372 List *prmquals = best_path->
path.param_info->ppi_clauses;
1381 if (prunequal !=
NIL)
1405 return (
Plan *) plan;
1423 bool tlist_was_changed;
1449 best_path->
path.parent->relids,
1454 &node->sortOperators,
1464 foreach(subpaths, best_path->
subpaths)
1496 if (memcmp(sortColIdx, node->sortColIdx,
1498 elog(
ERROR,
"MergeAppend child's targetlist doesn't match MergeAppend");
1499 Assert(memcmp(sortOperators, node->sortOperators,
1500 numsortkeys *
sizeof(
Oid)) == 0);
1501 Assert(memcmp(collations, node->collations,
1502 numsortkeys *
sizeof(
Oid)) == 0);
1503 Assert(memcmp(nullsFirst, node->nullsFirst,
1504 numsortkeys *
sizeof(
bool)) == 0);
1510 sortColIdx, sortOperators,
1511 collations, nullsFirst);
1517 subplans =
lappend(subplans, subplan);
1537 if (prunequal !=
NIL)
1668 operators =
palloc(nkeys *
sizeof(
Oid));
1669 collations =
palloc(nkeys *
sizeof(
Oid));
1677 operators[
i] = opno;
1684 plan =
make_memoize(subplan, operators, collations, param_exprs,
1712 Oid *groupCollations;
1747 foreach(l, uniq_exprs)
1759 newtlist =
lappend(newtlist, tle);
1779 groupCollations = (
Oid *)
palloc(numGroupCols *
sizeof(
Oid));
1782 foreach(l, uniq_exprs)
1789 elog(
ERROR,
"failed to find unique expression in subplan tlist");
1790 groupColIdx[groupColPos] = tle->
resno;
1797 Oid *groupOperators;
1805 groupOperators = (
Oid *)
palloc(numGroupCols *
sizeof(
Oid));
1807 foreach(l, in_operators)
1813 elog(
ERROR,
"could not find compatible hash operator for operator %u",
1815 groupOperators[groupColPos++] = eq_oper;
1844 foreach(l, in_operators)
1854 elog(
ERROR,
"could not find ordering operator for equality operator %u",
1865 elog(
ERROR,
"could not find equality operator for ordering operator %u",
1869 groupColIdx[groupColPos]);
1875 sortcl->
eqop = eqop;
1878 sortcl->hashable =
false;
1879 sortList =
lappend(sortList, sortcl);
1962 best_path->
subpath->parent->relids,
1963 gm_plan->sortColIdx,
1966 &gm_plan->sortColIdx,
1967 &gm_plan->sortOperators,
1968 &gm_plan->collations,
1969 &gm_plan->nullsFirst);
1980 elog(
ERROR,
"gather merge input not sufficiently sorted");
2004 bool needs_result_node =
false;
2030 best_path->
path.pathtarget);
2064 if (!needs_result_node)
2144 tlist_parallel_safe);
2182 best_path->
path.parent->relids : NULL);
2207 best_path->
spath.
path.parent->relids : NULL,
2337 AttrNumber *grouping_map = root->grouping_map;
2347 foreach(lc, groupClause)
2354 return new_grpColIdx;
2422 Assert(root->grouping_map == NULL);
2423 root->grouping_map = grouping_map;
2440 Plan *sort_plan = NULL;
2446 if (!rollup->
is_hashed && !is_first_sort)
2448 sort_plan = (
Plan *)
2455 is_first_sort =
false;
2487 chain =
lappend(chain, agg_plan);
2521 return (
Plan *) plan;
2557 0, NULL, NULL, NULL);
2608 Oid *partCollations;
2637 partCollations = (
Oid *)
palloc(
sizeof(
Oid) * numPart);
2646 partColIdx[partNumCols] = tle->
resno;
2647 partOperators[partNumCols] = sgc->
eqop;
2654 ordCollations = (
Oid *)
palloc(
sizeof(
Oid) * numOrder);
2663 ordColIdx[ordNumCols] = tle->
resno;
2664 ordOperators[ordNumCols] = sgc->
eqop;
2683 wc->startInRangeFunc,
2687 wc->inRangeNullsFirst,
2844 int numUniqkeys = 0;
2846 Oid *uniqOperators = NULL;
2847 Oid *uniqCollations = NULL;
2860 uniqOperators = (
Oid *)
palloc(numUniqkeys *
sizeof(
Oid));
2861 uniqCollations = (
Oid *)
palloc(numUniqkeys *
sizeof(
Oid));
2864 foreach(l,
parse->sortClause)
2869 uniqColIdx[numUniqkeys] = tle->
resno;
2870 uniqOperators[numUniqkeys] = sortcl->
eqop;
2880 numUniqkeys, uniqColIdx, uniqOperators, uniqCollations);
2905 Index scan_relid = best_path->parent->relid;
2918 if (best_path->param_info)
2920 scan_clauses = (
List *)
2943 Index scan_relid = best_path->parent->relid;
2961 if (best_path->param_info)
2963 scan_clauses = (
List *)
2999 Index baserelid = best_path->
path.parent->relid;
3003 List *stripped_indexquals;
3004 List *fixed_indexquals;
3005 List *fixed_indexorderbys;
3023 &stripped_indexquals,
3060 foreach(l, scan_clauses)
3064 if (rinfo->pseudoconstant)
3072 qpqual =
lappend(qpqual, rinfo);
3090 if (best_path->
path.param_info)
3092 stripped_indexquals = (
List *)
3096 indexorderbys = (
List *)
3128 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
3130 indexorderbyops =
lappend_oid(indexorderbyops, sortop);
3147 indextle->resjunk = !indexinfo->canreturn[
i];
3159 stripped_indexquals,
3160 fixed_indexorderbys,
3169 stripped_indexquals,
3170 fixed_indexorderbys,
3191 Index baserelid = best_path->
path.parent->relid;
3192 Plan *bitmapqualplan;
3193 List *bitmapqualorig;
3206 &bitmapqualorig, &indexquals,
3239 foreach(l, scan_clauses)
3244 if (rinfo->pseudoconstant)
3253 qpqual =
lappend(qpqual, rinfo);
3275 if (best_path->
path.param_info)
3279 bitmapqualorig = (
List *)
3345 &subqual, &subindexqual,
3347 subplans =
lappend(subplans, subplan);
3351 subindexECs =
list_concat(subindexECs, subindexEC);
3362 *indexqual = subindexquals;
3363 *indexECs = subindexECs;
3371 bool const_true_subqual =
false;
3372 bool const_true_subindexqual =
false;
3392 &subqual, &subindexqual,
3394 subplans =
lappend(subplans, subplan);
3396 const_true_subqual =
true;
3397 else if (!const_true_subqual)
3400 if (subindexqual ==
NIL)
3401 const_true_subindexqual =
true;
3402 else if (!const_true_subindexqual)
3403 subindexquals =
lappend(subindexquals,
3432 if (const_true_subqual)
3438 if (const_true_subindexqual)
3441 *indexqual = subindexquals;
3451 List *subindexquals;
3474 subindexquals =
NIL;
3481 Assert(!rinfo->pseudoconstant);
3485 if (rinfo->parent_ec)
3486 subindexECs =
lappend(subindexECs, rinfo->parent_ec);
3501 subquals =
lappend(subquals, pred);
3502 subindexquals =
lappend(subindexquals, pred);
3506 *indexqual = subindexquals;
3507 *indexECs = subindexECs;
3528 Index scan_relid = best_path->
path.parent->relid;
3559 foreach(l, scan_clauses)
3563 if (rinfo->pseudoconstant)
3569 qpqual =
lappend(qpqual, rinfo);
3571 scan_clauses = qpqual;
3597 if (best_path->
path.param_info)
3601 scan_clauses = (
List *)
3625 Index scan_relid = best_path->
path.parent->relid;
3641 foreach(l, scan_clauses)
3645 if (rinfo->pseudoconstant)
3649 qpqual =
lappend(qpqual, rinfo);
3651 scan_clauses = qpqual;
3662 if (best_path->
path.param_info)
3664 tidrangequals = (
List *)
3666 scan_clauses = (
List *)
3712 if (best_path->
path.param_info)
3714 scan_clauses = (
List *)
3740 Index scan_relid = best_path->parent->relid;
3757 if (best_path->param_info)
3759 scan_clauses = (
List *)
3783 Index scan_relid = best_path->parent->relid;
3800 if (best_path->param_info)
3802 scan_clauses = (
List *)
3826 Index scan_relid = best_path->parent->relid;
3843 if (best_path->param_info)
3845 scan_clauses = (
List *)
3848 values_lists = (
List *)
3870 Index scan_relid = best_path->parent->relid;
3890 while (levelsup-- > 0)
3892 cteroot = cteroot->parent_root;
3921 if (ctesplan->
plan_id == plan_id)
3940 if (best_path->param_info)
3942 scan_clauses = (
List *)
3946 scan_plan =
make_ctescan(tlist, scan_clauses, scan_relid,
3947 plan_id, cte_param_id);
3965 Index scan_relid = best_path->parent->relid;
3979 if (best_path->param_info)
3981 scan_clauses = (
List *)
4004 Index scan_relid = best_path->parent->relid;
4018 if (best_path->param_info)
4020 scan_clauses = (
List *)
4041 Index scan_relid = best_path->parent->relid;
4061 while (levelsup-- > 0)
4063 cteroot = cteroot->parent_root;
4077 if (best_path->param_info)
4079 scan_clauses = (
List *)
4104 Plan *outer_plan = NULL;
4106 Assert(rel->fdwroutine != NULL);
4124 rel_oid = rte->
relid;
4140 scan_plan = rel->fdwroutine->GetForeignPlan(root, rel, rel_oid,
4142 tlist, scan_clauses,
4188 if (best_path->
path.param_info)
4190 scan_plan->
scan.plan.qual = (
List *)
4266 custom_plans =
lappend(custom_plans, plan);
4304 if (best_path->
path.param_info)
4358 best_path->
jpath.path.parent->relids,
4359 &joinclauses, &otherclauses);
4369 if (best_path->
jpath.path.param_info)
4371 joinclauses = (
List *)
4373 otherclauses = (
List *)
4409 List *outerpathkeys;
4410 List *innerpathkeys;
4413 Oid *mergecollations;
4414 int *mergestrategies;
4415 bool *mergenullsfirst;
4446 best_path->
jpath.path.parent->relids,
4447 &joinclauses, &otherclauses);
4467 if (best_path->
jpath.path.param_info)
4469 joinclauses = (
List *)
4471 otherclauses = (
List *)
4488 Relids outer_relids = outer_path->parent->relids;
4502 Relids inner_relids = inner_path->parent->relids;
4530 inner_plan = matplan;
4542 mergefamilies = (
Oid *)
palloc(nClauses *
sizeof(
Oid));
4543 mergecollations = (
Oid *)
palloc(nClauses *
sizeof(
Oid));
4544 mergestrategies = (
int *)
palloc(nClauses *
sizeof(
int));
4545 mergenullsfirst = (
bool *)
palloc(nClauses *
sizeof(
bool));
4559 bool first_inner_match =
false;
4562 if (rinfo->outer_is_left)
4564 oeclass = rinfo->left_ec;
4565 ieclass = rinfo->right_ec;
4569 oeclass = rinfo->right_ec;
4570 ieclass = rinfo->left_ec;
4590 if (oeclass != opeclass)
4594 elog(
ERROR,
"outer pathkeys do not match mergeclauses");
4596 opeclass = opathkey->pk_eclass;
4597 lop =
lnext(outerpathkeys, lop);
4598 if (oeclass != opeclass)
4599 elog(
ERROR,
"outer pathkeys do not match mergeclauses");
4620 ipeclass = ipathkey->pk_eclass;
4621 if (ieclass == ipeclass)
4624 lip =
lnext(innerpathkeys, lip);
4625 first_inner_match =
true;
4628 if (!first_inner_match)
4633 foreach(l2, innerpathkeys)
4638 ipeclass = ipathkey->pk_eclass;
4639 if (ieclass == ipeclass)
4642 if (ieclass != ipeclass)
4643 elog(
ERROR,
"inner pathkeys do not match mergeclauses");
4661 opathkey->pk_eclass->ec_collation != ipathkey->pk_eclass->ec_collation)
4662 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
4663 if (first_inner_match &&
4666 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
4670 mergecollations[
i] = opathkey->pk_eclass->ec_collation;
4723 bool skewInherit =
false;
4748 best_path->
jpath.path.parent->relids,
4749 &joinclauses, &otherclauses);
4769 if (best_path->
jpath.path.param_info)
4771 joinclauses = (
List *)
4773 otherclauses = (
List *)
4806 rte = root->simple_rte_array[var->
varno];
4809 skewTable = rte->
relid;
4811 skewInherit = rte->
inh;
4824 foreach(lc, hashclauses)
4829 hashcollations =
lappend_oid(hashcollations, hclause->inputcollid);
4855 if (best_path->
jpath.path.parallel_aware)
4948 newphv->phexpr = (
Expr *)
4951 return (
Node *) newphv;
4983 List **stripped_indexquals_p,
List **fixed_indexquals_p)
4986 List *stripped_indexquals;
4987 List *fixed_indexquals;
4990 stripped_indexquals = fixed_indexquals =
NIL;
5003 stripped_indexquals =
lappend(stripped_indexquals, clause);
5006 fixed_indexquals =
lappend(fixed_indexquals, clause);
5010 *stripped_indexquals_p = stripped_indexquals;
5011 *fixed_indexquals_p = fixed_indexquals;
5026 List *fixed_indexorderbys;
5030 fixed_indexorderbys =
NIL;
5038 fixed_indexorderbys =
lappend(fixed_indexorderbys, clause);
5041 return fixed_indexorderbys;
5106 elog(
ERROR,
"unsupported indexqual type: %d",
5135 Assert(indexcol >= 0 && indexcol < index->ncolumns);
5137 if (
index->indexkeys[indexcol] != 0)
5141 ((
Var *) node)->varno ==
index->rel->relid &&
5142 ((
Var *) node)->varattno ==
index->indexkeys[indexcol])
5147 return (
Node *) result;
5150 elog(
ERROR,
"index key does not match expected index column");
5155 for (pos = 0; pos <
index->ncolumns; pos++)
5157 if (
index->indexkeys[pos] == 0)
5159 if (indexpr_item == NULL)
5160 elog(
ERROR,
"too few entries in indexprs list");
5161 if (pos == indexcol)
5168 if (
equal(node, indexkey))
5174 return (
Node *) result;
5177 elog(
ERROR,
"index key does not match expected index column");
5179 indexpr_item =
lnext(
index->indexprs, indexpr_item);
5184 elog(
ERROR,
"index key does not match expected index column");
5220 temp->opresulttype = clause->opresulttype;
5221 temp->opretset = clause->opretset;
5222 temp->opcollid = clause->opcollid;
5223 temp->inputcollid = clause->inputcollid;
5228 t_list =
lappend(t_list, temp);
5229 restrictinfo->outer_is_left =
false;
5234 t_list =
lappend(t_list, clause);
5235 restrictinfo->outer_is_left =
true;
5281 Index security_level;
5297 items = (QualItem *)
palloc(
nitems *
sizeof(QualItem));
5299 foreach(lc, clauses)
5305 items[
i].clause = clause;
5322 items[
i].security_level = 0;
5327 items[
i].security_level = 0;
5338 QualItem newitem = items[
i];
5342 for (
j =
i;
j > 0;
j--)
5344 QualItem *olditem = &items[
j - 1];
5346 if (newitem.security_level > olditem->security_level ||
5347 (newitem.security_level == olditem->security_level &&
5348 newitem.cost >= olditem->cost))
5350 items[
j] = *olditem;
5358 result =
lappend(result, items[
i].clause);
5374 dest->plan_width = src->pathtarget->width;
5391 dest->parallel_aware =
false;
5444 ((
BitmapOr *) plan)->isshared =
true;
5476 plan->
qual = qpqual;
5494 plan->
qual = qpqual;
5509 List *indexqualorig,
5511 List *indexorderbyorig,
5512 List *indexorderbyops,
5519 plan->
qual = qpqual;
5549 plan->
qual = qpqual;
5567 List *indexqualorig)
5588 List *bitmapqualorig,
5595 plan->
qual = qpqual;
5614 plan->
qual = qpqual;
5627 List *tidrangequals)
5633 plan->
qual = qpqual;
5652 plan->
qual = qpqual;
5667 bool funcordinality)
5673 plan->
qual = qpqual;
5693 plan->
qual = qpqual;