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

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

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

5495 {
5496  Path *best_path = rel->cheapest_total_path;
5497  ListCell *l;
5498 
5499  /* If all tuples will be retrieved, just return the cheapest-total path */
5500  if (tuple_fraction <= 0.0)
5501  return best_path;
5502 
5503  /* Convert absolute # of tuples to a fraction; no need to clamp to 0..1 */
5504  if (tuple_fraction >= 1.0 && best_path->rows > 0)
5505  tuple_fraction /= best_path->rows;
5506 
5507  foreach(l, rel->pathlist)
5508  {
5509  Path *path = (Path *) lfirst(l);
5510 
5511  if (path == rel->cheapest_total_path ||
5512  compare_fractional_path_costs(best_path, path, tuple_fraction) <= 0)
5513  continue;
5514 
5515  best_path = path;
5516  }
5517 
5518  return best_path;
5519 }
struct Path * cheapest_total_path
Definition: pathnodes.h:694
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1184
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
Definition: pathnode.c:117
List * pathlist
Definition: pathnodes.h:690

◆ limit_needed()

bool limit_needed ( Query parse)

Definition at line 2481 of file planner.c.

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

Referenced by grouping_planner(), and set_rel_consider_parallel().

2482 {
2483  Node *node;
2484 
2485  node = parse->limitCount;
2486  if (node)
2487  {
2488  if (IsA(node, Const))
2489  {
2490  /* NULL indicates LIMIT ALL, ie, no limit */
2491  if (!((Const *) node)->constisnull)
2492  return true; /* LIMIT with a constant value */
2493  }
2494  else
2495  return true; /* non-constant LIMIT */
2496  }
2497 
2498  node = parse->limitOffset;
2499  if (node)
2500  {
2501  if (IsA(node, Const))
2502  {
2503  /* Treat NULL as no offset; the executor would too */
2504  if (!((Const *) node)->constisnull)
2505  {
2506  int64 offset = DatumGetInt64(((Const *) node)->constvalue);
2507 
2508  if (offset != 0)
2509  return true; /* OFFSET with a nonzero value */
2510  }
2511  }
2512  else
2513  return true; /* non-constant OFFSET */
2514  }
2515 
2516  return false; /* don't need a Limit plan node */
2517 }
Node * limitOffset
Definition: parsenodes.h:171
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
Definition: nodes.h:539
#define DatumGetInt64(X)
Definition: postgres.h:651
Node * limitCount
Definition: parsenodes.h:172

◆ mark_partial_aggref()

void mark_partial_aggref ( Aggref agg,
AggSplit  aggsplit 
)

Definition at line 4894 of file planner.c.

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

Referenced by convert_combining_aggrefs(), and make_partial_grouping_target().

4895 {
4896  /* aggtranstype should be computed by this point */
4898  /* ... but aggsplit should still be as the parser left it */
4899  Assert(agg->aggsplit == AGGSPLIT_SIMPLE);
4900 
4901  /* Mark the Aggref with the intended partial-aggregation mode */
4902  agg->aggsplit = aggsplit;
4903 
4904  /*
4905  * Adjust result type if needed. Normally, a partial aggregate returns
4906  * the aggregate's transition type; but if that's INTERNAL and we're
4907  * serializing, it returns BYTEA instead.
4908  */
4909  if (DO_AGGSPLIT_SKIPFINAL(aggsplit))
4910  {
4911  if (agg->aggtranstype == INTERNALOID && DO_AGGSPLIT_SERIALIZE(aggsplit))
4912  agg->aggtype = BYTEAOID;
4913  else
4914  agg->aggtype = agg->aggtranstype;
4915  }
4916 }
#define OidIsValid(objectId)
Definition: c.h:710
#define DO_AGGSPLIT_SERIALIZE(as)
Definition: nodes.h:803
#define Assert(condition)
Definition: c.h:804
AggSplit aggsplit
Definition: primnodes.h:339
#define DO_AGGSPLIT_SKIPFINAL(as)
Definition: nodes.h:802
Oid aggtranstype
Definition: primnodes.h:327
Oid aggtype
Definition: primnodes.h:324

◆ preprocess_phv_expression()

Expr* preprocess_phv_expression ( PlannerInfo root,
Expr expr 
)

Definition at line 1198 of file planner.c.

References EXPRKIND_PHV, and preprocess_expression().

Referenced by extract_lateral_references().

1199 {
1200  return (Expr *) preprocess_expression(root, (Node *) expr, EXPRKIND_PHV);
1201 }
Definition: nodes.h:539
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
Definition: planner.c:1053
#define EXPRKIND_PHV
Definition: planner.c:89

◆ select_rowmark_type()

RowMarkType select_rowmark_type ( RangeTblEntry rte,
LockClauseStrength  strength 
)

Definition at line 2230 of file planner.c.

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

Referenced by expand_single_inheritance_child(), and preprocess_rowmarks().

2231 {
2232  if (rte->rtekind != RTE_RELATION)
2233  {
2234  /* If it's not a table at all, use ROW_MARK_COPY */
2235  return ROW_MARK_COPY;
2236  }
2237  else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2238  {
2239  /* Let the FDW select the rowmark type, if it wants to */
2240  FdwRoutine *fdwroutine = GetFdwRoutineByRelId(rte->relid);
2241 
2242  if (fdwroutine->GetForeignRowMarkType != NULL)
2243  return fdwroutine->GetForeignRowMarkType(rte, strength);
2244  /* Otherwise, use ROW_MARK_COPY by default */
2245  return ROW_MARK_COPY;
2246  }
2247  else
2248  {
2249  /* Regular table, apply the appropriate lock type */
2250  switch (strength)
2251  {
2252  case LCS_NONE:
2253 
2254  /*
2255  * We don't need a tuple lock, only the ability to re-fetch
2256  * the row.
2257  */
2258  return ROW_MARK_REFERENCE;
2259  break;
2260  case LCS_FORKEYSHARE:
2261  return ROW_MARK_KEYSHARE;
2262  break;
2263  case LCS_FORSHARE:
2264  return ROW_MARK_SHARE;
2265  break;
2266  case LCS_FORNOKEYUPDATE:
2267  return ROW_MARK_NOKEYEXCLUSIVE;
2268  break;
2269  case LCS_FORUPDATE:
2270  return ROW_MARK_EXCLUSIVE;
2271  break;
2272  }
2273  elog(ERROR, "unrecognized LockClauseStrength %d", (int) strength);
2274  return ROW_MARK_EXCLUSIVE; /* keep compiler quiet */
2275  }
2276 }
#define ERROR
Definition: elog.h:46
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition: foreign.c:404
GetForeignRowMarkType_function GetForeignRowMarkType
Definition: fdwapi.h:247
RTEKind rtekind
Definition: parsenodes.h:995
#define elog(elevel,...)
Definition: elog.h:232

◆ standard_planner()

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

Definition at line 276 of file planner.c.

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

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

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

◆ subquery_planner()

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

Definition at line 590 of file planner.c.

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

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

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

Variable Documentation

◆ create_upper_paths_hook

◆ planner_hook

Definition at line 74 of file planner.c.

Referenced by _PG_fini(), _PG_init(), and planner().