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, SetOperationStmt *setops)
 
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 6332 of file planner.c.

6333 {
6334  Path *best_path = rel->cheapest_total_path;
6335  ListCell *l;
6336 
6337  /* If all tuples will be retrieved, just return the cheapest-total path */
6338  if (tuple_fraction <= 0.0)
6339  return best_path;
6340 
6341  /* Convert absolute # of tuples to a fraction; no need to clamp to 0..1 */
6342  if (tuple_fraction >= 1.0 && best_path->rows > 0)
6343  tuple_fraction /= best_path->rows;
6344 
6345  foreach(l, rel->pathlist)
6346  {
6347  Path *path = (Path *) lfirst(l);
6348 
6349  if (path == rel->cheapest_total_path ||
6350  compare_fractional_path_costs(best_path, path, tuple_fraction) <= 0)
6351  continue;
6352 
6353  best_path = path;
6354  }
6355 
6356  return best_path;
6357 }
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
Definition: pathnode.c:115
#define lfirst(lc)
Definition: pg_list.h:172
Cardinality rows
Definition: pathnodes.h:1649
List * pathlist
Definition: pathnodes.h:888
struct Path * cheapest_total_path
Definition: pathnodes.h:892

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

Referenced by make_subplan(), and standard_planner().

◆ limit_needed()

bool limit_needed ( Query parse)

Definition at line 2625 of file planner.c.

2626 {
2627  Node *node;
2628 
2629  node = parse->limitCount;
2630  if (node)
2631  {
2632  if (IsA(node, Const))
2633  {
2634  /* NULL indicates LIMIT ALL, ie, no limit */
2635  if (!((Const *) node)->constisnull)
2636  return true; /* LIMIT with a constant value */
2637  }
2638  else
2639  return true; /* non-constant LIMIT */
2640  }
2641 
2642  node = parse->limitOffset;
2643  if (node)
2644  {
2645  if (IsA(node, Const))
2646  {
2647  /* Treat NULL as no offset; the executor would too */
2648  if (!((Const *) node)->constisnull)
2649  {
2650  int64 offset = DatumGetInt64(((Const *) node)->constvalue);
2651 
2652  if (offset != 0)
2653  return true; /* OFFSET with a nonzero value */
2654  }
2655  }
2656  else
2657  return true; /* non-constant OFFSET */
2658  }
2659 
2660  return false; /* don't need a Limit plan node */
2661 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:385
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
Definition: regcomp.c:715
Definition: nodes.h:129

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

5547 {
5548  /* aggtranstype should be computed by this point */
5549  Assert(OidIsValid(agg->aggtranstype));
5550  /* ... but aggsplit should still be as the parser left it */
5551  Assert(agg->aggsplit == AGGSPLIT_SIMPLE);
5552 
5553  /* Mark the Aggref with the intended partial-aggregation mode */
5554  agg->aggsplit = aggsplit;
5555 
5556  /*
5557  * Adjust result type if needed. Normally, a partial aggregate returns
5558  * the aggregate's transition type; but if that's INTERNAL and we're
5559  * serializing, it returns BYTEA instead.
5560  */
5561  if (DO_AGGSPLIT_SKIPFINAL(aggsplit))
5562  {
5563  if (agg->aggtranstype == INTERNALOID && DO_AGGSPLIT_SERIALIZE(aggsplit))
5564  agg->aggtype = BYTEAOID;
5565  else
5566  agg->aggtype = agg->aggtranstype;
5567  }
5568 }
#define Assert(condition)
Definition: c.h:858
#define OidIsValid(objectId)
Definition: c.h:775
#define DO_AGGSPLIT_SKIPFINAL(as)
Definition: nodes.h:385
#define DO_AGGSPLIT_SERIALIZE(as)
Definition: nodes.h:386
@ AGGSPLIT_SIMPLE
Definition: nodes.h:376

References AGGSPLIT_SIMPLE, 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 1269 of file planner.c.

1270 {
1271  return (Expr *) preprocess_expression(root, (Node *) expr, EXPRKIND_PHV);
1272 }
#define EXPRKIND_PHV
Definition: planner.c:86
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
Definition: planner.c:1123
tree ctl root
Definition: radixtree.h:1884

References EXPRKIND_PHV, preprocess_expression(), and root.

Referenced by extract_lateral_references().

◆ select_rowmark_type()

RowMarkType select_rowmark_type ( RangeTblEntry rte,
LockClauseStrength  strength 
)

Definition at line 2374 of file planner.c.

2375 {
2376  if (rte->rtekind != RTE_RELATION)
2377  {
2378  /* If it's not a table at all, use ROW_MARK_COPY */
2379  return ROW_MARK_COPY;
2380  }
2381  else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2382  {
2383  /* Let the FDW select the rowmark type, if it wants to */
2384  FdwRoutine *fdwroutine = GetFdwRoutineByRelId(rte->relid);
2385 
2386  if (fdwroutine->GetForeignRowMarkType != NULL)
2387  return fdwroutine->GetForeignRowMarkType(rte, strength);
2388  /* Otherwise, use ROW_MARK_COPY by default */
2389  return ROW_MARK_COPY;
2390  }
2391  else
2392  {
2393  /* Regular table, apply the appropriate lock type */
2394  switch (strength)
2395  {
2396  case LCS_NONE:
2397 
2398  /*
2399  * We don't need a tuple lock, only the ability to re-fetch
2400  * the row.
2401  */
2402  return ROW_MARK_REFERENCE;
2403  break;
2404  case LCS_FORKEYSHARE:
2405  return ROW_MARK_KEYSHARE;
2406  break;
2407  case LCS_FORSHARE:
2408  return ROW_MARK_SHARE;
2409  break;
2410  case LCS_FORNOKEYUPDATE:
2411  return ROW_MARK_NOKEYEXCLUSIVE;
2412  break;
2413  case LCS_FORUPDATE:
2414  return ROW_MARK_EXCLUSIVE;
2415  break;
2416  }
2417  elog(ERROR, "unrecognized LockClauseStrength %d", (int) strength);
2418  return ROW_MARK_EXCLUSIVE; /* keep compiler quiet */
2419  }
2420 }
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition: foreign.c:409
@ 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:1028
@ ROW_MARK_COPY
Definition: plannodes.h:1334
@ ROW_MARK_REFERENCE
Definition: plannodes.h:1333
@ ROW_MARK_SHARE
Definition: plannodes.h:1331
@ ROW_MARK_EXCLUSIVE
Definition: plannodes.h:1329
@ ROW_MARK_NOKEYEXCLUSIVE
Definition: plannodes.h:1330
@ ROW_MARK_KEYSHARE
Definition: plannodes.h:1332
GetForeignRowMarkType_function GetForeignRowMarkType
Definition: fdwapi.h:247
RTEKind rtekind
Definition: parsenodes.h:1057

References elog, ERROR, GetFdwRoutineByRelId(), FdwRoutine::GetForeignRowMarkType, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, LCS_NONE, RangeTblEntry::relid, 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 287 of file planner.c.

289 {
290  PlannedStmt *result;
291  PlannerGlobal *glob;
292  double tuple_fraction;
293  PlannerInfo *root;
294  RelOptInfo *final_rel;
295  Path *best_path;
296  Plan *top_plan;
297  ListCell *lp,
298  *lr;
299 
300  /*
301  * Set up global state for this planner invocation. This data is needed
302  * across all levels of sub-Query that might exist in the given command,
303  * so we keep it in a separate struct that's linked to by each per-Query
304  * PlannerInfo.
305  */
306  glob = makeNode(PlannerGlobal);
307 
308  glob->boundParams = boundParams;
309  glob->subplans = NIL;
310  glob->subpaths = NIL;
311  glob->subroots = NIL;
312  glob->rewindPlanIDs = NULL;
313  glob->finalrtable = NIL;
314  glob->finalrteperminfos = NIL;
315  glob->finalrowmarks = NIL;
316  glob->resultRelations = NIL;
317  glob->appendRelations = NIL;
318  glob->relationOids = NIL;
319  glob->invalItems = NIL;
320  glob->paramExecTypes = NIL;
321  glob->lastPHId = 0;
322  glob->lastRowMarkId = 0;
323  glob->lastPlanNodeId = 0;
324  glob->transientPlan = false;
325  glob->dependsOnRole = false;
326 
327  /*
328  * Assess whether it's feasible to use parallel mode for this query. We
329  * can't do this in a standalone backend, or if the command will try to
330  * modify any data, or if this is a cursor operation, or if GUCs are set
331  * to values that don't permit parallelism, or if parallel-unsafe
332  * functions are present in the query tree.
333  *
334  * (Note that we do allow CREATE TABLE AS, SELECT INTO, and CREATE
335  * MATERIALIZED VIEW to use parallel plans, but this is safe only because
336  * the command is writing into a completely new table which workers won't
337  * be able to see. If the workers could see the table, the fact that
338  * group locking would cause them to ignore the leader's heavyweight GIN
339  * page locks would make this unsafe. We'll have to fix that somehow if
340  * we want to allow parallel inserts in general; updates and deletes have
341  * additional problems especially around combo CIDs.)
342  *
343  * For now, we don't try to use parallel mode if we're running inside a
344  * parallel worker. We might eventually be able to relax this
345  * restriction, but for now it seems best not to have parallel workers
346  * trying to create their own parallel workers.
347  */
348  if ((cursorOptions & CURSOR_OPT_PARALLEL_OK) != 0 &&
350  parse->commandType == CMD_SELECT &&
351  !parse->hasModifyingCTE &&
353  !IsParallelWorker())
354  {
355  /* all the cheap tests pass, so scan the query tree */
357  glob->parallelModeOK = (glob->maxParallelHazard != PROPARALLEL_UNSAFE);
358  }
359  else
360  {
361  /* skip the query tree scan, just assume it's unsafe */
362  glob->maxParallelHazard = PROPARALLEL_UNSAFE;
363  glob->parallelModeOK = false;
364  }
365 
366  /*
367  * glob->parallelModeNeeded is normally set to false here and changed to
368  * true during plan creation if a Gather or Gather Merge plan is actually
369  * created (cf. create_gather_plan, create_gather_merge_plan).
370  *
371  * However, if debug_parallel_query = on or debug_parallel_query =
372  * regress, then we impose parallel mode whenever it's safe to do so, even
373  * if the final plan doesn't use parallelism. It's not safe to do so if
374  * the query contains anything parallel-unsafe; parallelModeOK will be
375  * false in that case. Note that parallelModeOK can't change after this
376  * point. Otherwise, everything in the query is either parallel-safe or
377  * parallel-restricted, and in either case it should be OK to impose
378  * parallel-mode restrictions. If that ends up breaking something, then
379  * either some function the user included in the query is incorrectly
380  * labeled as parallel-safe or parallel-restricted when in reality it's
381  * parallel-unsafe, or else the query planner itself has a bug.
382  */
383  glob->parallelModeNeeded = glob->parallelModeOK &&
385 
386  /* Determine what fraction of the plan is likely to be scanned */
387  if (cursorOptions & CURSOR_OPT_FAST_PLAN)
388  {
389  /*
390  * We have no real idea how many tuples the user will ultimately FETCH
391  * from a cursor, but it is often the case that he doesn't want 'em
392  * all, or would prefer a fast-start plan anyway so that he can
393  * process some of the tuples sooner. Use a GUC parameter to decide
394  * what fraction to optimize for.
395  */
396  tuple_fraction = cursor_tuple_fraction;
397 
398  /*
399  * We document cursor_tuple_fraction as simply being a fraction, which
400  * means the edge cases 0 and 1 have to be treated specially here. We
401  * convert 1 to 0 ("all the tuples") and 0 to a very small fraction.
402  */
403  if (tuple_fraction >= 1.0)
404  tuple_fraction = 0.0;
405  else if (tuple_fraction <= 0.0)
406  tuple_fraction = 1e-10;
407  }
408  else
409  {
410  /* Default assumption is we need all the tuples */
411  tuple_fraction = 0.0;
412  }
413 
414  /* primary planning entry point (may recurse for subqueries) */
415  root = subquery_planner(glob, parse, NULL, false, tuple_fraction, NULL);
416 
417  /* Select best Path and turn it into a Plan */
418  final_rel = fetch_upper_rel(root, UPPERREL_FINAL, NULL);
419  best_path = get_cheapest_fractional_path(final_rel, tuple_fraction);
420 
421  top_plan = create_plan(root, best_path);
422 
423  /*
424  * If creating a plan for a scrollable cursor, make sure it can run
425  * backwards on demand. Add a Material node at the top at need.
426  */
427  if (cursorOptions & CURSOR_OPT_SCROLL)
428  {
429  if (!ExecSupportsBackwardScan(top_plan))
430  top_plan = materialize_finished_plan(top_plan);
431  }
432 
433  /*
434  * Optionally add a Gather node for testing purposes, provided this is
435  * actually a safe thing to do.
436  *
437  * We can add Gather even when top_plan has parallel-safe initPlans, but
438  * then we have to move the initPlans to the Gather node because of
439  * SS_finalize_plan's limitations. That would cause cosmetic breakage of
440  * regression tests when debug_parallel_query = regress, because initPlans
441  * that would normally appear on the top_plan move to the Gather, causing
442  * them to disappear from EXPLAIN output. That doesn't seem worth kluging
443  * EXPLAIN to hide, so skip it when debug_parallel_query = regress.
444  */
446  top_plan->parallel_safe &&
447  (top_plan->initPlan == NIL ||
449  {
450  Gather *gather = makeNode(Gather);
451  Cost initplan_cost;
452  bool unsafe_initplans;
453 
454  gather->plan.targetlist = top_plan->targetlist;
455  gather->plan.qual = NIL;
456  gather->plan.lefttree = top_plan;
457  gather->plan.righttree = NULL;
458  gather->num_workers = 1;
459  gather->single_copy = true;
461 
462  /* Transfer any initPlans to the new top node */
463  gather->plan.initPlan = top_plan->initPlan;
464  top_plan->initPlan = NIL;
465 
466  /*
467  * Since this Gather has no parallel-aware descendants to signal to,
468  * we don't need a rescan Param.
469  */
470  gather->rescan_param = -1;
471 
472  /*
473  * Ideally we'd use cost_gather here, but setting up dummy path data
474  * to satisfy it doesn't seem much cleaner than knowing what it does.
475  */
476  gather->plan.startup_cost = top_plan->startup_cost +
478  gather->plan.total_cost = top_plan->total_cost +
480  gather->plan.plan_rows = top_plan->plan_rows;
481  gather->plan.plan_width = top_plan->plan_width;
482  gather->plan.parallel_aware = false;
483  gather->plan.parallel_safe = false;
484 
485  /*
486  * Delete the initplans' cost from top_plan. We needn't add it to the
487  * Gather node, since the above coding already included it there.
488  */
490  &initplan_cost, &unsafe_initplans);
491  top_plan->startup_cost -= initplan_cost;
492  top_plan->total_cost -= initplan_cost;
493 
494  /* use parallel mode for parallel plans. */
495  root->glob->parallelModeNeeded = true;
496 
497  top_plan = &gather->plan;
498  }
499 
500  /*
501  * If any Params were generated, run through the plan tree and compute
502  * each plan node's extParam/allParam sets. Ideally we'd merge this into
503  * set_plan_references' tree traversal, but for now it has to be separate
504  * because we need to visit subplans before not after main plan.
505  */
506  if (glob->paramExecTypes != NIL)
507  {
508  Assert(list_length(glob->subplans) == list_length(glob->subroots));
509  forboth(lp, glob->subplans, lr, glob->subroots)
510  {
511  Plan *subplan = (Plan *) lfirst(lp);
512  PlannerInfo *subroot = lfirst_node(PlannerInfo, lr);
513 
514  SS_finalize_plan(subroot, subplan);
515  }
516  SS_finalize_plan(root, top_plan);
517  }
518 
519  /* final cleanup of the plan */
520  Assert(glob->finalrtable == NIL);
521  Assert(glob->finalrteperminfos == NIL);
522  Assert(glob->finalrowmarks == NIL);
523  Assert(glob->resultRelations == NIL);
524  Assert(glob->appendRelations == NIL);
525  top_plan = set_plan_references(root, top_plan);
526  /* ... and the subplans (both regular subplans and initplans) */
527  Assert(list_length(glob->subplans) == list_length(glob->subroots));
528  forboth(lp, glob->subplans, lr, glob->subroots)
529  {
530  Plan *subplan = (Plan *) lfirst(lp);
531  PlannerInfo *subroot = lfirst_node(PlannerInfo, lr);
532 
533  lfirst(lp) = set_plan_references(subroot, subplan);
534  }
535 
536  /* build the PlannedStmt result */
537  result = makeNode(PlannedStmt);
538 
539  result->commandType = parse->commandType;
540  result->queryId = parse->queryId;
541  result->hasReturning = (parse->returningList != NIL);
542  result->hasModifyingCTE = parse->hasModifyingCTE;
543  result->canSetTag = parse->canSetTag;
544  result->transientPlan = glob->transientPlan;
545  result->dependsOnRole = glob->dependsOnRole;
546  result->parallelModeNeeded = glob->parallelModeNeeded;
547  result->planTree = top_plan;
548  result->rtable = glob->finalrtable;
549  result->permInfos = glob->finalrteperminfos;
550  result->resultRelations = glob->resultRelations;
551  result->appendRelations = glob->appendRelations;
552  result->subplans = glob->subplans;
553  result->rewindPlanIDs = glob->rewindPlanIDs;
554  result->rowMarks = glob->finalrowmarks;
555  result->relationOids = glob->relationOids;
556  result->invalItems = glob->invalItems;
557  result->paramExecTypes = glob->paramExecTypes;
558  /* utilityStmt should be null, but we might as well copy it */
559  result->utilityStmt = parse->utilityStmt;
560  result->stmt_location = parse->stmt_location;
561  result->stmt_len = parse->stmt_len;
562 
563  result->jitFlags = PGJIT_NONE;
564  if (jit_enabled && jit_above_cost >= 0 &&
565  top_plan->total_cost > jit_above_cost)
566  {
567  result->jitFlags |= PGJIT_PERFORM;
568 
569  /*
570  * Decide how much effort should be put into generating better code.
571  */
572  if (jit_optimize_above_cost >= 0 &&
574  result->jitFlags |= PGJIT_OPT3;
575  if (jit_inline_above_cost >= 0 &&
576  top_plan->total_cost > jit_inline_above_cost)
577  result->jitFlags |= PGJIT_INLINE;
578 
579  /*
580  * Decide which operations should be JITed.
581  */
582  if (jit_expressions)
583  result->jitFlags |= PGJIT_EXPR;
585  result->jitFlags |= PGJIT_DEFORM;
586  }
587 
588  if (glob->partition_directory != NULL)
589  DestroyPartitionDirectory(glob->partition_directory);
590 
591  return result;
592 }
char max_parallel_hazard(Query *parse)
Definition: clauses.c:734
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:337
Plan * materialize_finished_plan(Plan *subplan)
Definition: createplan.c:6527
bool ExecSupportsBackwardScan(Plan *node)
Definition: execAmi.c:510
bool IsUnderPostmaster
Definition: globals.c:117
#define IsParallelWorker()
Definition: parallel.h:60
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
double Cost
Definition: nodes.h:251
@ CMD_SELECT
Definition: nodes.h:265
#define makeNode(_type_)
Definition: nodes.h:155
@ DEBUG_PARALLEL_REGRESS
Definition: optimizer.h:108
@ DEBUG_PARALLEL_OFF
Definition: optimizer.h:106
#define CURSOR_OPT_SCROLL
Definition: parsenodes.h:3287
#define CURSOR_OPT_FAST_PLAN
Definition: parsenodes.h:3293
#define CURSOR_OPT_PARALLEL_OK
Definition: parsenodes.h:3296
void DestroyPartitionDirectory(PartitionDirectory pdir)
Definition: partdesc.c:442
@ UPPERREL_FINAL
Definition: pathnodes.h:79
#define lfirst_node(type, lc)
Definition: pg_list.h:176
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:518
PlannerInfo * subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction, SetOperationStmt *setops)
Definition: planner.c:628
double cursor_tuple_fraction
Definition: planner.c:66
int debug_parallel_query
Definition: planner.c:67
Path * get_cheapest_fractional_path(RelOptInfo *rel, double tuple_fraction)
Definition: planner.c:6332
e
Definition: preproc-init.c:82
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
Definition: relnode.c:1470
Plan * set_plan_references(PlannerInfo *root, Plan *plan)
Definition: setrefs.c:287
int num_workers
Definition: plannodes.h:1143
bool invisible
Definition: plannodes.h:1146
bool single_copy
Definition: plannodes.h:1145
Plan plan
Definition: plannodes.h:1142
int rescan_param
Definition: plannodes.h:1144
struct Plan * lefttree
Definition: plannodes.h:154
Cost total_cost
Definition: plannodes.h:129
struct Plan * righttree
Definition: plannodes.h:155
bool parallel_aware
Definition: plannodes.h:140
Cost startup_cost
Definition: plannodes.h:128
List * qual
Definition: plannodes.h:153
int plan_width
Definition: plannodes.h:135
bool parallel_safe
Definition: plannodes.h:141
Cardinality plan_rows
Definition: plannodes.h:134
List * targetlist
Definition: plannodes.h:152
List * initPlan
Definition: plannodes.h:156
struct Plan * planTree
Definition: plannodes.h:70
bool hasModifyingCTE
Definition: plannodes.h:58
List * appendRelations
Definition: plannodes.h:80
List * permInfos
Definition: plannodes.h:74
bool canSetTag
Definition: plannodes.h:60
List * rowMarks
Definition: plannodes.h:87
int jitFlags
Definition: plannodes.h:68
Bitmapset * rewindPlanIDs
Definition: plannodes.h:85
ParseLoc stmt_len
Definition: plannodes.h:99
bool hasReturning
Definition: plannodes.h:56
ParseLoc stmt_location
Definition: plannodes.h:98
List * invalItems
Definition: plannodes.h:91
bool transientPlan
Definition: plannodes.h:62
List * resultRelations
Definition: plannodes.h:78
List * subplans
Definition: plannodes.h:82
List * relationOids
Definition: plannodes.h:89
bool dependsOnRole
Definition: plannodes.h:64
CmdType commandType
Definition: plannodes.h:52
Node * utilityStmt
Definition: plannodes.h:95
List * rtable
Definition: plannodes.h:72
List * paramExecTypes
Definition: plannodes.h:93
bool parallelModeNeeded
Definition: plannodes.h:66
uint64 queryId
Definition: plannodes.h:54
int lastPlanNodeId
Definition: pathnodes.h:147
char maxParallelHazard
Definition: pathnodes.h:162
List * subplans
Definition: pathnodes.h:105
bool dependsOnRole
Definition: pathnodes.h:153
List * appendRelations
Definition: pathnodes.h:129
List * finalrowmarks
Definition: pathnodes.h:123
List * invalItems
Definition: pathnodes.h:135
List * relationOids
Definition: pathnodes.h:132
List * paramExecTypes
Definition: pathnodes.h:138
bool parallelModeOK
Definition: pathnodes.h:156
bool transientPlan
Definition: pathnodes.h:150
Bitmapset * rewindPlanIDs
Definition: pathnodes.h:114
List * finalrteperminfos
Definition: pathnodes.h:120
List * subpaths
Definition: pathnodes.h:108
Index lastPHId
Definition: pathnodes.h:141
Index lastRowMarkId
Definition: pathnodes.h:144
List * resultRelations
Definition: pathnodes.h:126
List * finalrtable
Definition: pathnodes.h:117
bool parallelModeNeeded
Definition: pathnodes.h:159
void SS_finalize_plan(PlannerInfo *root, Plan *plan)
Definition: subselect.c:2254
void SS_compute_initplan_cost(List *init_plans, Cost *initplan_cost_p, bool *unsafe_initplans_p)
Definition: subselect.c:2198

References PlannerGlobal::appendRelations, PlannedStmt::appendRelations, Assert, PlannedStmt::canSetTag, CMD_SELECT, PlannedStmt::commandType, create_plan(), CURSOR_OPT_FAST_PLAN, CURSOR_OPT_PARALLEL_OK, CURSOR_OPT_SCROLL, cursor_tuple_fraction, DEBUG_PARALLEL_OFF, debug_parallel_query, DEBUG_PARALLEL_REGRESS, PlannerGlobal::dependsOnRole, PlannedStmt::dependsOnRole, DestroyPartitionDirectory(), ExecSupportsBackwardScan(), fetch_upper_rel(), PlannerGlobal::finalrowmarks, PlannerGlobal::finalrtable, PlannerGlobal::finalrteperminfos, forboth, get_cheapest_fractional_path(), 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(), PlannedStmt::permInfos, 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, root, PlannedStmt::rowMarks, PlannedStmt::rtable, set_plan_references(), Gather::single_copy, SS_compute_initplan_cost(), SS_finalize_plan(), Plan::startup_cost, PlannedStmt::stmt_len, PlannedStmt::stmt_location, PlannerGlobal::subpaths, PlannerGlobal::subplans, PlannedStmt::subplans, subquery_planner(), 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,
SetOperationStmt setops 
)

Definition at line 628 of file planner.c.

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

References generate_unaccent_rules::action, assign_special_exec_param(), bms_make_singleton(), contain_agg_clause(), contain_subplans(), contain_volatile_functions(), copyObject, CurrentMemoryContext, WindowClause::endOffset, 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, grouping_planner(), has_subclass(), RangeTblEntry::inh, IS_OUTER_JOIN, RangeTblEntry::jointype, lappend(), lfirst, lfirst_node, list_length(), list_make1, makeNode, Max, NIL, parse(), preprocess_expression(), preprocess_function_rtes(), preprocess_qual_conditions(), preprocess_rowmarks(), pull_up_sublinks(), pull_up_subqueries(), WithCheckOption::qual, PlannerInfo::query_level, reduce_outer_joins(), RangeTblEntry::relid, remove_useless_result_rtes(), replace_empty_jointree(), root, rt_fetch, RTE_FUNCTION, RTE_JOIN, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, 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(), UPPERREL_FINAL, and RangeTblEntry::values_lists.

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

Referenced by _PG_init(), and planner().