PostgreSQL Source Code  git master
planner.h File Reference
#include "nodes/pathnodes.h"
#include "nodes/plannodes.h"
Include dependency graph for planner.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef PlannedStmt *(* planner_hook_type) (Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
 
typedef void(* create_upper_paths_hook_type) (PlannerInfo *root, UpperRelationKind stage, RelOptInfo *input_rel, RelOptInfo *output_rel, void *extra)
 

Functions

PlannedStmtstandard_planner (Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
 
PlannerInfosubquery_planner (PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction)
 
RowMarkType select_rowmark_type (RangeTblEntry *rte, LockClauseStrength strength)
 
bool limit_needed (Query *parse)
 
void mark_partial_aggref (Aggref *agg, AggSplit aggsplit)
 
Pathget_cheapest_fractional_path (RelOptInfo *rel, double tuple_fraction)
 
Exprpreprocess_phv_expression (PlannerInfo *root, Expr *expr)
 

Variables

PGDLLIMPORT planner_hook_type planner_hook
 
PGDLLIMPORT create_upper_paths_hook_type create_upper_paths_hook
 

Typedef Documentation

◆ create_upper_paths_hook_type

typedef void(* create_upper_paths_hook_type) (PlannerInfo *root, UpperRelationKind stage, RelOptInfo *input_rel, RelOptInfo *output_rel, void *extra)

Definition at line 33 of file planner.h.

◆ planner_hook_type

typedef PlannedStmt*(* planner_hook_type) (Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)

Definition at line 26 of file planner.h.

Function Documentation

◆ get_cheapest_fractional_path()

Path* get_cheapest_fractional_path ( RelOptInfo rel,
double  tuple_fraction 
)

Definition at line 5887 of file planner.c.

References RelOptInfo::cheapest_total_path, compare_fractional_path_costs(), lfirst, RelOptInfo::pathlist, and Path::rows.

Referenced by make_subplan(), recurse_set_operations(), and standard_planner().

5888 {
5889  Path *best_path = rel->cheapest_total_path;
5890  ListCell *l;
5891 
5892  /* If all tuples will be retrieved, just return the cheapest-total path */
5893  if (tuple_fraction <= 0.0)
5894  return best_path;
5895 
5896  /* Convert absolute # of tuples to a fraction; no need to clamp to 0..1 */
5897  if (tuple_fraction >= 1.0 && best_path->rows > 0)
5898  tuple_fraction /= best_path->rows;
5899 
5900  foreach(l, rel->pathlist)
5901  {
5902  Path *path = (Path *) lfirst(l);
5903 
5904  if (path == rel->cheapest_total_path ||
5905  compare_fractional_path_costs(best_path, path, tuple_fraction) <= 0)
5906  continue;
5907 
5908  best_path = path;
5909  }
5910 
5911  return best_path;
5912 }
struct Path * cheapest_total_path
Definition: pathnodes.h:661
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1127
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
Definition: pathnode.c:117
List * pathlist
Definition: pathnodes.h:657

◆ limit_needed()

bool limit_needed ( Query parse)

Definition at line 3011 of file planner.c.

References DatumGetInt64, IsA, Query::limitCount, and Query::limitOffset.

Referenced by grouping_planner(), and set_rel_consider_parallel().

3012 {
3013  Node *node;
3014 
3015  node = parse->limitCount;
3016  if (node)
3017  {
3018  if (IsA(node, Const))
3019  {
3020  /* NULL indicates LIMIT ALL, ie, no limit */
3021  if (!((Const *) node)->constisnull)
3022  return true; /* LIMIT with a constant value */
3023  }
3024  else
3025  return true; /* non-constant LIMIT */
3026  }
3027 
3028  node = parse->limitOffset;
3029  if (node)
3030  {
3031  if (IsA(node, Const))
3032  {
3033  /* Treat NULL as no offset; the executor would too */
3034  if (!((Const *) node)->constisnull)
3035  {
3036  int64 offset = DatumGetInt64(((Const *) node)->constvalue);
3037 
3038  if (offset != 0)
3039  return true; /* OFFSET with a nonzero value */
3040  }
3041  }
3042  else
3043  return true; /* non-constant OFFSET */
3044  }
3045 
3046  return false; /* don't need a Limit plan node */
3047 }
Node * limitOffset
Definition: parsenodes.h:160
#define IsA(nodeptr, _type_)
Definition: nodes.h:577
Definition: nodes.h:526
#define DatumGetInt64(X)
Definition: postgres.h:607
Node * limitCount
Definition: parsenodes.h:161

◆ mark_partial_aggref()

void mark_partial_aggref ( Aggref agg,
AggSplit  aggsplit 
)

Definition at line 5287 of file planner.c.

References Aggref::aggsplit, AGGSPLIT_SIMPLE, Aggref::aggtranstype, Aggref::aggtype, Assert, DO_AGGSPLIT_SERIALIZE, DO_AGGSPLIT_SKIPFINAL, and OidIsValid.

Referenced by convert_combining_aggrefs(), and make_partial_grouping_target().

5288 {
5289  /* aggtranstype should be computed by this point */
5291  /* ... but aggsplit should still be as the parser left it */
5292  Assert(agg->aggsplit == AGGSPLIT_SIMPLE);
5293 
5294  /* Mark the Aggref with the intended partial-aggregation mode */
5295  agg->aggsplit = aggsplit;
5296 
5297  /*
5298  * Adjust result type if needed. Normally, a partial aggregate returns
5299  * the aggregate's transition type; but if that's INTERNAL and we're
5300  * serializing, it returns BYTEA instead.
5301  */
5302  if (DO_AGGSPLIT_SKIPFINAL(aggsplit))
5303  {
5304  if (agg->aggtranstype == INTERNALOID && DO_AGGSPLIT_SERIALIZE(aggsplit))
5305  agg->aggtype = BYTEAOID;
5306  else
5307  agg->aggtype = agg->aggtranstype;
5308  }
5309 }
#define OidIsValid(objectId)
Definition: c.h:644
#define DO_AGGSPLIT_SERIALIZE(as)
Definition: nodes.h:790
#define Assert(condition)
Definition: c.h:738
AggSplit aggsplit
Definition: primnodes.h:328
#define DO_AGGSPLIT_SKIPFINAL(as)
Definition: nodes.h:789
Oid aggtranstype
Definition: primnodes.h:316
Oid aggtype
Definition: primnodes.h:313

◆ preprocess_phv_expression()

Expr* preprocess_phv_expression ( PlannerInfo root,
Expr expr 
)

Definition at line 1184 of file planner.c.

References EXPRKIND_PHV, and preprocess_expression().

Referenced by extract_lateral_references().

1185 {
1186  return (Expr *) preprocess_expression(root, (Node *) expr, EXPRKIND_PHV);
1187 }
Definition: nodes.h:526
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
Definition: planner.c:1049
#define EXPRKIND_PHV
Definition: planner.c:89

◆ select_rowmark_type()

RowMarkType select_rowmark_type ( RangeTblEntry rte,
LockClauseStrength  strength 
)

Definition at line 2760 of file planner.c.

References elog, ERROR, GetFdwRoutineByRelId(), FdwRoutine::GetForeignRowMarkType, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, LCS_NONE, RangeTblEntry::relid, RangeTblEntry::relkind, ROW_MARK_COPY, ROW_MARK_EXCLUSIVE, ROW_MARK_KEYSHARE, ROW_MARK_NOKEYEXCLUSIVE, ROW_MARK_REFERENCE, ROW_MARK_SHARE, RTE_RELATION, and RangeTblEntry::rtekind.

Referenced by expand_single_inheritance_child(), and preprocess_rowmarks().

2761 {
2762  if (rte->rtekind != RTE_RELATION)
2763  {
2764  /* If it's not a table at all, use ROW_MARK_COPY */
2765  return ROW_MARK_COPY;
2766  }
2767  else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2768  {
2769  /* Let the FDW select the rowmark type, if it wants to */
2770  FdwRoutine *fdwroutine = GetFdwRoutineByRelId(rte->relid);
2771 
2772  if (fdwroutine->GetForeignRowMarkType != NULL)
2773  return fdwroutine->GetForeignRowMarkType(rte, strength);
2774  /* Otherwise, use ROW_MARK_COPY by default */
2775  return ROW_MARK_COPY;
2776  }
2777  else
2778  {
2779  /* Regular table, apply the appropriate lock type */
2780  switch (strength)
2781  {
2782  case LCS_NONE:
2783 
2784  /*
2785  * We don't need a tuple lock, only the ability to re-fetch
2786  * the row.
2787  */
2788  return ROW_MARK_REFERENCE;
2789  break;
2790  case LCS_FORKEYSHARE:
2791  return ROW_MARK_KEYSHARE;
2792  break;
2793  case LCS_FORSHARE:
2794  return ROW_MARK_SHARE;
2795  break;
2796  case LCS_FORNOKEYUPDATE:
2797  return ROW_MARK_NOKEYEXCLUSIVE;
2798  break;
2799  case LCS_FORUPDATE:
2800  return ROW_MARK_EXCLUSIVE;
2801  break;
2802  }
2803  elog(ERROR, "unrecognized LockClauseStrength %d", (int) strength);
2804  return ROW_MARK_EXCLUSIVE; /* keep compiler quiet */
2805  }
2806 }
#define ERROR
Definition: elog.h:43
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition: foreign.c:404
GetForeignRowMarkType_function GetForeignRowMarkType
Definition: fdwapi.h:224
RTEKind rtekind
Definition: parsenodes.h:975
#define elog(elevel,...)
Definition: elog.h:214

◆ standard_planner()

PlannedStmt* standard_planner ( Query parse,
const char *  query_string,
int  cursorOptions,
ParamListInfo  boundParams 
)

Definition at line 280 of file planner.c.

References PlannedStmt::appendRelations, PlannerGlobal::appendRelations, Assert, PlannerGlobal::boundParams, PlannedStmt::canSetTag, Query::canSetTag, CMD_SELECT, PlannedStmt::commandType, Query::commandType, create_plan(), CURSOR_OPT_FAST_PLAN, CURSOR_OPT_PARALLEL_OK, CURSOR_OPT_SCROLL, cursor_tuple_fraction, PlannedStmt::dependsOnRole, PlannerGlobal::dependsOnRole, DestroyPartitionDirectory(), ExecSupportsBackwardScan(), fetch_upper_rel(), PlannerGlobal::finalrowmarks, PlannerGlobal::finalrtable, forboth, force_parallel_mode, FORCE_PARALLEL_OFF, FORCE_PARALLEL_REGRESS, get_cheapest_fractional_path(), PlannerInfo::glob, PlannedStmt::hasModifyingCTE, Query::hasModifyingCTE, PlannedStmt::hasReturning, Plan::initPlan, PlannedStmt::invalItems, PlannerGlobal::invalItems, Gather::invisible, IsParallelWorker, IsUnderPostmaster, jit_above_cost, jit_enabled, jit_expressions, jit_inline_above_cost, jit_optimize_above_cost, jit_tuple_deforming, PlannedStmt::jitFlags, PlannerGlobal::lastPHId, PlannerGlobal::lastPlanNodeId, PlannerGlobal::lastRowMarkId, Plan::lefttree, lfirst, lfirst_node, list_length(), makeNode, materialize_finished_plan(), max_parallel_hazard(), max_parallel_workers_per_gather, PlannerGlobal::maxParallelHazard, NIL, Gather::num_workers, Plan::parallel_aware, Plan::parallel_safe, parallel_setup_cost, parallel_tuple_cost, PlannedStmt::parallelModeNeeded, PlannerGlobal::parallelModeNeeded, PlannerGlobal::parallelModeOK, PlannedStmt::paramExecTypes, PlannerGlobal::paramExecTypes, PlannerGlobal::partition_directory, PGJIT_DEFORM, PGJIT_EXPR, PGJIT_INLINE, PGJIT_NONE, PGJIT_OPT3, PGJIT_PERFORM, Gather::plan, Plan::plan_rows, Plan::plan_width, PlannedStmt::planTree, Plan::qual, PlannedStmt::queryId, Query::queryId, PlannedStmt::relationOids, PlannerGlobal::relationOids, Gather::rescan_param, PlannedStmt::resultRelations, PlannerGlobal::resultRelations, Query::returningList, PlannedStmt::rewindPlanIDs, PlannerGlobal::rewindPlanIDs, Plan::righttree, PlannedStmt::rootResultRelations, PlannerGlobal::rootResultRelations, PlannedStmt::rowMarks, PlannedStmt::rtable, set_plan_references(), Gather::single_copy, SS_finalize_plan(), Plan::startup_cost, PlannedStmt::stmt_len, Query::stmt_len, PlannedStmt::stmt_location, Query::stmt_location, PlannedStmt::subplans, PlannerGlobal::subplans, subquery_planner(), PlannerGlobal::subroots, Plan::targetlist, Plan::total_cost, PlannedStmt::transientPlan, PlannerGlobal::transientPlan, UPPERREL_FINAL, PlannedStmt::utilityStmt, and Query::utilityStmt.

Referenced by planner().

282 {
283  PlannedStmt *result;
284  PlannerGlobal *glob;
285  double tuple_fraction;
286  PlannerInfo *root;
287  RelOptInfo *final_rel;
288  Path *best_path;
289  Plan *top_plan;
290  ListCell *lp,
291  *lr;
292 
293  /*
294  * Set up global state for this planner invocation. This data is needed
295  * across all levels of sub-Query that might exist in the given command,
296  * so we keep it in a separate struct that's linked to by each per-Query
297  * PlannerInfo.
298  */
299  glob = makeNode(PlannerGlobal);
300 
301  glob->boundParams = boundParams;
302  glob->subplans = NIL;
303  glob->subroots = NIL;
304  glob->rewindPlanIDs = NULL;
305  glob->finalrtable = NIL;
306  glob->finalrowmarks = NIL;
307  glob->resultRelations = NIL;
308  glob->rootResultRelations = NIL;
309  glob->appendRelations = NIL;
310  glob->relationOids = NIL;
311  glob->invalItems = NIL;
312  glob->paramExecTypes = NIL;
313  glob->lastPHId = 0;
314  glob->lastRowMarkId = 0;
315  glob->lastPlanNodeId = 0;
316  glob->transientPlan = false;
317  glob->dependsOnRole = false;
318 
319  /*
320  * Assess whether it's feasible to use parallel mode for this query. We
321  * can't do this in a standalone backend, or if the command will try to
322  * modify any data, or if this is a cursor operation, or if GUCs are set
323  * to values that don't permit parallelism, or if parallel-unsafe
324  * functions are present in the query tree.
325  *
326  * (Note that we do allow CREATE TABLE AS, SELECT INTO, and CREATE
327  * MATERIALIZED VIEW to use parallel plans, but as of now, only the leader
328  * backend writes into a completely new table. In the future, we can
329  * extend it to allow workers to write into the table. However, to allow
330  * parallel updates and deletes, we have to solve other problems,
331  * especially around combo CIDs.)
332  *
333  * For now, we don't try to use parallel mode if we're running inside a
334  * parallel worker. We might eventually be able to relax this
335  * restriction, but for now it seems best not to have parallel workers
336  * trying to create their own parallel workers.
337  */
338  if ((cursorOptions & CURSOR_OPT_PARALLEL_OK) != 0 &&
340  parse->commandType == CMD_SELECT &&
341  !parse->hasModifyingCTE &&
343  !IsParallelWorker())
344  {
345  /* all the cheap tests pass, so scan the query tree */
346  glob->maxParallelHazard = max_parallel_hazard(parse);
347  glob->parallelModeOK = (glob->maxParallelHazard != PROPARALLEL_UNSAFE);
348  }
349  else
350  {
351  /* skip the query tree scan, just assume it's unsafe */
352  glob->maxParallelHazard = PROPARALLEL_UNSAFE;
353  glob->parallelModeOK = false;
354  }
355 
356  /*
357  * glob->parallelModeNeeded is normally set to false here and changed to
358  * true during plan creation if a Gather or Gather Merge plan is actually
359  * created (cf. create_gather_plan, create_gather_merge_plan).
360  *
361  * However, if force_parallel_mode = on or force_parallel_mode = regress,
362  * then we impose parallel mode whenever it's safe to do so, even if the
363  * final plan doesn't use parallelism. It's not safe to do so if the
364  * query contains anything parallel-unsafe; parallelModeOK will be false
365  * in that case. Note that parallelModeOK can't change after this point.
366  * Otherwise, everything in the query is either parallel-safe or
367  * parallel-restricted, and in either case it should be OK to impose
368  * parallel-mode restrictions. If that ends up breaking something, then
369  * either some function the user included in the query is incorrectly
370  * labelled as parallel-safe or parallel-restricted when in reality it's
371  * parallel-unsafe, or else the query planner itself has a bug.
372  */
373  glob->parallelModeNeeded = glob->parallelModeOK &&
375 
376  /* Determine what fraction of the plan is likely to be scanned */
377  if (cursorOptions & CURSOR_OPT_FAST_PLAN)
378  {
379  /*
380  * We have no real idea how many tuples the user will ultimately FETCH
381  * from a cursor, but it is often the case that he doesn't want 'em
382  * all, or would prefer a fast-start plan anyway so that he can
383  * process some of the tuples sooner. Use a GUC parameter to decide
384  * what fraction to optimize for.
385  */
386  tuple_fraction = cursor_tuple_fraction;
387 
388  /*
389  * We document cursor_tuple_fraction as simply being a fraction, which
390  * means the edge cases 0 and 1 have to be treated specially here. We
391  * convert 1 to 0 ("all the tuples") and 0 to a very small fraction.
392  */
393  if (tuple_fraction >= 1.0)
394  tuple_fraction = 0.0;
395  else if (tuple_fraction <= 0.0)
396  tuple_fraction = 1e-10;
397  }
398  else
399  {
400  /* Default assumption is we need all the tuples */
401  tuple_fraction = 0.0;
402  }
403 
404  /* primary planning entry point (may recurse for subqueries) */
405  root = subquery_planner(glob, parse, NULL,
406  false, tuple_fraction);
407 
408  /* Select best Path and turn it into a Plan */
409  final_rel = fetch_upper_rel(root, UPPERREL_FINAL, NULL);
410  best_path = get_cheapest_fractional_path(final_rel, tuple_fraction);
411 
412  top_plan = create_plan(root, best_path);
413 
414  /*
415  * If creating a plan for a scrollable cursor, make sure it can run
416  * backwards on demand. Add a Material node at the top at need.
417  */
418  if (cursorOptions & CURSOR_OPT_SCROLL)
419  {
420  if (!ExecSupportsBackwardScan(top_plan))
421  top_plan = materialize_finished_plan(top_plan);
422  }
423 
424  /*
425  * Optionally add a Gather node for testing purposes, provided this is
426  * actually a safe thing to do.
427  */
429  {
430  Gather *gather = makeNode(Gather);
431 
432  /*
433  * If there are any initPlans attached to the formerly-top plan node,
434  * move them up to the Gather node; same as we do for Material node in
435  * materialize_finished_plan.
436  */
437  gather->plan.initPlan = top_plan->initPlan;
438  top_plan->initPlan = NIL;
439 
440  gather->plan.targetlist = top_plan->targetlist;
441  gather->plan.qual = NIL;
442  gather->plan.lefttree = top_plan;
443  gather->plan.righttree = NULL;
444  gather->num_workers = 1;
445  gather->single_copy = true;
447 
448  /*
449  * Since this Gather has no parallel-aware descendants to signal to,
450  * we don't need a rescan Param.
451  */
452  gather->rescan_param = -1;
453 
454  /*
455  * Ideally we'd use cost_gather here, but setting up dummy path data
456  * to satisfy it doesn't seem much cleaner than knowing what it does.
457  */
458  gather->plan.startup_cost = top_plan->startup_cost +
460  gather->plan.total_cost = top_plan->total_cost +
462  gather->plan.plan_rows = top_plan->plan_rows;
463  gather->plan.plan_width = top_plan->plan_width;
464  gather->plan.parallel_aware = false;
465  gather->plan.parallel_safe = false;
466 
467  /* use parallel mode for parallel plans. */
468  root->glob->parallelModeNeeded = true;
469 
470  top_plan = &gather->plan;
471  }
472 
473  /*
474  * If any Params were generated, run through the plan tree and compute
475  * each plan node's extParam/allParam sets. Ideally we'd merge this into
476  * set_plan_references' tree traversal, but for now it has to be separate
477  * because we need to visit subplans before not after main plan.
478  */
479  if (glob->paramExecTypes != NIL)
480  {
481  Assert(list_length(glob->subplans) == list_length(glob->subroots));
482  forboth(lp, glob->subplans, lr, glob->subroots)
483  {
484  Plan *subplan = (Plan *) lfirst(lp);
485  PlannerInfo *subroot = lfirst_node(PlannerInfo, lr);
486 
487  SS_finalize_plan(subroot, subplan);
488  }
489  SS_finalize_plan(root, top_plan);
490  }
491 
492  /* final cleanup of the plan */
493  Assert(glob->finalrtable == NIL);
494  Assert(glob->finalrowmarks == NIL);
495  Assert(glob->resultRelations == NIL);
496  Assert(glob->rootResultRelations == NIL);
497  Assert(glob->appendRelations == NIL);
498  top_plan = set_plan_references(root, top_plan);
499  /* ... and the subplans (both regular subplans and initplans) */
500  Assert(list_length(glob->subplans) == list_length(glob->subroots));
501  forboth(lp, glob->subplans, lr, glob->subroots)
502  {
503  Plan *subplan = (Plan *) lfirst(lp);
504  PlannerInfo *subroot = lfirst_node(PlannerInfo, lr);
505 
506  lfirst(lp) = set_plan_references(subroot, subplan);
507  }
508 
509  /* build the PlannedStmt result */
510  result = makeNode(PlannedStmt);
511 
512  result->commandType = parse->commandType;
513  result->queryId = parse->queryId;
514  result->hasReturning = (parse->returningList != NIL);
515  result->hasModifyingCTE = parse->hasModifyingCTE;
516  result->canSetTag = parse->canSetTag;
517  result->transientPlan = glob->transientPlan;
518  result->dependsOnRole = glob->dependsOnRole;
519  result->parallelModeNeeded = glob->parallelModeNeeded;
520  result->planTree = top_plan;
521  result->rtable = glob->finalrtable;
522  result->resultRelations = glob->resultRelations;
524  result->appendRelations = glob->appendRelations;
525  result->subplans = glob->subplans;
526  result->rewindPlanIDs = glob->rewindPlanIDs;
527  result->rowMarks = glob->finalrowmarks;
528  result->relationOids = glob->relationOids;
529  result->invalItems = glob->invalItems;
530  result->paramExecTypes = glob->paramExecTypes;
531  /* utilityStmt should be null, but we might as well copy it */
532  result->utilityStmt = parse->utilityStmt;
533  result->stmt_location = parse->stmt_location;
534  result->stmt_len = parse->stmt_len;
535 
536  result->jitFlags = PGJIT_NONE;
537  if (jit_enabled && jit_above_cost >= 0 &&
538  top_plan->total_cost > jit_above_cost)
539  {
540  result->jitFlags |= PGJIT_PERFORM;
541 
542  /*
543  * Decide how much effort should be put into generating better code.
544  */
545  if (jit_optimize_above_cost >= 0 &&
547  result->jitFlags |= PGJIT_OPT3;
548  if (jit_inline_above_cost >= 0 &&
549  top_plan->total_cost > jit_inline_above_cost)
550  result->jitFlags |= PGJIT_INLINE;
551 
552  /*
553  * Decide which operations should be JITed.
554  */
555  if (jit_expressions)
556  result->jitFlags |= PGJIT_EXPR;
558  result->jitFlags |= PGJIT_DEFORM;
559  }
560 
561  if (glob->partition_directory != NULL)
563 
564  return result;
565 }
char maxParallelHazard
Definition: pathnodes.h:147
bool dependsOnRole
Definition: plannodes.h:58
List * paramExecTypes
Definition: plannodes.h:90
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:143
double plan_rows
Definition: plannodes.h:129
#define PGJIT_EXPR
Definition: jit.h:23
#define PGJIT_NONE
Definition: jit.h:19
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:419
int stmt_location
Definition: parsenodes.h:180
List * relationOids
Definition: plannodes.h:86
int lastPlanNodeId
Definition: pathnodes.h:137
List * resultRelations
Definition: pathnodes.h:121
List * appendRelations
Definition: pathnodes.h:125
double parallel_setup_cost
Definition: costsize.c:117
Node * utilityStmt
Definition: parsenodes.h:120
bool transientPlan
Definition: plannodes.h:56
int stmt_len
Definition: plannodes.h:96
char max_parallel_hazard(Query *parse)
Definition: clauses.c:837
struct Plan * planTree
Definition: plannodes.h:64
List * invalItems
Definition: plannodes.h:88
List * rootResultRelations
Definition: pathnodes.h:123
Plan * create_plan(PlannerInfo *root, Path *best_path)
Definition: createplan.c:313
bool dependsOnRole
Definition: pathnodes.h:141
struct Plan * righttree
Definition: plannodes.h:145
#define PGJIT_OPT3
Definition: jit.h:21
bool parallelModeNeeded
Definition: pathnodes.h:145
bool jit_enabled
Definition: jit.c:32
List * paramExecTypes
Definition: pathnodes.h:131
void DestroyPartitionDirectory(PartitionDirectory pdir)
Definition: partdesc.c:344
Plan plan
Definition: plannodes.h:876
bool single_copy
Definition: plannodes.h:879
bool parallelModeOK
Definition: pathnodes.h:143
Bitmapset * rewindPlanIDs
Definition: pathnodes.h:115
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
Definition: relnode.c:1177
#define lfirst_node(type, lc)
Definition: pg_list.h:193
int stmt_location
Definition: plannodes.h:95
List * subplans
Definition: pathnodes.h:111
Cost startup_cost
Definition: plannodes.h:123
PlannerGlobal * glob
Definition: pathnodes.h:181
bool IsUnderPostmaster
Definition: globals.c:109
bool hasReturning
Definition: plannodes.h:50
Plan * materialize_finished_plan(Plan *subplan)
Definition: createplan.c:6162
List * rootResultRelations
Definition: plannodes.h:75
Node * utilityStmt
Definition: plannodes.h:92
bool parallel_aware
Definition: plannodes.h:135
int jitFlags
Definition: plannodes.h:62
double cursor_tuple_fraction
Definition: planner.c:69
bool jit_expressions
Definition: jit.c:36
List * returningList
Definition: parsenodes.h:146
#define IsParallelWorker()
Definition: parallel.h:61
uint64 queryId
Definition: parsenodes.h:116
List * invalItems
Definition: pathnodes.h:129
bool canSetTag
Definition: plannodes.h:54
CmdType commandType
Definition: plannodes.h:46
#define CURSOR_OPT_FAST_PLAN
Definition: parsenodes.h:2710
double jit_above_cost
Definition: jit.c:39
bool ExecSupportsBackwardScan(Plan *node)
Definition: execAmi.c:494
Index lastPHId
Definition: pathnodes.h:133
#define PGJIT_INLINE
Definition: jit.h:22
bool jit_tuple_deforming
Definition: jit.c:38
List * rowMarks
Definition: plannodes.h:84
int num_workers
Definition: plannodes.h:877
double jit_inline_above_cost
Definition: jit.c:40
CmdType commandType
Definition: parsenodes.h:112
#define makeNode(_type_)
Definition: nodes.h:574
List * subplans
Definition: plannodes.h:79
int plan_width
Definition: plannodes.h:130
int force_parallel_mode
Definition: planner.c:70
ParamListInfo boundParams
Definition: pathnodes.h:109
#define Assert(condition)
Definition: c.h:738
#define lfirst(lc)
Definition: pg_list.h:190
Bitmapset * rewindPlanIDs
Definition: plannodes.h:82
bool hasModifyingCTE
Definition: plannodes.h:52
bool canSetTag
Definition: parsenodes.h:118
int rescan_param
Definition: plannodes.h:878
#define PGJIT_PERFORM
Definition: jit.h:20
static int list_length(const List *l)
Definition: pg_list.h:169
List * relationOids
Definition: pathnodes.h:127
List * subroots
Definition: pathnodes.h:113
List * rtable
Definition: plannodes.h:66
struct Plan * lefttree
Definition: plannodes.h:144
double jit_optimize_above_cost
Definition: jit.c:41
List * targetlist
Definition: plannodes.h:142
bool invisible
Definition: plannodes.h:880
e
Definition: preproc-init.c:82
List * finalrtable
Definition: pathnodes.h:117
#define CURSOR_OPT_PARALLEL_OK
Definition: parsenodes.h:2713
Index lastRowMarkId
Definition: pathnodes.h:135
uint64 queryId
Definition: plannodes.h:48
List * resultRelations
Definition: plannodes.h:69
bool parallelModeNeeded
Definition: plannodes.h:60
List * initPlan
Definition: plannodes.h:146
#define CURSOR_OPT_SCROLL
Definition: parsenodes.h:2705
Cost total_cost
Definition: plannodes.h:124
bool hasModifyingCTE
Definition: parsenodes.h:131
bool parallel_safe
Definition: plannodes.h:136
Plan * set_plan_references(PlannerInfo *root, Plan *plan)
Definition: setrefs.c:223
#define PGJIT_DEFORM
Definition: jit.h:24
PartitionDirectory partition_directory
Definition: pathnodes.h:149
void SS_finalize_plan(PlannerInfo *root, Plan *plan)
Definition: subselect.c:2135
int max_parallel_workers_per_gather
Definition: costsize.c:123
List * finalrowmarks
Definition: pathnodes.h:119
int stmt_len
Definition: parsenodes.h:181
PlannerInfo * subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction)
Definition: planner.c:597
List * appendRelations
Definition: plannodes.h:77
Path * get_cheapest_fractional_path(RelOptInfo *rel, double tuple_fraction)
Definition: planner.c:5887
bool transientPlan
Definition: pathnodes.h:139
double parallel_tuple_cost
Definition: costsize.c:116

◆ subquery_planner()

PlannerInfo* subquery_planner ( PlannerGlobal glob,
Query parse,
PlannerInfo parent_root,
bool  hasRecursion,
double  tuple_fraction 
)

Definition at line 597 of file planner.c.

References PlannerInfo::append_rel_list, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, assign_special_exec_param(), contain_agg_clause(), contain_subplans(), contain_volatile_functions(), copyObject, PlannerInfo::cte_plan_ids, Query::cteList, CurrentMemoryContext, PlannerInfo::ec_merging_done, WindowClause::endOffset, PlannerInfo::eq_classes, expression_returns_set(), EXPRKIND_APPINFO, EXPRKIND_ARBITER_ELEM, EXPRKIND_LIMIT, EXPRKIND_QUAL, EXPRKIND_RTFUNC, EXPRKIND_RTFUNC_LATERAL, EXPRKIND_TABLEFUNC, EXPRKIND_TABLEFUNC_LATERAL, EXPRKIND_TABLESAMPLE, EXPRKIND_TARGET, EXPRKIND_VALUES, EXPRKIND_VALUES_LATERAL, fetch_upper_rel(), flatten_join_alias_vars(), flatten_simple_union_all(), RangeTblEntry::functions, PlannerInfo::glob, Query::groupClause, PlannerInfo::grouping_map, grouping_planner(), Query::groupingSets, has_subclass(), PlannerInfo::hasHavingQual, PlannerInfo::hasJoinRTEs, PlannerInfo::hasLateralRTEs, PlannerInfo::hasPseudoConstantQuals, PlannerInfo::hasRecursion, Query::hasSubLinks, Query::hasTargetSRFs, Query::havingQual, RangeTblEntry::inh, inheritance_planner(), INHKIND_NONE, PlannerInfo::inhTargetKind, PlannerInfo::init_plans, IS_OUTER_JOIN, RangeTblEntry::joinaliasvars, Query::jointree, RangeTblEntry::jointype, lappend(), RangeTblEntry::lateral, lfirst, lfirst_node, Query::limitCount, Query::limitOffset, list_length(), makeNode, Max, PlannerInfo::minmax_aggs, PlannerInfo::multiexpr_params, NIL, PlannerInfo::non_recursive_path, Query::onConflict, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, PlannerInfo::outer_params, PlannerInfo::parent_root, parse(), PlannerInfo::parse, PlannerInfo::partColsUpdated, PlannerInfo::plan_params, PlannerInfo::planner_cxt, preprocess_expression(), preprocess_function_rtes(), preprocess_qual_conditions(), preprocess_rowmarks(), PlannerInfo::processed_tlist, pull_up_sublinks(), pull_up_subqueries(), WithCheckOption::qual, PlannerInfo::qual_security_level, FromExpr::quals, PlannerInfo::query_level, reduce_outer_joins(), RangeTblEntry::relid, remove_useless_groupby_columns(), remove_useless_result_rtes(), replace_empty_jointree(), Query::resultRelation, Query::returningList, PlannerInfo::rowMarks, rt_fetch, Query::rtable, RTE_FUNCTION, RTE_JOIN, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, set_cheapest(), Query::setOperations, SS_charge_for_initplans(), SS_identify_outer_params(), SS_process_ctes(), WindowClause::startOffset, RangeTblEntry::subquery, RangeTblEntry::tablefunc, RangeTblEntry::tablesample, Query::targetList, PlannerInfo::upper_rels, PlannerInfo::upper_targets, UPPERREL_FINAL, RangeTblEntry::values_lists, Query::windowClause, Query::withCheckOptions, and PlannerInfo::wt_param_id.

Referenced by make_subplan(), recurse_set_operations(), set_subquery_pathlist(), SS_process_ctes(), and standard_planner().

600 {
601  PlannerInfo *root;
602  List *newWithCheckOptions;
603  List *newHaving;
604  bool hasOuterJoins;
605  bool hasResultRTEs;
606  RelOptInfo *final_rel;
607  ListCell *l;
608 
609  /* Create a PlannerInfo data structure for this subquery */
610  root = makeNode(PlannerInfo);
611  root->parse = parse;
612  root->glob = glob;
613  root->query_level = parent_root ? parent_root->query_level + 1 : 1;
614  root->parent_root = parent_root;
615  root->plan_params = NIL;
616  root->outer_params = NULL;
618  root->init_plans = NIL;
619  root->cte_plan_ids = NIL;
620  root->multiexpr_params = NIL;
621  root->eq_classes = NIL;
622  root->ec_merging_done = false;
623  root->append_rel_list = NIL;
624  root->rowMarks = NIL;
625  memset(root->upper_rels, 0, sizeof(root->upper_rels));
626  memset(root->upper_targets, 0, sizeof(root->upper_targets));
627  root->processed_tlist = NIL;
628  root->grouping_map = NULL;
629  root->minmax_aggs = NIL;
630  root->qual_security_level = 0;
631  root->inhTargetKind = INHKIND_NONE;
632  root->hasRecursion = hasRecursion;
633  if (hasRecursion)
635  else
636  root->wt_param_id = -1;
637  root->non_recursive_path = NULL;
638  root->partColsUpdated = false;
639 
640  /*
641  * If there is a WITH list, process each WITH query and either convert it
642  * to RTE_SUBQUERY RTE(s) or build an initplan SubPlan structure for it.
643  */
644  if (parse->cteList)
645  SS_process_ctes(root);
646 
647  /*
648  * If the FROM clause is empty, replace it with a dummy RTE_RESULT RTE, so
649  * that we don't need so many special cases to deal with that situation.
650  */
651  replace_empty_jointree(parse);
652 
653  /*
654  * Look for ANY and EXISTS SubLinks in WHERE and JOIN/ON clauses, and try
655  * to transform them into joins. Note that this step does not descend
656  * into subqueries; if we pull up any subqueries below, their SubLinks are
657  * processed just before pulling them up.
658  */
659  if (parse->hasSubLinks)
660  pull_up_sublinks(root);
661 
662  /*
663  * Scan the rangetable for function RTEs, do const-simplification on them,
664  * and then inline them if possible (producing subqueries that might get
665  * pulled up next). Recursion issues here are handled in the same way as
666  * for SubLinks.
667  */
669 
670  /*
671  * Check to see if any subqueries in the jointree can be merged into this
672  * query.
673  */
674  pull_up_subqueries(root);
675 
676  /*
677  * If this is a simple UNION ALL query, flatten it into an appendrel. We
678  * do this now because it requires applying pull_up_subqueries to the leaf
679  * queries of the UNION ALL, which weren't touched above because they
680  * weren't referenced by the jointree (they will be after we do this).
681  */
682  if (parse->setOperations)
684 
685  /*
686  * Survey the rangetable to see what kinds of entries are present. We can
687  * skip some later processing if relevant SQL features are not used; for
688  * example if there are no JOIN RTEs we can avoid the expense of doing
689  * flatten_join_alias_vars(). This must be done after we have finished
690  * adding rangetable entries, of course. (Note: actually, processing of
691  * inherited or partitioned rels can cause RTEs for their child tables to
692  * get added later; but those must all be RTE_RELATION entries, so they
693  * don't invalidate the conclusions drawn here.)
694  */
695  root->hasJoinRTEs = false;
696  root->hasLateralRTEs = false;
697  hasOuterJoins = false;
698  hasResultRTEs = false;
699  foreach(l, parse->rtable)
700  {
702 
703  switch (rte->rtekind)
704  {
705  case RTE_RELATION:
706  if (rte->inh)
707  {
708  /*
709  * Check to see if the relation actually has any children;
710  * if not, clear the inh flag so we can treat it as a
711  * plain base relation.
712  *
713  * Note: this could give a false-positive result, if the
714  * rel once had children but no longer does. We used to
715  * be able to clear rte->inh later on when we discovered
716  * that, but no more; we have to handle such cases as
717  * full-fledged inheritance.
718  */
719  rte->inh = has_subclass(rte->relid);
720  }
721  break;
722  case RTE_JOIN:
723  root->hasJoinRTEs = true;
724  if (IS_OUTER_JOIN(rte->jointype))
725  hasOuterJoins = true;
726  break;
727  case RTE_RESULT:
728  hasResultRTEs = true;
729  break;
730  default:
731  /* No work here for other RTE types */
732  break;
733  }
734 
735  if (rte->lateral)
736  root->hasLateralRTEs = true;
737 
738  /*
739  * We can also determine the maximum security level required for any
740  * securityQuals now. Addition of inheritance-child RTEs won't affect
741  * this, because child tables don't have their own securityQuals; see
742  * expand_single_inheritance_child().
743  */
744  if (rte->securityQuals)
746  list_length(rte->securityQuals));
747  }
748 
749  /*
750  * Preprocess RowMark information. We need to do this after subquery
751  * pullup, so that all base relations are present.
752  */
753  preprocess_rowmarks(root);
754 
755  /*
756  * Set hasHavingQual to remember if HAVING clause is present. Needed
757  * because preprocess_expression will reduce a constant-true condition to
758  * an empty qual list ... but "HAVING TRUE" is not a semantic no-op.
759  */
760  root->hasHavingQual = (parse->havingQual != NULL);
761 
762  /* Clear this flag; might get set in distribute_qual_to_rels */
763  root->hasPseudoConstantQuals = false;
764 
765  /*
766  * Do expression preprocessing on targetlist and quals, as well as other
767  * random expressions in the querytree. Note that we do not need to
768  * handle sort/group expressions explicitly, because they are actually
769  * part of the targetlist.
770  */
771  parse->targetList = (List *)
772  preprocess_expression(root, (Node *) parse->targetList,
774 
775  /* Constant-folding might have removed all set-returning functions */
776  if (parse->hasTargetSRFs)
778 
779  newWithCheckOptions = NIL;
780  foreach(l, parse->withCheckOptions)
781  {
783 
784  wco->qual = preprocess_expression(root, wco->qual,
785  EXPRKIND_QUAL);
786  if (wco->qual != NULL)
787  newWithCheckOptions = lappend(newWithCheckOptions, wco);
788  }
789  parse->withCheckOptions = newWithCheckOptions;
790 
791  parse->returningList = (List *)
792  preprocess_expression(root, (Node *) parse->returningList,
794 
795  preprocess_qual_conditions(root, (Node *) parse->jointree);
796 
797  parse->havingQual = preprocess_expression(root, parse->havingQual,
798  EXPRKIND_QUAL);
799 
800  foreach(l, parse->windowClause)
801  {
803 
804  /* partitionClause/orderClause are sort/group expressions */
807  wc->endOffset = preprocess_expression(root, wc->endOffset,
809  }
810 
811  parse->limitOffset = preprocess_expression(root, parse->limitOffset,
813  parse->limitCount = preprocess_expression(root, parse->limitCount,
815 
816  if (parse->onConflict)
817  {
818  parse->onConflict->arbiterElems = (List *)
820  (Node *) parse->onConflict->arbiterElems,
822  parse->onConflict->arbiterWhere =
824  parse->onConflict->arbiterWhere,
825  EXPRKIND_QUAL);
826  parse->onConflict->onConflictSet = (List *)
828  (Node *) parse->onConflict->onConflictSet,
830  parse->onConflict->onConflictWhere =
832  parse->onConflict->onConflictWhere,
833  EXPRKIND_QUAL);
834  /* exclRelTlist contains only Vars, so no preprocessing needed */
835  }
836 
837  root->append_rel_list = (List *)
840 
841  /* Also need to preprocess expressions within RTEs */
842  foreach(l, parse->rtable)
843  {
845  int kind;
846  ListCell *lcsq;
847 
848  if (rte->rtekind == RTE_RELATION)
849  {
850  if (rte->tablesample)
851  rte->tablesample = (TableSampleClause *)
853  (Node *) rte->tablesample,
855  }
856  else if (rte->rtekind == RTE_SUBQUERY)
857  {
858  /*
859  * We don't want to do all preprocessing yet on the subquery's
860  * expressions, since that will happen when we plan it. But if it
861  * contains any join aliases of our level, those have to get
862  * expanded now, because planning of the subquery won't do it.
863  * That's only possible if the subquery is LATERAL.
864  */
865  if (rte->lateral && root->hasJoinRTEs)
866  rte->subquery = (Query *)
868  (Node *) rte->subquery);
869  }
870  else if (rte->rtekind == RTE_FUNCTION)
871  {
872  /* Preprocess the function expression(s) fully */
874  rte->functions = (List *)
875  preprocess_expression(root, (Node *) rte->functions, kind);
876  }
877  else if (rte->rtekind == RTE_TABLEFUNC)
878  {
879  /* Preprocess the function expression(s) fully */
881  rte->tablefunc = (TableFunc *)
882  preprocess_expression(root, (Node *) rte->tablefunc, kind);
883  }
884  else if (rte->rtekind == RTE_VALUES)
885  {
886  /* Preprocess the values lists fully */
888  rte->values_lists = (List *)
889  preprocess_expression(root, (Node *) rte->values_lists, kind);
890  }
891 
892  /*
893  * Process each element of the securityQuals list as if it were a
894  * separate qual expression (as indeed it is). We need to do it this
895  * way to get proper canonicalization of AND/OR structure. Note that
896  * this converts each element into an implicit-AND sublist.
897  */
898  foreach(lcsq, rte->securityQuals)
899  {
900  lfirst(lcsq) = preprocess_expression(root,
901  (Node *) lfirst(lcsq),
902  EXPRKIND_QUAL);
903  }
904  }
905 
906  /*
907  * Now that we are done preprocessing expressions, and in particular done
908  * flattening join alias variables, get rid of the joinaliasvars lists.
909  * They no longer match what expressions in the rest of the tree look
910  * like, because we have not preprocessed expressions in those lists (and
911  * do not want to; for example, expanding a SubLink there would result in
912  * a useless unreferenced subplan). Leaving them in place simply creates
913  * a hazard for later scans of the tree. We could try to prevent that by
914  * using QTW_IGNORE_JOINALIASES in every tree scan done after this point,
915  * but that doesn't sound very reliable.
916  */
917  if (root->hasJoinRTEs)
918  {
919  foreach(l, parse->rtable)
920  {
922 
923  rte->joinaliasvars = NIL;
924  }
925  }
926 
927  /*
928  * In some cases we may want to transfer a HAVING clause into WHERE. We
929  * cannot do so if the HAVING clause contains aggregates (obviously) or
930  * volatile functions (since a HAVING clause is supposed to be executed
931  * only once per group). We also can't do this if there are any nonempty
932  * grouping sets; moving such a clause into WHERE would potentially change
933  * the results, if any referenced column isn't present in all the grouping
934  * sets. (If there are only empty grouping sets, then the HAVING clause
935  * must be degenerate as discussed below.)
936  *
937  * Also, it may be that the clause is so expensive to execute that we're
938  * better off doing it only once per group, despite the loss of
939  * selectivity. This is hard to estimate short of doing the entire
940  * planning process twice, so we use a heuristic: clauses containing
941  * subplans are left in HAVING. Otherwise, we move or copy the HAVING
942  * clause into WHERE, in hopes of eliminating tuples before aggregation
943  * instead of after.
944  *
945  * If the query has explicit grouping then we can simply move such a
946  * clause into WHERE; any group that fails the clause will not be in the
947  * output because none of its tuples will reach the grouping or
948  * aggregation stage. Otherwise we must have a degenerate (variable-free)
949  * HAVING clause, which we put in WHERE so that query_planner() can use it
950  * in a gating Result node, but also keep in HAVING to ensure that we
951  * don't emit a bogus aggregated row. (This could be done better, but it
952  * seems not worth optimizing.)
953  *
954  * Note that both havingQual and parse->jointree->quals are in
955  * implicitly-ANDed-list form at this point, even though they are declared
956  * as Node *.
957  */
958  newHaving = NIL;
959  foreach(l, (List *) parse->havingQual)
960  {
961  Node *havingclause = (Node *) lfirst(l);
962 
963  if ((parse->groupClause && parse->groupingSets) ||
964  contain_agg_clause(havingclause) ||
965  contain_volatile_functions(havingclause) ||
966  contain_subplans(havingclause))
967  {
968  /* keep it in HAVING */
969  newHaving = lappend(newHaving, havingclause);
970  }
971  else if (parse->groupClause && !parse->groupingSets)
972  {
973  /* move it to WHERE */
974  parse->jointree->quals = (Node *)
975  lappend((List *) parse->jointree->quals, havingclause);
976  }
977  else
978  {
979  /* put a copy in WHERE, keep it in HAVING */
980  parse->jointree->quals = (Node *)
981  lappend((List *) parse->jointree->quals,
982  copyObject(havingclause));
983  newHaving = lappend(newHaving, havingclause);
984  }
985  }
986  parse->havingQual = (Node *) newHaving;
987 
988  /* Remove any redundant GROUP BY columns */
990 
991  /*
992  * If we have any outer joins, try to reduce them to plain inner joins.
993  * This step is most easily done after we've done expression
994  * preprocessing.
995  */
996  if (hasOuterJoins)
997  reduce_outer_joins(root);
998 
999  /*
1000  * If we have any RTE_RESULT relations, see if they can be deleted from
1001  * the jointree. This step is most effectively done after we've done
1002  * expression preprocessing and outer join reduction.
1003  */
1004  if (hasResultRTEs)
1006 
1007  /*
1008  * Do the main planning. If we have an inherited target relation, that
1009  * needs special processing, else go straight to grouping_planner.
1010  */
1011  if (parse->resultRelation &&
1012  rt_fetch(parse->resultRelation, parse->rtable)->inh)
1013  inheritance_planner(root);
1014  else
1015  grouping_planner(root, false, tuple_fraction);
1016 
1017  /*
1018  * Capture the set of outer-level param IDs we have access to, for use in
1019  * extParam/allParam calculations later.
1020  */
1022 
1023  /*
1024  * If any initPlans were created in this query level, adjust the surviving
1025  * Paths' costs and parallel-safety flags to account for them. The
1026  * initPlans won't actually get attached to the plan tree till
1027  * create_plan() runs, but we must include their effects now.
1028  */
1029  final_rel = fetch_upper_rel(root, UPPERREL_FINAL, NULL);
1030  SS_charge_for_initplans(root, final_rel);
1031 
1032  /*
1033  * Make sure we've identified the cheapest Path for the final rel. (By
1034  * doing this here not in grouping_planner, we include initPlan costs in
1035  * the decision, though it's unlikely that will change anything.)
1036  */
1037  set_cheapest(final_rel);
1038 
1039  return root;
1040 }
Node * limitOffset
Definition: parsenodes.h:160
#define NIL
Definition: pg_list.h:65
List * rowMarks
Definition: pathnodes.h:292
void remove_useless_result_rtes(PlannerInfo *root)
Query * parse
Definition: pathnodes.h:179
List * joinaliasvars
Definition: parsenodes.h:1050
List * plan_params
Definition: pathnodes.h:193
bool hasJoinRTEs
Definition: pathnodes.h:345
bool ec_merging_done
Definition: pathnodes.h:268
#define EXPRKIND_ARBITER_ELEM
Definition: planner.c:91
void reduce_outer_joins(PlannerInfo *root)
FromExpr * jointree
Definition: parsenodes.h:138
OnConflictExpr * onConflict
Definition: parsenodes.h:144
PlannerInfo * parent_root
Definition: pathnodes.h:185
static void preprocess_rowmarks(PlannerInfo *root)
Definition: planner.c:2649
List * withCheckOptions
Definition: parsenodes.h:171
List * securityQuals
Definition: parsenodes.h:1124
#define EXPRKIND_APPINFO
Definition: planner.c:88
#define EXPRKIND_QUAL
Definition: planner.c:81
#define EXPRKIND_TABLEFUNC_LATERAL
Definition: planner.c:93
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:669
int resultRelation
Definition: parsenodes.h:122
void SS_charge_for_initplans(PlannerInfo *root, RelOptInfo *final_rel)
Definition: subselect.c:2063
#define IS_OUTER_JOIN(jointype)
Definition: nodes.h:742
#define EXPRKIND_RTFUNC
Definition: planner.c:83
List * groupingSets
Definition: parsenodes.h:150
Definition: nodes.h:526
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
Definition: planner.c:1049
List * minmax_aggs
Definition: pathnodes.h:329
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:726
int assign_special_exec_param(PlannerInfo *root)
Definition: paramassign.c:584
#define EXPRKIND_VALUES_LATERAL
Definition: planner.c:86
AttrNumber * grouping_map
Definition: pathnodes.h:328
bool hasRecursion
Definition: pathnodes.h:350
void pull_up_subqueries(PlannerInfo *root)
Definition: prepjointree.c:678
#define EXPRKIND_TARGET
Definition: planner.c:82
void replace_empty_jointree(Query *parse)
Definition: prepjointree.c:148
List * values_lists
Definition: parsenodes.h:1073
Node * quals
Definition: primnodes.h:1511
List * windowClause
Definition: parsenodes.h:154
List * targetList
Definition: parsenodes.h:140
List * arbiterElems
Definition: primnodes.h:1529
List * multiexpr_params
Definition: pathnodes.h:263
bool contain_subplans(Node *clause)
Definition: clauses.c:612
#define EXPRKIND_LIMIT
Definition: planner.c:87
void preprocess_function_rtes(PlannerInfo *root)
Definition: prepjointree.c:637
int wt_param_id
Definition: pathnodes.h:353
bool has_subclass(Oid relationId)
Definition: pg_inherits.c:266
List * rtable
Definition: parsenodes.h:137
TableFunc * tablefunc
Definition: parsenodes.h:1068
bool hasLateralRTEs
Definition: pathnodes.h:346
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
Definition: relnode.c:1177
#define lfirst_node(type, lc)
Definition: pg_list.h:193
static void remove_useless_groupby_columns(PlannerInfo *root)
Definition: planner.c:3068
Node * limitCount
Definition: parsenodes.h:161
PlannerGlobal * glob
Definition: pathnodes.h:181
bool partColsUpdated
Definition: pathnodes.h:364
JoinType jointype
Definition: parsenodes.h:1048
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
void SS_process_ctes(PlannerInfo *root)
Definition: subselect.c:830
List * returningList
Definition: parsenodes.h:146
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
List * lappend(List *list, void *datum)
Definition: list.c:322
void set_cheapest(RelOptInfo *parent_rel)
Definition: pathnode.c:244
Node * startOffset
Definition: parsenodes.h:1355
List * append_rel_list
Definition: pathnodes.h:290
List * cte_plan_ids
Definition: pathnodes.h:261
List * init_plans
Definition: pathnodes.h:259
bool hasPseudoConstantQuals
Definition: pathnodes.h:348
Node * flatten_join_alias_vars(Query *query, Node *node)
Definition: var.c:670
static void inheritance_planner(PlannerInfo *root)
Definition: planner.c:1209
bool hasTargetSRFs
Definition: parsenodes.h:127
#define Max(x, y)
Definition: c.h:914
#define makeNode(_type_)
Definition: nodes.h:574
#define lfirst(lc)
Definition: pg_list.h:190
void SS_identify_outer_params(PlannerInfo *root)
Definition: subselect.c:2001
List * eq_classes
Definition: pathnodes.h:266
List * functions
Definition: parsenodes.h:1062
InheritanceKind inhTargetKind
Definition: pathnodes.h:342
void flatten_simple_union_all(PlannerInfo *root)
Bitmapset * outer_params
Definition: pathnodes.h:194
struct Path * non_recursive_path
Definition: pathnodes.h:354
Node * endOffset
Definition: parsenodes.h:1356
static int list_length(const List *l)
Definition: pg_list.h:169
#define EXPRKIND_RTFUNC_LATERAL
Definition: planner.c:84
Index qual_security_level
Definition: pathnodes.h:339
Index query_level
Definition: pathnodes.h:183
void pull_up_sublinks(PlannerInfo *root)
Definition: prepjointree.c:206
RTEKind rtekind
Definition: parsenodes.h:975
Node * arbiterWhere
Definition: primnodes.h:1531
List * cteList
Definition: parsenodes.h:135
Node * setOperations
Definition: parsenodes.h:165
bool contain_agg_clause(Node *clause)
Definition: clauses.c:181
Query * subquery
Definition: parsenodes.h:1010
List * groupClause
Definition: parsenodes.h:148
bool hasSubLinks
Definition: parsenodes.h:128
static void grouping_planner(PlannerInfo *root, bool inheritance_update, double tuple_fraction)
Definition: planner.c:1833
static void preprocess_qual_conditions(PlannerInfo *root, Node *jtnode)
Definition: planner.c:1140
List * onConflictSet
Definition: primnodes.h:1535
bool hasHavingQual
Definition: pathnodes.h:347
#define EXPRKIND_TABLESAMPLE
Definition: planner.c:90
MemoryContext planner_cxt
Definition: pathnodes.h:331
#define copyObject(obj)
Definition: nodes.h:642
#define EXPRKIND_VALUES
Definition: planner.c:85
Node * havingQual
Definition: parsenodes.h:152
List * processed_tlist
Definition: pathnodes.h:325
Node * onConflictWhere
Definition: primnodes.h:1536
Definition: pg_list.h:50
struct TableSampleClause * tablesample
Definition: parsenodes.h:1005
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:648
struct PathTarget * upper_targets[UPPERREL_FINAL+1]
Definition: pathnodes.h:314
#define EXPRKIND_TABLEFUNC
Definition: planner.c:92
List * upper_rels[UPPERREL_FINAL+1]
Definition: pathnodes.h:311

Variable Documentation

◆ create_upper_paths_hook

◆ planner_hook

Definition at line 74 of file planner.c.

Referenced by planner().