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

6325 {
6326  Path *best_path = rel->cheapest_total_path;
6327  ListCell *l;
6328 
6329  /* If all tuples will be retrieved, just return the cheapest-total path */
6330  if (tuple_fraction <= 0.0)
6331  return best_path;
6332 
6333  /* Convert absolute # of tuples to a fraction; no need to clamp to 0..1 */
6334  if (tuple_fraction >= 1.0 && best_path->rows > 0)
6335  tuple_fraction /= best_path->rows;
6336 
6337  foreach(l, rel->pathlist)
6338  {
6339  Path *path = (Path *) lfirst(l);
6340 
6341  if (path == rel->cheapest_total_path ||
6342  compare_fractional_path_costs(best_path, path, tuple_fraction) <= 0)
6343  continue;
6344 
6345  best_path = path;
6346  }
6347 
6348  return best_path;
6349 }
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
Definition: pathnode.c:117
#define lfirst(lc)
Definition: pg_list.h:172
Cardinality rows
Definition: pathnodes.h:1628
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 2600 of file planner.c.

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

5539 {
5540  /* aggtranstype should be computed by this point */
5541  Assert(OidIsValid(agg->aggtranstype));
5542  /* ... but aggsplit should still be as the parser left it */
5543  Assert(agg->aggsplit == AGGSPLIT_SIMPLE);
5544 
5545  /* Mark the Aggref with the intended partial-aggregation mode */
5546  agg->aggsplit = aggsplit;
5547 
5548  /*
5549  * Adjust result type if needed. Normally, a partial aggregate returns
5550  * the aggregate's transition type; but if that's INTERNAL and we're
5551  * serializing, it returns BYTEA instead.
5552  */
5553  if (DO_AGGSPLIT_SKIPFINAL(aggsplit))
5554  {
5555  if (agg->aggtranstype == INTERNALOID && DO_AGGSPLIT_SERIALIZE(aggsplit))
5556  agg->aggtype = BYTEAOID;
5557  else
5558  agg->aggtype = agg->aggtranstype;
5559  }
5560 }
#define OidIsValid(objectId)
Definition: c.h:764
Assert(fmt[strlen(fmt) - 1] !='\n')
#define DO_AGGSPLIT_SKIPFINAL(as)
Definition: nodes.h:396
#define DO_AGGSPLIT_SERIALIZE(as)
Definition: nodes.h:397
@ AGGSPLIT_SIMPLE
Definition: nodes.h:387

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

1265 {
1266  return (Expr *) preprocess_expression(root, (Node *) expr, EXPRKIND_PHV);
1267 }
#define EXPRKIND_PHV
Definition: planner.c:92
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
Definition: planner.c:1118

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

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

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

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

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

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

Referenced by _PG_init(), and planner().