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 5110 of file createplan.c.

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

Referenced by create_bitmap_scan_plan().

5111 {
5112  if (IsA(plan, BitmapAnd))
5114  linitial(((BitmapAnd *) plan)->bitmapplans));
5115  else if (IsA(plan, BitmapOr))
5116  {
5117  ((BitmapOr *) plan)->isshared = true;
5119  linitial(((BitmapOr *) plan)->bitmapplans));
5120  }
5121  else if (IsA(plan, BitmapIndexScan))
5122  ((BitmapIndexScan *) plan)->isshared = true;
5123  else
5124  elog(ERROR, "unrecognized node type: %d", nodeTag(plan));
5125 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
#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:5110
#define nodeTag(nodeptr)
Definition: nodes.h:530
#define elog(elevel,...)
Definition: elog.h:228

◆ 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:1117
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4569
ParamPathInfo * param_info
Definition: pathnodes.h:1119
Definition: nodes.h:525
Index * sortgrouprefs
Definition: pathnodes.h:1047
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:236
List * lappend(List *list, void *datum)
Definition: list.c:322
List * exprs
Definition: pathnodes.h:1046
unsigned int Index
Definition: c.h:476
#define lfirst(lc)
Definition: pg_list.h:190
Index ressortgroupref
Definition: primnodes.h:1410
Definition: pg_list.h:50

◆ change_plan_targetlist()

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

Definition at line 1940 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().

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

◆ copy_generic_path_info()

static void copy_generic_path_info ( Plan dest,
Path src 
)
static

Definition at line 5047 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().

5048 {
5049  dest->startup_cost = src->startup_cost;
5050  dest->total_cost = src->total_cost;
5051  dest->plan_rows = src->rows;
5052  dest->plan_width = src->pathtarget->width;
5053  dest->parallel_aware = src->parallel_aware;
5054  dest->parallel_safe = src->parallel_safe;
5055 }
double plan_rows
Definition: plannodes.h:129
PathTarget * pathtarget
Definition: pathnodes.h:1117
Cost startup_cost
Definition: pathnodes.h:1127
Cost startup_cost
Definition: plannodes.h:123
bool parallel_aware
Definition: plannodes.h:135
Cost total_cost
Definition: pathnodes.h:1128
int plan_width
Definition: plannodes.h:130
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
Cost total_cost
Definition: plannodes.h:124
bool parallel_aware
Definition: pathnodes.h:1121
bool parallel_safe
Definition: plannodes.h:136

◆ copy_plan_costsize()

static void copy_plan_costsize ( Plan dest,
Plan src 
)
static

Definition at line 5062 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().

5063 {
5064  dest->startup_cost = src->startup_cost;
5065  dest->total_cost = src->total_cost;
5066  dest->plan_rows = src->plan_rows;
5067  dest->plan_width = src->plan_width;
5068  /* Assume the inserted node is not parallel-aware. */
5069  dest->parallel_aware = false;
5070  /* Assume the inserted node is parallel-safe, if child plan is. */
5071  dest->parallel_safe = src->parallel_safe;
5072 }
double plan_rows
Definition: plannodes.h:129
Cost startup_cost
Definition: plannodes.h:123
bool parallel_aware
Definition: plannodes.h:135
int plan_width
Definition: plannodes.h:130
Cost total_cost
Definition: plannodes.h:124
bool parallel_safe
Definition: plannodes.h:136

◆ create_agg_plan()

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

Definition at line 2070 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().

2071 {
2072  Agg *plan;
2073  Plan *subplan;
2074  List *tlist;
2075  List *quals;
2076 
2077  /*
2078  * Agg can project, so no need to be terribly picky about child tlist, but
2079  * we do need grouping columns to be available
2080  */
2081  subplan = create_plan_recurse(root, best_path->subpath, CP_LABEL_TLIST);
2082 
2083  tlist = build_path_tlist(root, &best_path->path);
2084 
2085  quals = order_qual_clauses(root, best_path->qual);
2086 
2087  plan = make_agg(tlist, quals,
2088  best_path->aggstrategy,
2089  best_path->aggsplit,
2090  list_length(best_path->groupClause),
2092  subplan->targetlist),
2093  extract_grouping_ops(best_path->groupClause),
2095  subplan->targetlist),
2096  NIL,
2097  NIL,
2098  best_path->numGroups,
2099  subplan);
2100 
2101  copy_generic_path_info(&plan->plan, (Path *) best_path);
2102 
2103  return plan;
2104 }
#define NIL
Definition: pg_list.h:65
AggStrategy aggstrategy
Definition: pathnodes.h:1663
Oid * extract_grouping_collations(List *groupClause, List *tlist)
Definition: tlist.c:511
List * qual
Definition: pathnodes.h:1667
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4953
AggSplit aggsplit
Definition: pathnodes.h:1664
Oid * extract_grouping_ops(List *groupClause)
Definition: tlist.c:485
double numGroups
Definition: pathnodes.h:1665
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:6194
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:5047
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
List * groupClause
Definition: pathnodes.h:1666
Plan plan
Definition: plannodes.h:808
#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:1662
List * targetlist
Definition: plannodes.h:142
Definition: plannodes.h:806
Definition: pg_list.h:50
Path path
Definition: pathnodes.h:1661

◆ 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, Append::apprelids, 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  plan->apprelids = rel->relids;
1122 
1123  if (pathkeys != NIL)
1124  {
1125  /*
1126  * Compute sort column info, and adjust the Append's tlist as needed.
1127  * Because we pass adjust_tlist_in_place = true, we may ignore the
1128  * function result; it must be the same plan node. However, we then
1129  * need to detect whether any tlist entries were added.
1130  */
1131  (void) prepare_sort_from_pathkeys((Plan *) plan, pathkeys,
1132  best_path->path.parent->relids,
1133  NULL,
1134  true,
1135  &nodenumsortkeys,
1136  &nodeSortColIdx,
1137  &nodeSortOperators,
1138  &nodeCollations,
1139  &nodeNullsFirst);
1140  tlist_was_changed = (orig_tlist_length != list_length(plan->plan.targetlist));
1141  }
1142 
1143  /* Build the plan for each child */
1144  foreach(subpaths, best_path->subpaths)
1145  {
1146  Path *subpath = (Path *) lfirst(subpaths);
1147  Plan *subplan;
1148 
1149  /* Must insist that all children return the same tlist */
1150  subplan = create_plan_recurse(root, subpath, CP_EXACT_TLIST);
1151 
1152  /*
1153  * For ordered Appends, we must insert a Sort node if subplan isn't
1154  * sufficiently ordered.
1155  */
1156  if (pathkeys != NIL)
1157  {
1158  int numsortkeys;
1159  AttrNumber *sortColIdx;
1160  Oid *sortOperators;
1161  Oid *collations;
1162  bool *nullsFirst;
1163 
1164  /*
1165  * Compute sort column info, and adjust subplan's tlist as needed.
1166  * We must apply prepare_sort_from_pathkeys even to subplans that
1167  * don't need an explicit sort, to make sure they are returning
1168  * the same sort key columns the Append expects.
1169  */
1170  subplan = prepare_sort_from_pathkeys(subplan, pathkeys,
1171  subpath->parent->relids,
1172  nodeSortColIdx,
1173  false,
1174  &numsortkeys,
1175  &sortColIdx,
1176  &sortOperators,
1177  &collations,
1178  &nullsFirst);
1179 
1180  /*
1181  * Check that we got the same sort key information. We just
1182  * Assert that the sortops match, since those depend only on the
1183  * pathkeys; but it seems like a good idea to check the sort
1184  * column numbers explicitly, to ensure the tlists match up.
1185  */
1186  Assert(numsortkeys == nodenumsortkeys);
1187  if (memcmp(sortColIdx, nodeSortColIdx,
1188  numsortkeys * sizeof(AttrNumber)) != 0)
1189  elog(ERROR, "Append child's targetlist doesn't match Append");
1190  Assert(memcmp(sortOperators, nodeSortOperators,
1191  numsortkeys * sizeof(Oid)) == 0);
1192  Assert(memcmp(collations, nodeCollations,
1193  numsortkeys * sizeof(Oid)) == 0);
1194  Assert(memcmp(nullsFirst, nodeNullsFirst,
1195  numsortkeys * sizeof(bool)) == 0);
1196 
1197  /* Now, insert a Sort node if subplan isn't sufficiently ordered */
1198  if (!pathkeys_contained_in(pathkeys, subpath->pathkeys))
1199  {
1200  Sort *sort = make_sort(subplan, numsortkeys,
1201  sortColIdx, sortOperators,
1202  collations, nullsFirst);
1203 
1204  label_sort_with_costsize(root, sort, best_path->limit_tuples);
1205  subplan = (Plan *) sort;
1206  }
1207  }
1208 
1209  subplans = lappend(subplans, subplan);
1210  }
1211 
1212  /*
1213  * If any quals exist, they may be useful to perform further partition
1214  * pruning during execution. Gather information needed by the executor to
1215  * do partition pruning.
1216  */
1218  rel->reloptkind == RELOPT_BASEREL &&
1219  best_path->partitioned_rels != NIL)
1220  {
1221  List *prunequal;
1222 
1223  prunequal = extract_actual_clauses(rel->baserestrictinfo, false);
1224 
1225  if (best_path->path.param_info)
1226  {
1227  List *prmquals = best_path->path.param_info->ppi_clauses;
1228 
1229  prmquals = extract_actual_clauses(prmquals, false);
1230  prmquals = (List *) replace_nestloop_params(root,
1231  (Node *) prmquals);
1232 
1233  prunequal = list_concat(prunequal, prmquals);
1234  }
1235 
1236  if (prunequal != NIL)
1237  partpruneinfo =
1238  make_partition_pruneinfo(root, rel,
1239  best_path->subpaths,
1240  best_path->partitioned_rels,
1241  prunequal);
1242  }
1243 
1244  plan->appendplans = subplans;
1245  plan->first_partial_plan = best_path->first_partial_path;
1246  plan->part_prune_info = partpruneinfo;
1247 
1248  copy_generic_path_info(&plan->plan, (Path *) best_path);
1249 
1250  /*
1251  * If prepare_sort_from_pathkeys added sort columns, but we were told to
1252  * produce either the exact tlist or a narrow tlist, we should get rid of
1253  * the sort columns again. We must inject a projection node to do so.
1254  */
1255  if (tlist_was_changed && (flags & (CP_EXACT_TLIST | CP_SMALL_TLIST)))
1256  {
1257  tlist = list_truncate(list_copy(plan->plan.targetlist),
1258  orig_tlist_length);
1259  return inject_projection_plan((Plan *) plan, tlist,
1260  plan->plan.parallel_safe);
1261  }
1262  else
1263  return (Plan *) plan;
1264 }
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:143
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4569
RelOptKind reloptkind
Definition: pathnodes.h:640
double limit_tuples
Definition: pathnodes.h:1379
List * baserestrictinfo
Definition: pathnodes.h:705
List * list_truncate(List *list, int new_size)
Definition: list.c:586
ParamPathInfo * param_info
Definition: pathnodes.h:1119
#define CP_SMALL_TLIST
Definition: createplan.c:69
List * list_copy(const List *oldlist)
Definition: list.c:1404
Definition: nodes.h:525
List * list_concat(List *list1, const List *list2)
Definition: list.c:516
unsigned int Oid
Definition: postgres_ext.h:31
int first_partial_path
Definition: pathnodes.h:1378
#define list_make1(x1)
Definition: pg_list.h:227
List * subpaths
Definition: pathnodes.h:1376
static Plan * create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
Definition: createplan.c:364
struct Plan * righttree
Definition: plannodes.h:145
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5047
#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:1116
Datum sort(PG_FUNCTION_ARGS)
Definition: _int_op.c:199
Relids relids
Definition: pathnodes.h:643
static Result * make_result(List *tlist, Node *resconstantqual, Plan *subplan)
Definition: createplan.c:6578
List * lappend(List *list, void *datum)
Definition: list.c:322
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:1130
static Sort * make_sort(Plan *lefttree, int numCols, AttrNumber *sortColIdx, Oid *sortOperators, Oid *collations, bool *nullsFirst)
Definition: createplan.c:5674
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
List * ppi_clauses
Definition: pathnodes.h:1077
static Plan * inject_projection_plan(Plan *subplan, List *tlist, bool parallel_safe)
Definition: createplan.c:1908
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:144
List * partitioned_rels
Definition: pathnodes.h:1375
List * targetlist
Definition: plannodes.h:142
#define elog(elevel,...)
Definition: elog.h:228
bool parallel_safe
Definition: plannodes.h:136
#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:5084
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:5736

◆ create_bitmap_scan_plan()

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

Definition at line 2937 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().

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

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

◆ create_ctescan_plan()

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

Definition at line 3552 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().

3554 {
3555  CteScan *scan_plan;
3556  Index scan_relid = best_path->parent->relid;
3557  RangeTblEntry *rte;
3558  SubPlan *ctesplan = NULL;
3559  int plan_id;
3560  int cte_param_id;
3561  PlannerInfo *cteroot;
3562  Index levelsup;
3563  int ndx;
3564  ListCell *lc;
3565 
3566  Assert(scan_relid > 0);
3567  rte = planner_rt_fetch(scan_relid, root);
3568  Assert(rte->rtekind == RTE_CTE);
3569  Assert(!rte->self_reference);
3570 
3571  /*
3572  * Find the referenced CTE, and locate the SubPlan previously made for it.
3573  */
3574  levelsup = rte->ctelevelsup;
3575  cteroot = root;
3576  while (levelsup-- > 0)
3577  {
3578  cteroot = cteroot->parent_root;
3579  if (!cteroot) /* shouldn't happen */
3580  elog(ERROR, "bad levelsup for CTE \"%s\"", rte->ctename);
3581  }
3582 
3583  /*
3584  * Note: cte_plan_ids can be shorter than cteList, if we are still working
3585  * on planning the CTEs (ie, this is a side-reference from another CTE).
3586  * So we mustn't use forboth here.
3587  */
3588  ndx = 0;
3589  foreach(lc, cteroot->parse->cteList)
3590  {
3591  CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc);
3592 
3593  if (strcmp(cte->ctename, rte->ctename) == 0)
3594  break;
3595  ndx++;
3596  }
3597  if (lc == NULL) /* shouldn't happen */
3598  elog(ERROR, "could not find CTE \"%s\"", rte->ctename);
3599  if (ndx >= list_length(cteroot->cte_plan_ids))
3600  elog(ERROR, "could not find plan for CTE \"%s\"", rte->ctename);
3601  plan_id = list_nth_int(cteroot->cte_plan_ids, ndx);
3602  Assert(plan_id > 0);
3603  foreach(lc, cteroot->init_plans)
3604  {
3605  ctesplan = (SubPlan *) lfirst(lc);
3606  if (ctesplan->plan_id == plan_id)
3607  break;
3608  }
3609  if (lc == NULL) /* shouldn't happen */
3610  elog(ERROR, "could not find plan for CTE \"%s\"", rte->ctename);
3611 
3612  /*
3613  * We need the CTE param ID, which is the sole member of the SubPlan's
3614  * setParam list.
3615  */
3616  cte_param_id = linitial_int(ctesplan->setParam);
3617 
3618  /* Sort clauses into best execution order */
3619  scan_clauses = order_qual_clauses(root, scan_clauses);
3620 
3621  /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
3622  scan_clauses = extract_actual_clauses(scan_clauses, false);
3623 
3624  /* Replace any outer-relation variables with nestloop params */
3625  if (best_path->param_info)
3626  {
3627  scan_clauses = (List *)
3628  replace_nestloop_params(root, (Node *) scan_clauses);
3629  }
3630 
3631  scan_plan = make_ctescan(tlist, scan_clauses, scan_relid,
3632  plan_id, cte_param_id);
3633 
3634  copy_generic_path_info(&scan_plan->scan.plan, best_path);
3635 
3636  return scan_plan;
3637 }
Plan plan
Definition: plannodes.h:344
Query * parse
Definition: pathnodes.h:179
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4569
int plan_id
Definition: primnodes.h:709
PlannerInfo * parent_root
Definition: pathnodes.h:185
ParamPathInfo * param_info
Definition: pathnodes.h:1119
Definition: nodes.h:525
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4953
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:5047
#define ERROR
Definition: elog.h:43
Scan scan
Definition: plannodes.h:555
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:373
RelOptInfo * parent
Definition: pathnodes.h:1116
Index relid
Definition: pathnodes.h:671
static CteScan * make_ctescan(List *qptlist, List *qpqual, Index scanrelid, int ctePlanId, int cteParam)
Definition: createplan.c:5374
List * cte_plan_ids
Definition: pathnodes.h:261
bool self_reference
Definition: parsenodes.h:1079
unsigned int Index
Definition: c.h:476
List * init_plans
Definition: pathnodes.h:259
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
List * setParam
Definition: primnodes.h:727
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:1078
RTEKind rtekind
Definition: parsenodes.h:974
List * cteList
Definition: parsenodes.h:135
char * ctename
Definition: parsenodes.h:1077
#define elog(elevel,...)
Definition: elog.h:228
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 3926 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().

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

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

◆ create_functionscan_plan()

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

Definition at line 3422 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().

3424 {
3425  FunctionScan *scan_plan;
3426  Index scan_relid = best_path->parent->relid;
3427  RangeTblEntry *rte;
3428  List *functions;
3429 
3430  /* it should be a function base rel... */
3431  Assert(scan_relid > 0);
3432  rte = planner_rt_fetch(scan_relid, root);
3433  Assert(rte->rtekind == RTE_FUNCTION);
3434  functions = rte->functions;
3435 
3436  /* Sort clauses into best execution order */
3437  scan_clauses = order_qual_clauses(root, scan_clauses);
3438 
3439  /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
3440  scan_clauses = extract_actual_clauses(scan_clauses, false);
3441 
3442  /* Replace any outer-relation variables with nestloop params */
3443  if (best_path->param_info)
3444  {
3445  scan_clauses = (List *)
3446  replace_nestloop_params(root, (Node *) scan_clauses);
3447  /* The function expressions could contain nestloop params, too */
3448  functions = (List *) replace_nestloop_params(root, (Node *) functions);
3449  }
3450 
3451  scan_plan = make_functionscan(tlist, scan_clauses, scan_relid,
3452  functions, rte->funcordinality);
3453 
3454  copy_generic_path_info(&scan_plan->scan.plan, best_path);
3455 
3456  return scan_plan;
3457 }
Plan plan
Definition: plannodes.h:344
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4569
ParamPathInfo * param_info
Definition: pathnodes.h:1119
Definition: nodes.h:525
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4953
bool funcordinality
Definition: parsenodes.h:1062
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5047
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:373
RelOptInfo * parent
Definition: pathnodes.h:1116
Index relid
Definition: pathnodes.h:671
unsigned int Index
Definition: c.h:476
static FunctionScan * make_functionscan(List *qptlist, List *qpqual, Index scanrelid, List *functions, bool funcordinality)
Definition: createplan.c:5315
#define Assert(condition)
Definition: c.h:739
List * functions
Definition: parsenodes.h:1061
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 1748 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().

1749 {
1750  GatherMerge *gm_plan;
1751  Plan *subplan;
1752  List *pathkeys = best_path->path.pathkeys;
1753  List *tlist = build_path_tlist(root, &best_path->path);
1754 
1755  /* As with Gather, it's best to project away columns in the workers. */
1756  subplan = create_plan_recurse(root, best_path->subpath, CP_EXACT_TLIST);
1757 
1758  /* Create a shell for a GatherMerge plan. */
1759  gm_plan = makeNode(GatherMerge);
1760  gm_plan->plan.targetlist = tlist;
1761  gm_plan->num_workers = best_path->num_workers;
1762  copy_generic_path_info(&gm_plan->plan, &best_path->path);
1763 
1764  /* Assign the rescan Param. */
1765  gm_plan->rescan_param = assign_special_exec_param(root);
1766 
1767  /* Gather Merge is pointless with no pathkeys; use Gather instead. */
1768  Assert(pathkeys != NIL);
1769 
1770  /* Compute sort column info, and adjust subplan's tlist as needed */
1771  subplan = prepare_sort_from_pathkeys(subplan, pathkeys,
1772  best_path->subpath->parent->relids,
1773  gm_plan->sortColIdx,
1774  false,
1775  &gm_plan->numCols,
1776  &gm_plan->sortColIdx,
1777  &gm_plan->sortOperators,
1778  &gm_plan->collations,
1779  &gm_plan->nullsFirst);
1780 
1781 
1782  /* Now, insert a Sort node if subplan isn't sufficiently ordered */
1783  if (!pathkeys_contained_in(pathkeys, best_path->subpath->pathkeys))
1784  subplan = (Plan *) make_sort(subplan, gm_plan->numCols,
1785  gm_plan->sortColIdx,
1786  gm_plan->sortOperators,
1787  gm_plan->collations,
1788  gm_plan->nullsFirst);
1789 
1790  /* Now insert the subplan under GatherMerge. */
1791  gm_plan->plan.lefttree = subplan;
1792 
1793  /* use parallel mode for parallel plans. */
1794  root->glob->parallelModeNeeded = true;
1795 
1796  return gm_plan;
1797 }
#define NIL
Definition: pg_list.h:65
Oid * collations
Definition: plannodes.h:897
AttrNumber * sortColIdx
Definition: plannodes.h:895
bool * nullsFirst
Definition: plannodes.h:898
int assign_special_exec_param(PlannerInfo *root)
Definition: paramassign.c:584
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:5047
bool parallelModeNeeded
Definition: pathnodes.h:145
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
RelOptInfo * parent
Definition: pathnodes.h:1116
PlannerGlobal * glob
Definition: pathnodes.h:181
Relids relids
Definition: pathnodes.h:643
Oid * sortOperators
Definition: plannodes.h:896
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
List * pathkeys
Definition: pathnodes.h:1130
static Sort * make_sort(Plan *lefttree, int numCols, AttrNumber *sortColIdx, Oid *sortOperators, Oid *collations, bool *nullsFirst)
Definition: createplan.c:5674
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
struct Plan * lefttree
Definition: plannodes.h:144
List * targetlist
Definition: plannodes.h:142
int num_workers
Definition: plannodes.h:891
int rescan_param
Definition: plannodes.h:892
#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:5736

◆ create_gather_plan()

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

Definition at line 1712 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().

1713 {
1714  Gather *gather_plan;
1715  Plan *subplan;
1716  List *tlist;
1717 
1718  /*
1719  * Although the Gather node can project, we prefer to push down such work
1720  * to its child node, so demand an exact tlist from the child.
1721  */
1722  subplan = create_plan_recurse(root, best_path->subpath, CP_EXACT_TLIST);
1723 
1724  tlist = build_path_tlist(root, &best_path->path);
1725 
1726  gather_plan = make_gather(tlist,
1727  NIL,
1728  best_path->num_workers,
1730  best_path->single_copy,
1731  subplan);
1732 
1733  copy_generic_path_info(&gather_plan->plan, &best_path->path);
1734 
1735  /* use parallel mode for parallel plans. */
1736  root->glob->parallelModeNeeded = true;
1737 
1738  return gather_plan;
1739 }
#define NIL
Definition: pg_list.h:65
bool single_copy
Definition: pathnodes.h:1468
int assign_special_exec_param(PlannerInfo *root)
Definition: paramassign.c:584
int num_workers
Definition: pathnodes.h:1469
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:5047
bool parallelModeNeeded
Definition: pathnodes.h:145
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
Plan plan
Definition: plannodes.h:875
PlannerGlobal * glob
Definition: pathnodes.h:181
Path * subpath
Definition: pathnodes.h:1467
static Gather * make_gather(List *qptlist, List *qpqual, int nworkers, int rescan_param, bool single_copy, Plan *subplan)
Definition: createplan.c:6451
#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:188
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Definition: nodes.h:525
Node * resconstantqual
Definition: plannodes.h:189
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:5062
static SPIPlanPtr splan
Definition: regress.c:258
static Result * make_result(List *tlist, Node *resconstantqual, Plan *subplan)
Definition: createplan.c:6578
#define Assert(condition)
Definition: c.h:739
bool parallel_safe
Definition: pathnodes.h:1122
struct Plan * lefttree
Definition: plannodes.h:144
bool parallel_safe
Definition: plannodes.h:136

◆ create_group_plan()

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

Definition at line 2003 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().

2004 {
2005  Group *plan;
2006  Plan *subplan;
2007  List *tlist;
2008  List *quals;
2009 
2010  /*
2011  * Group can project, so no need to be terribly picky about child tlist,
2012  * but we do need grouping columns to be available
2013  */
2014  subplan = create_plan_recurse(root, best_path->subpath, CP_LABEL_TLIST);
2015 
2016  tlist = build_path_tlist(root, &best_path->path);
2017 
2018  quals = order_qual_clauses(root, best_path->qual);
2019 
2020  plan = make_group(tlist,
2021  quals,
2022  list_length(best_path->groupClause),
2024  subplan->targetlist),
2025  extract_grouping_ops(best_path->groupClause),
2027  subplan->targetlist),
2028  subplan);
2029 
2030  copy_generic_path_info(&plan->plan, (Path *) best_path);
2031 
2032  return plan;
2033 }
List * qual
Definition: pathnodes.h:1636
Oid * extract_grouping_collations(List *groupClause, List *tlist)
Definition: tlist.c:511
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4953
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:5047
static Group * make_group(List *tlist, List *qual, int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, Plan *lefttree)
Definition: createplan.c:6266
static List * build_path_tlist(PlannerInfo *root, Path *path)
Definition: createplan.c:764
Path path
Definition: pathnodes.h:1633
List * groupClause
Definition: pathnodes.h:1635
#define CP_LABEL_TLIST
Definition: createplan.c:70
Path * subpath
Definition: pathnodes.h:1634
Plan plan
Definition: plannodes.h:785
static int list_length(const List *l)
Definition: pg_list.h:169
List * targetlist
Definition: plannodes.h:142
Definition: pg_list.h:50

◆ create_group_result_plan()

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

Definition at line 1435 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().

1436 {
1437  Result *plan;
1438  List *tlist;
1439  List *quals;
1440 
1441  tlist = build_path_tlist(root, &best_path->path);
1442 
1443  /* best_path->quals is just bare clauses */
1444  quals = order_qual_clauses(root, best_path->quals);
1445 
1446  plan = make_result(tlist, (Node *) quals, NULL);
1447 
1448  copy_generic_path_info(&plan->plan, (Path *) best_path);
1449 
1450  return plan;
1451 }
Plan plan
Definition: plannodes.h:188
Definition: nodes.h:525
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4953
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5047
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:6578
Definition: pg_list.h:50

◆ create_groupingsets_plan()

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

Definition at line 2153 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().

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

◆ create_hashjoin_plan()

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

Definition at line 4380 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().

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

◆ create_indexscan_plan()

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

Definition at line 2764 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().

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

2645 {
2646  Limit *plan;
2647  Plan *subplan;
2648 
2649  /* Limit doesn't project, so tlist requirements pass through */
2650  subplan = create_plan_recurse(root, best_path->subpath, flags);
2651 
2652  plan = make_limit(subplan,
2653  best_path->limitOffset,
2654  best_path->limitCount);
2655 
2656  copy_generic_path_info(&plan->plan, (Path *) best_path);
2657 
2658  return plan;
2659 }
Plan plan
Definition: plannodes.h:971
Node * limitOffset
Definition: pathnodes.h:1796
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:5047
Path * subpath
Definition: pathnodes.h:1795
Limit * make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount)
Definition: createplan.c:6557
Node * limitCount
Definition: pathnodes.h:1797

◆ create_lockrows_plan()

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

Definition at line 2560 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().

2562 {
2563  LockRows *plan;
2564  Plan *subplan;
2565 
2566  /* LockRows doesn't project, so tlist requirements pass through */
2567  subplan = create_plan_recurse(root, best_path->subpath, flags);
2568 
2569  plan = make_lockrows(subplan, best_path->rowMarks, best_path->epqParam);
2570 
2571  copy_generic_path_info(&plan->plan, (Path *) best_path);
2572 
2573  return plan;
2574 }
Plan plan
Definition: plannodes.h:957
List * rowMarks
Definition: pathnodes.h:1760
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:5047
Path * subpath
Definition: pathnodes.h:1759
static LockRows * make_lockrows(Plan *lefttree, List *rowMarks, int epqParam)
Definition: createplan.c:6536

◆ create_material_plan()

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

Definition at line 1486 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().

1487 {
1488  Material *plan;
1489  Plan *subplan;
1490 
1491  /*
1492  * We don't want any excess columns in the materialized tuples, so request
1493  * a smaller tlist. Otherwise, since Material doesn't project, tlist
1494  * requirements pass through.
1495  */
1496  subplan = create_plan_recurse(root, best_path->subpath,
1497  flags | CP_SMALL_TLIST);
1498 
1499  plan = make_material(subplan);
1500 
1501  copy_generic_path_info(&plan->plan, (Path *) best_path);
1502 
1503  return plan;
1504 }
#define CP_SMALL_TLIST
Definition: createplan.c:69
Path * subpath
Definition: pathnodes.h:1428
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:6138
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5047
Plan plan
Definition: plannodes.h:760

◆ create_merge_append_plan()

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

Definition at line 1274 of file createplan.c.

References MergeAppend::apprelids, 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().

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

◆ create_mergejoin_plan()

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

Definition at line 4073 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().

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

◆ create_minmaxagg_plan()

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

Definition at line 2314 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().

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

◆ create_modifytable_plan()

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

Definition at line 2583 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().

2584 {
2585  ModifyTable *plan;
2586  List *subplans = NIL;
2587  ListCell *subpaths,
2588  *subroots;
2589 
2590  /* Build the plan for each input path */
2591  forboth(subpaths, best_path->subpaths,
2592  subroots, best_path->subroots)
2593  {
2594  Path *subpath = (Path *) lfirst(subpaths);
2595  PlannerInfo *subroot = (PlannerInfo *) lfirst(subroots);
2596  Plan *subplan;
2597 
2598  /*
2599  * In an inherited UPDATE/DELETE, reference the per-child modified
2600  * subroot while creating Plans from Paths for the child rel. This is
2601  * a kluge, but otherwise it's too hard to ensure that Plan creation
2602  * functions (particularly in FDWs) don't depend on the contents of
2603  * "root" matching what they saw at Path creation time. The main
2604  * downside is that creation functions for Plans that might appear
2605  * below a ModifyTable cannot expect to modify the contents of "root"
2606  * and have it "stick" for subsequent processing such as setrefs.c.
2607  * That's not great, but it seems better than the alternative.
2608  */
2609  subplan = create_plan_recurse(subroot, subpath, CP_EXACT_TLIST);
2610 
2611  /* Transfer resname/resjunk labeling, too, to keep executor happy */
2612  apply_tlist_labeling(subplan->targetlist, subroot->processed_tlist);
2613 
2614  subplans = lappend(subplans, subplan);
2615  }
2616 
2617  plan = make_modifytable(root,
2618  best_path->operation,
2619  best_path->canSetTag,
2620  best_path->nominalRelation,
2621  best_path->rootRelation,
2622  best_path->partColsUpdated,
2623  best_path->resultRelations,
2624  subplans,
2625  best_path->subroots,
2626  best_path->withCheckOptionLists,
2627  best_path->returningLists,
2628  best_path->rowMarks,
2629  best_path->onconflict,
2630  best_path->epqParam);
2631 
2632  copy_generic_path_info(&plan->plan, &best_path->path);
2633 
2634  return plan;
2635 }
#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:1783
OnConflictExpr * onconflict
Definition: pathnodes.h:1785
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:419
Index nominalRelation
Definition: pathnodes.h:1776
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:5047
bool partColsUpdated
Definition: pathnodes.h:1778
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:6618
List * lappend(List *list, void *datum)
Definition: list.c:322
#define lfirst(lc)
Definition: pg_list.h:190
Index rootRelation
Definition: pathnodes.h:1777
List * targetlist
Definition: plannodes.h:142
List * withCheckOptionLists
Definition: pathnodes.h:1782
CmdType operation
Definition: pathnodes.h:1774
List * resultRelations
Definition: pathnodes.h:1779
List * processed_tlist
Definition: pathnodes.h:325
#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 3646 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().

3648 {
3649  NamedTuplestoreScan *scan_plan;
3650  Index scan_relid = best_path->parent->relid;
3651  RangeTblEntry *rte;
3652 
3653  Assert(scan_relid > 0);
3654  rte = planner_rt_fetch(scan_relid, root);
3656 
3657  /* Sort clauses into best execution order */
3658  scan_clauses = order_qual_clauses(root, scan_clauses);
3659 
3660  /* Reduce RestrictInfo list to bare expressions; ignore pseudoconstants */
3661  scan_clauses = extract_actual_clauses(scan_clauses, false);
3662 
3663  /* Replace any outer-relation variables with nestloop params */
3664  if (best_path->param_info)
3665  {
3666  scan_clauses = (List *)
3667  replace_nestloop_params(root, (Node *) scan_clauses);
3668  }
3669 
3670  scan_plan = make_namedtuplestorescan(tlist, scan_clauses, scan_relid,
3671  rte->enrname);
3672 
3673  copy_generic_path_info(&scan_plan->scan.plan, best_path);
3674 
3675  return scan_plan;
3676 }
Plan plan
Definition: plannodes.h:344
static Node * replace_nestloop_params(PlannerInfo *root, Node *expr)
Definition: createplan.c:4569
ParamPathInfo * param_info
Definition: pathnodes.h:1119
Definition: nodes.h:525
static List * order_qual_clauses(PlannerInfo *root, List *clauses)
Definition: createplan.c:4953
static void copy_generic_path_info(Plan *dest, Path *src)
Definition: createplan.c:5047
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:373
RelOptInfo * parent
Definition: pathnodes.h:1116
char * enrname
Definition: parsenodes.h:1106
Index relid
Definition: pathnodes.h:671
static NamedTuplestoreScan * make_namedtuplestorescan(List *qptlist, List *qpqual, Index scanrelid, char *enrname)
Definition: createplan.c:5395
unsigned int Index
Definition: c.h:476
#define Assert(condition)
Definition: c.h:739
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 3997 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().

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

◆ 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:576
List * plan_params
Definition: pathnodes.h:193
Relids curOuterRels
Definition: pathnodes.h:357
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:358
#define Assert(condition)
Definition: c.h:739
void SS_attach_initplans(PlannerInfo *root, Plan *plan)
Definition: subselect.c:2120
List * targetlist
Definition: plannodes.h:142
#define elog(elevel,...)
Definition: elog.h:228
List * processed_tlist
Definition: pathnodes.h:325
#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:1514
static Result * create_minmaxagg_plan(PlannerInfo *root, MinMaxAggPath *best_path)
Definition: createplan.c:2314
Definition: nodes.h:78
static Group * create_group_plan(PlannerInfo *root, GroupPath *best_path)
Definition: createplan.c:2003
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
static Plan * create_projection_plan(PlannerInfo *root, ProjectionPath *best_path, int flags)
Definition: createplan.c:1807
Definition: nodes.h:80
static Sort * create_sort_plan(PlannerInfo *root, SortPath *best_path, int flags)
Definition: createplan.c:1968
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:2560
static ProjectSet * create_project_set_plan(PlannerInfo *root, ProjectSetPath *best_path)
Definition: createplan.c:1460
static RecursiveUnion * create_recursiveunion_plan(PlannerInfo *root, RecursiveUnionPath *best_path)
Definition: createplan.c:2524
static Agg * create_agg_plan(PlannerInfo *root, AggPath *best_path)
Definition: createplan.c:2070
static Unique * create_upper_unique_plan(PlannerInfo *root, UpperUniquePath *best_path, int flags)
Definition: createplan.c:2042
Definition: nodes.h:49
Definition: nodes.h:76
static ModifyTable * create_modifytable_plan(PlannerInfo *root, ModifyTablePath *best_path)
Definition: createplan.c:2583
NodeTag pathtype
Definition: pathnodes.h:1114
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:3288
static GatherMerge * create_gather_merge_plan(PlannerInfo *root, GatherMergePath *best_path)
Definition: createplan.c:1748
static SetOp * create_setop_plan(PlannerInfo *root, SetOpPath *best_path, int flags)
Definition: createplan.c:2488
#define Assert(condition)
Definition: c.h:739
static Gather * create_gather_plan(PlannerInfo *root, GatherPath *best_path)
Definition: createplan.c:1712
static WindowAgg * create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
Definition: createplan.c:2383
static Material * create_material_plan(PlannerInfo *root, MaterialPath *best_path, int flags)
Definition: createplan.c:1486
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:2153
#define elog(elevel,...)
Definition: elog.h:228
static Limit * create_limit_plan(PlannerInfo *root, LimitPath *best_path, int flags)
Definition: createplan.c:2644
static Plan * create_merge_append_plan(PlannerInfo *root, MergeAppendPath *best_path, int fla