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

6242 {
6243  Path *best_path = rel->cheapest_total_path;
6244  ListCell *l;
6245 
6246  /* If all tuples will be retrieved, just return the cheapest-total path */
6247  if (tuple_fraction <= 0.0)
6248  return best_path;
6249 
6250  /* Convert absolute # of tuples to a fraction; no need to clamp to 0..1 */
6251  if (tuple_fraction >= 1.0 && best_path->rows > 0)
6252  tuple_fraction /= best_path->rows;
6253 
6254  foreach(l, rel->pathlist)
6255  {
6256  Path *path = (Path *) lfirst(l);
6257 
6258  if (path == rel->cheapest_total_path ||
6259  compare_fractional_path_costs(best_path, path, tuple_fraction) <= 0)
6260  continue;
6261 
6262  best_path = path;
6263  }
6264 
6265  return best_path;
6266 }
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
Definition: pathnode.c:113
#define lfirst(lc)
Definition: pg_list.h:172
Cardinality rows
Definition: pathnodes.h:1640
List * pathlist
Definition: pathnodes.h:883
struct Path * cheapest_total_path
Definition: pathnodes.h:887

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

2597 {
2598  Node *node;
2599 
2600  node = parse->limitCount;
2601  if (node)
2602  {
2603  if (IsA(node, Const))
2604  {
2605  /* NULL indicates LIMIT ALL, ie, no limit */
2606  if (!((Const *) node)->constisnull)
2607  return true; /* LIMIT with a constant value */
2608  }
2609  else
2610  return true; /* non-constant LIMIT */
2611  }
2612 
2613  node = parse->limitOffset;
2614  if (node)
2615  {
2616  if (IsA(node, Const))
2617  {
2618  /* Treat NULL as no offset; the executor would too */
2619  if (!((Const *) node)->constisnull)
2620  {
2621  int64 offset = DatumGetInt64(((Const *) node)->constvalue);
2622 
2623  if (offset != 0)
2624  return true; /* OFFSET with a nonzero value */
2625  }
2626  }
2627  else
2628  return true; /* non-constant OFFSET */
2629  }
2630 
2631  return false; /* don't need a Limit plan node */
2632 }
#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 5455 of file planner.c.

5456 {
5457  /* aggtranstype should be computed by this point */
5458  Assert(OidIsValid(agg->aggtranstype));
5459  /* ... but aggsplit should still be as the parser left it */
5460  Assert(agg->aggsplit == AGGSPLIT_SIMPLE);
5461 
5462  /* Mark the Aggref with the intended partial-aggregation mode */
5463  agg->aggsplit = aggsplit;
5464 
5465  /*
5466  * Adjust result type if needed. Normally, a partial aggregate returns
5467  * the aggregate's transition type; but if that's INTERNAL and we're
5468  * serializing, it returns BYTEA instead.
5469  */
5470  if (DO_AGGSPLIT_SKIPFINAL(aggsplit))
5471  {
5472  if (agg->aggtranstype == INTERNALOID && DO_AGGSPLIT_SERIALIZE(aggsplit))
5473  agg->aggtype = BYTEAOID;
5474  else
5475  agg->aggtype = agg->aggtranstype;
5476  }
5477 }
#define OidIsValid(objectId)
Definition: c.h:762
Assert(fmt[strlen(fmt) - 1] !='\n')
#define DO_AGGSPLIT_SKIPFINAL(as)
Definition: nodes.h:375
#define DO_AGGSPLIT_SERIALIZE(as)
Definition: nodes.h:376
@ AGGSPLIT_SIMPLE
Definition: nodes.h:366

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

1260 {
1261  return (Expr *) preprocess_expression(root, (Node *) expr, EXPRKIND_PHV);
1262 }
#define EXPRKIND_PHV
Definition: planner.c:85
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
Definition: planner.c:1113

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

2346 {
2347  if (rte->rtekind != RTE_RELATION)
2348  {
2349  /* If it's not a table at all, use ROW_MARK_COPY */
2350  return ROW_MARK_COPY;
2351  }
2352  else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2353  {
2354  /* Let the FDW select the rowmark type, if it wants to */
2355  FdwRoutine *fdwroutine = GetFdwRoutineByRelId(rte->relid);
2356 
2357  if (fdwroutine->GetForeignRowMarkType != NULL)
2358  return fdwroutine->GetForeignRowMarkType(rte, strength);
2359  /* Otherwise, use ROW_MARK_COPY by default */
2360  return ROW_MARK_COPY;
2361  }
2362  else
2363  {
2364  /* Regular table, apply the appropriate lock type */
2365  switch (strength)
2366  {
2367  case LCS_NONE:
2368 
2369  /*
2370  * We don't need a tuple lock, only the ability to re-fetch
2371  * the row.
2372  */
2373  return ROW_MARK_REFERENCE;
2374  break;
2375  case LCS_FORKEYSHARE:
2376  return ROW_MARK_KEYSHARE;
2377  break;
2378  case LCS_FORSHARE:
2379  return ROW_MARK_SHARE;
2380  break;
2381  case LCS_FORNOKEYUPDATE:
2382  return ROW_MARK_NOKEYEXCLUSIVE;
2383  break;
2384  case LCS_FORUPDATE:
2385  return ROW_MARK_EXCLUSIVE;
2386  break;
2387  }
2388  elog(ERROR, "unrecognized LockClauseStrength %d", (int) strength);
2389  return ROW_MARK_EXCLUSIVE; /* keep compiler quiet */
2390  }
2391 }
#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:1011
@ ROW_MARK_COPY
Definition: plannodes.h:1332
@ ROW_MARK_REFERENCE
Definition: plannodes.h:1331
@ ROW_MARK_SHARE
Definition: plannodes.h:1329
@ ROW_MARK_EXCLUSIVE
Definition: plannodes.h:1327
@ ROW_MARK_NOKEYEXCLUSIVE
Definition: plannodes.h:1328
@ ROW_MARK_KEYSHARE
Definition: plannodes.h:1330
GetForeignRowMarkType_function GetForeignRowMarkType
Definition: fdwapi.h:247
RTEKind rtekind
Definition: parsenodes.h:1030

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

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

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(), 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(), 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, 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::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 
)

Definition at line 618 of file planner.c.

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

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, grouping_planner(), has_subclass(), PlannerInfo::hasAlternativeSubPlans, PlannerInfo::hasHavingQual, PlannerInfo::hasJoinRTEs, PlannerInfo::hasLateralRTEs, PlannerInfo::hasPseudoConstantQuals, PlannerInfo::hasRecursion, RangeTblEntry::inh, PlannerInfo::init_plans, IS_OUTER_JOIN, PlannerInfo::join_domains, RangeTblEntry::joinaliasvars, RangeTblEntry::jointype, lappend(), PlannerInfo::last_rinfo_serial, RangeTblEntry::lateral, PlannerInfo::leaf_result_relids, lfirst, lfirst_node, list_length(), list_make1, makeNode, Max, PlannerInfo::minmax_aggs, PlannerInfo::multiexpr_params, NIL, PlannerInfo::non_recursive_path, PlannerInfo::outer_params, parse(), PlannerInfo::parse, PlannerInfo::partColsUpdated, PlannerInfo::placeholdersFrozen, PlannerInfo::plan_params, preprocess_expression(), preprocess_function_rtes(), preprocess_qual_conditions(), preprocess_rowmarks(), PlannerInfo::processed_distinctClause, PlannerInfo::processed_groupClause, 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_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, 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 70 of file planner.c.

Referenced by _PG_init(), and planner().