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 5723 of file planner.c.

5724 {
5725  Path *best_path = rel->cheapest_total_path;
5726  ListCell *l;
5727 
5728  /* If all tuples will be retrieved, just return the cheapest-total path */
5729  if (tuple_fraction <= 0.0)
5730  return best_path;
5731 
5732  /* Convert absolute # of tuples to a fraction; no need to clamp to 0..1 */
5733  if (tuple_fraction >= 1.0 && best_path->rows > 0)
5734  tuple_fraction /= best_path->rows;
5735 
5736  foreach(l, rel->pathlist)
5737  {
5738  Path *path = (Path *) lfirst(l);
5739 
5740  if (path == rel->cheapest_total_path ||
5741  compare_fractional_path_costs(best_path, path, tuple_fraction) <= 0)
5742  continue;
5743 
5744  best_path = path;
5745  }
5746 
5747  return best_path;
5748 }
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
Definition: pathnode.c:117
#define lfirst(lc)
Definition: pg_list.h:169
Cardinality rows
Definition: pathnodes.h:1204
List * pathlist
Definition: pathnodes.h:696
struct Path * cheapest_total_path
Definition: pathnodes.h:700

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().

◆ limit_needed()

bool limit_needed ( Query parse)

Definition at line 2551 of file planner.c.

2552 {
2553  Node *node;
2554 
2555  node = parse->limitCount;
2556  if (node)
2557  {
2558  if (IsA(node, Const))
2559  {
2560  /* NULL indicates LIMIT ALL, ie, no limit */
2561  if (!((Const *) node)->constisnull)
2562  return true; /* LIMIT with a constant value */
2563  }
2564  else
2565  return true; /* non-constant LIMIT */
2566  }
2567 
2568  node = parse->limitOffset;
2569  if (node)
2570  {
2571  if (IsA(node, Const))
2572  {
2573  /* Treat NULL as no offset; the executor would too */
2574  if (!((Const *) node)->constisnull)
2575  {
2576  int64 offset = DatumGetInt64(((Const *) node)->constvalue);
2577 
2578  if (offset != 0)
2579  return true; /* OFFSET with a nonzero value */
2580  }
2581  }
2582  else
2583  return true; /* non-constant OFFSET */
2584  }
2585 
2586  return false; /* don't need a Limit plan node */
2587 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:624
#define DatumGetInt64(X)
Definition: postgres.h:651
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:673
Definition: nodes.h:574

References DatumGetInt64, IsA, and parse().

Referenced by grouping_planner(), and set_rel_consider_parallel().

◆ mark_partial_aggref()

void mark_partial_aggref ( Aggref agg,
AggSplit  aggsplit 
)

Definition at line 5123 of file planner.c.

5124 {
5125  /* aggtranstype should be computed by this point */
5127  /* ... but aggsplit should still be as the parser left it */
5128  Assert(agg->aggsplit == AGGSPLIT_SIMPLE);
5129 
5130  /* Mark the Aggref with the intended partial-aggregation mode */
5131  agg->aggsplit = aggsplit;
5132 
5133  /*
5134  * Adjust result type if needed. Normally, a partial aggregate returns
5135  * the aggregate's transition type; but if that's INTERNAL and we're
5136  * serializing, it returns BYTEA instead.
5137  */
5138  if (DO_AGGSPLIT_SKIPFINAL(aggsplit))
5139  {
5140  if (agg->aggtranstype == INTERNALOID && DO_AGGSPLIT_SERIALIZE(aggsplit))
5141  agg->aggtype = BYTEAOID;
5142  else
5143  agg->aggtype = agg->aggtranstype;
5144  }
5145 }
#define OidIsValid(objectId)
Definition: c.h:710
Assert(fmt[strlen(fmt) - 1] !='\n')
#define DO_AGGSPLIT_SKIPFINAL(as)
Definition: nodes.h:839
#define DO_AGGSPLIT_SERIALIZE(as)
Definition: nodes.h:840
@ AGGSPLIT_SIMPLE
Definition: nodes.h:830
Oid aggtranstype
Definition: primnodes.h:336
Oid aggtype
Definition: primnodes.h:333
AggSplit aggsplit
Definition: primnodes.h:348

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().

◆ preprocess_phv_expression()

Expr* preprocess_phv_expression ( PlannerInfo root,
Expr expr 
)

Definition at line 1224 of file planner.c.

1225 {
1226  return (Expr *) preprocess_expression(root, (Node *) expr, EXPRKIND_PHV);
1227 }
#define EXPRKIND_PHV
Definition: planner.c:89
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
Definition: planner.c:1078

References EXPRKIND_PHV, and preprocess_expression().

Referenced by extract_lateral_references().

◆ select_rowmark_type()

RowMarkType select_rowmark_type ( RangeTblEntry rte,
LockClauseStrength  strength 
)

Definition at line 2300 of file planner.c.

2301 {
2302  if (rte->rtekind != RTE_RELATION)
2303  {
2304  /* If it's not a table at all, use ROW_MARK_COPY */
2305  return ROW_MARK_COPY;
2306  }
2307  else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2308  {
2309  /* Let the FDW select the rowmark type, if it wants to */
2310  FdwRoutine *fdwroutine = GetFdwRoutineByRelId(rte->relid);
2311 
2312  if (fdwroutine->GetForeignRowMarkType != NULL)
2313  return fdwroutine->GetForeignRowMarkType(rte, strength);
2314  /* Otherwise, use ROW_MARK_COPY by default */
2315  return ROW_MARK_COPY;
2316  }
2317  else
2318  {
2319  /* Regular table, apply the appropriate lock type */
2320  switch (strength)
2321  {
2322  case LCS_NONE:
2323 
2324  /*
2325  * We don't need a tuple lock, only the ability to re-fetch
2326  * the row.
2327  */
2328  return ROW_MARK_REFERENCE;
2329  break;
2330  case LCS_FORKEYSHARE:
2331  return ROW_MARK_KEYSHARE;
2332  break;
2333  case LCS_FORSHARE:
2334  return ROW_MARK_SHARE;
2335  break;
2336  case LCS_FORNOKEYUPDATE:
2337  return ROW_MARK_NOKEYEXCLUSIVE;
2338  break;
2339  case LCS_FORUPDATE:
2340  return ROW_MARK_EXCLUSIVE;
2341  break;
2342  }
2343  elog(ERROR, "unrecognized LockClauseStrength %d", (int) strength);
2344  return ROW_MARK_EXCLUSIVE; /* keep compiler quiet */
2345  }
2346 }
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition: foreign.c:405
@ LCS_FORUPDATE
Definition: lockoptions.h:27
@ LCS_NONE
Definition: lockoptions.h:23
@ LCS_FORSHARE
Definition: lockoptions.h:25
@ LCS_FORKEYSHARE
Definition: lockoptions.h:24
@ LCS_FORNOKEYUPDATE
Definition: lockoptions.h:26
@ RTE_RELATION
Definition: parsenodes.h:998
@ ROW_MARK_COPY
Definition: plannodes.h:1111
@ ROW_MARK_REFERENCE
Definition: plannodes.h:1110
@ ROW_MARK_SHARE
Definition: plannodes.h:1108
@ ROW_MARK_EXCLUSIVE
Definition: plannodes.h:1106
@ ROW_MARK_NOKEYEXCLUSIVE
Definition: plannodes.h:1107
@ ROW_MARK_KEYSHARE
Definition: plannodes.h:1109
GetForeignRowMarkType_function GetForeignRowMarkType
Definition: fdwapi.h:247
RTEKind rtekind
Definition: parsenodes.h:1015

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().

◆ standard_planner()

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

Definition at line 282 of file planner.c.

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

References PlannerGlobal::appendRelations, PlannedStmt::appendRelations, Assert(), PlannerGlobal::boundParams, PlannedStmt::canSetTag, CMD_SELECT, PlannedStmt::commandType, create_plan(), CURSOR_OPT_FAST_PLAN, CURSOR_OPT_PARALLEL_OK, CURSOR_OPT_SCROLL, cursor_tuple_fraction, PlannerGlobal::dependsOnRole, PlannedStmt::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, PlannedStmt::hasReturning, Plan::initPlan, PlannerGlobal::invalItems, PlannedStmt::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, PlannerGlobal::parallelModeNeeded, PlannedStmt::parallelModeNeeded, PlannerGlobal::parallelModeOK, PlannerGlobal::paramExecTypes, PlannedStmt::paramExecTypes, parse(), 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, PlannerGlobal::relationOids, PlannedStmt::relationOids, Gather::rescan_param, PlannerGlobal::resultRelations, PlannedStmt::resultRelations, PlannerGlobal::rewindPlanIDs, PlannedStmt::rewindPlanIDs, Plan::righttree, PlannedStmt::rowMarks, PlannedStmt::rtable, set_plan_references(), Gather::single_copy, SS_finalize_plan(), Plan::startup_cost, PlannedStmt::stmt_len, PlannedStmt::stmt_location, PlannerGlobal::subplans, PlannedStmt::subplans, subquery_planner(), PlannerGlobal::subroots, Plan::targetlist, Plan::total_cost, PlannerGlobal::transientPlan, PlannedStmt::transientPlan, UPPERREL_FINAL, and PlannedStmt::utilityStmt.

Referenced by delay_execution_planner(), pgss_planner(), and planner().

◆ subquery_planner()

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

Definition at line 596 of file planner.c.

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

References generate_unaccent_rules::action, PlannerInfo::all_result_relids, PlannerInfo::append_rel_list, assign_special_exec_param(), bms_make_singleton(), contain_agg_clause(), contain_subplans(), contain_volatile_functions(), copyObject, PlannerInfo::cte_plan_ids, 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, PlannerInfo::grouping_map, grouping_planner(), has_subclass(), PlannerInfo::hasAlternativeSubPlans, PlannerInfo::hasHavingQual, PlannerInfo::hasJoinRTEs, PlannerInfo::hasLateralRTEs, PlannerInfo::hasPseudoConstantQuals, PlannerInfo::hasRecursion, RangeTblEntry::inh, PlannerInfo::init_plans, IS_OUTER_JOIN, RangeTblEntry::joinaliasvars, RangeTblEntry::jointype, lappend(), RangeTblEntry::lateral, PlannerInfo::leaf_result_relids, lfirst, lfirst_node, list_length(), makeNode, Max, PlannerInfo::minmax_aggs, PlannerInfo::multiexpr_params, NIL, PlannerInfo::non_recursive_path, 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, PlannerInfo::query_level, reduce_outer_joins(), RangeTblEntry::relid, remove_useless_groupby_columns(), remove_useless_result_rtes(), replace_empty_jointree(), PlannerInfo::row_identity_vars, PlannerInfo::rowMarks, rt_fetch, RTE_FUNCTION, RTE_JOIN, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, set_cheapest(), SS_charge_for_initplans(), SS_identify_outer_params(), SS_process_ctes(), WindowClause::startOffset, RangeTblEntry::subquery, RangeTblEntry::tablefunc, RangeTblEntry::tablesample, transform_MERGE_to_join(), PlannerInfo::update_colnos, PlannerInfo::upper_rels, PlannerInfo::upper_targets, UPPERREL_FINAL, RangeTblEntry::values_lists, and PlannerInfo::wt_param_id.

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

Variable Documentation

◆ create_upper_paths_hook

◆ planner_hook

PGDLLIMPORT planner_hook_type planner_hook
extern

Definition at line 74 of file planner.c.

Referenced by _PG_init(), and planner().