PostgreSQL Source Code  git master
createplan.c File Reference
#include "postgres.h"
#include <limits.h>
#include <math.h>
#include "access/sysattr.h"
#include "catalog/pg_class.h"
#include "foreign/fdwapi.h"
#include "miscadmin.h"
#include "nodes/extensible.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/optimizer.h"
#include "optimizer/paramassign.h"
#include "optimizer/paths.h"
#include "optimizer/placeholder.h"
#include "optimizer/plancat.h"
#include "optimizer/planmain.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/subselect.h"
#include "optimizer/tlist.h"
#include "parser/parse_clause.h"
#include "parser/parsetree.h"
#include "partitioning/partprune.h"
#include "utils/lsyscache.h"
Include dependency graph for createplan.c:

Go to the source code of this file.

Macros

#define CP_EXACT_TLIST   0x0001 /* Plan must return specified tlist */
 
#define CP_SMALL_TLIST   0x0002 /* Prefer narrower tlists */
 
#define CP_LABEL_TLIST   0x0004 /* tlist must contain sortgrouprefs */
 
#define CP_IGNORE_TLIST   0x0008 /* caller will replace tlist */
 

Functions

static Plancreate_plan_recurse (PlannerInfo *root, Path *best_path, int flags)
 
static Plancreate_scan_plan (PlannerInfo *root, Path *best_path, int flags)
 
static Listbuild_path_tlist (PlannerInfo *root, Path *path)
 
static bool use_physical_tlist (PlannerInfo *root, Path *path, int flags)
 
static Listget_gating_quals (PlannerInfo *root, List *quals)
 
static Plancreate_gating_plan (PlannerInfo *root, Path *path, Plan *plan, List *gating_quals)
 
static Plancreate_join_plan (PlannerInfo *root, JoinPath *best_path)
 
static Plancreate_append_plan (PlannerInfo *root, AppendPath *best_path, int flags)
 
static Plancreate_merge_append_plan (PlannerInfo *root, MergeAppendPath *best_path, int flags)
 
static Resultcreate_group_result_plan (PlannerInfo *root, GroupResultPath *best_path)
 
static ProjectSetcreate_project_set_plan (PlannerInfo *root, ProjectSetPath *best_path)
 
static Materialcreate_material_plan (PlannerInfo *root, MaterialPath *best_path, int flags)
 
static Plancreate_unique_plan (PlannerInfo *root, UniquePath *best_path, int flags)
 
static Gathercreate_gather_plan (PlannerInfo *root, GatherPath *best_path)
 
static Plancreate_projection_plan (PlannerInfo *root, ProjectionPath *best_path, int flags)
 
static Planinject_projection_plan (Plan *subplan, List *tlist, bool parallel_safe)
 
static Sortcreate_sort_plan (PlannerInfo *root, SortPath *best_path, int flags)
 
static Groupcreate_group_plan (PlannerInfo *root, GroupPath *best_path)
 
static Uniquecreate_upper_unique_plan (PlannerInfo *root, UpperUniquePath *best_path, int flags)
 
static Aggcreate_agg_plan (PlannerInfo *root, AggPath *best_path)
 
static Plancreate_groupingsets_plan (PlannerInfo *root, GroupingSetsPath *best_path)
 
static Resultcreate_minmaxagg_plan (PlannerInfo *root, MinMaxAggPath *best_path)
 
static WindowAggcreate_windowagg_plan (PlannerInfo *root, WindowAggPath *best_path)
 
static SetOpcreate_setop_plan (PlannerInfo *root, SetOpPath *best_path, int flags)
 
static RecursiveUnioncreate_recursiveunion_plan (PlannerInfo *root, RecursiveUnionPath *best_path)
 
static LockRowscreate_lockrows_plan (PlannerInfo *root, LockRowsPath *best_path, int flags)
 
static ModifyTablecreate_modifytable_plan (PlannerInfo *root, ModifyTablePath *best_path)
 
static Limitcreate_limit_plan (PlannerInfo *root, LimitPath *best_path, int flags)
 
static SeqScancreate_seqscan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static SampleScancreate_samplescan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static Scancreate_indexscan_plan (PlannerInfo *root, IndexPath *best_path, List *tlist, List *scan_clauses, bool indexonly)
 
static BitmapHeapScancreate_bitmap_scan_plan (PlannerInfo *root, BitmapHeapPath *best_path, List *tlist, List *scan_clauses)
 
static Plancreate_bitmap_subplan (PlannerInfo *root, Path *bitmapqual, List **qual, List **indexqual, List **indexECs)
 
static void bitmap_subplan_mark_shared (Plan *plan)
 
static TidScancreate_tidscan_plan (PlannerInfo *root, TidPath *best_path, List *tlist, List *scan_clauses)
 
static SubqueryScancreate_subqueryscan_plan (PlannerInfo *root, SubqueryScanPath *best_path, List *tlist, List *scan_clauses)
 
static FunctionScancreate_functionscan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static ValuesScancreate_valuesscan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static TableFuncScancreate_tablefuncscan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static CteScancreate_ctescan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static NamedTuplestoreScancreate_namedtuplestorescan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static Resultcreate_resultscan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static WorkTableScancreate_worktablescan_plan (PlannerInfo *root, Path *best_path, List *tlist, List *scan_clauses)
 
static ForeignScancreate_foreignscan_plan (PlannerInfo *root, ForeignPath *best_path, List *tlist, List *scan_clauses)
 
static CustomScancreate_customscan_plan (PlannerInfo *root, CustomPath *best_path, List *tlist, List *scan_clauses)
 
static NestLoopcreate_nestloop_plan (PlannerInfo *root, NestPath *best_path)
 
static MergeJoincreate_mergejoin_plan (PlannerInfo *root, MergePath *best_path)
 
static HashJoincreate_hashjoin_plan (PlannerInfo *root, HashPath *best_path)
 
static Nodereplace_nestloop_params (PlannerInfo *root, Node *expr)
 
static Nodereplace_nestloop_params_mutator (Node *node, PlannerInfo *root)
 
static void fix_indexqual_references (PlannerInfo *root, IndexPath *index_path, List **stripped_indexquals_p, List **fixed_indexquals_p)
 
static Listfix_indexorderby_references (PlannerInfo *root, IndexPath *index_path)
 
static Nodefix_indexqual_clause (PlannerInfo *root, IndexOptInfo *index, int indexcol, Node *clause, List *indexcolnos)
 
static Nodefix_indexqual_operand (Node *node, IndexOptInfo *index, int indexcol)
 
static Listget_switched_clauses (List *clauses, Relids outerrelids)
 
static Listorder_qual_clauses (PlannerInfo *root, List *clauses)
 
static void copy_generic_path_info (Plan *dest, Path *src)
 
static void copy_plan_costsize (Plan *dest, Plan *src)
 
static void label_sort_with_costsize (PlannerInfo *root, Sort *plan, double limit_tuples)
 
static SeqScanmake_seqscan (List *qptlist, List *qpqual, Index scanrelid)
 
static SampleScanmake_samplescan (List *qptlist, List *qpqual, Index scanrelid, TableSampleClause *tsc)
 
static IndexScanmake_indexscan (List *qptlist, List *qpqual, Index scanrelid, Oid indexid, List *indexqual, List *indexqualorig, List *indexorderby, List *indexorderbyorig, List *indexorderbyops, ScanDirection indexscandir)
 
static IndexOnlyScanmake_indexonlyscan (List *qptlist, List *qpqual, Index scanrelid, Oid indexid, List *indexqual, List *indexorderby, List *indextlist, ScanDirection indexscandir)
 
static BitmapIndexScanmake_bitmap_indexscan (Index scanrelid, Oid indexid, List *indexqual, List *indexqualorig)
 
static BitmapHeapScanmake_bitmap_heapscan (List *qptlist, List *qpqual, Plan *lefttree, List *bitmapqualorig, Index scanrelid)
 
static TidScanmake_tidscan (List *qptlist, List *qpqual, Index scanrelid, List *tidquals)
 
static SubqueryScanmake_subqueryscan (List *qptlist, List *qpqual, Index scanrelid, Plan *subplan)
 
static FunctionScanmake_functionscan (List *qptlist, List *qpqual, Index scanrelid, List *functions, bool funcordinality)
 
static ValuesScanmake_valuesscan (List *qptlist, List *qpqual, Index scanrelid, List *values_lists)
 
static TableFuncScanmake_tablefuncscan (List *qptlist, List *qpqual, Index scanrelid, TableFunc *tablefunc)
 
static CteScanmake_ctescan (List *qptlist, List *qpqual, Index scanrelid, int ctePlanId, int cteParam)
 
static NamedTuplestoreScanmake_namedtuplestorescan (List *qptlist, List *qpqual, Index scanrelid, char *enrname)
 
static WorkTableScanmake_worktablescan (List *qptlist, List *qpqual, Index scanrelid, int wtParam)
 
static RecursiveUnionmake_recursive_union (List *tlist, Plan *lefttree, Plan *righttree, int wtParam, List *distinctList, long numGroups)
 
static BitmapAndmake_bitmap_and (List *bitmapplans)
 
static BitmapOrmake_bitmap_or (List *bitmapplans)
 
static NestLoopmake_nestloop (List *tlist, List *joinclauses, List *otherclauses, List *nestParams, Plan *lefttree, Plan *righttree, JoinType jointype, bool inner_unique)
 
static HashJoinmake_hashjoin (List *tlist, List *joinclauses, List *otherclauses, List *hashclauses, List *hashoperators, List *hashcollations, List *hashkeys, Plan *lefttree, Plan *righttree, JoinType jointype, bool inner_unique)
 
static Hashmake_hash (Plan *lefttree, List *hashkeys, Oid skewTable, AttrNumber skewColumn, bool skewInherit)
 
static MergeJoinmake_mergejoin (List *tlist, List *joinclauses, List *otherclauses, List *mergeclauses, Oid *mergefamilies, Oid *mergecollations, int *mergestrategies, bool *mergenullsfirst, Plan *lefttree, Plan *righttree, JoinType jointype, bool inner_unique, bool skip_mark_restore)
 
static Sortmake_sort (Plan *lefttree, int numCols, AttrNumber *sortColIdx, Oid *sortOperators, Oid *collations, bool *nullsFirst)
 
static Planprepare_sort_from_pathkeys (Plan *lefttree, List *pathkeys, Relids relids, const AttrNumber *reqColIdx, bool adjust_tlist_in_place, int *p_numsortkeys, AttrNumber **p_sortColIdx, Oid **p_sortOperators, Oid **p_collations, bool **p_nullsFirst)
 
static EquivalenceMemberfind_ec_member_for_tle (EquivalenceClass *ec, TargetEntry *tle, Relids relids)
 
static Sortmake_sort_from_pathkeys (Plan *lefttree, List *pathkeys, Relids relids)
 
static Sortmake_sort_from_groupcols (List *groupcls, AttrNumber *grpColIdx, Plan *lefttree)
 
static Materialmake_material (Plan *lefttree)
 
static WindowAggmake_windowagg (List *tlist, Index winref, int partNumCols, AttrNumber *partColIdx, Oid *partOperators, Oid *partCollations, int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations, int frameOptions, Node *startOffset, Node *endOffset, Oid startInRangeFunc, Oid endInRangeFunc, Oid inRangeColl, bool inRangeAsc, bool inRangeNullsFirst, Plan *lefttree)
 
static Groupmake_group (List *tlist, List *qual, int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, Plan *lefttree)
 
static Uniquemake_unique_from_sortclauses (Plan *lefttree, List *distinctList)
 
static Uniquemake_unique_from_pathkeys (Plan *lefttree, List *pathkeys, int numCols)
 
static Gathermake_gather (List *qptlist, List *qpqual, int nworkers, int rescan_param, bool single_copy, Plan *subplan)
 
static SetOpmake_setop (SetOpCmd cmd, SetOpStrategy strategy, Plan *lefttree, List *distinctList, AttrNumber flagColIdx, int firstFlag, long numGroups)
 
static LockRowsmake_lockrows (Plan *lefttree, List *rowMarks, int epqParam)
 
static Resultmake_result (List *tlist, Node *resconstantqual, Plan *subplan)
 
static ProjectSetmake_project_set (List *tlist, Plan *subplan)
 
static ModifyTablemake_modifytable (PlannerInfo *root, CmdType operation, bool canSetTag, Index nominalRelation, Index rootRelation, bool partColsUpdated, List *resultRelations, List *subplans, List *subroots, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam)
 
static GatherMergecreate_gather_merge_plan (PlannerInfo *root, GatherMergePath *best_path)
 
Plancreate_plan (PlannerInfo *root, Path *best_path)
 
Planchange_plan_targetlist (Plan *subplan, List *tlist, bool tlist_parallel_safe)
 
static AttrNumberremap_groupColIdx (PlannerInfo *root, List *groupClause)
 
ForeignScanmake_foreignscan (List *qptlist, List *qpqual, Index scanrelid, List *fdw_exprs, List *fdw_private, List *fdw_scan_tlist, List *fdw_recheck_quals, Plan *outer_plan)
 
Sortmake_sort_from_sortclauses (List *sortcls, Plan *lefttree)
 
Planmaterialize_finished_plan (Plan *subplan)
 
Aggmake_agg (List *tlist, List *qual, AggStrategy aggstrategy, AggSplit aggsplit, int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, List *groupingSets, List *chain, double dNumGroups, Plan *lefttree)
 
Limitmake_limit (Plan *lefttree, Node *limitOffset, Node *limitCount)
 
bool is_projection_capable_path (Path *path)
 
bool is_projection_capable_plan (Plan *plan)
 

Macro Definition Documentation

◆ CP_EXACT_TLIST

◆ CP_IGNORE_TLIST

#define CP_IGNORE_TLIST   0x0008 /* caller will replace tlist */

Definition at line 71 of file createplan.c.

Referenced by create_projection_plan(), and create_scan_plan().

◆ CP_LABEL_TLIST

#define CP_LABEL_TLIST   0x0004 /* tlist must contain sortgrouprefs */

◆ CP_SMALL_TLIST

#define CP_SMALL_TLIST   0x0002 /* Prefer narrower tlists */

Function Documentation

◆ bitmap_subplan_mark_shared()

static void bitmap_subplan_mark_shared ( Plan plan)
static

Definition at line 5105 of file createplan.c.

References elog, ERROR, IsA, linitial, and nodeTag.

Referenced by create_bitmap_scan_plan().

5106 {
5107  if (IsA(plan, BitmapAnd))
5109  linitial(((BitmapAnd *) plan)->bitmapplans));
5110  else if (IsA(plan, BitmapOr))
5111  {
5112  ((BitmapOr *) plan)->isshared = true;
5114  linitial(((BitmapOr *) plan)->bitmapplans));
5115  }
5116  else if (IsA(plan, BitmapIndexScan))
5117  ((BitmapIndexScan *) plan)->isshared = true;
5118  else
5119  elog(ERROR, "unrecognized node type: %d", nodeTag(plan));
5120 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:575
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
static void bitmap_subplan_mark_shared(Plan *plan)
Definition: createplan.c:5105
#define nodeTag(nodeptr)
Definition: nodes.h:529
#define elog(elevel,...)
Definition: elog.h:226

◆ build_path_tlist()

static List * build_path_tlist ( PlannerInfo root,
Path path 
)
static

Definition at line 764 of file createplan.c.

References PathTarget::exprs, lappend(), lfirst, makeTargetEntry(), NIL, Path::param_info, Path::pathtarget, replace_nestloop_params(), TargetEntry::ressortgroupref, and PathTarget::sortgrouprefs.

Referenced by create_agg_plan(), create_append_plan(), create_gather_merge_plan(), create_gather_plan(), create_gating_plan(), create_group_plan(), create_group_result_plan(), create_groupingsets_plan(), create_hashjoin_plan(), create_merge_append_plan(), create_mergejoin_plan(), create_minmaxagg_plan(), create_nestloop_plan(), create_project_set_plan(), create_projection_plan(), create_recursiveunion_plan(), create_scan_plan(), create_unique_plan(), and create_windowagg_plan().

765 {
766  List *tlist = NIL;
767  Index *sortgrouprefs = path->pathtarget->sortgrouprefs;
768  int resno = 1;
769  ListCell *v;
770 
771  foreach(v, path->pathtarget->exprs)
772  {
773  Node *node = (Node *) lfirst(v);
774  TargetEntry *tle;
775 
776  /*
777  * If it's a parameterized path, there might be lateral references in
778  * the tlist, which need to be replaced with Params. There's no need
779  * to remake the TargetEntry nodes, so apply this to each list item
780  * separately.
781  */
782  if (path->param_info)
783  node = replace_nestloop_params(root, node);
784 
785  tle = makeTargetEntry((Expr *) node,
786  resno,
787  NULL,
788  false);
789  if (sortgrouprefs)
790  tle->ressortgroupref = sortgrouprefs[resno - 1];
791 
792  tlist = lappend(tlist, tle);
793  resno++;
794  }
795  return tlist;
796 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1115
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
Index * sortgrouprefs
Definition: pathnodes.h:1045
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:236
List * lappend(List *list, void *datum)
Definition: list.c:321
List * exprs
Definition: pathnodes.h:1044
unsigned int Index
Definition: c.h:475
#define lfirst(lc)
Definition: pg_list.h:190
Index ressortgroupref
Definition: primnodes.h:1396
Definition: pg_list.h:50

◆ change_plan_targetlist()

Plan* change_plan_targetlist ( Plan subplan,
List tlist,
bool  tlist_parallel_safe 
)

Definition at line 1938 of file createplan.c.

References inject_projection_plan(), is_projection_capable_plan(), Plan::parallel_safe, Plan::targetlist, and tlist_same_exprs().

Referenced by create_unique_plan(), and postgresGetForeignPlan().

1939 {
1940  /*
1941  * If the top plan node can't do projections and its existing target list
1942  * isn't already what we need, we need to add a Result node to help it
1943  * along.
1944  */
1945  if (!is_projection_capable_plan(subplan) &&
1946  !tlist_same_exprs(tlist, subplan->targetlist))
1947  subplan = inject_projection_plan(subplan, tlist,
1948  subplan->parallel_safe &&
1949  tlist_parallel_safe);
1950  else
1951  {
1952  /* Else we can just replace the plan node's tlist */
1953  subplan->targetlist = tlist;
1954  subplan->parallel_safe &= tlist_parallel_safe;
1955  }
1956  return subplan;
1957 }
bool is_projection_capable_plan(Plan *plan)
Definition: createplan.c:6805
static Plan * inject_projection_plan(Plan *subplan, List *tlist, bool parallel_safe)
Definition: createplan.c:1906
bool tlist_same_exprs(List *tlist1, List *tlist2)
Definition: tlist.c:240
List * targetlist
Definition: plannodes.h:140
bool parallel_safe
Definition: plannodes.h:134

◆ copy_generic_path_info()

static void copy_generic_path_info ( Plan dest,
Path src 
)
static

Definition at line 5042 of file createplan.c.

References Plan::parallel_aware, Path::parallel_aware, Plan::parallel_safe, Path::parallel_safe, Path::pathtarget, Plan::plan_rows, Plan::plan_width, Path::rows, Plan::startup_cost, Path::startup_cost, Plan::total_cost, Path::total_cost, and PathTarget::width.

Referenced by create_agg_plan(), create_append_plan(), create_bitmap_scan_plan(), create_ctescan_plan(), create_customscan_plan(), create_foreignscan_plan(), create_functionscan_plan(), create_gather_merge_plan(), create_gather_plan(), create_group_plan(), create_group_result_plan(), create_groupingsets_plan(), create_hashjoin_plan(), create_indexscan_plan(), create_limit_plan(), create_lockrows_plan(), create_material_plan(), create_merge_append_plan(), create_mergejoin_plan(), create_minmaxagg_plan(), create_modifytable_plan(), create_namedtuplestorescan_plan(), create_nestloop_plan(), create_project_set_plan(), create_projection_plan(), create_recursiveunion_plan(), create_resultscan_plan(), create_samplescan_plan(), create_seqscan_plan(), create_setop_plan(), create_sort_plan(), create_subqueryscan_plan(), create_tablefuncscan_plan(), create_tidscan_plan(), create_unique_plan(), create_upper_unique_plan(), create_valuesscan_plan(), create_windowagg_plan(), and create_worktablescan_plan().

5043 {
5044  dest->startup_cost = src->startup_cost;
5045  dest->total_cost = src->total_cost;
5046  dest->plan_rows = src->rows;
5047  dest->plan_width = src->pathtarget->width;
5048  dest->parallel_aware = src->parallel_aware;
5049  dest->parallel_safe = src->parallel_safe;
5050 }
double plan_rows
Definition: plannodes.h:127
PathTarget * pathtarget
Definition: pathnodes.h:1115
Cost startup_cost
Definition: pathnodes.h:1125
Cost startup_cost
Definition: plannodes.h:121
bool parallel_aware
Definition: plannodes.h:133
Cost total_cost
Definition: pathnodes.h:1126
int plan_width
Definition: plannodes.h:128
double rows
Definition: pathnodes.h:1124
bool parallel_safe
Definition: pathnodes.h:1120
Cost total_cost
Definition: plannodes.h:122
bool parallel_aware
Definition: pathnodes.h:1119
bool parallel_safe
Definition: plannodes.h:134

◆ copy_plan_costsize()

static void copy_plan_costsize ( Plan dest,
Plan src 
)
static

Definition at line 5057 of file createplan.c.

References Plan::parallel_aware, Plan::parallel_safe, Plan::plan_rows, Plan::plan_width, Plan::startup_cost, and Plan::total_cost.

Referenced by create_gating_plan(), create_hashjoin_plan(), create_mergejoin_plan(), and inject_projection_plan().

5058 {
5059  dest->startup_cost = src->startup_cost;
5060  dest->total_cost = src->total_cost;
5061  dest->plan_rows = src->plan_rows;
5062  dest->plan_width = src->plan_width;
5063  /* Assume the inserted node is not parallel-aware. */
5064  dest->parallel_aware = false;
5065  /* Assume the inserted node is parallel-safe, if child plan is. */
5066  dest->parallel_safe = src->parallel_safe;
5067 }
double plan_rows
Definition: plannodes.h:127
Cost startup_cost
Definition: plannodes.h:121
bool parallel_aware
Definition: plannodes.h:133
int plan_width
Definition: plannodes.h:128
Cost total_cost
Definition: plannodes.h:122
bool parallel_safe
Definition: plannodes.h:134

◆ create_agg_plan()

static Agg * create_agg_plan ( PlannerInfo root,
AggPath best_path 
)
static

Definition at line 2068 of file createplan.c.

References AggPath::aggsplit, AggPath::aggstrategy, build_path_tlist(), copy_generic_path_info(), CP_LABEL_TLIST, create_plan_recurse(), extract_grouping_collations(), extract_grouping_cols(), extract_grouping_ops(), AggPath::groupClause, list_length(), make_agg(), NIL, AggPath::numGroups, order_qual_clauses(), AggPath::path, Agg::plan, AggPath::qual, AggPath::subpath, and Plan::targetlist.

Referenced by create_plan_recurse().

2069 {
2070  Agg *plan;
2071  Plan *subplan;
2072  List *tlist;
2073  List *quals;
2074 
2075  /*
2076  * Agg can project, so no need to be terribly picky about child tlist, but
2077  * we do need grouping columns to be available
2078  */
2079  subplan = create_plan_recurse(root, best_path->subpath, CP_LABEL_TLIST);
2080 
2081  tlist = build_path_tlist(root, &best_path->path);
2082 
2083  quals = order_qual_clauses(root, best_path->qual);
2084 
2085  plan = make_agg(tlist, quals,
2086  best_path->aggstrategy,
2087  best_path->aggsplit,
2088  list_length(best_path->groupClause),
2090  subplan->targetlist),
2091  extract_grouping_ops(best_path->groupClause),
2093  subplan->targetlist),
2094  NIL,
2095  NIL,
2096  best_path->numGroups,
2097  subplan);
2098 
2099  copy_generic_path_info(&plan->plan, (Path *) best_path);
2100 
2101  return plan;
2102 }
#define NIL
Definition: pg_list.h:65
AggStrategy aggstrategy
Definition: pathnodes.h:1661
Oid * extract_grouping_collations(List *groupClause, List *tlist)
Definition: tlist.c:511
List * qual
Definition: pathnodes.h:1665
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
AggSplit aggsplit
Definition: pathnodes.h:1662
Oid * extract_grouping_ops(List *groupClause)
Definition: tlist.c:485
double numGroups
Definition: pathnodes.h:1663
AttrNumber * extract_grouping_cols(List *groupClause, List *tlist)
Definition: tlist.c:536
Agg * make_agg(List *tlist, List *qual, AggStrategy aggstrategy, AggSplit aggsplit, int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, List *groupingSets, List *chain, double dNumGroups, Plan *lefttree)
Definition: createplan.c:6189
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
List * groupClause
Definition: pathnodes.h:1664
Plan plan
Definition: plannodes.h:804
#define CP_LABEL_TLIST
Definition: createplan.c:70
static int list_length(const List *l)
Definition: pg_list.h:169
Path * subpath
Definition: pathnodes.h:1660
List * targetlist
Definition: plannodes.h:140
Definition: plannodes.h:802
Definition: pg_list.h:50
Path path
Definition: pathnodes.h:1659

◆ create_append_plan()

static Plan * create_append_plan ( PlannerInfo root,
AppendPath best_path,
int  flags 
)
static

Definition at line 1064 of file createplan.c.

References Append::appendplans, Assert, RelOptInfo::baserestrictinfo, build_path_tlist(), copy_generic_path_info(), CP_EXACT_TLIST, CP_SMALL_TLIST, create_plan_recurse(), elog, enable_partition_pruning, ERROR, extract_actual_clauses(), AppendPath::first_partial_path, Append::first_partial_plan, inject_projection_plan(), label_sort_with_costsize(), lappend(), Plan::lefttree, lfirst, AppendPath::limit_tuples, list_concat(), list_copy(), list_length(), list_make1, list_truncate(), make_partition_pruneinfo(), make_result(), make_sort(), makeBoolConst(), makeNode, NIL, Plan::parallel_safe, Path::param_info, Path::parent, Append::part_prune_info, AppendPath::partitioned_rels, AppendPath::path, Path::pathkeys, pathkeys_contained_in(), Append::plan, ParamPathInfo::ppi_clauses, prepare_sort_from_pathkeys(), Plan::qual, RelOptInfo::relids, RELOPT_BASEREL, RelOptInfo::reloptkind, replace_nestloop_params(), Plan::righttree, sort(), subpath(), AppendPath::subpaths, and Plan::targetlist.

Referenced by create_plan_recurse().

1065 {
1066  Append *plan;
1067  List *tlist = build_path_tlist(root, &best_path->path);
1068  int orig_tlist_length = list_length(tlist);
1069  bool tlist_was_changed = false;
1070  List *pathkeys = best_path->path.pathkeys;
1071  List *subplans = NIL;
1072  ListCell *subpaths;
1073  RelOptInfo *rel = best_path->path.parent;
1074  PartitionPruneInfo *partpruneinfo = NULL;
1075  int nodenumsortkeys = 0;
1076  AttrNumber *nodeSortColIdx = NULL;
1077  Oid *nodeSortOperators = NULL;
1078  Oid *nodeCollations = NULL;
1079  bool *nodeNullsFirst = NULL;
1080 
1081  /*
1082  * The subpaths list could be empty, if every child was proven empty by
1083  * constraint exclusion. In that case generate a dummy plan that returns
1084  * no rows.
1085  *
1086  * Note that an AppendPath with no members is also generated in certain
1087  * cases where there was no appending construct at all, but we know the
1088  * relation is empty (see set_dummy_rel_pathlist and mark_dummy_rel).
1089  */
1090  if (best_path->subpaths == NIL)
1091  {
1092  /* Generate a Result plan with constant-FALSE gating qual */
1093  Plan *plan;
1094 
1095  plan = (Plan *) make_result(tlist,
1096  (Node *) list_make1(makeBoolConst(false,
1097  false)),
1098  NULL);
1099 
1100  copy_generic_path_info(plan, (Path *) best_path);
1101 
1102  return plan;
1103  }
1104 
1105  /*
1106  * Otherwise build an Append plan. Note that if there's just one child,
1107  * the Append is pretty useless; but we wait till setrefs.c to get rid of
1108  * it. Doing so here doesn't work because the varno of the child scan
1109  * plan won't match the parent-rel Vars it'll be asked to emit.
1110  *
1111  * We don't have the actual creation of the Append node split out into a
1112  * separate make_xxx function. This is because we want to run
1113  * prepare_sort_from_pathkeys on it before we do so on the individual
1114  * child plans, to make cross-checking the sort info easier.
1115  */
1116  plan = makeNode(Append);
1117  plan->plan.targetlist = tlist;
1118  plan->plan.qual = NIL;
1119  plan->plan.lefttree = NULL;
1120  plan->plan.righttree = NULL;
1121 
1122  if (pathkeys != NIL)
1123  {
1124  /*
1125  * Compute sort column info, and adjust the Append's tlist as needed.
1126  * Because we pass adjust_tlist_in_place = true, we may ignore the
1127  * function result; it must be the same plan node. However, we then
1128  * need to detect whether any tlist entries were added.
1129  */
1130  (void) prepare_sort_from_pathkeys((Plan *) plan, pathkeys,
1131  best_path->path.parent->relids,
1132  NULL,
1133  true,
1134  &nodenumsortkeys,
1135  &nodeSortColIdx,
1136  &nodeSortOperators,
1137  &nodeCollations,
1138  &nodeNullsFirst);
1139  tlist_was_changed = (orig_tlist_length != list_length(plan->plan.targetlist));
1140  }
1141 
1142  /* Build the plan for each child */
1143  foreach(subpaths, best_path->subpaths)
1144  {
1145  Path *subpath = (Path *) lfirst(subpaths);
1146  Plan *subplan;
1147 
1148  /* Must insist that all children return the same tlist */
1149  subplan = create_plan_recurse(root, subpath, CP_EXACT_TLIST);
1150 
1151  /*
1152  * For ordered Appends, we must insert a Sort node if subplan isn't
1153  * sufficiently ordered.
1154  */
1155  if (pathkeys != NIL)
1156  {
1157  int numsortkeys;
1158  AttrNumber *sortColIdx;
1159  Oid *sortOperators;
1160  Oid *collations;
1161  bool *nullsFirst;
1162 
1163  /*
1164  * Compute sort column info, and adjust subplan's tlist as needed.
1165  * We must apply prepare_sort_from_pathkeys even to subplans that
1166  * don't need an explicit sort, to make sure they are returning
1167  * the same sort key columns the Append expects.
1168  */
1169  subplan = prepare_sort_from_pathkeys(subplan, pathkeys,
1170  subpath->parent->relids,
1171  nodeSortColIdx,
1172  false,
1173  &numsortkeys,
1174  &sortColIdx,
1175  &sortOperators,
1176  &collations,
1177  &nullsFirst);
1178 
1179  /*
1180  * Check that we got the same sort key information. We just
1181  * Assert that the sortops match, since those depend only on the
1182  * pathkeys; but it seems like a good idea to check the sort
1183  * column numbers explicitly, to ensure the tlists match up.
1184  */
1185  Assert(numsortkeys == nodenumsortkeys);
1186  if (memcmp(sortColIdx, nodeSortColIdx,
1187  numsortkeys * sizeof(AttrNumber)) != 0)
1188  elog(ERROR, "Append child's targetlist doesn't match Append");
1189  Assert(memcmp(sortOperators, nodeSortOperators,
1190  numsortkeys * sizeof(Oid)) == 0);
1191  Assert(memcmp(collations, nodeCollations,
1192  numsortkeys * sizeof(Oid)) == 0);
1193  Assert(memcmp(nullsFirst, nodeNullsFirst,
1194  numsortkeys * sizeof(bool)) == 0);
1195 
1196  /* Now, insert a Sort node if subplan isn't sufficiently ordered */
1197  if (!pathkeys_contained_in(pathkeys, subpath->pathkeys))
1198  {
1199  Sort *sort = make_sort(subplan, numsortkeys,
1200  sortColIdx, sortOperators,
1201  collations, nullsFirst);
1202 
1203  label_sort_with_costsize(root, sort, best_path->limit_tuples);
1204  subplan = (Plan *) sort;
1205  }
1206  }
1207 
1208  subplans = lappend(subplans, subplan);
1209  }
1210 
1211  /*
1212  * If any quals exist, they may be useful to perform further partition
1213  * pruning during execution. Gather information needed by the executor to
1214  * do partition pruning.
1215  */
1217  rel->reloptkind == RELOPT_BASEREL &&
1218  best_path->partitioned_rels != NIL)
1219  {
1220  List *prunequal;
1221 
1222  prunequal = extract_actual_clauses(rel->baserestrictinfo, false);
1223 
1224  if (best_path->path.param_info)
1225  {
1226  List *prmquals = best_path->path.param_info->ppi_clauses;
1227 
1228  prmquals = extract_actual_clauses(prmquals, false);
1229  prmquals = (List *) replace_nestloop_params(root,
1230  (Node *) prmquals);
1231 
1232  prunequal = list_concat(prunequal, prmquals);
1233  }
1234 
1235  if (prunequal != NIL)
1236  partpruneinfo =
1237  make_partition_pruneinfo(root, rel,
1238  best_path->subpaths,
1239  best_path->partitioned_rels,
1240  prunequal);
1241  }
1242 
1243  plan->appendplans = subplans;
1244  plan->first_partial_plan = best_path->first_partial_path;
1245  plan->part_prune_info = partpruneinfo;
1246 
1247  copy_generic_path_info(&plan->plan, (Path *) best_path);
1248 
1249  /*
1250  * If prepare_sort_from_pathkeys added sort columns, but we were told to
1251  * produce either the exact tlist or a narrow tlist, we should get rid of
1252  * the sort columns again. We must inject a projection node to do so.
1253  */
1254  if (tlist_was_changed && (flags & (CP_EXACT_TLIST | CP_SMALL_TLIST)))
1255  {
1256  tlist = list_truncate(list_copy(plan->plan.targetlist),
1257  orig_tlist_length);
1258  return inject_projection_plan((Plan *) plan, tlist,
1259  plan->plan.parallel_safe);
1260  }
1261  else
1262  return (Plan *) plan;
1263 }
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:141
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
RelOptKind reloptkind
Definition: pathnodes.h:638
double limit_tuples
Definition: pathnodes.h:1377
List * baserestrictinfo
Definition: pathnodes.h:703
List * list_truncate(List *list, int new_size)
Definition: list.c:585
ParamPathInfo * param_info
Definition: pathnodes.h:1117
#define CP_SMALL_TLIST
Definition: createplan.c:69
List * list_copy(const List *oldlist)
Definition: list.c:1400
Definition: nodes.h:524
List * list_concat(List *list1, const List *list2)
Definition: list.c:515
unsigned int Oid
Definition: postgres_ext.h:31
int first_partial_path
Definition: pathnodes.h:1376
#define list_make1(x1)
Definition: pg_list.h:227
List * subpaths
Definition: pathnodes.h:1374
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
struct Plan * righttree
Definition: plannodes.h:143
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
#define ERROR
Definition: elog.h:43
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:355
RelOptInfo * parent
Definition: pathnodes.h:1114
Datum sort(PG_FUNCTION_ARGS)
Definition: _int_op.c:200
Relids relids
Definition: pathnodes.h:641
static Result * make_result(List *tlist, Node *resconstantqual, Plan *subplan)
Definition: createplan.c:6573
List * lappend(List *list, void *datum)
Definition: list.c:321
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
bool enable_partition_pruning
Definition: costsize.c:140
List * pathkeys
Definition: pathnodes.h:1128
static Sort * make_sort(Plan *lefttree, int numCols, AttrNumber *sortColIdx, Oid *sortOperators, Oid *collations, bool *nullsFirst)
Definition: createplan.c:5669
#define makeNode(_type_)
Definition: nodes.h:572
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
List * ppi_clauses
Definition: pathnodes.h:1075
static Plan * inject_projection_plan(Plan *subplan, List *tlist, bool parallel_safe)
Definition: createplan.c:1906
static int list_length(const List *l)
Definition: pg_list.h:169
PartitionPruneInfo * make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, List *subpaths, List *partitioned_rels, List *prunequal)
Definition: partprune.c:230
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
struct Plan * lefttree
Definition: plannodes.h:142
List * partitioned_rels
Definition: pathnodes.h:1373
List * targetlist
Definition: plannodes.h:140
#define elog(elevel,...)
Definition: elog.h:226
bool parallel_safe
Definition: plannodes.h:134
#define CP_EXACT_TLIST
Definition: createplan.c:68
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
static void label_sort_with_costsize(PlannerInfo *root, Sort *plan, double limit_tuples)
Definition: createplan.c:5079
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
static Plan * prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys, Relids relids, const AttrNumber *reqColIdx, bool adjust_tlist_in_place, int *p_numsortkeys, AttrNumber **p_sortColIdx, Oid **p_sortOperators, Oid **p_collations, bool **p_nullsFirst)
Definition: createplan.c:5731

◆ create_bitmap_scan_plan()

static BitmapHeapScan * create_bitmap_scan_plan ( PlannerInfo root,
BitmapHeapPath best_path,
List tlist,
List scan_clauses 
)
static

Definition at line 2932 of file createplan.c.

References Assert, bitmap_subplan_mark_shared(), BitmapHeapPath::bitmapqual, RestrictInfo::clause, contain_mutable_functions(), copy_generic_path_info(), create_bitmap_subplan(), extract_actual_clauses(), lappend(), lfirst_node, list_difference_ptr(), list_make1, list_member(), list_member_ptr(), make_bitmap_heapscan(), NIL, order_qual_clauses(), Path::parallel_aware, Path::param_info, Path::parent, RestrictInfo::parent_ec, BitmapHeapPath::path, Scan::plan, predicate_implied_by(), RestrictInfo::pseudoconstant, RelOptInfo::relid, replace_nestloop_params(), RTE_RELATION, RelOptInfo::rtekind, and BitmapHeapScan::scan.

Referenced by create_scan_plan().

2936 {
2937  Index baserelid = best_path->path.parent->relid;
2938  Plan *bitmapqualplan;
2939  List *bitmapqualorig;
2940  List *indexquals;
2941  List *indexECs;
2942  List *qpqual;
2943  ListCell *l;
2944  BitmapHeapScan *scan_plan;
2945 
2946  /* it should be a base rel... */
2947  Assert(baserelid > 0);
2948  Assert(best_path->path.parent->rtekind == RTE_RELATION);
2949 
2950  /* Process the bitmapqual tree into a Plan tree and qual lists */
2951  bitmapqualplan = create_bitmap_subplan(root, best_path->bitmapqual,
2952  &bitmapqualorig, &indexquals,
2953  &indexECs);
2954 
2955  if (best_path->path.parallel_aware)
2956  bitmap_subplan_mark_shared(bitmapqualplan);
2957 
2958  /*
2959  * The qpqual list must contain all restrictions not automatically handled
2960  * by the index, other than pseudoconstant clauses which will be handled
2961  * by a separate gating plan node. All the predicates in the indexquals
2962  * will be checked (either by the index itself, or by
2963  * nodeBitmapHeapscan.c), but if there are any "special" operators
2964  * involved then they must be added to qpqual. The upshot is that qpqual
2965  * must contain scan_clauses minus whatever appears in indexquals.
2966  *
2967  * This loop is similar to the comparable code in create_indexscan_plan(),
2968  * but with some differences because it has to compare the scan clauses to
2969  * stripped (no RestrictInfos) indexquals. See comments there for more
2970  * info.
2971  *
2972  * In normal cases simple equal() checks will be enough to spot duplicate
2973  * clauses, so we try that first. We next see if the scan clause is
2974  * redundant with any top-level indexqual by virtue of being generated
2975  * from the same EC. After that, try predicate_implied_by().
2976  *
2977  * Unlike create_indexscan_plan(), the predicate_implied_by() test here is
2978  * useful for getting rid of qpquals that are implied by index predicates,
2979  * because the predicate conditions are included in the "indexquals"
2980  * returned by create_bitmap_subplan(). Bitmap scans have to do it that
2981  * way because predicate conditions need to be rechecked if the scan
2982  * becomes lossy, so they have to be included in bitmapqualorig.
2983  */
2984  qpqual = NIL;
2985  foreach(l, scan_clauses)
2986  {
2987  RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
2988  Node *clause = (Node *) rinfo->clause;
2989 
2990  if (rinfo->pseudoconstant)
2991  continue; /* we may drop pseudoconstants here */
2992  if (list_member(indexquals, clause))
2993  continue; /* simple duplicate */
2994  if (rinfo->parent_ec && list_member_ptr(indexECs, rinfo->parent_ec))
2995  continue; /* derived from same EquivalenceClass */
2996  if (!contain_mutable_functions(clause) &&
2997  predicate_implied_by(list_make1(clause), indexquals, false))
2998  continue; /* provably implied by indexquals */
2999  qpqual = lappend(qpqual, rinfo);
3000  }
3001 
3002  /* Sort clauses into best execution order */
3003  qpqual = order_qual_clauses(root, qpqual);
3004 
3005  /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
3006  qpqual = extract_actual_clauses(qpqual, false);
3007 
3008  /*
3009  * When dealing with special operators, we will at this point have
3010  * duplicate clauses in qpqual and bitmapqualorig. We may as well drop
3011  * 'em from bitmapqualorig, since there's no point in making the tests
3012  * twice.
3013  */
3014  bitmapqualorig = list_difference_ptr(bitmapqualorig, qpqual);
3015 
3016  /*
3017  * We have to replace any outer-relation variables with nestloop params in
3018  * the qpqual and bitmapqualorig expressions. (This was already done for
3019  * expressions attached to plan nodes in the bitmapqualplan tree.)
3020  */
3021  if (best_path->path.param_info)
3022  {
3023  qpqual = (List *)
3024  replace_nestloop_params(root, (Node *) qpqual);
3025  bitmapqualorig = (List *)
3026  replace_nestloop_params(root, (Node *) bitmapqualorig);
3027  }
3028 
3029  /* Finally ready to build the plan node */
3030  scan_plan = make_bitmap_heapscan(tlist,
3031  qpqual,
3032  bitmapqualplan,
3033  bitmapqualorig,
3034  baserelid);
3035 
3036  copy_generic_path_info(&scan_plan->scan.plan, &best_path->path);
3037 
3038  return scan_plan;
3039 }
#define NIL
Definition: pg_list.h:65
Plan plan
Definition: plannodes.h:340
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
List * list_difference_ptr(const List *list1, const List *list2)
Definition: list.c:1099
bool pseudoconstant
Definition: pathnodes.h:1951
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
static Plan * create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual, List **qual, List **indexqual, List **indexECs)
Definition: createplan.c:3062
#define list_make1(x1)
Definition: pg_list.h:227
static BitmapHeapScan * make_bitmap_heapscan(List *qptlist, List *qpqual, Plan *lefttree, List *bitmapqualorig, Index scanrelid)
Definition: createplan.c:5252
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
bool list_member(const List *list, const void *datum)
Definition: list.c:613
EquivalenceClass * parent_ec
Definition: pathnodes.h:1977
RelOptInfo * parent
Definition: pathnodes.h:1114
Path * bitmapqual
Definition: pathnodes.h:1250
#define lfirst_node(type, lc)
Definition: pg_list.h:193
Index relid
Definition: pathnodes.h:669
List * lappend(List *list, void *datum)
Definition: list.c:321
static void bitmap_subplan_mark_shared(Plan *plan)
Definition: createplan.c:5105
Expr * clause
Definition: pathnodes.h:1943
unsigned int Index
Definition: c.h:475
RTEKind rtekind
Definition: pathnodes.h:671
bool list_member_ptr(const List *list, const void *datum)
Definition: list.c:634
#define Assert(condition)
Definition: c.h:732
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:645
bool parallel_aware
Definition: pathnodes.h:1119
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:151
Definition: pg_list.h:50

◆ create_bitmap_subplan()

static Plan * create_bitmap_subplan ( PlannerInfo root,
Path bitmapqual,
List **  qual,
List **  indexqual,
List **  indexECs 
)
static

Definition at line 3062 of file createplan.c.

References Assert, BitmapAndPath::bitmapquals, BitmapOrPath::bitmapquals, BitmapAndPath::bitmapselectivity, BitmapOrPath::bitmapselectivity, castNode, clamp_row_est(), RestrictInfo::clause, create_indexscan_plan(), elog, ERROR, get_actual_clauses(), IndexPath::indexclauses, IndexScan::indexid, IndexPath::indexinfo, IndexScan::indexqual, IndexScan::indexqualorig, IndexClause::indexquals, IndexPath::indexselectivity, IndexPath::indextotalcost, IndexOptInfo::indpred, IsA, lappend(), lfirst, linitial, list_concat(), list_concat_unique(), list_length(), list_make1, make_ands_explicit(), make_bitmap_and(), make_bitmap_indexscan(), make_bitmap_or(), make_orclause(), NIL, nodeTag, Plan::parallel_aware, Plan::parallel_safe, Path::parallel_safe, Path::parent, RestrictInfo::parent_ec, IndexPath::path, BitmapAndPath::path, BitmapOrPath::path, Plan::plan_rows, Plan::plan_width, predicate_implied_by(), RestrictInfo::pseudoconstant, IndexClause::rinfo, IndexScan::scan, Scan::scanrelid, Plan::startup_cost, Path::startup_cost, Plan::total_cost, Path::total_cost, and RelOptInfo::tuples.

Referenced by create_bitmap_scan_plan().

3064 {
3065  Plan *plan;
3066 
3067  if (IsA(bitmapqual, BitmapAndPath))
3068  {
3069  BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
3070  List *subplans = NIL;
3071  List *subquals = NIL;
3072  List *subindexquals = NIL;
3073  List *subindexECs = NIL;
3074  ListCell *l;
3075 
3076  /*
3077  * There may well be redundant quals among the subplans, since a
3078  * top-level WHERE qual might have gotten used to form several
3079  * different index quals. We don't try exceedingly hard to eliminate
3080  * redundancies, but we do eliminate obvious duplicates by using
3081  * list_concat_unique.
3082  */
3083  foreach(l, apath->bitmapquals)
3084  {
3085  Plan *subplan;
3086  List *subqual;
3087  List *subindexqual;
3088  List *subindexEC;
3089 
3090  subplan = create_bitmap_subplan(root, (Path *) lfirst(l),
3091  &subqual, &subindexqual,
3092  &subindexEC);
3093  subplans = lappend(subplans, subplan);
3094  subquals = list_concat_unique(subquals, subqual);
3095  subindexquals = list_concat_unique(subindexquals, subindexqual);
3096  /* Duplicates in indexECs aren't worth getting rid of */
3097  subindexECs = list_concat(subindexECs, subindexEC);
3098  }
3099  plan = (Plan *) make_bitmap_and(subplans);
3100  plan->startup_cost = apath->path.startup_cost;
3101  plan->total_cost = apath->path.total_cost;
3102  plan->plan_rows =
3103  clamp_row_est(apath->bitmapselectivity * apath->path.parent->tuples);
3104  plan->plan_width = 0; /* meaningless */
3105  plan->parallel_aware = false;
3106  plan->parallel_safe = apath->path.parallel_safe;
3107  *qual = subquals;
3108  *indexqual = subindexquals;
3109  *indexECs = subindexECs;
3110  }
3111  else if (IsA(bitmapqual, BitmapOrPath))
3112  {
3113  BitmapOrPath *opath = (BitmapOrPath *) bitmapqual;
3114  List *subplans = NIL;
3115  List *subquals = NIL;
3116  List *subindexquals = NIL;
3117  bool const_true_subqual = false;
3118  bool const_true_subindexqual = false;
3119  ListCell *l;
3120 
3121  /*
3122  * Here, we only detect qual-free subplans. A qual-free subplan would
3123  * cause us to generate "... OR true ..." which we may as well reduce
3124  * to just "true". We do not try to eliminate redundant subclauses
3125  * because (a) it's not as likely as in the AND case, and (b) we might
3126  * well be working with hundreds or even thousands of OR conditions,
3127  * perhaps from a long IN list. The performance of list_append_unique
3128  * would be unacceptable.
3129  */
3130  foreach(l, opath->bitmapquals)
3131  {
3132  Plan *subplan;
3133  List *subqual;
3134  List *subindexqual;
3135  List *subindexEC;
3136 
3137  subplan = create_bitmap_subplan(root, (Path *) lfirst(l),
3138  &subqual, &subindexqual,
3139  &subindexEC);
3140  subplans = lappend(subplans, subplan);
3141  if (subqual == NIL)
3142  const_true_subqual = true;
3143  else if (!const_true_subqual)
3144  subquals = lappend(subquals,
3145  make_ands_explicit(subqual));
3146  if (subindexqual == NIL)
3147  const_true_subindexqual = true;
3148  else if (!const_true_subindexqual)
3149  subindexquals = lappend(subindexquals,
3150  make_ands_explicit(subindexqual));
3151  }
3152 
3153  /*
3154  * In the presence of ScalarArrayOpExpr quals, we might have built
3155  * BitmapOrPaths with just one subpath; don't add an OR step.
3156  */
3157  if (list_length(subplans) == 1)
3158  {
3159  plan = (Plan *) linitial(subplans);
3160  }
3161  else
3162  {
3163  plan = (Plan *) make_bitmap_or(subplans);
3164  plan->startup_cost = opath->path.startup_cost;
3165  plan->total_cost = opath->path.total_cost;
3166  plan->plan_rows =
3167  clamp_row_est(opath->bitmapselectivity * opath->path.parent->tuples);
3168  plan->plan_width = 0; /* meaningless */
3169  plan->parallel_aware = false;
3170  plan->parallel_safe = opath->path.parallel_safe;
3171  }
3172 
3173  /*
3174  * If there were constant-TRUE subquals, the OR reduces to constant
3175  * TRUE. Also, avoid generating one-element ORs, which could happen
3176  * due to redundancy elimination or ScalarArrayOpExpr quals.
3177  */
3178  if (const_true_subqual)
3179  *qual = NIL;
3180  else if (list_length(subquals) <= 1)
3181  *qual = subquals;
3182  else
3183  *qual = list_make1(make_orclause(subquals));
3184  if (const_true_subindexqual)
3185  *indexqual = NIL;
3186  else if (list_length(subindexquals) <= 1)
3187  *indexqual = subindexquals;
3188  else
3189  *indexqual = list_make1(make_orclause(subindexquals));
3190  *indexECs = NIL;
3191  }
3192  else if (IsA(bitmapqual, IndexPath))
3193  {
3194  IndexPath *ipath = (IndexPath *) bitmapqual;
3195  IndexScan *iscan;
3196  List *subquals;
3197  List *subindexquals;
3198  List *subindexECs;
3199  ListCell *l;
3200 
3201  /* Use the regular indexscan plan build machinery... */
3202  iscan = castNode(IndexScan,
3203  create_indexscan_plan(root, ipath,
3204  NIL, NIL, false));
3205  /* then convert to a bitmap indexscan */
3206  plan = (Plan *) make_bitmap_indexscan(iscan->scan.scanrelid,
3207  iscan->indexid,
3208  iscan->indexqual,
3209  iscan->indexqualorig);
3210  /* and set its cost/width fields appropriately */
3211  plan->startup_cost = 0.0;
3212  plan->total_cost = ipath->indextotalcost;
3213  plan->plan_rows =
3214  clamp_row_est(ipath->indexselectivity * ipath->path.parent->tuples);
3215  plan->plan_width = 0; /* meaningless */
3216  plan->parallel_aware = false;
3217  plan->parallel_safe = ipath->path.parallel_safe;
3218  /* Extract original index clauses, actual index quals, relevant ECs */
3219  subquals = NIL;
3220  subindexquals = NIL;
3221  subindexECs = NIL;
3222  foreach(l, ipath->indexclauses)
3223  {
3224  IndexClause *iclause = (IndexClause *) lfirst(l);
3225  RestrictInfo *rinfo = iclause->rinfo;
3226 
3227  Assert(!rinfo->pseudoconstant);
3228  subquals = lappend(subquals, rinfo->clause);
3229  subindexquals = list_concat(subindexquals,
3230  get_actual_clauses(iclause->indexquals));
3231  if (rinfo->parent_ec)
3232  subindexECs = lappend(subindexECs, rinfo->parent_ec);
3233  }
3234  /* We can add any index predicate conditions, too */
3235  foreach(l, ipath->indexinfo->indpred)
3236  {
3237  Expr *pred = (Expr *) lfirst(l);
3238 
3239  /*
3240  * We know that the index predicate must have been implied by the
3241  * query condition as a whole, but it may or may not be implied by
3242  * the conditions that got pushed into the bitmapqual. Avoid
3243  * generating redundant conditions.
3244  */
3245  if (!predicate_implied_by(list_make1(pred), subquals, false))
3246  {
3247  subquals = lappend(subquals, pred);
3248  subindexquals = lappend(subindexquals, pred);
3249  }
3250  }
3251  *qual = subquals;
3252  *indexqual = subindexquals;
3253  *indexECs = subindexECs;
3254  }
3255  else
3256  {
3257  elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));
3258  plan = NULL; /* keep compiler quiet */
3259  }
3260 
3261  return plan;
3262 }
#define NIL
Definition: pg_list.h:65
double plan_rows
Definition: plannodes.h:127
#define IsA(nodeptr, _type_)
Definition: nodes.h:575
Path path
Definition: pathnodes.h:1176
IndexOptInfo * indexinfo
Definition: pathnodes.h:1177
Index scanrelid
Definition: plannodes.h:341
#define castNode(_type_, nodeptr)
Definition: nodes.h:593
double tuples
Definition: pathnodes.h:681
bool pseudoconstant
Definition: pathnodes.h:1951
List * indexqualorig
Definition: plannodes.h:403
List * get_actual_clauses(List *restrictinfo_list)
Definition: restrictinfo.c:399
List * list_concat(List *list1, const List *list2)
Definition: list.c:515
List * indexclauses
Definition: pathnodes.h:1178
static Plan * create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual, List **qual, List **indexqual, List **indexECs)
Definition: createplan.c:3062
Selectivity bitmapselectivity
Definition: pathnodes.h:1263
Expr * make_orclause(List *orclauses)
Definition: makefuncs.c:649
static BitmapAnd * make_bitmap_and(List *bitmapplans)
Definition: createplan.c:5519
Oid indexid
Definition: plannodes.h:401
List * bitmapquals
Definition: pathnodes.h:1262
List * bitmapquals
Definition: pathnodes.h:1275
#define list_make1(x1)
Definition: pg_list.h:227
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
Cost indextotalcost
Definition: pathnodes.h:1182
Cost startup_cost
Definition: pathnodes.h:1125
Scan scan
Definition: plannodes.h:400
EquivalenceClass * parent_ec
Definition: pathnodes.h:1977
RelOptInfo * parent
Definition: pathnodes.h:1114
Selectivity indexselectivity
Definition: pathnodes.h:1183
struct RestrictInfo * rinfo
Definition: pathnodes.h:1223
Cost startup_cost
Definition: plannodes.h:121
bool parallel_aware
Definition: plannodes.h:133
Selectivity bitmapselectivity
Definition: pathnodes.h:1276
List * indexqual
Definition: plannodes.h:402
List * indexquals
Definition: pathnodes.h:1224
List * lappend(List *list, void *datum)
Definition: list.c:321
Expr * clause
Definition: pathnodes.h:1943
Expr * make_ands_explicit(List *andclauses)
Definition: makefuncs.c:705
static BitmapOr * make_bitmap_or(List *bitmapplans)
Definition: createplan.c:5534
Cost total_cost
Definition: pathnodes.h:1126
int plan_width
Definition: plannodes.h:128
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
bool parallel_safe
Definition: pathnodes.h:1120
static int list_length(const List *l)
Definition: pg_list.h:169
static BitmapIndexScan * make_bitmap_indexscan(Index scanrelid, Oid indexid, List *indexqual, List *indexqualorig)
Definition: createplan.c:5231
#define nodeTag(nodeptr)
Definition: nodes.h:529
#define elog(elevel,...)
Definition: elog.h:226
Cost total_cost
Definition: plannodes.h:122
bool parallel_safe
Definition: plannodes.h:134
List * indpred
Definition: pathnodes.h:814
double clamp_row_est(double nrows)
Definition: costsize.c:187
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:151
Definition: pg_list.h:50
static Scan * create_indexscan_plan(PlannerInfo *root, IndexPath *best_path, List *tlist, List *scan_clauses, bool indexonly)
Definition: createplan.c:2759
List * list_concat_unique(List *list1, const List *list2)
Definition: list.c:1234

◆ create_ctescan_plan()

static CteScan * create_ctescan_plan ( PlannerInfo root,
Path best_path,
List tlist,
List scan_clauses 
)
static

Definition at line 3547 of file createplan.c.

References Assert, copy_generic_path_info(), PlannerInfo::cte_plan_ids, RangeTblEntry::ctelevelsup, Query::cteList, RangeTblEntry::ctename, CommonTableExpr::ctename, elog, ERROR, extract_actual_clauses(), PlannerInfo::init_plans, lfirst, linitial_int, list_length(), list_nth_int(), make_ctescan(), order_qual_clauses(), Path::param_info, Path::parent, PlannerInfo::parent_root, PlannerInfo::parse, Scan::plan, SubPlan::plan_id, planner_rt_fetch, RelOptInfo::relid, replace_nestloop_params(), RTE_CTE, RangeTblEntry::rtekind, CteScan::scan, RangeTblEntry::self_reference, and SubPlan::setParam.

Referenced by create_scan_plan().

3549 {
3550  CteScan *scan_plan;
3551  Index scan_relid = best_path->parent->relid;
3552  RangeTblEntry *rte;
3553  SubPlan *ctesplan = NULL;
3554  int plan_id;
3555  int cte_param_id;
3556  PlannerInfo *cteroot;
3557  Index levelsup;
3558  int ndx;
3559  ListCell *lc;
3560 
3561  Assert(scan_relid > 0);
3562  rte = planner_rt_fetch(scan_relid, root);
3563  Assert(rte->rtekind == RTE_CTE);
3564  Assert(!rte->self_reference);
3565 
3566  /*
3567  * Find the referenced CTE, and locate the SubPlan previously made for it.
3568  */
3569  levelsup = rte->ctelevelsup;
3570  cteroot = root;
3571  while (levelsup-- > 0)
3572  {
3573  cteroot = cteroot->parent_root;
3574  if (!cteroot) /* shouldn't happen */
3575  elog(ERROR, "bad levelsup for CTE \"%s\"", rte->ctename);
3576  }
3577 
3578  /*
3579  * Note: cte_plan_ids can be shorter than cteList, if we are still working
3580  * on planning the CTEs (ie, this is a side-reference from another CTE).
3581  * So we mustn't use forboth here.
3582  */
3583  ndx = 0;
3584  foreach(lc, cteroot->parse->cteList)
3585  {
3586  CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc);
3587 
3588  if (strcmp(cte->ctename, rte->ctename) == 0)
3589  break;
3590  ndx++;
3591  }
3592  if (lc == NULL) /* shouldn't happen */
3593  elog(ERROR, "could not find CTE \"%s\"", rte->ctename);
3594  if (ndx >= list_length(cteroot->cte_plan_ids))
3595  elog(ERROR, "could not find plan for CTE \"%s\"", rte->ctename);
3596  plan_id = list_nth_int(cteroot->cte_plan_ids, ndx);
3597  Assert(plan_id > 0);
3598  foreach(lc, cteroot->init_plans)
3599  {
3600  ctesplan = (SubPlan *) lfirst(lc);
3601  if (ctesplan->plan_id == plan_id)
3602  break;
3603  }
3604  if (lc == NULL) /* shouldn't happen */
3605  elog(ERROR, "could not find plan for CTE \"%s\"", rte->ctename);
3606 
3607  /*
3608  * We need the CTE param ID, which is the sole member of the SubPlan's
3609  * setParam list.
3610  */
3611  cte_param_id = linitial_int(ctesplan->setParam);
3612 
3613  /* Sort clauses into best execution order */
3614  scan_clauses = order_qual_clauses(root, scan_clauses);
3615 
3616  /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
3617  scan_clauses = extract_actual_clauses(scan_clauses, false);
3618 
3619  /* Replace any outer-relation variables with nestloop params */
3620  if (best_path->param_info)
3621  {
3622  scan_clauses = (List *)
3623  replace_nestloop_params(root, (Node *) scan_clauses);
3624  }
3625 
3626  scan_plan = make_ctescan(tlist, scan_clauses, scan_relid,
3627  plan_id, cte_param_id);
3628 
3629  copy_generic_path_info(&scan_plan->scan.plan, best_path);
3630 
3631  return scan_plan;
3632 }
Plan plan
Definition: plannodes.h:340
Query * parse
Definition: pathnodes.h:177
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
int plan_id
Definition: primnodes.h:695
PlannerInfo * parent_root
Definition: pathnodes.h:183
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
static int list_nth_int(const List *list, int n)
Definition: pg_list.h:288
#define linitial_int(l)
Definition: pg_list.h:196
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
#define ERROR
Definition: elog.h:43
Scan scan
Definition: plannodes.h:551
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:371
RelOptInfo * parent
Definition: pathnodes.h:1114
Index relid
Definition: pathnodes.h:669
static CteScan * make_ctescan(List *qptlist, List *qpqual, Index scanrelid, int ctePlanId, int cteParam)
Definition: createplan.c:5369
List * cte_plan_ids
Definition: pathnodes.h:259
bool self_reference
Definition: parsenodes.h:1058
unsigned int Index
Definition: c.h:475
List * init_plans
Definition: pathnodes.h:257
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
List * setParam
Definition: primnodes.h:713
static int list_length(const List *l)
Definition: pg_list.h:169
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
Index ctelevelsup
Definition: parsenodes.h:1057
RTEKind rtekind
Definition: parsenodes.h:974
List * cteList
Definition: parsenodes.h:135
char * ctename
Definition: parsenodes.h:1056
#define elog(elevel,...)
Definition: elog.h:226
Definition: pg_list.h:50

◆ create_customscan_plan()

static CustomScan * create_customscan_plan ( PlannerInfo root,
CustomPath best_path,
List tlist,
List scan_clauses 
)
static

Definition at line 3921 of file createplan.c.

References castNode, copy_generic_path_info(), CP_EXACT_TLIST, create_plan_recurse(), CustomScan::custom_exprs, CustomPath::custom_paths, CustomScan::custom_relids, lappend(), lfirst, CustomPath::methods, NIL, order_qual_clauses(), Path::param_info, Path::parent, CustomPath::path, Scan::plan, CustomPathMethods::PlanCustomPath, Plan::qual, RelOptInfo::relids, replace_nestloop_params(), and CustomScan::scan.

Referenced by create_scan_plan().

3923 {
3924  CustomScan *cplan;
3925  RelOptInfo *rel = best_path->path.parent;
3926  List *custom_plans = NIL;
3927  ListCell *lc;
3928 
3929  /* Recursively transform child paths. */
3930  foreach(lc, best_path->custom_paths)
3931  {
3932  Plan *plan = create_plan_recurse(root, (Path *) lfirst(lc),
3933  CP_EXACT_TLIST);
3934 
3935  custom_plans = lappend(custom_plans, plan);
3936  }
3937 
3938  /*
3939  * Sort clauses into the best execution order, although custom-scan
3940  * provider can reorder them again.
3941  */
3942  scan_clauses = order_qual_clauses(root, scan_clauses);
3943 
3944  /*
3945  * Invoke custom plan provider to create the Plan node represented by the
3946  * CustomPath.
3947  */
3948  cplan = castNode(CustomScan,
3949  best_path->methods->PlanCustomPath(root,
3950  rel,
3951  best_path,
3952  tlist,
3953  scan_clauses,
3954  custom_plans));
3955 
3956  /*
3957  * Copy cost data from Path to Plan; no need to make custom-plan providers
3958  * do this
3959  */
3960  copy_generic_path_info(&cplan->scan.plan, &best_path->path);
3961 
3962  /* Likewise, copy the relids that are represented by this custom scan */
3963  cplan->custom_relids = best_path->path.parent->relids;
3964 
3965  /*
3966  * Replace any outer-relation variables with nestloop params in the qual
3967  * and custom_exprs expressions. We do this last so that the custom-plan
3968  * provider doesn't have to be involved. (Note that parts of custom_exprs
3969  * could have come from join clauses, so doing this beforehand on the
3970  * scan_clauses wouldn't work.) We assume custom_scan_tlist contains no
3971  * such variables.
3972  */
3973  if (best_path->path.param_info)
3974  {
3975  cplan->scan.plan.qual = (List *)
3976  replace_nestloop_params(root, (Node *) cplan->scan.plan.qual);
3977  cplan->custom_exprs = (List *)
3978  replace_nestloop_params(root, (Node *) cplan->custom_exprs);
3979  }
3980 
3981  return cplan;
3982 }
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:141
Plan plan
Definition: plannodes.h:340
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
List * custom_paths
Definition: pathnodes.h:1349
#define castNode(_type_, nodeptr)
Definition: nodes.h:593
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
List * custom_exprs
Definition: plannodes.h:642
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
const struct CustomPathMethods * methods
Definition: pathnodes.h:1351
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
RelOptInfo * parent
Definition: pathnodes.h:1114
Relids relids
Definition: pathnodes.h:641
List * lappend(List *list, void *datum)
Definition: list.c:321
Scan scan
Definition: plannodes.h:638
struct Plan *(* PlanCustomPath)(PlannerInfo *root, RelOptInfo *rel, struct CustomPath *best_path, List *tlist, List *clauses, List *custom_plans)
Definition: extensible.h:93
#define lfirst(lc)
Definition: pg_list.h:190
Bitmapset * custom_relids
Definition: plannodes.h:645
#define CP_EXACT_TLIST
Definition: createplan.c:68
Definition: pg_list.h:50

◆ create_foreignscan_plan()

static ForeignScan * create_foreignscan_plan ( PlannerInfo root,
ForeignPath best_path,
List tlist,
List scan_clauses 
)
static

Definition at line 3777 of file createplan.c.

References PlannerInfo::all_baserels, Assert, RelOptInfo::baserestrictinfo, bms_free(), bms_is_member(), RestrictInfo::clause, copy_generic_path_info(), CP_EXACT_TLIST, create_plan_recurse(), PlannerGlobal::dependsOnRole, PathTarget::exprs, ForeignScan::fdw_exprs, ForeignPath::fdw_outerpath, ForeignScan::fdw_recheck_quals, RelOptInfo::fdwroutine, FirstLowInvalidHeapAttributeNumber, ForeignScan::fs_relids, ForeignScan::fs_server, ForeignScan::fsSystemCol, FdwRoutine::GetForeignPlan, PlannerInfo::glob, i, InvalidOid, lfirst, order_qual_clauses(), Path::param_info, Path::parent, ForeignPath::path, Scan::plan, planner_rt_fetch, pull_varattnos(), Plan::qual, RelOptInfo::relid, RangeTblEntry::relid, RelOptInfo::relids, RELOPT_UPPER_REL, RelOptInfo::reloptkind, RelOptInfo::reltarget, replace_nestloop_params(), RTE_RELATION, RelOptInfo::rtekind, RangeTblEntry::rtekind, ForeignScan::scan, RelOptInfo::serverid, and RelOptInfo::useridiscurrent.

Referenced by create_scan_plan().

3779 {
3780  ForeignScan *scan_plan;
3781  RelOptInfo *rel = best_path->path.parent;
3782  Index scan_relid = rel->relid;
3783  Oid rel_oid = InvalidOid;
3784  Plan *outer_plan = NULL;
3785 
3786  Assert(rel->fdwroutine != NULL);
3787 
3788  /* transform the child path if any */
3789  if (best_path->fdw_outerpath)
3790  outer_plan = create_plan_recurse(root, best_path->fdw_outerpath,
3791  CP_EXACT_TLIST);
3792 
3793  /*
3794  * If we're scanning a base relation, fetch its OID. (Irrelevant if
3795  * scanning a join relation.)
3796  */
3797  if (scan_relid > 0)
3798  {
3799  RangeTblEntry *rte;
3800 
3801  Assert(rel->rtekind == RTE_RELATION);
3802  rte = planner_rt_fetch(scan_relid, root);
3803  Assert(rte->rtekind == RTE_RELATION);
3804  rel_oid = rte->relid;
3805  }
3806 
3807  /*
3808  * Sort clauses into best execution order. We do this first since the FDW
3809  * might have more info than we do and wish to adjust the ordering.
3810  */
3811  scan_clauses = order_qual_clauses(root, scan_clauses);
3812 
3813  /*
3814  * Let the FDW perform its processing on the restriction clauses and
3815  * generate the plan node. Note that the FDW might remove restriction
3816  * clauses that it intends to execute remotely, or even add more (if it
3817  * has selected some join clauses for remote use but also wants them
3818  * rechecked locally).
3819  */
3820  scan_plan = rel->fdwroutine->GetForeignPlan(root, rel, rel_oid,
3821  best_path,
3822  tlist, scan_clauses,
3823  outer_plan);
3824 
3825  /* Copy cost data from Path to Plan; no need to make FDW do this */
3826  copy_generic_path_info(&scan_plan->scan.plan, &best_path->path);
3827 
3828  /* Copy foreign server OID; likewise, no need to make FDW do this */
3829  scan_plan->fs_server = rel->serverid;
3830 
3831  /*
3832  * Likewise, copy the relids that are represented by this foreign scan. An
3833  * upper rel doesn't have relids set, but it covers all the base relations
3834  * participating in the underlying scan, so use root's all_baserels.
3835  */
3836  if (rel->reloptkind == RELOPT_UPPER_REL)
3837  scan_plan->fs_relids = root->all_baserels;
3838  else
3839  scan_plan->fs_relids = best_path->path.parent->relids;
3840 
3841  /*
3842  * If this is a foreign join, and to make it valid to push down we had to
3843  * assume that the current user is the same as some user explicitly named
3844  * in the query, mark the finished plan as depending on the current user.
3845  */
3846  if (rel->useridiscurrent)
3847  root->glob->dependsOnRole = true;
3848 
3849  /*
3850  * Replace any outer-relation variables with nestloop params in the qual,
3851  * fdw_exprs and fdw_recheck_quals expressions. We do this last so that
3852  * the FDW doesn't have to be involved. (Note that parts of fdw_exprs or
3853  * fdw_recheck_quals could have come from join clauses, so doing this
3854  * beforehand on the scan_clauses wouldn't work.) We assume
3855  * fdw_scan_tlist contains no such variables.
3856  */
3857  if (best_path->path.param_info)
3858  {
3859  scan_plan->scan.plan.qual = (List *)
3860  replace_nestloop_params(root, (Node *) scan_plan->scan.plan.qual);
3861  scan_plan->fdw_exprs = (List *)
3862  replace_nestloop_params(root, (Node *) scan_plan->fdw_exprs);
3863  scan_plan->fdw_recheck_quals = (List *)
3865  (Node *) scan_plan->fdw_recheck_quals);
3866  }
3867 
3868  /*
3869  * If rel is a base relation, detect whether any system columns are
3870  * requested from the rel. (If rel is a join relation, rel->relid will be
3871  * 0, but there can be no Var with relid 0 in the rel's targetlist or the
3872  * restriction clauses, so we skip this in that case. Note that any such
3873  * columns in base relations that were joined are assumed to be contained
3874  * in fdw_scan_tlist.) This is a bit of a kluge and might go away
3875  * someday, so we intentionally leave it out of the API presented to FDWs.
3876  */
3877  scan_plan->fsSystemCol = false;
3878  if (scan_relid > 0)
3879  {
3880  Bitmapset *attrs_used = NULL;
3881  ListCell *lc;
3882  int i;
3883 
3884  /*
3885  * First, examine all the attributes needed for joins or final output.
3886  * Note: we must look at rel's targetlist, not the attr_needed data,
3887  * because attr_needed isn't computed for inheritance child rels.
3888  */
3889  pull_varattnos((Node *) rel->reltarget->exprs, scan_relid, &attrs_used);
3890 
3891  /* Add all the attributes used by restriction clauses. */
3892  foreach(lc, rel->baserestrictinfo)
3893  {
3894  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
3895 
3896  pull_varattnos((Node *) rinfo->clause, scan_relid, &attrs_used);
3897  }
3898 
3899  /* Now, are any system columns requested from rel? */
3900  for (i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++)
3901  {
3903  {
3904  scan_plan->fsSystemCol = true;
3905  break;
3906  }
3907  }
3908 
3909  bms_free(attrs_used);
3910  }
3911 
3912  return scan_plan;
3913 }
GetForeignPlan_function GetForeignPlan
Definition: fdwapi.h:190
List * qual
Definition: plannodes.h:141
Plan plan
Definition: plannodes.h:340
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
Path * fdw_outerpath
Definition: pathnodes.h:1319
RelOptKind reloptkind
Definition: pathnodes.h:638
Oid fs_server
Definition: plannodes.h:612
List * baserestrictinfo
Definition: pathnodes.h:703
List * fdw_exprs
Definition: plannodes.h:613
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
bool useridiscurrent
Definition: pathnodes.h:692
unsigned int Oid
Definition: postgres_ext.h:31
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:219
bool dependsOnRole
Definition: pathnodes.h:139
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
Relids all_baserels
Definition: pathnodes.h:225
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:371
RelOptInfo * parent
Definition: pathnodes.h:1114
PlannerGlobal * glob
Definition: pathnodes.h:179
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:694
Relids relids
Definition: pathnodes.h:641
List * fdw_recheck_quals
Definition: plannodes.h:616
Index relid
Definition: pathnodes.h:669
Expr * clause
Definition: pathnodes.h:1943
Oid serverid
Definition: pathnodes.h:690
List * exprs
Definition: pathnodes.h:1044
unsigned int Index
Definition: c.h:475
RTEKind rtekind
Definition: pathnodes.h:671
#define InvalidOid
Definition: postgres_ext.h:36
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
RTEKind rtekind
Definition: parsenodes.h:974
int i
#define CP_EXACT_TLIST
Definition: createplan.c:68
Definition: pg_list.h:50
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427
struct PathTarget * reltarget
Definition: pathnodes.h:652
bool fsSystemCol
Definition: plannodes.h:618
Bitmapset * fs_relids
Definition: plannodes.h:617

◆ create_functionscan_plan()

static FunctionScan * create_functionscan_plan ( PlannerInfo root,
Path best_path,
List tlist,
List scan_clauses 
)
static

Definition at line 3417 of file createplan.c.

References Assert, copy_generic_path_info(), extract_actual_clauses(), RangeTblEntry::funcordinality, functions, RangeTblEntry::functions, make_functionscan(), order_qual_clauses(), Path::param_info, Path::parent, Scan::plan, planner_rt_fetch, RelOptInfo::relid, replace_nestloop_params(), RTE_FUNCTION, RangeTblEntry::rtekind, and FunctionScan::scan.

Referenced by create_scan_plan().

3419 {
3420  FunctionScan *scan_plan;
3421  Index scan_relid = best_path->parent->relid;
3422  RangeTblEntry *rte;
3423  List *functions;
3424 
3425  /* it should be a function base rel... */
3426  Assert(scan_relid > 0);
3427  rte = planner_rt_fetch(scan_relid, root);
3428  Assert(rte->rtekind == RTE_FUNCTION);
3429  functions = rte->functions;
3430 
3431  /* Sort clauses into best execution order */
3432  scan_clauses = order_qual_clauses(root, scan_clauses);
3433 
3434  /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
3435  scan_clauses = extract_actual_clauses(scan_clauses, false);
3436 
3437  /* Replace any outer-relation variables with nestloop params */
3438  if (best_path->param_info)
3439  {
3440  scan_clauses = (List *)
3441  replace_nestloop_params(root, (Node *) scan_clauses);
3442  /* The function expressions could contain nestloop params, too */
3443  functions = (List *) replace_nestloop_params(root, (Node *) functions);
3444  }
3445 
3446  scan_plan = make_functionscan(tlist, scan_clauses, scan_relid,
3447  functions, rte->funcordinality);
3448 
3449  copy_generic_path_info(&scan_plan->scan.plan, best_path);
3450 
3451  return scan_plan;
3452 }
Plan plan
Definition: plannodes.h:340
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
bool funcordinality
Definition: parsenodes.h:1041
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:371
RelOptInfo * parent
Definition: pathnodes.h:1114
Index relid
Definition: pathnodes.h:669
unsigned int Index
Definition: c.h:475
static FunctionScan * make_functionscan(List *qptlist, List *qpqual, Index scanrelid, List *functions, bool funcordinality)
Definition: createplan.c:5310
#define Assert(condition)
Definition: c.h:732
List * functions
Definition: parsenodes.h:1040
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
static const struct fns functions
Definition: regcomp.c:298
RTEKind rtekind
Definition: parsenodes.h:974
Definition: pg_list.h:50

◆ create_gather_merge_plan()

static GatherMerge * create_gather_merge_plan ( PlannerInfo root,
GatherMergePath best_path 
)
static

Definition at line 1746 of file createplan.c.

References Assert, assign_special_exec_param(), build_path_tlist(), GatherMerge::collations, copy_generic_path_info(), CP_EXACT_TLIST, create_plan_recurse(), PlannerInfo::glob, Plan::lefttree, make_sort(), makeNode, NIL, GatherMerge::nullsFirst, GatherMerge::num_workers, GatherMergePath::num_workers, GatherMerge::numCols, PlannerGlobal::parallelModeNeeded, Path::parent, GatherMergePath::path, Path::pathkeys, pathkeys_contained_in(), GatherMerge::plan, prepare_sort_from_pathkeys(), RelOptInfo::relids, GatherMerge::rescan_param, GatherMerge::sortColIdx, GatherMerge::sortOperators, GatherMergePath::subpath, and Plan::targetlist.

Referenced by create_plan_recurse().

1747 {
1748  GatherMerge *gm_plan;
1749  Plan *subplan;
1750  List *pathkeys = best_path->path.pathkeys;
1751  List *tlist = build_path_tlist(root, &best_path->path);
1752 
1753  /* As with Gather, it's best to project away columns in the workers. */
1754  subplan = create_plan_recurse(root, best_path->subpath, CP_EXACT_TLIST);
1755 
1756  /* Create a shell for a GatherMerge plan. */
1757  gm_plan = makeNode(GatherMerge);
1758  gm_plan->plan.targetlist = tlist;
1759  gm_plan->num_workers = best_path->num_workers;
1760  copy_generic_path_info(&gm_plan->plan, &best_path->path);
1761 
1762  /* Assign the rescan Param. */
1763  gm_plan->rescan_param = assign_special_exec_param(root);
1764 
1765  /* Gather Merge is pointless with no pathkeys; use Gather instead. */
1766  Assert(pathkeys != NIL);
1767 
1768  /* Compute sort column info, and adjust subplan's tlist as needed */
1769  subplan = prepare_sort_from_pathkeys(subplan, pathkeys,
1770  best_path->subpath->parent->relids,
1771  gm_plan->sortColIdx,
1772  false,
1773  &gm_plan->numCols,
1774  &gm_plan->sortColIdx,
1775  &gm_plan->sortOperators,
1776  &gm_plan->collations,
1777  &gm_plan->nullsFirst);
1778 
1779 
1780  /* Now, insert a Sort node if subplan isn't sufficiently ordered */
1781  if (!pathkeys_contained_in(pathkeys, best_path->subpath->pathkeys))
1782  subplan = (Plan *) make_sort(subplan, gm_plan->numCols,
1783  gm_plan->sortColIdx,
1784  gm_plan->sortOperators,
1785  gm_plan->collations,
1786  gm_plan->nullsFirst);
1787 
1788  /* Now insert the subplan under GatherMerge. */
1789  gm_plan->plan.lefttree = subplan;
1790 
1791  /* use parallel mode for parallel plans. */
1792  root->glob->parallelModeNeeded = true;
1793 
1794  return gm_plan;
1795 }
#define NIL
Definition: pg_list.h:65
Oid * collations
Definition: plannodes.h:893
AttrNumber * sortColIdx
Definition: plannodes.h:891
bool * nullsFirst
Definition: plannodes.h:894
int assign_special_exec_param(PlannerInfo *root)
Definition: paramassign.c:585
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
bool parallelModeNeeded
Definition: pathnodes.h:143
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
RelOptInfo * parent
Definition: pathnodes.h:1114
PlannerGlobal * glob
Definition: pathnodes.h:179
Relids relids
Definition: pathnodes.h:641
Oid * sortOperators
Definition: plannodes.h:892
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
List * pathkeys
Definition: pathnodes.h:1128
static Sort * make_sort(Plan *lefttree, int numCols, AttrNumber *sortColIdx, Oid *sortOperators, Oid *collations, bool *nullsFirst)
Definition: createplan.c:5669
#define makeNode(_type_)
Definition: nodes.h:572
#define Assert(condition)
Definition: c.h:732
struct Plan * lefttree
Definition: plannodes.h:142
List * targetlist
Definition: plannodes.h:140
int num_workers
Definition: plannodes.h:887
int rescan_param
Definition: plannodes.h:888
#define CP_EXACT_TLIST
Definition: createplan.c:68
Definition: pg_list.h:50
static Plan * prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys, Relids relids, const AttrNumber *reqColIdx, bool adjust_tlist_in_place, int *p_numsortkeys, AttrNumber **p_sortColIdx, Oid **p_sortOperators, Oid **p_collations, bool **p_nullsFirst)
Definition: createplan.c:5731

◆ create_gather_plan()

static Gather * create_gather_plan ( PlannerInfo root,
GatherPath best_path 
)
static

Definition at line 1710 of file createplan.c.

References assign_special_exec_param(), build_path_tlist(), copy_generic_path_info(), CP_EXACT_TLIST, create_plan_recurse(), PlannerInfo::glob, make_gather(), NIL, GatherPath::num_workers, PlannerGlobal::parallelModeNeeded, GatherPath::path, Gather::plan, GatherPath::single_copy, and GatherPath::subpath.

Referenced by create_plan_recurse().

1711 {
1712  Gather *gather_plan;
1713  Plan *subplan;
1714  List *tlist;
1715 
1716  /*
1717  * Although the Gather node can project, we prefer to push down such work
1718  * to its child node, so demand an exact tlist from the child.
1719  */
1720  subplan = create_plan_recurse(root, best_path->subpath, CP_EXACT_TLIST);
1721 
1722  tlist = build_path_tlist(root, &best_path->path);
1723 
1724  gather_plan = make_gather(tlist,
1725  NIL,
1726  best_path->num_workers,
1728  best_path->single_copy,
1729  subplan);
1730 
1731  copy_generic_path_info(&gather_plan->plan, &best_path->path);
1732 
1733  /* use parallel mode for parallel plans. */
1734  root->glob->parallelModeNeeded = true;
1735 
1736  return gather_plan;
1737 }
#define NIL
Definition: pg_list.h:65
bool single_copy
Definition: pathnodes.h:1466
int assign_special_exec_param(PlannerInfo *root)
Definition: paramassign.c:585
int num_workers
Definition: pathnodes.h:1467
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
bool parallelModeNeeded
Definition: pathnodes.h:143
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
Plan plan
Definition: plannodes.h:871
PlannerGlobal * glob
Definition: pathnodes.h:179
Path * subpath
Definition: pathnodes.h:1465
static Gather * make_gather(List *qptlist, List *qpqual, int nworkers, int rescan_param, bool single_copy, Plan *subplan)
Definition: createplan.c:6446
#define CP_EXACT_TLIST
Definition: createplan.c:68
Definition: pg_list.h:50

◆ create_gating_plan()

static Plan * create_gating_plan ( PlannerInfo root,
Path path,
Plan plan,
List gating_quals 
)
static

Definition at line 945 of file createplan.c.

References Assert, build_path_tlist(), copy_plan_costsize(), IsA, Plan::lefttree, make_result(), Plan::parallel_safe, Path::parallel_safe, Result::plan, Result::resconstantqual, and splan.

Referenced by create_join_plan(), and create_scan_plan().

947 {
948  Plan *gplan;
949  Plan *splan;
950 
951  Assert(gating_quals);
952 
953  /*
954  * We might have a trivial Result plan already. Stacking one Result atop
955  * another is silly, so if that applies, just discard the input plan.
956  * (We're assuming its targetlist is uninteresting; it should be either
957  * the same as the result of build_path_tlist, or a simplified version.)
958  */
959  splan = plan;
960  if (IsA(plan, Result))
961  {
962  Result *rplan = (Result *) plan;
963 
964  if (rplan->plan.lefttree == NULL &&
965  rplan->resconstantqual == NULL)
966  splan = NULL;
967  }
968 
969  /*
970  * Since we need a Result node anyway, always return the path's requested
971  * tlist; that's never a wrong choice, even if the parent node didn't ask
972  * for CP_EXACT_TLIST.
973  */
974  gplan = (Plan *) make_result(build_path_tlist(root, path),
975  (Node *) gating_quals,
976  splan);
977 
978  /*
979  * Notice that we don't change cost or size estimates when doing gating.
980  * The costs of qual eval were already included in the subplan's cost.
981  * Leaving the size alone amounts to assuming that the gating qual will
982  * succeed, which is the conservative estimate for planning upper queries.
983  * We certainly don't want to assume the output size is zero (unless the
984  * gating qual is actually constant FALSE, and that case is dealt with in
985  * clausesel.c). Interpolating between the two cases is silly, because it
986  * doesn't reflect what will really happen at runtime, and besides which
987  * in most cases we have only a very bad idea of the probability of the
988  * gating qual being true.
989  */
990  copy_plan_costsize(gplan, plan);
991 
992  /* Gating quals could be unsafe, so better use the Path's safety flag */
993  gplan->parallel_safe = path->parallel_safe;
994 
995  return gplan;
996 }
Plan plan
Definition: plannodes.h:186
#define IsA(nodeptr, _type_)
Definition: nodes.h:575
Definition: nodes.h:524
Node * resconstantqual
Definition: plannodes.h:187
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
static void copy_plan_costsize(Plan *dest, Plan *src)
Definition: createplan.c:5057
static SPIPlanPtr splan
Definition: regress.c:231
static Result * make_result(List *tlist, Node *resconstantqual, Plan *subplan)
Definition: createplan.c:6573
#define Assert(condition)
Definition: c.h:732
bool parallel_safe
Definition: pathnodes.h:1120
struct Plan * lefttree
Definition: plannodes.h:142
bool parallel_safe
Definition: plannodes.h:134

◆ create_group_plan()

static Group * create_group_plan ( PlannerInfo root,
GroupPath best_path 
)
static

Definition at line 2001 of file createplan.c.

References build_path_tlist(), copy_generic_path_info(), CP_LABEL_TLIST, create_plan_recurse(), extract_grouping_collations(), extract_grouping_cols(), extract_grouping_ops(), GroupPath::groupClause, list_length(), make_group(), order_qual_clauses(), GroupPath::path, Group::plan, GroupPath::qual, GroupPath::subpath, and Plan::targetlist.

Referenced by create_plan_recurse().

2002 {
2003  Group *plan;
2004  Plan *subplan;
2005  List *tlist;
2006  List *quals;
2007 
2008  /*
2009  * Group can project, so no need to be terribly picky about child tlist,
2010  * but we do need grouping columns to be available
2011  */
2012  subplan = create_plan_recurse(root, best_path->subpath, CP_LABEL_TLIST);
2013 
2014  tlist = build_path_tlist(root, &best_path->path);
2015 
2016  quals = order_qual_clauses(root, best_path->qual);
2017 
2018  plan = make_group(tlist,
2019  quals,
2020  list_length(best_path->groupClause),
2022  subplan->targetlist),
2023  extract_grouping_ops(best_path->groupClause),
2025  subplan->targetlist),
2026  subplan);
2027 
2028  copy_generic_path_info(&plan->plan, (Path *) best_path);
2029 
2030  return plan;
2031 }
List * qual
Definition: pathnodes.h:1634
Oid * extract_grouping_collations(List *groupClause, List *tlist)
Definition: tlist.c:511
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
Oid * extract_grouping_ops(List *groupClause)
Definition: tlist.c:485
AttrNumber * extract_grouping_cols(List *groupClause, List *tlist)
Definition: tlist.c:536
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
static Group * make_group(List *tlist, List *qual, int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, Plan *lefttree)
Definition: createplan.c:6261
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
Path path
Definition: pathnodes.h:1631
List * groupClause
Definition: pathnodes.h:1633
#define CP_LABEL_TLIST
Definition: createplan.c:70
Path * subpath
Definition: pathnodes.h:1632
Plan plan
Definition: plannodes.h:781
static int list_length(const List *l)
Definition: pg_list.h:169
List * targetlist
Definition: plannodes.h:140
Definition: pg_list.h:50

◆ create_group_result_plan()

static Result * create_group_result_plan ( PlannerInfo root,
GroupResultPath best_path 
)
static

Definition at line 1433 of file createplan.c.

References build_path_tlist(), copy_generic_path_info(), make_result(), order_qual_clauses(), GroupResultPath::path, Result::plan, and GroupResultPath::quals.

Referenced by create_plan_recurse().

1434 {
1435  Result *plan;
1436  List *tlist;
1437  List *quals;
1438 
1439  tlist = build_path_tlist(root, &best_path->path);
1440 
1441  /* best_path->quals is just bare clauses */
1442  quals = order_qual_clauses(root, best_path->quals);
1443 
1444  plan = make_result(tlist, (Node *) quals, NULL);
1445 
1446  copy_generic_path_info(&plan->plan, (Path *) best_path);
1447 
1448  return plan;
1449 }
Plan plan
Definition: plannodes.h:186
Definition: nodes.h:524
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
static Result * make_result(List *tlist, Node *resconstantqual, Plan *subplan)
Definition: createplan.c:6573
Definition: pg_list.h:50

◆ create_groupingsets_plan()

static Plan * create_groupingsets_plan ( PlannerInfo root,
GroupingSetsPath best_path 
)
static

Definition at line 2151 of file createplan.c.

References AGG_HASHED, AGG_PLAIN, AGG_SORTED, AGGSPLIT_SIMPLE, GroupingSetsPath::aggstrategy, Assert, build_path_tlist(), copy_generic_path_info(), CP_LABEL_TLIST, create_plan_recurse(), extract_grouping_collations(), extract_grouping_ops(), for_each_cell, get_sortgroupclause_tle(), Query::groupClause, RollupData::groupClause, PlannerInfo::grouping_map, Query::groupingSets, RollupData::gsets, INHKIND_NONE, PlannerInfo::inhTargetKind, RollupData::is_hashed, lappend(), Plan::lefttree, lfirst, linitial, list_length(), list_second_cell(), make_agg(), make_sort_from_groupcols(), NIL, RollupData::numGroups, palloc0(), PlannerInfo::parse, GroupingSetsPath::path, Agg::plan, GroupingSetsPath::qual, remap_groupColIdx(), TargetEntry::resno, GroupingSetsPath::rollups, GroupingSetsPath::subpath, Plan::targetlist, and SortGroupClause::tleSortGroupRef.

Referenced by create_plan_recurse().

2152 {
2153  Agg *plan;
2154  Plan *subplan;
2155  List *rollups = best_path->rollups;
2156  AttrNumber *grouping_map;
2157  int maxref;
2158  List *chain;
2159  ListCell *lc;
2160 
2161  /* Shouldn't get here without grouping sets */
2162  Assert(root->parse->groupingSets);
2163  Assert(rollups != NIL);
2164 
2165  /*
2166  * Agg can project, so no need to be terribly picky about child tlist, but
2167  * we do need grouping columns to be available
2168  */
2169  subplan = create_plan_recurse(root, best_path->subpath, CP_LABEL_TLIST);
2170 
2171  /*
2172  * Compute the mapping from tleSortGroupRef to column index in the child's
2173  * tlist. First, identify max SortGroupRef in groupClause, for array
2174  * sizing.
2175  */
2176  maxref = 0;
2177  foreach(lc, root->parse->groupClause)
2178  {
2179  SortGroupClause *gc = (SortGroupClause *) lfirst(lc);
2180 
2181  if (gc->tleSortGroupRef > maxref)
2182  maxref = gc->tleSortGroupRef;
2183  }
2184 
2185  grouping_map = (AttrNumber *) palloc0((maxref + 1) * sizeof(AttrNumber));
2186 
2187  /* Now look up the column numbers in the child's tlist */
2188  foreach(lc, root->parse->groupClause)
2189  {
2190  SortGroupClause *gc = (SortGroupClause *) lfirst(lc);
2191  TargetEntry *tle = get_sortgroupclause_tle(gc, subplan->targetlist);
2192 
2193  grouping_map[gc->tleSortGroupRef] = tle->resno;
2194  }
2195 
2196  /*
2197  * During setrefs.c, we'll need the grouping_map to fix up the cols lists
2198  * in GroupingFunc nodes. Save it for setrefs.c to use.
2199  *
2200  * This doesn't work if we're in an inheritance subtree (see notes in
2201  * create_modifytable_plan). Fortunately we can't be because there would
2202  * never be grouping in an UPDATE/DELETE; but let's Assert that.
2203  */
2204  Assert(root->inhTargetKind == INHKIND_NONE);
2205  Assert(root->grouping_map == NULL);
2206  root->grouping_map = grouping_map;
2207 
2208  /*
2209  * Generate the side nodes that describe the other sort and group
2210  * operations besides the top one. Note that we don't worry about putting
2211  * accurate cost estimates in the side nodes; only the topmost Agg node's
2212  * costs will be shown by EXPLAIN.
2213  */
2214  chain = NIL;
2215  if (list_length(rollups) > 1)
2216  {
2217  bool is_first_sort = ((RollupData *) linitial(rollups))->is_hashed;
2218 
2219  for_each_cell(lc, rollups, list_second_cell(rollups))
2220  {
2221  RollupData *rollup = lfirst(lc);
2222  AttrNumber *new_grpColIdx;
2223  Plan *sort_plan = NULL;
2224  Plan *agg_plan;
2225  AggStrategy strat;
2226 
2227  new_grpColIdx = remap_groupColIdx(root, rollup->groupClause);
2228 
2229  if (!rollup->is_hashed && !is_first_sort)
2230  {
2231  sort_plan = (Plan *)
2233  new_grpColIdx,
2234  subplan);
2235  }
2236 
2237  if (!rollup->is_hashed)
2238  is_first_sort = false;
2239 
2240  if (rollup->is_hashed)
2241  strat = AGG_HASHED;
2242  else if (list_length(linitial(rollup->gsets)) == 0)
2243  strat = AGG_PLAIN;
2244  else
2245  strat = AGG_SORTED;
2246 
2247  agg_plan = (Plan *) make_agg(NIL,
2248  NIL,
2249  strat,
2251  list_length((List *) linitial(rollup->gsets)),
2252  new_grpColIdx,
2255  rollup->gsets,
2256  NIL,
2257  rollup->numGroups,
2258  sort_plan);
2259 
2260  /*
2261  * Remove stuff we don't need to avoid bloating debug output.
2262  */
2263  if (sort_plan)
2264  {
2265  sort_plan->targetlist = NIL;
2266  sort_plan->lefttree = NULL;
2267  }
2268 
2269  chain = lappend(chain, agg_plan);
2270  }
2271  }
2272 
2273  /*
2274  * Now make the real Agg node
2275  */
2276  {
2277  RollupData *rollup = linitial(rollups);
2278  AttrNumber *top_grpColIdx;
2279  int numGroupCols;
2280 
2281  top_grpColIdx = remap_groupColIdx(root, rollup->groupClause);
2282 
2283  numGroupCols = list_length((List *) linitial(rollup->gsets));
2284 
2285  plan = make_agg(build_path_tlist(root, &best_path->path),
2286  best_path->qual,
2287  best_path->aggstrategy,
2289  numGroupCols,
2290  top_grpColIdx,
2293  rollup->gsets,
2294  chain,
2295  rollup->numGroups,
2296  subplan);
2297 
2298  /* Copy cost data from Path to Plan */
2299  copy_generic_path_info(&plan->plan, &best_path->path);
2300  }
2301 
2302  return (Plan *) plan;
2303 }
#define NIL
Definition: pg_list.h:65
Query * parse
Definition: pathnodes.h:177
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:389
List * groupClause
Definition: pathnodes.h:1682
Oid * extract_grouping_collations(List *groupClause, List *tlist)
Definition: tlist.c:511
static AttrNumber * remap_groupColIdx(PlannerInfo *root, List *groupClause)
Definition: createplan.c:2113
#define for_each_cell(cell, lst, initcell)
Definition: pg_list.h:390
Index tleSortGroupRef
Definition: parsenodes.h:1234
bool is_hashed
Definition: pathnodes.h:1687
List * groupingSets
Definition: parsenodes.h:150
Oid * extract_grouping_ops(List *groupClause)
Definition: tlist.c:485
AttrNumber * grouping_map
Definition: pathnodes.h:326
double numGroups
Definition: pathnodes.h:1685
Agg * make_agg(List *tlist, List *qual, AggStrategy aggstrategy, AggSplit aggsplit, int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, List *groupingSets, List *chain, double dNumGroups, Plan *lefttree)
Definition: createplan.c:6189
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
#define linitial(l)
Definition: pg_list.h:195
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
static ListCell * list_second_cell(const List *l)
Definition: pg_list.h:139
AttrNumber resno
Definition: primnodes.h:1394
static Sort * make_sort_from_groupcols(List *groupcls, AttrNumber *grpColIdx, Plan *lefttree)
Definition: createplan.c:6092
AggStrategy aggstrategy
Definition: pathnodes.h:1698
List * lappend(List *list, void *datum)
Definition: list.c:321
Plan plan
Definition: plannodes.h:804
void * palloc0(Size size)
Definition: mcxt.c:955
#define CP_LABEL_TLIST
Definition: createplan.c:70
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
InheritanceKind inhTargetKind
Definition: pathnodes.h:340
static int list_length(const List *l)
Definition: pg_list.h:169
struct Plan * lefttree
Definition: plannodes.h:142
List * targetlist
Definition: plannodes.h:140
AggStrategy
Definition: nodes.h:753
List * groupClause
Definition: parsenodes.h:148
Definition: plannodes.h:802
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
List * gsets
Definition: pathnodes.h:1683

◆ create_hashjoin_plan()

static HashJoin * create_hashjoin_plan ( PlannerInfo root,
HashPath best_path 
)
static

Definition at line 4375 of file createplan.c.

References OpExpr::args, Assert, build_path_tlist(), copy_generic_path_info(), copy_plan_costsize(), CP_SMALL_TLIST, create_plan_recurse(), extract_actual_clauses(), extract_actual_join_clauses(), get_actual_clauses(), get_switched_clauses(), RangeTblEntry::inh, HashPath::inner_rows_total, JoinPath::inner_unique, JoinPath::innerjoinpath, OpExpr::inputcollid, InvalidAttrNumber, InvalidOid, is_opclause(), IS_OUTER_JOIN, IsA, HashJoin::join, JoinPath::joinrestrictinfo, JoinPath::jointype, HashPath::jpath, lappend(), lappend_oid(), lfirst_node, linitial, list_difference(), list_length(), lsecond, make_hash(), make_hashjoin(), NIL, HashPath::num_batches, OpExpr::opno, order_qual_clauses(), JoinPath::outerjoinpath, Plan::parallel_aware, Path::parallel_aware, Path::param_info, Path::parent, JoinPath::path, HashPath::path_hashclauses, Join::plan, Hash::plan, RangeTblEntry::relid, RelOptInfo::relids, replace_nestloop_params(), Hash::rows_total, RTE_RELATION, RangeTblEntry::rtekind, PlannerInfo::simple_rte_array, Plan::startup_cost, Plan::total_cost, RangeQueryClause::var, Var::varattno, and Var::varno.

Referenced by create_join_plan().

4377 {
4378  HashJoin *join_plan;
4379  Hash *hash_plan;
4380  Plan *outer_plan;
4381  Plan *inner_plan;
4382  List *tlist = build_path_tlist(root, &best_path->jpath.path);
4383  List *joinclauses;
4384  List *otherclauses;
4385  List *hashclauses;
4386  List *hashoperators = NIL;
4387  List *hashcollations = NIL;
4388  List *inner_hashkeys = NIL;
4389  List *outer_hashkeys = NIL;
4390  Oid skewTable = InvalidOid;
4391  AttrNumber skewColumn = InvalidAttrNumber;
4392  bool skewInherit = false;
4393  ListCell *lc;
4394 
4395  /*
4396  * HashJoin can project, so we don't have to demand exact tlists from the
4397  * inputs. However, it's best to request a small tlist from the inner
4398  * side, so that we aren't storing more data than necessary. Likewise, if
4399  * we anticipate batching, request a small tlist from the outer side so
4400  * that we don't put extra data in the outer batch files.
4401  */
4402  outer_plan = create_plan_recurse(root, best_path->jpath.outerjoinpath,
4403  (best_path->num_batches > 1) ? CP_SMALL_TLIST : 0);
4404 
4405  inner_plan = create_plan_recurse(root, best_path->jpath.innerjoinpath,
4406  CP_SMALL_TLIST);
4407 
4408  /* Sort join qual clauses into best execution order */
4409  joinclauses = order_qual_clauses(root, best_path->jpath.joinrestrictinfo);
4410  /* There's no point in sorting the hash clauses ... */
4411 
4412  /* Get the join qual clauses (in plain expression form) */
4413  /* Any pseudoconstant clauses are ignored here */
4414  if (IS_OUTER_JOIN(best_path->jpath.jointype))
4415  {
4416  extract_actual_join_clauses(joinclauses,
4417  best_path->jpath.path.parent->relids,
4418  &joinclauses, &otherclauses);
4419  }
4420  else
4421  {
4422  /* We can treat all clauses alike for an inner join */
4423  joinclauses = extract_actual_clauses(joinclauses, false);
4424  otherclauses = NIL;
4425  }
4426 
4427  /*
4428  * Remove the hashclauses from the list of join qual clauses, leaving the
4429  * list of quals that must be checked as qpquals.
4430  */
4431  hashclauses = get_actual_clauses(best_path->path_hashclauses);
4432  joinclauses = list_difference(joinclauses, hashclauses);
4433 
4434  /*
4435  * Replace any outer-relation variables with nestloop params. There
4436  * should not be any in the hashclauses.
4437  */
4438  if (best_path->jpath.path.param_info)
4439  {
4440  joinclauses = (List *)
4441  replace_nestloop_params(root, (Node *) joinclauses);
4442  otherclauses = (List *)
4443  replace_nestloop_params(root, (Node *) otherclauses);
4444  }
4445 
4446  /*
4447  * Rearrange hashclauses, if needed, so that the outer variable is always
4448  * on the left.
4449  */
4450  hashclauses = get_switched_clauses(best_path->path_hashclauses,
4451  best_path->jpath.outerjoinpath->parent->relids);
4452 
4453  /*
4454  * If there is a single join clause and we can identify the outer variable
4455  * as a simple column reference, supply its identity for possible use in
4456  * skew optimization. (Note: in principle we could do skew optimization
4457  * with multiple join clauses, but we'd have to be able to determine the
4458  * most common combinations of outer values, which we don't currently have
4459  * enough stats for.)
4460  */
4461  if (list_length(hashclauses) == 1)
4462  {
4463  OpExpr *clause = (OpExpr *) linitial(hashclauses);
4464  Node *node;
4465 
4466  Assert(is_opclause(clause));
4467  node = (Node *) linitial(clause->args);
4468  if (IsA(node, RelabelType))
4469  node = (Node *) ((RelabelType *) node)->arg;
4470  if (IsA(node, Var))
4471  {
4472  Var *var = (Var *) node;
4473  RangeTblEntry *rte;
4474 
4475  rte = root->simple_rte_array[var->varno];
4476  if (rte->rtekind == RTE_RELATION)
4477  {
4478  skewTable = rte->relid;
4479  skewColumn = var->varattno;
4480  skewInherit = rte->inh;
4481  }
4482  }
4483  }
4484 
4485  /*
4486  * Collect hash related information. The hashed expressions are
4487  * deconstructed into outer/inner expressions, so they can be computed
4488  * separately (inner expressions are used to build the hashtable via Hash,
4489  * outer expressions to perform lookups of tuples from HashJoin's outer
4490  * plan in the hashtable). Also collect operator information necessary to
4491  * build the hashtable.
4492  */
4493  foreach(lc, hashclauses)
4494  {
4495  OpExpr *hclause = lfirst_node(OpExpr, lc);
4496 
4497  hashoperators = lappend_oid(hashoperators, hclause->opno);
4498  hashcollations = lappend_oid(hashcollations, hclause->inputcollid);
4499  outer_hashkeys = lappend(outer_hashkeys, linitial(hclause->args));
4500  inner_hashkeys = lappend(inner_hashkeys, lsecond(hclause->args));
4501  }
4502 
4503  /*
4504  * Build the hash node and hash join node.
4505  */
4506  hash_plan = make_hash(inner_plan,
4507  inner_hashkeys,
4508  skewTable,
4509  skewColumn,
4510  skewInherit);
4511 
4512  /*
4513  * Set Hash node's startup & total costs equal to total cost of input
4514  * plan; this only affects EXPLAIN display not decisions.
4515  */
4516  copy_plan_costsize(&hash_plan->plan, inner_plan);
4517  hash_plan->plan.startup_cost = hash_plan->plan.total_cost;
4518 
4519  /*
4520  * If parallel-aware, the executor will also need an estimate of the total
4521  * number of rows expected from all participants so that it can size the
4522  * shared hash table.
4523  */
4524  if (best_path->jpath.path.parallel_aware)
4525  {
4526  hash_plan->plan.parallel_aware = true;
4527  hash_plan->rows_total = best_path->inner_rows_total;
4528  }
4529 
4530  join_plan = make_hashjoin(tlist,
4531  joinclauses,
4532  otherclauses,
4533  hashclauses,
4534  hashoperators,
4535  hashcollations,
4536  outer_hashkeys,
4537  outer_plan,
4538  (Plan *) hash_plan,
4539  best_path->jpath.jointype,
4540  best_path->jpath.inner_unique);
4541 
4542  copy_generic_path_info(&join_plan->join.plan, &best_path->jpath.path);
4543 
4544  return join_plan;
4545 }
double rows_total
Definition: plannodes.h:920
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:575
JoinPath jpath
Definition: pathnodes.h:1569
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
static List * get_switched_clauses(List *clauses, Relids outerrelids)
Definition: createplan.c:4871
int num_batches
Definition: pathnodes.h:1571
void extract_actual_join_clauses(List *restrictinfo_list, Relids joinrelids, List **joinquals, List **otherquals)
Definition: restrictinfo.c:449
Path * innerjoinpath
Definition: pathnodes.h:1496
static Hash * make_hash(Plan *lefttree, List *hashkeys, Oid skewTable, AttrNumber skewColumn, bool skewInherit)
Definition: createplan.c:5605
#define IS_OUTER_JOIN(jointype)
Definition: nodes.h:740
ParamPathInfo * param_info
Definition: pathnodes.h:1117
#define CP_SMALL_TLIST
Definition: createplan.c:69
Definition: nodes.h:524
List * get_actual_clauses(List *restrictinfo_list)
Definition: restrictinfo.c:399
AttrNumber varattno
Definition: primnodes.h:172
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
unsigned int Oid
Definition: postgres_ext.h:31
Definition: primnodes.h:167
List * lappend_oid(List *list, Oid datum)
Definition: list.c:357
double inner_rows_total
Definition: pathnodes.h:1572
#define lsecond(l)
Definition: pg_list.h:200
Join join
Definition: plannodes.h:738
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
#define linitial(l)
Definition: pg_list.h:195
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
List * joinrestrictinfo
Definition: pathnodes.h:1498
RelOptInfo * parent
Definition: pathnodes.h:1114
#define lfirst_node(type, lc)
Definition: pg_list.h:193
Cost startup_cost
Definition: plannodes.h:121
static void copy_plan_costsize(Plan *dest, Plan *src)
Definition: createplan.c:5057
bool parallel_aware
Definition: plannodes.h:133
Relids relids
Definition: pathnodes.h:641
List * lappend(List *list, void *datum)
Definition: list.c:321
RangeTblEntry ** simple_rte_array
Definition: pathnodes.h:209
Index varno
Definition: primnodes.h:170
Path * outerjoinpath
Definition: pathnodes.h:1495
#define InvalidOid
Definition: postgres_ext.h:36
Path path
Definition: pathnodes.h:1488
#define Assert(condition)
Definition: c.h:732
static HashJoin * make_hashjoin(List *tlist, List *joinclauses, List *otherclauses, List *hashclauses, List *hashoperators, List *hashcollations, List *hashkeys, Plan *lefttree, Plan *righttree, JoinType jointype, bool inner_unique)
Definition: createplan.c:5574
static int list_length(const List *l)
Definition: pg_list.h:169
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
Oid inputcollid
Definition: primnodes.h:507
bool inner_unique
Definition: pathnodes.h:1492
List * list_difference(const List *list1, const List *list2)
Definition: list.c:1073
#define InvalidAttrNumber
Definition: attnum.h:23
RTEKind rtekind
Definition: parsenodes.h:974
Plan plan
Definition: plannodes.h:909
JoinType jointype
Definition: pathnodes.h:1490
Cost total_cost
Definition: plannodes.h:122
bool parallel_aware
Definition: pathnodes.h:1119
List * path_hashclauses
Definition: pathnodes.h:1570
Oid opno
Definition: primnodes.h:502
static bool is_opclause(const void *clause)
Definition: nodeFuncs.h:62
List * args
Definition: primnodes.h:508
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
Plan plan
Definition: plannodes.h:679

◆ create_indexscan_plan()

static Scan * create_indexscan_plan ( PlannerInfo root,
IndexPath best_path,
List tlist,
List scan_clauses,
bool  indexonly 
)
static

Definition at line 2759 of file createplan.c.

References Assert, RestrictInfo::clause, contain_mutable_functions(), copy_generic_path_info(), elog, ERROR, exprType(), extract_actual_clauses(), fix_indexorderby_references(), fix_indexqual_references(), forboth, get_opfamily_member(), IndexPath::indexclauses, IndexPath::indexinfo, IndexOptInfo::indexoid, IndexPath::indexorderbys, IndexPath::indexscandir, IndexOptInfo::indextlist, is_redundant_with_indexclauses(), lappend(), lappend_oid(), lfirst, lfirst_node, list_length(), list_make1, make_indexonlyscan(), make_indexscan(), NIL, OidIsValid, order_qual_clauses(), Path::param_info, Path::parent, IndexPath::path, Path::pathkeys, PathKey::pk_opfamily, PathKey::pk_strategy, Scan::plan, predicate_implied_by(), RestrictInfo::pseudoconstant, RelOptInfo::relid, replace_nestloop_params(), RTE_RELATION, and RelOptInfo::rtekind.

Referenced by create_bitmap_subplan(), and create_scan_plan().

2764 {
2765  Scan *scan_plan;
2766  List *indexclauses = best_path->indexclauses;
2767  List *indexorderbys = best_path->indexorderbys;
2768  Index baserelid = best_path->path.parent->relid;
2769  Oid indexoid = best_path->indexinfo->indexoid;
2770  List *qpqual;
2771  List *stripped_indexquals;
2772  List *fixed_indexquals;
2773  List *fixed_indexorderbys;
2774  List *indexorderbyops = NIL;
2775  ListCell *l;
2776 
2777  /* it should be a base rel... */
2778  Assert(baserelid > 0);
2779  Assert(best_path->path.parent->rtekind == RTE_RELATION);
2780 
2781  /*
2782  * Extract the index qual expressions (stripped of RestrictInfos) from the
2783  * IndexClauses list, and prepare a copy with index Vars substituted for
2784  * table Vars. (This step also does replace_nestloop_params on the
2785  * fixed_indexquals.)
2786  */
2787  fix_indexqual_references(root, best_path,
2788  &stripped_indexquals,
2789  &fixed_indexquals);
2790 
2791  /*
2792  * Likewise fix up index attr references in the ORDER BY expressions.
2793  */
2794  fixed_indexorderbys = fix_indexorderby_references(root, best_path);
2795 
2796  /*
2797  * The qpqual list must contain all restrictions not automatically handled
2798  * by the index, other than pseudoconstant clauses which will be handled
2799  * by a separate gating plan node. All the predicates in the indexquals
2800  * will be checked (either by the index itself, or by nodeIndexscan.c),
2801  * but if there are any "special" operators involved then they must be
2802  * included in qpqual. The upshot is that qpqual must contain
2803  * scan_clauses minus whatever appears in indexquals.
2804  *
2805  * is_redundant_with_indexclauses() detects cases where a scan clause is
2806  * present in the indexclauses list or is generated from the same
2807  * EquivalenceClass as some indexclause, and is therefore redundant with
2808  * it, though not equal. (The latter happens when indxpath.c prefers a
2809  * different derived equality than what generate_join_implied_equalities
2810  * picked for a parameterized scan's ppi_clauses.) Note that it will not
2811  * match to lossy index clauses, which is critical because we have to
2812  * include the original clause in qpqual in that case.
2813  *
2814  * In some situations (particularly with OR'd index conditions) we may
2815  * have scan_clauses that are not equal to, but are logically implied by,
2816  * the index quals; so we also try a predicate_implied_by() check to see
2817  * if we can discard quals that way. (predicate_implied_by assumes its
2818  * first input contains only immutable functions, so we have to check
2819  * that.)
2820  *
2821  * Note: if you change this bit of code you should also look at
2822  * extract_nonindex_conditions() in costsize.c.
2823  */
2824  qpqual = NIL;
2825  foreach(l, scan_clauses)
2826  {
2827  RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
2828 
2829  if (rinfo->pseudoconstant)
2830  continue; /* we may drop pseudoconstants here */
2831  if (is_redundant_with_indexclauses(rinfo, indexclauses))
2832  continue; /* dup or derived from same EquivalenceClass */
2833  if (!contain_mutable_functions((Node *) rinfo->clause) &&
2834  predicate_implied_by(list_make1(rinfo->clause), stripped_indexquals,
2835  false))
2836  continue; /* provably implied by indexquals */
2837  qpqual = lappend(qpqual, rinfo);
2838  }
2839 
2840  /* Sort clauses into best execution order */
2841  qpqual = order_qual_clauses(root, qpqual);
2842 
2843  /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
2844  qpqual = extract_actual_clauses(qpqual, false);
2845 
2846  /*
2847  * We have to replace any outer-relation variables with nestloop params in
2848  * the indexqualorig, qpqual, and indexorderbyorig expressions. A bit
2849  * annoying to have to do this separately from the processing in
2850  * fix_indexqual_references --- rethink this when generalizing the inner
2851  * indexscan support. But note we can't really do this earlier because
2852  * it'd break the comparisons to predicates above ... (or would it? Those
2853  * wouldn't have outer refs)
2854  */
2855  if (best_path->path.param_info)
2856  {
2857  stripped_indexquals = (List *)
2858  replace_nestloop_params(root, (Node *) stripped_indexquals);
2859  qpqual = (List *)
2860  replace_nestloop_params(root, (Node *) qpqual);
2861  indexorderbys = (List *)
2862  replace_nestloop_params(root, (Node *) indexorderbys);
2863  }
2864 
2865  /*
2866  * If there are ORDER BY expressions, look up the sort operators for their
2867  * result datatypes.
2868  */
2869  if (indexorderbys)
2870  {
2871  ListCell *pathkeyCell,
2872  *exprCell;
2873 
2874  /*
2875  * PathKey contains OID of the btree opfamily we're sorting by, but
2876  * that's not quite enough because we need the expression's datatype
2877  * to look up the sort operator in the operator family.
2878  */
2879  Assert(list_length(best_path->path.pathkeys) == list_length(indexorderbys));
2880  forboth(pathkeyCell, best_path->path.pathkeys, exprCell, indexorderbys)
2881  {
2882  PathKey *pathkey = (PathKey *) lfirst(pathkeyCell);
2883  Node *expr = (Node *) lfirst(exprCell);
2884  Oid exprtype = exprType(expr);
2885  Oid sortop;
2886 
2887  /* Get sort operator from opfamily */
2888  sortop = get_opfamily_member(pathkey->pk_opfamily,
2889  exprtype,
2890  exprtype,
2891  pathkey->pk_strategy);
2892  if (!OidIsValid(sortop))
2893  elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
2894  pathkey->pk_strategy, exprtype, exprtype, pathkey->pk_opfamily);
2895  indexorderbyops = lappend_oid(indexorderbyops, sortop);
2896  }
2897  }
2898 
2899  /* Finally ready to build the plan node */
2900  if (indexonly)
2901  scan_plan = (Scan *) make_indexonlyscan(tlist,
2902  qpqual,
2903  baserelid,
2904  indexoid,
2905  fixed_indexquals,
2906  fixed_indexorderbys,
2907  best_path->indexinfo->indextlist,
2908  best_path->indexscandir);
2909  else
2910  scan_plan = (Scan *) make_indexscan(tlist,
2911  qpqual,
2912  baserelid,
2913  indexoid,
2914  fixed_indexquals,
2915  stripped_indexquals,
2916  fixed_indexorderbys,
2917  indexorderbys,
2918  indexorderbyops,
2919  best_path->indexscandir);
2920 
2921  copy_generic_path_info(&scan_plan->plan, &best_path->path);
2922 
2923  return scan_plan;
2924 }
#define NIL
Definition: pg_list.h:65
Plan plan
Definition: plannodes.h:340
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:419
Path path
Definition: pathnodes.h:1176
IndexOptInfo * indexinfo
Definition: pathnodes.h:1177
List * indextlist
Definition: pathnodes.h:816
bool pseudoconstant
Definition: pathnodes.h:1951
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
List * indexclauses
Definition: pathnodes.h:1178
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:357
#define OidIsValid(objectId)
Definition: c.h:638
int pk_strategy
Definition: pathnodes.h:1013
#define list_make1(x1)
Definition: pg_list.h:227
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
#define ERROR
Definition: elog.h:43
static IndexScan * make_indexscan(List *qptlist, List *qpqual, Index scanrelid, Oid indexid, List *indexqual, List *indexqualorig, List *indexorderby, List *indexorderbyorig, List *indexorderbyops, ScanDirection indexscandir)
Definition: createplan.c:5173
RelOptInfo * parent
Definition: pathnodes.h:1114
bool is_redundant_with_indexclauses(RestrictInfo *rinfo, List *indexclauses)
Definition: equivclass.c:2688
#define lfirst_node(type, lc)
Definition: pg_list.h:193
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
Definition: lsyscache.c:163
static List * fix_indexorderby_references(PlannerInfo *root, IndexPath *index_path)
Definition: createplan.c:4696
Index relid
Definition: pathnodes.h:669
List * lappend(List *list, void *datum)
Definition: list.c:321
Expr * clause
Definition: pathnodes.h:1943
List * indexorderbys
Definition: pathnodes.h:1179
unsigned int Index
Definition: c.h:475
RTEKind rtekind
Definition: pathnodes.h:671
List * pathkeys
Definition: pathnodes.h:1128
static IndexOnlyScan * make_indexonlyscan(List *qptlist, List *qpqual, Index scanrelid, Oid indexid, List *indexqual, List *indexorderby, List *indextlist, ScanDirection indexscandir)
Definition: createplan.c:5204
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
static int list_length(const List *l)
Definition: pg_list.h:169
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
Oid pk_opfamily
Definition: pathnodes.h:1012
ScanDirection indexscandir
Definition: pathnodes.h:1181
static void fix_indexqual_references(PlannerInfo *root, IndexPath *index_path, List **stripped_indexquals_p, List **fixed_indexquals_p)
Definition: createplan.c:4655
#define elog(elevel,...)
Definition: elog.h:226
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:645
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:151
Definition: pg_list.h:50

◆ create_join_plan()

static Plan * create_join_plan ( PlannerInfo root,
JoinPath best_path 
)
static

Definition at line 1004 of file createplan.c.

References create_gating_plan(), create_hashjoin_plan(), create_mergejoin_plan(), create_nestloop_plan(), elog, ERROR, get_actual_clauses(), get_gating_quals(), JoinPath::joinrestrictinfo, list_concat(), NIL, JoinPath::path, Path::pathtype, T_HashJoin, T_MergeJoin, and T_NestLoop.

Referenced by create_plan_recurse().

1005 {
1006  Plan *plan;
1007  List *gating_clauses;
1008 
1009  switch (best_path->path.pathtype)
1010  {
1011  case T_MergeJoin:
1012  plan = (Plan *) create_mergejoin_plan(root,
1013  (MergePath *) best_path);
1014  break;
1015  case T_HashJoin:
1016  plan = (Plan *) create_hashjoin_plan(root,
1017  (HashPath *) best_path);
1018  break;
1019  case T_NestLoop:
1020  plan = (Plan *) create_nestloop_plan(root,
1021  (NestPath *) best_path);
1022  break;
1023  default:
1024  elog(ERROR, "unrecognized node type: %d",
1025  (int) best_path->path.pathtype);
1026  plan = NULL; /* keep compiler quiet */
1027  break;
1028  }
1029 
1030  /*
1031  * If there are any pseudoconstant clauses attached to this node, insert a
1032  * gating Result node that evaluates the pseudoconstants as one-time
1033  * quals.
1034  */
1035  gating_clauses = get_gating_quals(root, best_path->joinrestrictinfo);
1036  if (gating_clauses)
1037  plan = create_gating_plan(root, (Path *) best_path, plan,
1038  gating_clauses);
1039 
1040 #ifdef NOT_USED
1041 
1042  /*
1043  * * Expensive function pullups may have pulled local predicates * into
1044  * this path node. Put them in the qpqual of the plan node. * JMH,
1045  * 6/15/92
1046  */
1047  if (get_loc_restrictinfo(best_path) != NIL)
1048  set_qpqual((Plan) plan,
1049  list_concat(get_qpqual((Plan) plan),
1050  get_actual_clauses(get_loc_restrictinfo(best_path))));
1051 #endif
1052 
1053  return plan;
1054 }
#define NIL
Definition: pg_list.h:65
List * get_actual_clauses(List *restrictinfo_list)
Definition: restrictinfo.c:399
List * list_concat(List *list1, const List *list2)
Definition: list.c:515
static NestLoop * create_nestloop_plan(PlannerInfo *root, NestPath *best_path)
Definition: createplan.c:3992
NodeTag pathtype
Definition: pathnodes.h:1112
#define ERROR
Definition: elog.h:43
List * joinrestrictinfo
Definition: pathnodes.h:1498
Path path
Definition: pathnodes.h:1488
static HashJoin * create_hashjoin_plan(PlannerInfo *root, HashPath *best_path)
Definition: createplan.c:4375
static Plan * create_gating_plan(PlannerInfo *root, Path *path, Plan *plan, List *gating_quals)
Definition: createplan.c:945
#define elog(elevel,...)
Definition: elog.h:226
static MergeJoin * create_mergejoin_plan(PlannerInfo *root, MergePath *best_path)
Definition: createplan.c:4068
Definition: pg_list.h:50
static List * get_gating_quals(PlannerInfo *root, List *quals)
Definition: createplan.c:925

◆ create_limit_plan()

static Limit * create_limit_plan ( PlannerInfo root,
LimitPath best_path,
int  flags 
)
static

Definition at line 2639 of file createplan.c.

References copy_generic_path_info(), create_plan_recurse(), LimitPath::limitCount, LimitPath::limitOffset, make_limit(), Limit::plan, and LimitPath::subpath.

Referenced by create_plan_recurse().

2640 {
2641  Limit *plan;
2642  Plan *subplan;
2643 
2644  /* Limit doesn't project, so tlist requirements pass through */
2645  subplan = create_plan_recurse(root, best_path->subpath, flags);
2646 
2647  plan = make_limit(subplan,
2648  best_path->limitOffset,
2649  best_path->limitCount);
2650 
2651  copy_generic_path_info(&plan->plan, (Path *) best_path);
2652 
2653  return plan;
2654 }
Plan plan
Definition: plannodes.h:967
Node * limitOffset
Definition: pathnodes.h:1794
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
Path * subpath
Definition: pathnodes.h:1793
Limit * make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount)
Definition: createplan.c:6552
Node * limitCount
Definition: pathnodes.h:1795

◆ create_lockrows_plan()

static LockRows * create_lockrows_plan ( PlannerInfo root,
LockRowsPath best_path,
int  flags 
)
static

Definition at line 2555 of file createplan.c.

References copy_generic_path_info(), create_plan_recurse(), LockRowsPath::epqParam, make_lockrows(), LockRows::plan, LockRowsPath::rowMarks, and LockRowsPath::subpath.

Referenced by create_plan_recurse().

2557 {
2558  LockRows *plan;
2559  Plan *subplan;
2560 
2561  /* LockRows doesn't project, so tlist requirements pass through */
2562  subplan = create_plan_recurse(root, best_path->subpath, flags);
2563 
2564  plan = make_lockrows(subplan, best_path->rowMarks, best_path->epqParam);
2565 
2566  copy_generic_path_info(&plan->plan, (Path *) best_path);
2567 
2568  return plan;
2569 }
Plan plan
Definition: plannodes.h:953
List * rowMarks
Definition: pathnodes.h:1758
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
Path * subpath
Definition: pathnodes.h:1757
static LockRows * make_lockrows(Plan *lefttree, List *rowMarks, int epqParam)
Definition: createplan.c:6531

◆ create_material_plan()

static Material * create_material_plan ( PlannerInfo root,
MaterialPath best_path,
int  flags 
)
static

Definition at line 1484 of file createplan.c.

References copy_generic_path_info(), CP_SMALL_TLIST, create_plan_recurse(), make_material(), Material::plan, and MaterialPath::subpath.

Referenced by create_plan_recurse().

1485 {
1486  Material *plan;
1487  Plan *subplan;
1488 
1489  /*
1490  * We don't want any excess columns in the materialized tuples, so request
1491  * a smaller tlist. Otherwise, since Material doesn't project, tlist
1492  * requirements pass through.
1493  */
1494  subplan = create_plan_recurse(root, best_path->subpath,
1495  flags | CP_SMALL_TLIST);
1496 
1497  plan = make_material(subplan);
1498 
1499  copy_generic_path_info(&plan->plan, (Path *) best_path);
1500 
1501  return plan;
1502 }
#define CP_SMALL_TLIST
Definition: createplan.c:69
Path * subpath
Definition: pathnodes.h:1426
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static Material * make_material(Plan *lefttree)
Definition: createplan.c:6133
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
Plan plan
Definition: plannodes.h:756

◆ create_merge_append_plan()

static Plan * create_merge_append_plan ( PlannerInfo root,
MergeAppendPath best_path,
int  flags 
)
static

Definition at line 1273 of file createplan.c.

References Assert, RelOptInfo::baserestrictinfo, build_path_tlist(), MergeAppend::collations, copy_generic_path_info(), CP_EXACT_TLIST, CP_SMALL_TLIST, create_plan_recurse(), elog, enable_partition_pruning, ERROR, extract_actual_clauses(), inject_projection_plan(), label_sort_with_costsize(), lappend(), Plan::lefttree, lfirst, list_concat(), list_copy(), list_length(), list_truncate(), make_partition_pruneinfo(), make_sort(), makeNode, MergeAppend::mergeplans, NIL, MergeAppend::nullsFirst, MergeAppend::numCols, Plan::parallel_safe, Path::param_info, Path::parent, MergeAppend::part_prune_info, MergeAppendPath::path, Path::pathkeys, pathkeys_contained_in(), MergeAppend::plan, ParamPathInfo::ppi_clauses, prepare_sort_from_pathkeys(), Plan::qual, RelOptInfo::relids, RELOPT_BASEREL, RelOptInfo::reloptkind, replace_nestloop_params(), Plan::righttree, sort(), MergeAppend::sortColIdx, MergeAppend::sortOperators, subpath(), and Plan::targetlist.

Referenced by create_plan_recurse().

1275 {
1276  MergeAppend *node = makeNode(MergeAppend);
1277  Plan *plan = &node->plan;
1278  List *tlist = build_path_tlist(root, &best_path->path);
1279  int orig_tlist_length = list_length(tlist);
1280  bool tlist_was_changed;
1281  List *pathkeys = best_path->path.pathkeys;
1282  List *subplans = NIL;
1283  ListCell *subpaths;
1284  RelOptInfo *rel = best_path->path.parent;
1285  PartitionPruneInfo *partpruneinfo = NULL;
1286 
1287  /*
1288  * We don't have the actual creation of the MergeAppend node split out
1289  * into a separate make_xxx function. This is because we want to run
1290  * prepare_sort_from_pathkeys on it before we do so on the individual
1291  * child plans, to make cross-checking the sort info easier.
1292  */
1293  copy_generic_path_info(plan, (Path *) best_path);
1294  plan->targetlist = tlist;
1295  plan->qual = NIL;
1296  plan->lefttree = NULL;
1297  plan->righttree = NULL;
1298 
1299  /*
1300  * Compute sort column info, and adjust MergeAppend's tlist as needed.
1301  * Because we pass adjust_tlist_in_place = true, we may ignore the
1302  * function result; it must be the same plan node. However, we then need
1303  * to detect whether any tlist entries were added.
1304  */
1305  (void) prepare_sort_from_pathkeys(plan, pathkeys,
1306  best_path->path.parent->relids,
1307  NULL,
1308  true,
1309  &node->numCols,
1310  &node->sortColIdx,
1311  &node->sortOperators,
1312  &node->collations,
1313  &node->nullsFirst);
1314  tlist_was_changed = (orig_tlist_length != list_length(plan->targetlist));
1315 
1316  /*
1317  * Now prepare the child plans. We must apply prepare_sort_from_pathkeys
1318  * even to subplans that don't need an explicit sort, to make sure they
1319  * are returning the same sort key columns the MergeAppend expects.
1320  */
1321  foreach(subpaths, best_path->subpaths)
1322  {
1323  Path *subpath = (Path *) lfirst(subpaths);
1324  Plan *subplan;
1325  int numsortkeys;
1326  AttrNumber *sortColIdx;
1327  Oid *sortOperators;
1328  Oid *collations;
1329  bool *nullsFirst;
1330 
1331  /* Build the child plan */
1332  /* Must insist that all children return the same tlist */
1333  subplan = create_plan_recurse(root, subpath, CP_EXACT_TLIST);
1334 
1335  /* Compute sort column info, and adjust subplan's tlist as needed */
1336  subplan = prepare_sort_from_pathkeys(subplan, pathkeys,
1337  subpath->parent->relids,
1338  node->sortColIdx,
1339  false,
1340  &numsortkeys,
1341  &sortColIdx,
1342  &sortOperators,
1343  &collations,
1344  &nullsFirst);
1345 
1346  /*
1347  * Check that we got the same sort key information. We just Assert
1348  * that the sortops match, since those depend only on the pathkeys;
1349  * but it seems like a good idea to check the sort column numbers
1350  * explicitly, to ensure the tlists really do match up.
1351  */
1352  Assert(numsortkeys == node->numCols);
1353  if (memcmp(sortColIdx, node->sortColIdx,
1354  numsortkeys * sizeof(AttrNumber)) != 0)
1355  elog(ERROR, "MergeAppend child's targetlist doesn't match MergeAppend");
1356  Assert(memcmp(sortOperators, node->sortOperators,
1357  numsortkeys * sizeof(Oid)) == 0);
1358  Assert(memcmp(collations, node->collations,
1359  numsortkeys * sizeof(Oid)) == 0);
1360  Assert(memcmp(nullsFirst, node->nullsFirst,
1361  numsortkeys * sizeof(bool)) == 0);
1362 
1363  /* Now, insert a Sort node if subplan isn't sufficiently ordered */
1364  if (!pathkeys_contained_in(pathkeys, subpath->pathkeys))
1365  {
1366  Sort *sort = make_sort(subplan, numsortkeys,
1367  sortColIdx, sortOperators,
1368  collations, nullsFirst);
1369 
1370  label_sort_with_costsize(root, sort, best_path->limit_tuples);
1371  subplan = (Plan *) sort;
1372  }
1373 
1374  subplans = lappend(subplans, subplan);
1375  }
1376 
1377  /*
1378  * If any quals exist, they may be useful to perform further partition
1379  * pruning during execution. Gather information needed by the executor to
1380  * do partition pruning.
1381  */
1383  rel->reloptkind == RELOPT_BASEREL &&
1384  best_path->partitioned_rels != NIL)
1385  {
1386  List *prunequal;
1387 
1388  prunequal = extract_actual_clauses(rel->baserestrictinfo, false);
1389 
1390  if (best_path->path.param_info)
1391  {
1392  List *prmquals = best_path->path.param_info->ppi_clauses;
1393 
1394  prmquals = extract_actual_clauses(prmquals, false);
1395  prmquals = (List *) replace_nestloop_params(root,
1396  (Node *) prmquals);
1397 
1398  prunequal = list_concat(prunequal, prmquals);
1399  }
1400 
1401  if (prunequal != NIL)
1402  partpruneinfo = make_partition_pruneinfo(root, rel,
1403  best_path->subpaths,
1404  best_path->partitioned_rels,
1405  prunequal);
1406  }
1407 
1408  node->mergeplans = subplans;
1409  node->part_prune_info = partpruneinfo;
1410 
1411  /*
1412  * If prepare_sort_from_pathkeys added sort columns, but we were told to
1413  * produce either the exact tlist or a narrow tlist, we should get rid of
1414  * the sort columns again. We must inject a projection node to do so.
1415  */
1416  if (tlist_was_changed && (flags & (CP_EXACT_TLIST | CP_SMALL_TLIST)))
1417  {
1418  tlist = list_truncate(list_copy(plan->targetlist), orig_tlist_length);
1419  return inject_projection_plan(plan, tlist, plan->parallel_safe);
1420  }
1421  else
1422  return plan;
1423 }
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:141
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
RelOptKind reloptkind
Definition: pathnodes.h:638
Oid * collations
Definition: plannodes.h:277
List * baserestrictinfo
Definition: pathnodes.h:703
List * list_truncate(List *list, int new_size)
Definition: list.c:585
ParamPathInfo * param_info
Definition: pathnodes.h:1117
#define CP_SMALL_TLIST
Definition: createplan.c:69
List * list_copy(const List *oldlist)
Definition: list.c:1400
Definition: nodes.h:524
List * list_concat(List *list1, const List *list2)
Definition: list.c:515
struct PartitionPruneInfo * part_prune_info
Definition: plannodes.h:280
List * partitioned_rels
Definition: pathnodes.h:1399
unsigned int Oid
Definition: postgres_ext.h:31
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
struct Plan * righttree
Definition: plannodes.h:143
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
#define ERROR
Definition: elog.h:43
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
RelOptInfo * parent
Definition: pathnodes.h:1114
Datum sort(PG_FUNCTION_ARGS)
Definition: _int_op.c:200
Relids relids
Definition: pathnodes.h:641
List * lappend(List *list, void *datum)
Definition: list.c:321
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
bool enable_partition_pruning
Definition: costsize.c:140
List * pathkeys
Definition: pathnodes.h:1128
static Sort * make_sort(Plan *lefttree, int numCols, AttrNumber *sortColIdx, Oid *sortOperators, Oid *collations, bool *nullsFirst)
Definition: createplan.c:5669
#define makeNode(_type_)
Definition: nodes.h:572
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
AttrNumber * sortColIdx
Definition: plannodes.h:275
List * ppi_clauses
Definition: pathnodes.h:1075
static Plan * inject_projection_plan(Plan *subplan, List *tlist, bool parallel_safe)
Definition: createplan.c:1906
static int list_length(const List *l)
Definition: pg_list.h:169
PartitionPruneInfo * make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, List *subpaths, List *partitioned_rels, List *prunequal)
Definition: partprune.c:230
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
struct Plan * lefttree
Definition: plannodes.h:142
List * targetlist
Definition: plannodes.h:140
bool * nullsFirst
Definition: plannodes.h:278
List * mergeplans
Definition: plannodes.h:272
#define elog(elevel,...)
Definition: elog.h:226
bool parallel_safe
Definition: plannodes.h:134
Oid * sortOperators
Definition: plannodes.h:276
#define CP_EXACT_TLIST
Definition: createplan.c:68
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
static void label_sort_with_costsize(PlannerInfo *root, Sort *plan, double limit_tuples)
Definition: createplan.c:5079
double limit_tuples
Definition: pathnodes.h:1401
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
static Plan * prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys, Relids relids, const AttrNumber *reqColIdx, bool adjust_tlist_in_place, int *p_numsortkeys, AttrNumber **p_sortColIdx, Oid **p_sortOperators, Oid **p_collations, bool **p_nullsFirst)
Definition: createplan.c:5731

◆ create_mergejoin_plan()

static MergeJoin * create_mergejoin_plan ( PlannerInfo root,
MergePath best_path 
)
static

Definition at line 4068 of file createplan.c.

References Assert, build_path_tlist(), copy_generic_path_info(), copy_plan_costsize(), CP_SMALL_TLIST, cpu_operator_cost, create_plan_recurse(), EquivalenceClass::ec_collation, elog, ERROR, extract_actual_clauses(), extract_actual_join_clauses(), get_actual_clauses(), get_switched_clauses(), i, JoinPath::inner_unique, JoinPath::innerjoinpath, MergePath::innersortkeys, IS_OUTER_JOIN, MergeJoin::join, JoinPath::joinrestrictinfo, JoinPath::jointype, MergePath::jpath, label_sort_with_costsize(), RestrictInfo::left_ec, lfirst, lfirst_node, list_difference(), list_head(), list_length(), lnext(), make_material(), make_mergejoin(), make_sort_from_pathkeys(), MergePath::materialize_inner, NIL, order_qual_clauses(), RestrictInfo::outer_is_left, JoinPath::outerjoinpath, MergePath::outersortkeys, palloc(), Path::param_info, Path::parent, JoinPath::path, MergePath::path_mergeclauses, Path::pathkeys, PathKey::pk_eclass, PathKey::pk_nulls_first, PathKey::pk_opfamily, PathKey::pk_strategy, Join::plan, Plan::plan_rows, RelOptInfo::relids, replace_nestloop_params(), RestrictInfo::right_ec, MergePath::skip_mark_restore, sort(), and Plan::total_cost.

Referenced by create_join_plan().

4070 {
4071  MergeJoin *join_plan;
4072  Plan *outer_plan;
4073  Plan *inner_plan;
4074  List *tlist = build_path_tlist(root, &best_path->jpath.path);
4075  List *joinclauses;
4076  List *otherclauses;
4077  List *mergeclauses;
4078  List *outerpathkeys;
4079  List *innerpathkeys;
4080  int nClauses;
4081  Oid *mergefamilies;
4082  Oid *mergecollations;
4083  int *mergestrategies;
4084  bool *mergenullsfirst;
4085  PathKey *opathkey;
4086  EquivalenceClass *opeclass;
4087  int i;
4088  ListCell *lc;
4089  ListCell *lop;
4090  ListCell *lip;
4091  Path *outer_path = best_path->jpath.outerjoinpath;
4092  Path *inner_path = best_path->jpath.innerjoinpath;
4093 
4094  /*
4095  * MergeJoin can project, so we don't have to demand exact tlists from the
4096  * inputs. However, if we're intending to sort an input's result, it's
4097  * best to request a small tlist so we aren't sorting more data than
4098  * necessary.
4099  */
4100  outer_plan = create_plan_recurse(root, best_path->jpath.outerjoinpath,
4101  (best_path->outersortkeys != NIL) ? CP_SMALL_TLIST : 0);
4102 
4103  inner_plan = create_plan_recurse(root, best_path->jpath.innerjoinpath,
4104  (best_path->innersortkeys != NIL) ? CP_SMALL_TLIST : 0);
4105 
4106  /* Sort join qual clauses into best execution order */
4107  /* NB: do NOT reorder the mergeclauses */
4108  joinclauses = order_qual_clauses(root, best_path->jpath.joinrestrictinfo);
4109 
4110  /* Get the join qual clauses (in plain expression form) */
4111  /* Any pseudoconstant clauses are ignored here */
4112  if (IS_OUTER_JOIN(best_path->jpath.jointype))
4113  {
4114  extract_actual_join_clauses(joinclauses,
4115  best_path->jpath.path.parent->relids,
4116  &joinclauses, &otherclauses);
4117  }
4118  else
4119  {
4120  /* We can treat all clauses alike for an inner join */
4121  joinclauses = extract_actual_clauses(joinclauses, false);
4122  otherclauses = NIL;
4123  }
4124 
4125  /*
4126  * Remove the mergeclauses from the list of join qual clauses, leaving the
4127  * list of quals that must be checked as qpquals.
4128  */
4129  mergeclauses = get_actual_clauses(best_path->path_mergeclauses);
4130  joinclauses = list_difference(joinclauses, mergeclauses);
4131 
4132  /*
4133  * Replace any outer-relation variables with nestloop params. There
4134  * should not be any in the mergeclauses.
4135  */
4136  if (best_path->jpath.path.param_info)
4137  {
4138  joinclauses = (List *)
4139  replace_nestloop_params(root, (Node *) joinclauses);
4140  otherclauses = (List *)
4141  replace_nestloop_params(root, (Node *) otherclauses);
4142  }
4143 
4144  /*
4145  * Rearrange mergeclauses, if needed, so that the outer variable is always
4146  * on the left; mark the mergeclause restrictinfos with correct
4147  * outer_is_left status.
4148  */
4149  mergeclauses = get_switched_clauses(best_path->path_mergeclauses,
4150  best_path->jpath.outerjoinpath->parent->relids);
4151 
4152  /*
4153  * Create explicit sort nodes for the outer and inner paths if necessary.
4154  */
4155  if (best_path->outersortkeys)
4156  {
4157  Relids outer_relids = outer_path->parent->relids;
4158  Sort *sort = make_sort_from_pathkeys(outer_plan,
4159  best_path->outersortkeys,
4160  outer_relids);
4161 
4162  label_sort_with_costsize(root, sort, -1.0);
4163  outer_plan = (Plan *) sort;
4164  outerpathkeys = best_path->outersortkeys;
4165  }
4166  else
4167  outerpathkeys = best_path->jpath.outerjoinpath->pathkeys;
4168 
4169  if (best_path->innersortkeys)
4170  {
4171  Relids inner_relids = inner_path->parent->relids;
4172  Sort *sort = make_sort_from_pathkeys(inner_plan,
4173  best_path->innersortkeys,
4174  inner_relids);
4175 
4176  label_sort_with_costsize(root, sort, -1.0);
4177  inner_plan = (Plan *) sort;
4178  innerpathkeys = best_path->innersortkeys;
4179  }
4180  else
4181  innerpathkeys = best_path->jpath.innerjoinpath->pathkeys;
4182 
4183  /*
4184  * If specified, add a materialize node to shield the inner plan from the
4185  * need to handle mark/restore.
4186  */
4187  if (best_path->materialize_inner)
4188  {
4189  Plan *matplan = (Plan *) make_material(inner_plan);
4190 
4191  /*
4192  * We assume the materialize will not spill to disk, and therefore
4193  * charge just cpu_operator_cost per tuple. (Keep this estimate in
4194  * sync with final_cost_mergejoin.)
4195  */
4196  copy_plan_costsize(matplan, inner_plan);
4197  matplan->total_cost += cpu_operator_cost * matplan->plan_rows;
4198 
4199  inner_plan = matplan;
4200  }
4201 
4202  /*
4203  * Compute the opfamily/collation/strategy/nullsfirst arrays needed by the
4204  * executor. The information is in the pathkeys for the two inputs, but
4205  * we need to be careful about the possibility of mergeclauses sharing a
4206  * pathkey, as well as the possibility that the inner pathkeys are not in
4207  * an order matching the mergeclauses.
4208  */
4209  nClauses = list_length(mergeclauses);
4210  Assert(nClauses == list_length(best_path->path_mergeclauses));
4211  mergefamilies = (Oid *) palloc(nClauses * sizeof(Oid));
4212  mergecollations = (Oid *) palloc(nClauses * sizeof(Oid));
4213  mergestrategies = (int *) palloc(nClauses * sizeof(int));
4214  mergenullsfirst = (bool *) palloc(nClauses * sizeof(bool));
4215 
4216  opathkey = NULL;
4217  opeclass = NULL;
4218  lop = list_head(outerpathkeys);
4219  lip = list_head(innerpathkeys);
4220  i = 0;
4221  foreach(lc, best_path->path_mergeclauses)
4222  {
4223  RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
4224  EquivalenceClass *oeclass;
4225  EquivalenceClass *ieclass;
4226  PathKey *ipathkey = NULL;
4227  EquivalenceClass *ipeclass = NULL;
4228  bool first_inner_match = false;
4229 
4230  /* fetch outer/inner eclass from mergeclause */
4231  if (rinfo->outer_is_left)
4232  {
4233  oeclass = rinfo->left_ec;
4234  ieclass = rinfo->right_ec;
4235  }
4236  else
4237  {
4238  oeclass = rinfo->right_ec;
4239  ieclass = rinfo->left_ec;
4240  }
4241  Assert(oeclass != NULL);
4242  Assert(ieclass != NULL);
4243 
4244  /*
4245  * We must identify the pathkey elements associated with this clause
4246  * by matching the eclasses (which should give a unique match, since
4247  * the pathkey lists should be canonical). In typical cases the merge
4248  * clauses are one-to-one with the pathkeys, but when dealing with
4249  * partially redundant query conditions, things are more complicated.
4250  *
4251  * lop and lip reference the first as-yet-unmatched pathkey elements.
4252  * If they're NULL then all pathkey elements have been matched.
4253  *
4254  * The ordering of the outer pathkeys should match the mergeclauses,
4255  * by construction (see find_mergeclauses_for_outer_pathkeys()). There
4256  * could be more than one mergeclause for the same outer pathkey, but
4257  * no pathkey may be entirely skipped over.
4258  */
4259  if (oeclass != opeclass) /* multiple matches are not interesting */
4260  {
4261  /* doesn't match the current opathkey, so must match the next */
4262  if (lop == NULL)
4263  elog(ERROR, "outer pathkeys do not match mergeclauses");
4264  opathkey = (PathKey *) lfirst(lop);
4265  opeclass = opathkey->pk_eclass;
4266  lop = lnext(outerpathkeys, lop);
4267  if (oeclass != opeclass)
4268  elog(ERROR, "outer pathkeys do not match mergeclauses");
4269  }
4270 
4271  /*
4272  * The inner pathkeys likewise should not have skipped-over keys, but
4273  * it's possible for a mergeclause to reference some earlier inner
4274  * pathkey if we had redundant pathkeys. For example we might have
4275  * mergeclauses like "o.a = i.x AND o.b = i.y AND o.c = i.x". The
4276  * implied inner ordering is then "ORDER BY x, y, x", but the pathkey
4277  * mechanism drops the second sort by x as redundant, and this code
4278  * must cope.
4279  *
4280  * It's also possible for the implied inner-rel ordering to be like
4281  * "ORDER BY x, y, x DESC". We still drop the second instance of x as
4282  * redundant; but this means that the sort ordering of a redundant
4283  * inner pathkey should not be considered significant. So we must
4284  * detect whether this is the first clause matching an inner pathkey.
4285  */
4286  if (lip)
4287  {
4288  ipathkey = (PathKey *) lfirst(lip);
4289  ipeclass = ipathkey->pk_eclass;
4290  if (ieclass == ipeclass)
4291  {
4292  /* successful first match to this inner pathkey */
4293  lip = lnext(innerpathkeys, lip);
4294  first_inner_match = true;
4295  }
4296  }
4297  if (!first_inner_match)
4298  {
4299  /* redundant clause ... must match something before lip */
4300  ListCell *l2;
4301 
4302  foreach(l2, innerpathkeys)
4303  {
4304  if (l2 == lip)
4305  break;
4306  ipathkey = (PathKey *) lfirst(l2);
4307  ipeclass = ipathkey->pk_eclass;
4308  if (ieclass == ipeclass)
4309  break;
4310  }
4311  if (ieclass != ipeclass)
4312  elog(ERROR, "inner pathkeys do not match mergeclauses");
4313  }
4314 
4315  /*
4316  * The pathkeys should always match each other as to opfamily and
4317  * collation (which affect equality), but if we're considering a
4318  * redundant inner pathkey, its sort ordering might not match. In
4319  * such cases we may ignore the inner pathkey's sort ordering and use
4320  * the outer's. (In effect, we're lying to the executor about the
4321  * sort direction of this inner column, but it does not matter since
4322  * the run-time row comparisons would only reach this column when
4323  * there's equality for the earlier column containing the same eclass.
4324  * There could be only one value in this column for the range of inner
4325  * rows having a given value in the earlier column, so it does not
4326  * matter which way we imagine this column to be ordered.) But a
4327  * non-redundant inner pathkey had better match outer's ordering too.
4328  */
4329  if (opathkey->pk_opfamily != ipathkey->pk_opfamily ||
4330  opathkey->pk_eclass->ec_collation != ipathkey->pk_eclass->ec_collation)
4331  elog(ERROR, "left and right pathkeys do not match in mergejoin");
4332  if (first_inner_match &&
4333  (opathkey->pk_strategy != ipathkey->pk_strategy ||
4334  opathkey->pk_nulls_first != ipathkey->pk_nulls_first))
4335  elog(ERROR, "left and right pathkeys do not match in mergejoin");
4336 
4337  /* OK, save info for executor */
4338  mergefamilies[i] = opathkey->pk_opfamily;
4339  mergecollations[i] = opathkey->pk_eclass->ec_collation;
4340  mergestrategies[i] = opathkey->pk_strategy;
4341  mergenullsfirst[i] = opathkey->pk_nulls_first;
4342  i++;
4343  }
4344 
4345  /*
4346  * Note: it is not an error if we have additional pathkey elements (i.e.,
4347  * lop or lip isn't NULL here). The input paths might be better-sorted
4348  * than we need for the current mergejoin.
4349  */
4350 
4351  /*
4352  * Now we can build the mergejoin node.
4353  */
4354  join_plan = make_mergejoin(tlist,
4355  joinclauses,
4356  otherclauses,
4357  mergeclauses,
4358  mergefamilies,
4359  mergecollations,
4360  mergestrategies,
4361  mergenullsfirst,
4362  outer_plan,
4363  inner_plan,
4364  best_path->jpath.jointype,
4365  best_path->jpath.inner_unique,
4366  best_path->skip_mark_restore);
4367 
4368  /* Costs of sort and material steps are included in path cost already */
4369  copy_generic_path_info(&join_plan->join.plan, &best_path->jpath.path);
4370 
4371  return join_plan;
4372 }
#define NIL
Definition: pg_list.h:65
List * path_mergeclauses
Definition: pathnodes.h:1551
List * outersortkeys
Definition: pathnodes.h:1552
double plan_rows
Definition: plannodes.h:127
static Sort * make_sort_from_pathkeys(Plan *lefttree, List *pathkeys, Relids relids)
Definition: createplan.c:6010
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
static List * get_switched_clauses(List *clauses, Relids outerrelids)
Definition: createplan.c:4871
bool materialize_inner
Definition: pathnodes.h:1555
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:321
void extract_actual_join_clauses(List *restrictinfo_list, Relids joinrelids, List **joinquals, List **otherquals)
Definition: restrictinfo.c:449
static MergeJoin * make_mergejoin(List *tlist, List *joinclauses, List *otherclauses, List *mergeclauses, Oid *mergefamilies, Oid *mergecollations, int *mergestrategies, bool *mergenullsfirst, Plan *lefttree, Plan *righttree, JoinType jointype, bool inner_unique, bool skip_mark_restore)
Definition: createplan.c:5628
Path * innerjoinpath
Definition: pathnodes.h:1496
#define IS_OUTER_JOIN(jointype)
Definition: nodes.h:740
ParamPathInfo * param_info
Definition: pathnodes.h:1117
#define CP_SMALL_TLIST
Definition: createplan.c:69
Definition: nodes.h:524
List * get_actual_clauses(List *restrictinfo_list)
Definition: restrictinfo.c:399
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
EquivalenceClass * right_ec
Definition: pathnodes.h:1992
unsigned int Oid
Definition: postgres_ext.h:31
int pk_strategy
Definition: pathnodes.h:1013
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static Material * make_material(Plan *lefttree)
Definition: createplan.c:6133
bool skip_mark_restore
Definition: pathnodes.h:1554
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
bool pk_nulls_first
Definition: pathnodes.h:1014
#define ERROR
Definition: elog.h:43
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
List * joinrestrictinfo
Definition: pathnodes.h:1498
RelOptInfo * parent
Definition: pathnodes.h:1114
#define lfirst_node(type, lc)
Definition: pg_list.h:193
bool outer_is_left
Definition: pathnodes.h:1998
Datum sort(PG_FUNCTION_ARGS)
Definition: _int_op.c:200
static void copy_plan_costsize(Plan *dest, Plan *src)
Definition: createplan.c:5057
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
Relids relids
Definition: pathnodes.h:641
double cpu_operator_cost
Definition: costsize.c:114
Path * outerjoinpath
Definition: pathnodes.h:1495
List * pathkeys
Definition: pathnodes.h:1128
Path path
Definition: pathnodes.h:1488
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
EquivalenceClass * pk_eclass
Definition: pathnodes.h:1011
static int list_length(const List *l)
Definition: pg_list.h:169
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
bool inner_unique
Definition: pathnodes.h:1492
List * list_difference(const List *list1, const List *list2)
Definition: list.c:1073
List * innersortkeys
Definition: pathnodes.h:1553
Oid pk_opfamily
Definition: pathnodes.h:1012
void * palloc(Size size)
Definition: mcxt.c:924
EquivalenceClass * left_ec
Definition: pathnodes.h:1991
Join join
Definition: plannodes.h:722
JoinType jointype
Definition: pathnodes.h:1490
#define elog(elevel,...)
Definition: elog.h:226
int i
Cost total_cost
Definition: plannodes.h:122
JoinPath jpath
Definition: pathnodes.h:1550
Definition: pg_list.h:50
static void label_sort_with_costsize(PlannerInfo *root, Sort *plan, double limit_tuples)
Definition: createplan.c:5079
Plan plan
Definition: plannodes.h:679

◆ create_minmaxagg_plan()

static Result * create_minmaxagg_plan ( PlannerInfo root,
MinMaxAggPath best_path 
)
static

Definition at line 2312 of file createplan.c.

References Assert, build_path_tlist(), copy_generic_path_info(), create_plan(), INHKIND_NONE, PlannerInfo::inhTargetKind, lfirst, Query::limitCount, Query::limitOffset, make_limit(), make_result(), PlannerInfo::minmax_aggs, MinMaxAggPath::mmaggregates, NIL, Plan::parallel_aware, Plan::parallel_safe, Path::parallel_safe, MinMaxAggInfo::param, PlannerInfo::parse, MinMaxAggPath::path, MinMaxAggInfo::path, MinMaxAggInfo::pathcost, Path::pathtarget, Result::plan, Plan::plan_rows, Plan::plan_width, MinMaxAggPath::quals, SS_make_initplan_from_plan(), Plan::startup_cost, Path::startup_cost, MinMaxAggInfo::subroot, Plan::total_cost, and PathTarget::width.

Referenced by create_plan_recurse().

2313 {
2314  Result *plan;
2315  List *tlist;
2316  ListCell *lc;
2317 
2318  /* Prepare an InitPlan for each aggregate's subquery. */
2319  foreach(lc, best_path->mmaggregates)
2320  {
2321  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
2322  PlannerInfo *subroot = mminfo->subroot;
2323  Query *subparse = subroot->parse;
2324  Plan *plan;
2325 
2326  /*
2327  * Generate the plan for the subquery. We already have a Path, but we
2328  * have to convert it to a Plan and attach a LIMIT node above it.
2329  * Since we are entering a different planner context (subroot),
2330  * recurse to create_plan not create_plan_recurse.
2331  */
2332  plan = create_plan(subroot, mminfo->path);
2333 
2334  plan = (Plan *) make_limit(plan,
2335  subparse->limitOffset,
2336  subparse->limitCount);
2337 
2338  /* Must apply correct cost/width data to Limit node */
2339  plan->startup_cost = mminfo->path->startup_cost;
2340  plan->total_cost = mminfo->pathcost;
2341  plan->plan_rows = 1;
2342  plan->plan_width = mminfo->path->pathtarget->width;
2343  plan->parallel_aware = false;
2344  plan->parallel_safe = mminfo->path->parallel_safe;
2345 
2346  /* Convert the plan into an InitPlan in the outer query. */
2347  SS_make_initplan_from_plan(root, subroot, plan, mminfo->param);
2348  }
2349 
2350  /* Generate the output plan --- basically just a Result */
2351  tlist = build_path_tlist(root, &best_path->path);
2352 
2353  plan = make_result(tlist, (Node *) best_path->quals, NULL);
2354 
2355  copy_generic_path_info(&plan->plan, (Path *) best_path);
2356 
2357  /*
2358  * During setrefs.c, we'll need to replace references to the Agg nodes
2359  * with InitPlan output params. (We can't just do that locally in the
2360  * MinMaxAgg node, because path nodes above here may have Agg references
2361  * as well.) Save the mmaggregates list to tell setrefs.c to do that.
2362  *
2363  * This doesn't work if we're in an inheritance subtree (see notes in
2364  * create_modifytable_plan). Fortunately we can't be because there would
2365  * never be aggregates in an UPDATE/DELETE; but let's Assert that.
2366  */
2367  Assert(root->inhTargetKind == INHKIND_NONE);
2368  Assert(root->minmax_aggs == NIL);
2369  root->minmax_aggs = best_path->mmaggregates;
2370 
2371  return plan;
2372 }
Node * limitOffset
Definition: parsenodes.h:160
#define NIL
Definition: pg_list.h:65
double plan_rows
Definition: plannodes.h:127
PathTarget * pathtarget
Definition: pathnodes.h:1115
Query * parse
Definition: pathnodes.h:177
Param * param
Definition: pathnodes.h:2282
Definition: nodes.h:524
List * minmax_aggs
Definition: pathnodes.h:327
List * quals
Definition: pathnodes.h:1710
Plan * create_plan(PlannerInfo *root, Path *best_path)
Definition: createplan.c:313
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
Cost startup_cost
Definition: pathnodes.h:1125
Node * limitCount
Definition: parsenodes.h:161
Cost startup_cost
Definition: plannodes.h:121
bool parallel_aware
Definition: plannodes.h:133
static Result * make_result(List *tlist, Node *resconstantqual, Plan *subplan)
Definition: createplan.c:6573
List * mmaggregates
Definition: pathnodes.h:1709
int plan_width
Definition: plannodes.h:128
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
bool parallel_safe
Definition: pathnodes.h:1120
InheritanceKind inhTargetKind
Definition: pathnodes.h:340
void SS_make_initplan_from_plan(PlannerInfo *root, PlannerInfo *subroot, Plan *plan, Param *prm)
Definition: subselect.c:2889
Limit * make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount)
Definition: createplan.c:6552
Cost total_cost
Definition: plannodes.h:122
bool parallel_safe
Definition: plannodes.h:134
Definition: pg_list.h:50
PlannerInfo * subroot
Definition: pathnodes.h:2279

◆ create_modifytable_plan()

static ModifyTable * create_modifytable_plan ( PlannerInfo root,
ModifyTablePath best_path 
)
static

Definition at line 2578 of file createplan.c.

References apply_tlist_labeling(), ModifyTablePath::canSetTag, copy_generic_path_info(), CP_EXACT_TLIST, create_plan_recurse(), ModifyTablePath::epqParam, forboth, lappend(), lfirst, make_modifytable(), NIL, ModifyTablePath::nominalRelation, ModifyTablePath::onconflict, ModifyTablePath::operation, ModifyTablePath::partColsUpdated, ModifyTablePath::path, ModifyTable::plan, PlannerInfo::processed_tlist, ModifyTablePath::resultRelations, ModifyTablePath::returningLists, ModifyTablePath::rootRelation, ModifyTablePath::rowMarks, subpath(), ModifyTablePath::subpaths, ModifyTablePath::subroots, Plan::targetlist, and ModifyTablePath::withCheckOptionLists.

Referenced by create_plan_recurse().

2579 {
2580  ModifyTable *plan;
2581  List *subplans = NIL;
2582  ListCell *subpaths,
2583  *subroots;
2584 
2585  /* Build the plan for each input path */
2586  forboth(subpaths, best_path->subpaths,
2587  subroots, best_path->subroots)
2588  {
2589  Path *subpath = (Path *) lfirst(subpaths);
2590  PlannerInfo *subroot = (PlannerInfo *) lfirst(subroots);
2591  Plan *subplan;
2592 
2593  /*
2594  * In an inherited UPDATE/DELETE, reference the per-child modified
2595  * subroot while creating Plans from Paths for the child rel. This is
2596  * a kluge, but otherwise it's too hard to ensure that Plan creation
2597  * functions (particularly in FDWs) don't depend on the contents of
2598  * "root" matching what they saw at Path creation time. The main
2599  * downside is that creation functions for Plans that might appear
2600  * below a ModifyTable cannot expect to modify the contents of "root"
2601  * and have it "stick" for subsequent processing such as setrefs.c.
2602  * That's not great, but it seems better than the alternative.
2603  */
2604  subplan = create_plan_recurse(subroot, subpath, CP_EXACT_TLIST);
2605 
2606  /* Transfer resname/resjunk labeling, too, to keep executor happy */
2607  apply_tlist_labeling(subplan->targetlist, subroot->processed_tlist);
2608 
2609  subplans = lappend(subplans, subplan);
2610  }
2611 
2612  plan = make_modifytable(root,
2613  best_path->operation,
2614  best_path->canSetTag,
2615  best_path->nominalRelation,
2616  best_path->rootRelation,
2617  best_path->partColsUpdated,
2618  best_path->resultRelations,
2619  subplans,
2620  best_path->subroots,
2621  best_path->withCheckOptionLists,
2622  best_path->returningLists,
2623  best_path->rowMarks,
2624  best_path->onconflict,
2625  best_path->epqParam);
2626 
2627  copy_generic_path_info(&plan->plan, &best_path->path);
2628 
2629  return plan;
2630 }
#define NIL
Definition: pg_list.h:65
void apply_tlist_labeling(List *dest_tlist, List *src_tlist)
Definition: tlist.c:340
List * returningLists
Definition: pathnodes.h:1781
OnConflictExpr * onconflict
Definition: pathnodes.h:1783
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:419
Index nominalRelation
Definition: pathnodes.h:1774
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
bool partColsUpdated
Definition: pathnodes.h:1776
static ModifyTable * make_modifytable(PlannerInfo *root, CmdType operation, bool canSetTag, Index nominalRelation, Index rootRelation, bool partColsUpdated, List *resultRelations, List *subplans, List *subroots, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam)
Definition: createplan.c:6613
List * lappend(List *list, void *datum)
Definition: list.c:321
#define lfirst(lc)
Definition: pg_list.h:190
Index rootRelation
Definition: pathnodes.h:1775
List * targetlist
Definition: plannodes.h:140
List * withCheckOptionLists
Definition: pathnodes.h:1780
CmdType operation
Definition: pathnodes.h:1772
List * resultRelations
Definition: pathnodes.h:1777
List * processed_tlist
Definition: pathnodes.h:323
#define CP_EXACT_TLIST
Definition: createplan.c:68
Definition: pg_list.h:50
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_namedtuplestorescan_plan()

static NamedTuplestoreScan * create_namedtuplestorescan_plan ( PlannerInfo root,
Path best_path,
List tlist,
List scan_clauses 
)
static

Definition at line 3641 of file createplan.c.

References Assert, copy_generic_path_info(), RangeTblEntry::enrname, extract_actual_clauses(), make_namedtuplestorescan(), order_qual_clauses(), Path::param_info, Path::parent, Scan::plan, planner_rt_fetch, RelOptInfo::relid, replace_nestloop_params(), RTE_NAMEDTUPLESTORE, RangeTblEntry::rtekind, and NamedTuplestoreScan::scan.

Referenced by create_scan_plan().

3643 {
3644  NamedTuplestoreScan *scan_plan;
3645  Index scan_relid = best_path->parent->relid;
3646  RangeTblEntry *rte;
3647 
3648  Assert(scan_relid > 0);
3649  rte = planner_rt_fetch(scan_relid, root);
3651 
3652  /* Sort clauses into best execution order */
3653  scan_clauses = order_qual_clauses(root, scan_clauses);
3654 
3655  /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
3656  scan_clauses = extract_actual_clauses(scan_clauses, false);
3657 
3658  /* Replace any outer-relation variables with nestloop params */
3659  if (best_path->param_info)
3660  {
3661  scan_clauses = (List *)
3662  replace_nestloop_params(root, (Node *) scan_clauses);
3663  }
3664 
3665  scan_plan = make_namedtuplestorescan(tlist, scan_clauses, scan_relid,
3666  rte->enrname);
3667 
3668  copy_generic_path_info(&scan_plan->scan.plan, best_path);
3669 
3670  return scan_plan;
3671 }
Plan plan
Definition: plannodes.h:340
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:371
RelOptInfo * parent
Definition: pathnodes.h:1114
char * enrname
Definition: parsenodes.h:1085
Index relid
Definition: pathnodes.h:669
static NamedTuplestoreScan * make_namedtuplestorescan(List *qptlist, List *qpqual, Index scanrelid, char *enrname)
Definition: createplan.c:5390
unsigned int Index
Definition: c.h:475
#define Assert(condition)
Definition: c.h:732
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
RTEKind rtekind
Definition: parsenodes.h:974
Definition: pg_list.h:50

◆ create_nestloop_plan()

static NestLoop * create_nestloop_plan ( PlannerInfo root,
NestPath best_path 
)
static

Definition at line 3992 of file createplan.c.

References bms_free(), bms_union(), build_path_tlist(), copy_generic_path_info(), create_plan_recurse(), PlannerInfo::curOuterRels, extract_actual_clauses(), extract_actual_join_clauses(), identify_current_nestloop_params(), JoinPath::inner_unique, JoinPath::innerjoinpath, IS_OUTER_JOIN, NestLoop::join, JoinPath::joinrestrictinfo, JoinPath::jointype, make_nestloop(), NIL, order_qual_clauses(), JoinPath::outerjoinpath, Path::param_info, Path::parent, JoinPath::path, Join::plan, RelOptInfo::relids, and replace_nestloop_params().

Referenced by create_join_plan().

3994 {
3995  NestLoop *join_plan;
3996  Plan *outer_plan;
3997  Plan *inner_plan;
3998  List *tlist = build_path_tlist(root, &best_path->path);
3999  List *joinrestrictclauses = best_path->joinrestrictinfo;
4000  List *joinclauses;
4001  List *otherclauses;
4002  Relids outerrelids;
4003  List *nestParams;
4004  Relids saveOuterRels = root->curOuterRels;
4005 
4006  /* NestLoop can project, so no need to be picky about child tlists */
4007  outer_plan = create_plan_recurse(root, best_path->outerjoinpath, 0);
4008 
4009  /* For a nestloop, include outer relids in curOuterRels for inner side */
4010  root->curOuterRels = bms_union(root->curOuterRels,
4011  best_path->outerjoinpath->parent->relids);
4012 
4013  inner_plan = create_plan_recurse(root, best_path->innerjoinpath, 0);
4014 
4015  /* Restore curOuterRels */
4016  bms_free(root->curOuterRels);
4017  root->curOuterRels = saveOuterRels;
4018 
4019  /* Sort join qual clauses into best execution order */
4020  joinrestrictclauses = order_qual_clauses(root, joinrestrictclauses);
4021 
4022  /* Get the join qual clauses (in plain expression form) */
4023  /* Any pseudoconstant clauses are ignored here */
4024  if (IS_OUTER_JOIN(best_path->jointype))
4025  {
4026  extract_actual_join_clauses(joinrestrictclauses,
4027  best_path->path.parent->relids,
4028  &joinclauses, &otherclauses);
4029  }
4030  else
4031  {
4032  /* We can treat all clauses alike for an inner join */
4033  joinclauses = extract_actual_clauses(joinrestrictclauses, false);
4034  otherclauses = NIL;
4035  }
4036 
4037  /* Replace any outer-relation variables with nestloop params */
4038  if (best_path->path.param_info)
4039  {
4040  joinclauses = (List *)
4041  replace_nestloop_params(root, (Node *) joinclauses);
4042  otherclauses = (List *)
4043  replace_nestloop_params(root, (Node *) otherclauses);
4044  }
4045 
4046  /*
4047  * Identify any nestloop parameters that should be supplied by this join
4048  * node, and remove them from root->curOuterParams.
4049  */
4050  outerrelids = best_path->outerjoinpath->parent->relids;
4051  nestParams = identify_current_nestloop_params(root, outerrelids);
4052 
4053  join_plan = make_nestloop(tlist,
4054  joinclauses,
4055  otherclauses,
4056  nestParams,
4057  outer_plan,
4058  inner_plan,
4059  best_path->jointype,
4060  best_path->inner_unique);
4061 
4062  copy_generic_path_info(&join_plan->join.plan, &best_path->path);
4063 
4064  return join_plan;
4065 }
#define NIL
Definition: pg_list.h:65
List * identify_current_nestloop_params(PlannerInfo *root, Relids leftrelids)
Definition: paramassign.c:509
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4564
Relids curOuterRels
Definition: pathnodes.h:355
void extract_actual_join_clauses(List *restrictinfo_list, Relids joinrelids, List **joinquals, List **otherquals)
Definition: restrictinfo.c:449
Path * innerjoinpath
Definition: pathnodes.h:1496
#define IS_OUTER_JOIN(jointype)
Definition: nodes.h:740
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Definition: nodes.h:524
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4948
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5042
Join join
Definition: plannodes.h:698
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
List * joinrestrictinfo
Definition: pathnodes.h:1498
RelOptInfo * parent
Definition: pathnodes.h:1114
static NestLoop * make_nestloop(List *tlist, List *joinclauses, List *otherclauses, List *nestParams, Plan *lefttree, Plan *righttree, JoinType jointype, bool inner_unique)
Definition: createplan.c:5549
Relids relids
Definition: pathnodes.h:641
Path * outerjoinpath
Definition: pathnodes.h:1495
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
Path path
Definition: pathnodes.h:1488
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:422
bool inner_unique
Definition: pathnodes.h:1492
JoinType jointype
Definition: pathnodes.h:1490
Definition: pg_list.h:50
Plan plan
Definition: plannodes.h:679

◆ create_plan()

Plan* create_plan ( PlannerInfo root,
Path best_path 
)

Definition at line 313 of file createplan.c.

References apply_tlist_labeling(), Assert, CP_EXACT_TLIST, create_plan_recurse(), PlannerInfo::curOuterParams, PlannerInfo::curOuterRels, elog, ERROR, IsA, NIL, PlannerInfo::plan_params, PlannerInfo::processed_tlist, SS_attach_initplans(), and Plan::targetlist.

Referenced by create_minmaxagg_plan(), create_subqueryscan_plan(), make_subplan(), SS_process_ctes(), and standard_planner().

314 {
315  Plan *plan;
316 
317  /* plan_params should not be in use in current query level */
318  Assert(root->plan_params == NIL);
319 
320  /* Initialize this module's workspace in PlannerInfo */
321  root->curOuterRels = NULL;
322  root->curOuterParams = NIL;
323 
324  /* Recursively process the path tree, demanding the correct tlist result */
325  plan = create_plan_recurse(root, best_path, CP_EXACT_TLIST);
326 
327  /*
328  * Make sure the topmost plan node's targetlist exposes the original
329  * column names and other decorative info. Targetlists generated within
330  * the planner don't bother with that stuff, but we must have it on the
331  * top-level tlist seen at execution time. However, ModifyTable plan
332  * nodes don't have a tlist matching the querytree targetlist.
333  */
334  if (!IsA(plan, ModifyTable))
336 
337  /*
338  * Attach any initPlans created in this query level to the topmost plan
339  * node. (In principle the initplans could go in any plan node at or
340  * above where they're referenced, but there seems no reason to put them
341  * any lower than the topmost node for the query level. Also, see
342  * comments for SS_finalize_plan before you try to change this.)
343  */
344  SS_attach_initplans(root, plan);
345 
346  /* Check we successfully assigned all NestLoopParams to plan nodes */
347  if (root->curOuterParams != NIL)
348  elog(ERROR, "failed to assign all NestLoopParams to plan nodes");
349 
350  /*
351  * Reset plan_params to ensure param IDs used for nestloop params are not
352  * re-used later
353  */
354  root->plan_params = NIL;
355 
356  return plan;
357 }
#define NIL
Definition: pg_list.h:65
void apply_tlist_labeling(List *dest_tlist, List *src_tlist)
Definition: tlist.c:340
#define IsA(nodeptr, _type_)
Definition: nodes.h:575
List * plan_params
Definition: pathnodes.h:191
Relids curOuterRels
Definition: pathnodes.h:355
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
#define ERROR
Definition: elog.h:43
List * curOuterParams
Definition: pathnodes.h:356
#define Assert(condition)
Definition: c.h:732
void SS_attach_initplans(PlannerInfo *root, Plan *plan)
Definition: subselect.c:2118
List * targetlist
Definition: plannodes.h:140
#define elog(elevel,...)
Definition: elog.h:226
List * processed_tlist
Definition: pathnodes.h:323
#define CP_EXACT_TLIST
Definition: createplan.c:68

◆ create_plan_recurse()

static Plan * create_plan_recurse ( PlannerInfo root,
Path best_path,
int  flags 
)
static

Definition at line 364 of file createplan.c.

References Assert, check_stack_depth(), create_agg_plan(), create_append_plan(), create_gather_merge_plan(), create_gather_plan(), create_group_plan(), create_group_result_plan(), create_groupingsets_plan(), create_join_plan(), create_limit_plan(), create_lockrows_plan(), create_material_plan(), create_merge_append_plan(), create_minmaxagg_plan(), create_modifytable_plan(), create_project_set_plan(), create_projection_plan(), create_recursiveunion_plan(), create_scan_plan(), create_setop_plan(), create_sort_plan(), create_unique_plan(), create_upper_unique_plan(), create_windowagg_plan(), elog, ERROR, IsA, Path::pathtype, T_Agg, T_Append, T_BitmapHeapScan, T_CteScan, T_CustomScan, T_ForeignScan, T_FunctionScan, T_Gather, T_GatherMerge, T_Group, T_HashJoin, T_IndexOnlyScan, T_IndexScan, T_Limit, T_LockRows, T_Material, T_MergeAppend, T_MergeJoin, T_ModifyTable, T_NamedTuplestoreScan, T_NestLoop, T_ProjectSet, T_RecursiveUnion, T_Result, T_SampleScan, T_SeqScan, T_SetOp, T_Sort, T_SubqueryScan, T_TableFuncScan, T_TidScan, T_Unique, T_ValuesScan, T_WindowAgg, and T_WorkTableScan.

Referenced by create_agg_plan(), create_append_plan(), create_customscan_plan(), create_foreignscan_plan(), create_gather_merge_plan(), create_gather_plan(), create_group_plan(), create_groupingsets_plan(), create_hashjoin_plan(), create_limit_plan(), create_lockrows_plan(), create_material_plan(), create_merge_append_plan(), create_mergejoin_plan(), create_modifytable_plan(), create_nestloop_plan(), create_plan(), create_project_set_plan(), create_projection_plan(), create_recursiveunion_plan(), create_setop_plan(), create_sort_plan(), create_unique_plan(), create_upper_unique_plan(), and create_windowagg_plan().

365 {
366  Plan *plan;
367 
368  /* Guard against stack overflow due to overly complex plans */
370 
371  switch (best_path->pathtype)
372  {
373  case T_SeqScan:
374  case T_SampleScan:
375  case T_IndexScan:
376  case T_IndexOnlyScan:
377  case T_BitmapHeapScan:
378  case T_TidScan:
379  case T_SubqueryScan:
380  case T_FunctionScan:
381  case T_TableFuncScan:
382  case T_ValuesScan:
383  case T_CteScan:
384  case T_WorkTableScan:
386  case T_ForeignScan:
387  case T_CustomScan:
388  plan = create_scan_plan(root, best_path, flags);
389  break;
390  case T_HashJoin:
391  case T_MergeJoin:
392  case T_NestLoop:
393  plan = create_join_plan(root,
394  (JoinPath *) best_path);
395  break;
396  case T_Append:
397  plan = create_append_plan(root,
398  (AppendPath *) best_path,
399  flags);
400  break;
401  case T_MergeAppend:
402  plan = create_merge_append_plan(root,
403  (MergeAppendPath *) best_path,
404  flags);
405  break;
406  case T_Result:
407  if (IsA(best_path, ProjectionPath))
408  {
409  plan = create_projection_plan(root,
410  (ProjectionPath *) best_path,
411  flags);
412  }
413  else if (IsA(best_path, MinMaxAggPath))
414  {
415  plan = (Plan *) create_minmaxagg_plan(root,
416  (MinMaxAggPath *) best_path);
417  }
418  else if (IsA(best_path, GroupResultPath))
419  {
420  plan = (Plan *) create_group_result_plan(root,
421  (GroupResultPath *) best_path);
422  }
423  else
424  {
425  /* Simple RTE_RESULT base relation */
426  Assert(IsA(best_path, Path));
427  plan = create_scan_plan(root, best_path, flags);
428  }
429  break;
430  case T_ProjectSet:
431  plan = (Plan *) create_project_set_plan(root,
432  (ProjectSetPath *) best_path);
433  break;
434  case T_Material:
435  plan = (Plan *) create_material_plan(root,
436  (MaterialPath *) best_path,
437  flags);
438  break;
439  case T_Unique:
440  if (IsA(best_path, UpperUniquePath))
441  {
442  plan = (Plan *) create_upper_unique_plan(root,
443  (UpperUniquePath *) best_path,
444  flags);
445  }
446  else
447  {
448  Assert(IsA(best_path, UniquePath));
449  plan = create_unique_plan(root,
450  (UniquePath *) best_path,
451  flags);
452  }
453  break;
454  case T_Gather:
455  plan = (Plan *) create_gather_plan(root,
456  (GatherPath *) best_path);
457  break;
458  case T_Sort:
459  plan = (Plan *) create_sort_plan(root,
460  (SortPath *) best_path,
461  flags);
462  break;
463  case T_Group:
464  plan = (Plan *) create_group_plan(root,
465  (GroupPath *) best_path);
466  break;
467  case T_Agg:
468  if (IsA(best_path, GroupingSetsPath))
469  plan = create_groupingsets_plan(root,
470  (GroupingSetsPath *) best_path);
471  else
472  {
473  Assert(IsA(best_path, AggPath));
474  plan = (Plan *) create_agg_plan(root,
475  (AggPath *) best_path);
476  }
477  break;
478  case T_WindowAgg:
479  plan = (Plan *) create_windowagg_plan(root,
480  (WindowAggPath *) best_path);
481  break;
482  case T_SetOp:
483  plan = (Plan *) create_setop_plan(root,
484  (SetOpPath *) best_path,
485  flags);
486  break;
487  case T_RecursiveUnion:
488  plan = (Plan *) create_recursiveunion_plan(root,
489  (RecursiveUnionPath *) best_path);
490  break;
491  case T_LockRows:
492  plan = (Plan *) create_lockrows_plan(root,
493  (LockRowsPath *) best_path,
494  flags);
495  break;
496  case T_ModifyTable:
497  plan = (Plan *) create_modifytable_plan(root,
498  (ModifyTablePath *) best_path);
499  break;
500  case T_Limit:
501  plan = (Plan *) create_limit_plan(root,
502  (LimitPath *) best_path,
503  flags);
504  break;
505  case T_GatherMerge:
506  plan = (Plan *) create_gather_merge_plan(root,
507  (GatherMergePath *) best_path);
508  break;
509  default:
510  elog(ERROR, "unrecognized node type: %d",
511  (int) best_path->pathtype);
512  plan = NULL; /* keep compiler quiet */
513  break;
514  }
515 
516  return plan;
517 }
static Plan * create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags)
Definition: createplan.c:1512
static Result * create_minmaxagg_plan(PlannerInfo *root, MinMaxAggPath *best_path)
Definition: createplan.c:2312
Definition: nodes.h:78
static Group * create_group_plan(PlannerInfo *root, GroupPath *best_path)
Definition: createplan.c:2001
#define IsA(nodeptr, _type_)
Definition: nodes.h:575
static Plan * create_projection_plan(PlannerInfo *root, ProjectionPath *best_path, int flags)
Definition: createplan.c:1805
Definition: nodes.h:80
static Sort * create_sort_plan(PlannerInfo *root, SortPath *best_path, int flags)
Definition: createplan.c:1966
static Plan * create_scan_plan(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:524
static LockRows * create_lockrows_plan(PlannerInfo *root, LockRowsPath *best_path, int flags)
Definition: createplan.c:2555
static ProjectSet * create_project_set_plan(PlannerInfo *root, ProjectSetPath *best_path)
Definition: createplan.c:1458
static RecursiveUnion * create_recursiveunion_plan(PlannerInfo *root, RecursiveUnionPath *best_path)
Definition: createplan.c:2519
static Agg * create_agg_plan(PlannerInfo *root, AggPath *best_path)
Definition: createplan.c:2068
static Unique * create_upper_unique_plan(PlannerInfo *root, UpperUniquePath *best_path, int flags)
Definition: createplan.c:2040
Definition: nodes.h:49
Definition: nodes.h:76
static ModifyTable * create_modifytable_plan(PlannerInfo *root, ModifyTablePath *best_path)
Definition: createplan.c:2578
NodeTag pathtype
Definition: pathnodes.h:1112
Definition: nodes.h:46
#define ERROR
Definition: elog.h:43
Definition: nodes.h:77
static Plan * create_join_plan(PlannerInfo *root, JoinPath *best_path)
Definition: createplan.c:1004
void check_stack_depth(void)
Definition: postgres.c:3262
static GatherMerge * create_gather_merge_plan(PlannerInfo *root, GatherMergePath *best_path)
Definition: createplan.c:1746
static SetOp * create_setop_plan(PlannerInfo *root, SetOpPath *best_path, int flags)
Definition: createplan.c:2483
#define Assert(condition)
Definition: c.h:732
static Gather * create_gather_plan(PlannerInfo *root, GatherPath *best_path)
Definition: createplan.c:1710
static WindowAgg * create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
Definition: createplan.c:2381
static Material * create_material_plan(PlannerInfo *root, MaterialPath *best_path, int flags)
Definition: createplan.c:1484
static Plan * create_append_plan(PlannerInfo *root, AppendPath *best_path, int flags)
Definition: createplan.c:1064
Definition: nodes.h:84
Definition: nodes.h:81
static Plan * create_groupingsets_plan(PlannerInfo *root, GroupingSetsPath *best_path)
Definition: createplan.c:2151
#define elog(elevel,...)
Definition: elog.h:226
static Limit * create_limit_plan(PlannerInfo *root, LimitPath *best_path, int flags)
Definition: createplan.c:2639
static Plan * create_merge_append_plan(PlannerInfo *root, MergeAppendPath *best_path, int flags)
Definition: createplan.c:1273
Definition: nodes.h:86