116 #define NUM_EXEC_TLIST(parentplan) ((parentplan)->plan_rows)
117 #define NUM_EXEC_QUAL(parentplan) ((parentplan)->plan_rows * 2.0)
126 #define ISREGCLASSCONST(con) \
127 (((con)->consttype == REGCLASSOID || (con)->consttype == OIDOID) && \
130 #define fix_scan_list(root, lst, rtoffset, num_exec) \
131 ((List *) fix_scan_expr(root, (Node *) (lst), rtoffset, num_exec))
161 int rtoffset,
double num_exec);
190 Index acceptable_rel,
208 Index resultRelation,
305 foreach(lc,
root->rowMarks)
315 newrc->
rti += rtoffset;
316 newrc->
prti += rtoffset;
326 foreach(lc,
root->append_rel_list)
344 if (
root->hasAlternativeSubPlans)
346 root->isAltSubplan = (
bool *)
348 root->isUsedSubplan = (
bool *)
363 if (
root->hasAlternativeSubPlans)
375 if (
root->isAltSubplan[ndx] && !
root->isUsedSubplan[ndx])
406 foreach(lc,
root->parse->rtable)
426 foreach(lc,
root->parse->rtable)
437 rti < root->simple_rel_array_size)
466 else if (recursing ||
521 cxt->
query = save_query;
550 newrte->joinaliasvars =
NIL;
551 newrte->joinleftcols =
NIL;
552 newrte->joinrightcols =
NIL;
553 newrte->join_using_alias = NULL;
557 newrte->coltypes =
NIL;
558 newrte->coltypmods =
NIL;
559 newrte->colcollations =
NIL;
560 newrte->groupexprs =
NIL;
561 newrte->securityQuals =
NIL;
585 if (rte->perminfoindex > 0)
599 newrte->perminfoindex = 0;
617 plan->plan_node_id =
root->glob->lastPlanNodeId++;
628 splan->scan.scanrelid += rtoffset;
629 splan->scan.plan.targetlist =
632 splan->scan.plan.qual =
641 splan->scan.scanrelid += rtoffset;
642 splan->scan.plan.targetlist =
645 splan->scan.plan.qual =
657 splan->scan.scanrelid += rtoffset;
658 splan->scan.plan.targetlist =
661 splan->scan.plan.qual =
667 splan->indexqualorig =
670 splan->indexorderby =
673 splan->indexorderbyorig =
678 case T_IndexOnlyScan:
685 case T_BitmapIndexScan:
689 splan->scan.scanrelid += rtoffset;
695 splan->indexqualorig =
700 case T_BitmapHeapScan:
704 splan->scan.scanrelid += rtoffset;
705 splan->scan.plan.targetlist =
708 splan->scan.plan.qual =
711 splan->bitmapqualorig =
720 splan->scan.scanrelid += rtoffset;
721 splan->scan.plan.targetlist =
724 splan->scan.plan.qual =
736 splan->scan.scanrelid += rtoffset;
737 splan->scan.plan.targetlist =
740 splan->scan.plan.qual =
743 splan->tidrangequals =
757 splan->scan.scanrelid += rtoffset;
758 splan->scan.plan.targetlist =
761 splan->scan.plan.qual =
768 case T_TableFuncScan:
772 splan->scan.scanrelid += rtoffset;
773 splan->scan.plan.targetlist =
776 splan->scan.plan.qual =
788 splan->scan.scanrelid += rtoffset;
789 splan->scan.plan.targetlist =
792 splan->scan.plan.qual =
795 splan->values_lists =
804 splan->scan.scanrelid += rtoffset;
805 splan->scan.plan.targetlist =
808 splan->scan.plan.qual =
813 case T_NamedTuplestoreScan:
817 splan->scan.scanrelid += rtoffset;
818 splan->scan.plan.targetlist =
821 splan->scan.plan.qual =
826 case T_WorkTableScan:
830 splan->scan.scanrelid += rtoffset;
831 splan->scan.plan.targetlist =
834 splan->scan.plan.qual =
882 case T_IncrementalSort:
913 foreach(l,
splan->rowMarks)
918 rc->
prti += rtoffset;
1012 if (
splan->plan.lefttree != NULL)
1028 foreach(l,
splan->plan.targetlist)
1039 splan->plan.targetlist =
1047 splan->resconstantqual =
1062 splan->withCheckOptionLists =
1066 if (
splan->returningLists)
1078 lcrr,
splan->resultRelations)
1088 newRL =
lappend(newRL, rlist);
1090 splan->returningLists = newRL;
1111 if (
splan->onConflictSet)
1117 splan->onConflictSet =
1131 splan->exclRelTlist =
1145 if (
splan->mergeActionLists !=
NIL)
1171 lcj,
splan->mergeJoinConditions,
1172 lcr,
splan->resultRelations)
1178 foreach(l, mergeActionList)
1202 mergeJoinCondition = (
Node *)
1204 (
List *) mergeJoinCondition,
1210 newMJC =
lappend(newMJC, mergeJoinCondition);
1212 splan->mergeJoinConditions = newMJC;
1215 splan->nominalRelation += rtoffset;
1216 if (
splan->rootRelation)
1217 splan->rootRelation += rtoffset;
1218 splan->exclRelRTI += rtoffset;
1220 foreach(l,
splan->resultRelations)
1224 foreach(l,
splan->rowMarks)
1228 rc->
rti += rtoffset;
1229 rc->
prti += rtoffset;
1236 root->glob->resultRelations =
1238 splan->resultRelations);
1239 if (
splan->rootRelation)
1241 root->glob->resultRelations =
1243 splan->rootRelation);
1257 case T_RecursiveUnion:
1269 foreach(l,
splan->bitmapplans)
1284 foreach(l,
splan->bitmapplans)
1293 elog(
ERROR,
"unrecognized node type: %d",
1327 List *stripped_indextlist;
1337 stripped_indextlist =
NIL;
1338 foreach(lc,
plan->indextlist)
1342 if (!indextle->resjunk)
1343 stripped_indextlist =
lappend(stripped_indextlist, indextle);
1348 plan->scan.scanrelid += rtoffset;
1349 plan->scan.plan.targetlist = (
List *)
1351 (
Node *)
plan->scan.plan.targetlist,
1383 pfree(index_itlist);
1425 plan->scan.scanrelid += rtoffset;
1426 plan->scan.plan.targetlist =
1429 plan->scan.plan.qual =
1480 if (
plan->scan.plan.qual !=
NIL)
1488 forboth(lp,
plan->scan.plan.targetlist, lc,
plan->subplan->targetlist)
1493 if (ptle->resjunk != ctle->resjunk)
1546 bool unsafe_initplans;
1549 &initplan_cost, &unsafe_initplans);
1552 if (unsafe_initplans)
1595 fscan->
scan.plan.targetlist = (
List *)
1597 (
Node *) fscan->
scan.plan.targetlist,
1611 fscan->fdw_exprs = (
List *)
1613 (
Node *) fscan->fdw_exprs,
1619 fscan->fdw_recheck_quals = (
List *)
1621 (
Node *) fscan->fdw_recheck_quals,
1629 fscan->fdw_scan_tlist =
1639 fscan->
scan.plan.targetlist =
1642 fscan->scan.plan.
qual =
1648 fscan->fdw_recheck_quals =
1681 cscan->
scan.plan.targetlist = (
List *)
1683 (
Node *) cscan->
scan.plan.targetlist,
1697 cscan->custom_exprs = (
List *)
1699 (
Node *) cscan->custom_exprs,
1707 cscan->custom_scan_tlist =
1714 cscan->
scan.plan.targetlist =
1717 cscan->scan.plan.
qual =
1720 cscan->custom_exprs =
1793 foreach(l2, prune_infos)
1806 return (
Plan *) aplan;
1869 foreach(l2, prune_infos)
1882 return (
Plan *) mplan;
1973 ((
Aggref *) node)->aggfnoid);
1989 ((
OpExpr *) node)->opfuncid);
2022 root->glob->relationOids =
2040 foreach(lc, g->refs)
2066 int subqueryid = p->
paramid >> 16;
2067 int colno = p->
paramid & 0xFFFF;
2070 if (subqueryid <= 0 ||
2114 if (bestplan == NULL || curcost <= bestcost)
2125 root->isUsedSubplan[bestplan->
plan_id - 1] =
true;
2127 return (
Node *) bestplan;
2157 if (rtoffset != 0 ||
2158 root->multiexpr_params !=
NIL ||
2159 root->glob->lastPHId != 0 ||
2161 root->hasAlternativeSubPlans)
2203 if (var->varnosyn > 0)
2204 var->varnosyn +=
context->rtoffset;
2205 return (
Node *) var;
2216 if (aggparam != NULL)
2229 return (
Node *) cexpr;
2271 Plan *outer_plan = join->plan.lefttree;
2272 Plan *inner_plan = join->plan.righttree;
2326 elog(
ERROR,
"NestLoopParam was not reduced to a simple Var");
2379 join->plan.targetlist,
2395 pfree(outer_itlist);
2396 pfree(inner_itlist);
2422 List *output_targetlist;
2436 root->group_rtindex > 0 &&
2449 output_targetlist =
NIL;
2450 foreach(l,
plan->targetlist)
2482 output_targetlist =
lappend(output_targetlist, tle);
2484 plan->targetlist = output_targetlist;
2495 pfree(subplan_itlist);
2510 if (
plan->lefttree->extParam)
2516 for (proot =
root; proot != NULL; proot = proot->parent_root)
2581 memcpy(child_agg, orig_agg,
sizeof(
Aggref));
2610 return (
Node *) parent_agg;
2631 List *output_targetlist;
2634 output_targetlist =
NIL;
2635 foreach(l,
plan->targetlist)
2650 output_targetlist =
lappend(output_targetlist, tle);
2661 oldvar->varnosyn > 0)
2663 newvar->varnosyn = oldvar->varnosyn + rtoffset;
2664 newvar->varattnosyn = oldvar->varattnosyn;
2668 newvar->varnosyn = 0;
2669 newvar->varattnosyn = 0;
2674 output_targetlist =
lappend(output_targetlist, tle);
2676 plan->targetlist = output_targetlist;
2707 itlist->
tlist = tlist;
2712 vinfo = itlist->
vars;
2758 itlist->
tlist = tlist;
2763 vinfo = itlist->
vars;
2806 int newvarno,
int rtoffset,
2809 int varno = var->
varno;
2814 vinfo = itlist->
vars;
2837 if (!(varattno <= 0 ||
2843 elog(
ERROR,
"wrong varnullingrels %s (expected %s) for Var %d/%d",
2848 newvar->
varno = newvarno;
2850 if (newvar->varnosyn > 0)
2851 newvar->varnosyn += rtoffset;
2876 foreach(lc, itlist->
tlist)
2899 elog(
ERROR,
"wrong phnullingrels %s (expected %s) for PlaceHolderVar %d",
2906 newvar->varnosyn = 0;
2907 newvar->varattnosyn = 0;
2945 newvar->varnosyn = 0;
2946 newvar->varattnosyn = 0;
2970 foreach(lc, itlist->
tlist)
2989 newvar->varnosyn = 0;
2990 newvar->varattnosyn = 0;
3045 Index acceptable_rel,
3053 context.outer_itlist = outer_itlist;
3054 context.inner_itlist = inner_itlist;
3055 context.acceptable_rel = acceptable_rel;
3057 context.nrm_match = nrm_match;
3082 return (
Node *) newvar;
3094 return (
Node *) newvar;
3102 if (var->varnosyn > 0)
3103 var->varnosyn +=
context->rtoffset;
3104 return (
Node *) var;
3108 elog(
ERROR,
"variable not found in subplan target lists");
3122 return (
Node *) newvar;
3131 return (
Node *) newvar;
3139 if (
context->outer_itlist &&
context->outer_itlist->has_non_vars)
3145 return (
Node *) newvar;
3147 if (
context->inner_itlist &&
context->inner_itlist->has_non_vars)
3153 return (
Node *) newvar;
3211 context.subplan_itlist = subplan_itlist;
3214 context.nrm_match = nrm_match;
3236 elog(
ERROR,
"variable not found in subplan target list");
3237 return (
Node *) newvar;
3244 if (
context->subplan_itlist->has_ph_vars)
3251 return (
Node *) newvar;
3258 if (
context->subplan_itlist->has_non_vars)
3264 return (
Node *) newvar;
3276 if (aggparam != NULL)
3324 Index resultRelation,
3379 return (
Node *) newvar;
3380 elog(
ERROR,
"WindowFunc not found in subplan target lists");
3402 context.subplan_itlist = subplan_itlist;
3445 if (
root->minmax_aggs !=
NIL &&
3451 foreach(lc,
root->minmax_aggs)
3457 return mminfo->
param;
3495 inval_item->
cacheId = PROCOID;
3531 inval_item->
cacheId = TYPEOID;
3558 List **relationOids,
3560 bool *hasRowSecurity)
3566 MemSet(&glob, 0,
sizeof(glob));
3567 glob.type = T_PlannerGlobal;
3574 root.type = T_PlannerInfo;
3634 if (query->hasRowSecurity)
3635 context->glob->dependsOnRole =
true;
3638 foreach(lc, query->
rtable)
bool bms_equal(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)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
#define OidIsValid(objectId)
bool equal(const void *a, const void *b)
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
Datum lca(PG_FUNCTION_ARGS)
Var * makeVarFromTargetEntry(int varno, TargetEntry *tle)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
TargetEntry * flatCopyTargetEntry(TargetEntry *src_tle)
void pfree(void *pointer)
void * palloc0(Size size)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
void set_opfuncid(OpExpr *opexpr)
#define expression_tree_mutator(n, m, c)
#define query_tree_walker(q, w, c, f)
#define expression_tree_walker(n, w, c)
#define QTW_EXAMINE_RTES_BEFORE
#define IsA(nodeptr, _type_)
#define DO_AGGSPLIT_COMBINE(as)
@ AGGSPLIT_FINAL_DESERIAL
@ AGGSPLIT_INITIAL_SERIAL
char * bmsToString(const Bitmapset *bms)
RTEPermissionInfo * addRTEPermissionInfo(List **rteperminfos, RangeTblEntry *rte)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define foreach_current_index(var_or_cell)
#define forthree(cell1, list1, cell2, list2, cell3, list3)
static void * list_nth(const List *list, int n)
void mark_partial_aggref(Aggref *agg, AggSplit aggsplit)
@ SUBQUERY_SCAN_NONTRIVIAL
static Oid DatumGetObjectId(Datum X)
static Datum ObjectIdGetDatum(Oid X)
#define IS_SPECIAL_VARNO(varno)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
Node * remove_nulling_relids(Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
void record_plan_type_dependency(PlannerInfo *root, Oid typid)
#define NUM_EXEC_QUAL(parentplan)
static void set_hash_references(PlannerInfo *root, Plan *plan, int rtoffset)
static void fix_expr_common(PlannerInfo *root, Node *node)
static void add_rtes_to_flat_rtable(PlannerInfo *root, bool recursing)
static Node * fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
static void add_rte_to_flat_rtable(PlannerGlobal *glob, List *rteperminfos, RangeTblEntry *rte)
static Plan * set_append_references(PlannerInfo *root, Append *aplan, int rtoffset)
static Node * fix_param_node(PlannerInfo *root, Param *p)
static Plan * set_mergeappend_references(PlannerInfo *root, MergeAppend *mplan, int rtoffset)
static indexed_tlist * build_tlist_index_other_vars(List *tlist, int ignore_rel)
static List * set_returning_clause_references(PlannerInfo *root, List *rlist, Plan *topplan, Index resultRelation, int rtoffset)
void record_plan_function_dependency(PlannerInfo *root, Oid funcid)
static Relids offset_relid_set(Relids relids, int rtoffset)
static bool flatten_rtes_walker(Node *node, flatten_rtes_walker_context *cxt)
static indexed_tlist * build_tlist_index(List *tlist)
static List * set_windowagg_runcondition_references(PlannerInfo *root, List *runcondition, Plan *plan)
bool trivial_subqueryscan(SubqueryScan *plan)
static void set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
static Node * fix_alternative_subplan(PlannerInfo *root, AlternativeSubPlan *asplan, double num_exec)
static Var * search_indexed_tlist_for_sortgroupref(Expr *node, Index sortgroupref, indexed_tlist *itlist, int newvarno)
static void flatten_unplanned_rtes(PlannerGlobal *glob, RangeTblEntry *rte)
static Node * fix_upper_expr(PlannerInfo *root, Node *node, indexed_tlist *subplan_itlist, int newvarno, int rtoffset, NullingRelsMatch nrm_match, double num_exec)
static void set_param_references(PlannerInfo *root, Plan *plan)
static Var * search_indexed_tlist_for_non_var(Expr *node, indexed_tlist *itlist, int newvarno)
static Node * fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
static Node * fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
static void set_foreignscan_references(PlannerInfo *root, ForeignScan *fscan, int rtoffset)
static Plan * set_subqueryscan_references(PlannerInfo *root, SubqueryScan *plan, int rtoffset)
static Var * search_indexed_tlist_for_phv(PlaceHolderVar *phv, indexed_tlist *itlist, int newvarno, NullingRelsMatch nrm_match)
static Plan * set_indexonlyscan_references(PlannerInfo *root, IndexOnlyScan *plan, int rtoffset)
static List * fix_join_expr(PlannerInfo *root, List *clauses, indexed_tlist *outer_itlist, indexed_tlist *inner_itlist, Index acceptable_rel, int rtoffset, NullingRelsMatch nrm_match, double num_exec)
static Node * convert_combining_aggrefs(Node *node, void *context)
static void set_dummy_tlist_references(Plan *plan, int rtoffset)
static void set_customscan_references(PlannerInfo *root, CustomScan *cscan, int rtoffset)
static Node * fix_windowagg_condition_expr_mutator(Node *node, fix_windowagg_cond_context *context)
#define ISREGCLASSCONST(con)
Plan * set_plan_references(PlannerInfo *root, Plan *plan)
void extract_query_dependencies(Node *query, List **relationOids, List **invalItems, bool *hasRowSecurity)
bool extract_query_dependencies_walker(Node *node, PlannerInfo *context)
static Var * copyVar(Var *var)
#define NUM_EXEC_TLIST(parentplan)
Param * find_minmax_agg_replacement_param(PlannerInfo *root, Aggref *aggref)
static void set_join_references(PlannerInfo *root, Join *join, int rtoffset)
static List * fix_windowagg_condition_expr(PlannerInfo *root, List *runcondition, indexed_tlist *subplan_itlist)
static Plan * clean_up_removed_plan_level(Plan *parent, Plan *child)
static Node * fix_scan_expr(PlannerInfo *root, Node *node, int rtoffset, double num_exec)
static Plan * set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
static bool fix_scan_expr_walker(Node *node, fix_scan_expr_context *context)
static Var * search_indexed_tlist_for_var(Var *var, indexed_tlist *itlist, int newvarno, int rtoffset, NullingRelsMatch nrm_match)
#define fix_scan_list(root, lst, rtoffset, num_exec)
struct PartitionPruneInfo * part_prune_info
Bitmapset * custom_relids
Bitmapset * fs_base_relids
struct PartitionPruneInfo * part_prune_info
struct TableSampleClause * tablesample
NullingRelsMatch nrm_match
indexed_tlist * outer_itlist
indexed_tlist * inner_itlist
indexed_tlist * subplan_itlist
NullingRelsMatch nrm_match
indexed_tlist * subplan_itlist
tlist_vinfo vars[FLEXIBLE_ARRAY_MEMBER]
Bitmapset * varnullingrels
void SS_compute_initplan_cost(List *init_plans, Cost *initplan_cost_p, bool *unsafe_initplans_p)
#define GetSysCacheHashValue1(cacheId, key1)
void apply_tlist_labeling(List *dest_tlist, List *src_tlist)
TargetEntry * tlist_member(Expr *node, List *targetlist)
#define FirstUnpinnedObjectId
Query * UtilityContainsQuery(Node *parsetree)