PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 struct ExplainState ExplainState
 
typedef PlannedStmt *(* planner_hook_type) (Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams, ExplainState *es)
 
typedef void(* planner_setup_hook_type) (PlannerGlobal *glob, Query *parse, const char *query_string, int cursorOptions, double *tuple_fraction, ExplainState *es)
 
typedef void(* planner_shutdown_hook_type) (PlannerGlobal *glob, Query *parse, const char *query_string, PlannedStmt *pstmt)
 
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, ExplainState *es)
 
PlannerInfosubquery_planner (PlannerGlobal *glob, Query *parse, char *plan_name, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction, SetOperationStmt *setops)
 
RowMarkType select_rowmark_type (RangeTblEntry *rte, LockClauseStrength strength)
 
bool limit_needed (Query *parse)
 
void mark_partial_aggref (Aggref *agg, AggSplit aggsplit)
 
Pathget_cheapest_fractional_path (RelOptInfo *rel, double tuple_fraction)
 
Exprpreprocess_phv_expression (PlannerInfo *root, Expr *expr)
 
RelOptInfocreate_unique_paths (PlannerInfo *root, RelOptInfo *rel, SpecialJoinInfo *sjinfo)
 
charchoose_plan_name (PlannerGlobal *glob, const char *name, bool always_number)
 

Variables

PGDLLIMPORT planner_hook_type planner_hook
 
PGDLLIMPORT planner_setup_hook_type planner_setup_hook
 
PGDLLIMPORT planner_shutdown_hook_type planner_shutdown_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 50 of file planner.h.

◆ ExplainState

Definition at line 25 of file planner.h.

◆ planner_hook_type

typedef PlannedStmt *(* planner_hook_type) (Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams, ExplainState *es)

Definition at line 28 of file planner.h.

◆ planner_setup_hook_type

typedef void(* planner_setup_hook_type) (PlannerGlobal *glob, Query *parse, const char *query_string, int cursorOptions, double *tuple_fraction, ExplainState *es)

Definition at line 36 of file planner.h.

◆ planner_shutdown_hook_type

typedef void(* planner_shutdown_hook_type) (PlannerGlobal *glob, Query *parse, const char *query_string, PlannedStmt *pstmt)

Definition at line 44 of file planner.h.

Function Documentation

◆ choose_plan_name()

char * choose_plan_name ( PlannerGlobal glob,
const char name,
bool  always_number 
)
extern

Definition at line 9024 of file planner.c.

9025{
9026 unsigned n;
9027
9028 /*
9029 * If a numeric suffix is not required, then search the list of
9030 * previously-assigned names for a match. If none is found, then we can
9031 * use the provided name without modification.
9032 */
9033 if (!always_number)
9034 {
9035 bool found = false;
9036
9037 foreach_ptr(char, subplan_name, glob->subplanNames)
9038 {
9039 if (strcmp(subplan_name, name) == 0)
9040 {
9041 found = true;
9042 break;
9043 }
9044 }
9045
9046 if (!found)
9047 {
9048 /* pstrdup here is just to avoid cast-away-const */
9049 char *chosen_name = pstrdup(name);
9050
9051 glob->subplanNames = lappend(glob->subplanNames, chosen_name);
9052 return chosen_name;
9053 }
9054 }
9055
9056 /*
9057 * If a numeric suffix is required or if the un-suffixed name is already
9058 * in use, then loop until we find a positive integer that produces a
9059 * novel name.
9060 */
9061 for (n = 1; true; ++n)
9062 {
9063 char *proposed_name = psprintf("%s_%u", name, n);
9064 bool found = false;
9065
9066 foreach_ptr(char, subplan_name, glob->subplanNames)
9067 {
9069 {
9070 found = true;
9071 break;
9072 }
9073 }
9074
9075 if (!found)
9076 {
9077 glob->subplanNames = lappend(glob->subplanNames, proposed_name);
9078 return proposed_name;
9079 }
9080
9082 }
9083}
List * lappend(List *list, void *datum)
Definition list.c:339
char * pstrdup(const char *in)
Definition mcxt.c:1781
void pfree(void *pointer)
Definition mcxt.c:1616
#define foreach_ptr(type, var, lst)
Definition pg_list.h:469
static int fb(int x)
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
const char * name

References fb(), foreach_ptr, lappend(), name, pfree(), psprintf(), and pstrdup().

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

◆ create_unique_paths()

RelOptInfo * create_unique_paths ( PlannerInfo root,
RelOptInfo rel,
SpecialJoinInfo sjinfo 
)
extern

Definition at line 8472 of file planner.c.

8473{
8474 RelOptInfo *unique_rel;
8476 List *groupClause = NIL;
8477 MemoryContext oldcontext;
8478
8479 /* Caller made a mistake if SpecialJoinInfo is the wrong one */
8480 Assert(sjinfo->jointype == JOIN_SEMI);
8481 Assert(bms_equal(rel->relids, sjinfo->syn_righthand));
8482
8483 /* If result already cached, return it */
8484 if (rel->unique_rel)
8485 return rel->unique_rel;
8486
8487 /* If it's not possible to unique-ify, return NULL */
8488 if (!(sjinfo->semi_can_btree || sjinfo->semi_can_hash))
8489 return NULL;
8490
8491 /*
8492 * Punt if this is a child relation and we failed to build a unique-ified
8493 * relation for its parent. This can happen if all the RHS columns were
8494 * found to be equated to constants when unique-ifying the parent table,
8495 * leaving no columns to unique-ify.
8496 */
8497 if (IS_OTHER_REL(rel) && rel->top_parent->unique_rel == NULL)
8498 return NULL;
8499
8500 /*
8501 * When called during GEQO join planning, we are in a short-lived memory
8502 * context. We must make sure that the unique rel and any subsidiary data
8503 * structures created for a baserel survive the GEQO cycle, else the
8504 * baserel is trashed for future GEQO cycles. On the other hand, when we
8505 * are creating those for a joinrel during GEQO, we don't want them to
8506 * clutter the main planning context. Upshot is that the best solution is
8507 * to explicitly allocate memory in the same context the given RelOptInfo
8508 * is in.
8509 */
8511
8512 unique_rel = makeNode(RelOptInfo);
8513 memcpy(unique_rel, rel, sizeof(RelOptInfo));
8514
8515 /*
8516 * clear path info
8517 */
8518 unique_rel->pathlist = NIL;
8519 unique_rel->ppilist = NIL;
8520 unique_rel->partial_pathlist = NIL;
8521 unique_rel->cheapest_startup_path = NULL;
8522 unique_rel->cheapest_total_path = NULL;
8523 unique_rel->cheapest_parameterized_paths = NIL;
8524
8525 /*
8526 * Build the target list for the unique rel. We also build the pathkeys
8527 * that represent the ordering requirements for the sort-based
8528 * implementation, and the list of SortGroupClause nodes that represent
8529 * the columns to be grouped on for the hash-based implementation.
8530 *
8531 * For a child rel, we can construct these fields from those of its
8532 * parent.
8533 */
8534 if (IS_OTHER_REL(rel))
8535 {
8538
8539 parent_unique_target = rel->top_parent->unique_rel->reltarget;
8540
8542
8543 /* Translate the target expressions */
8544 child_unique_target->exprs = (List *)
8546 (Node *) parent_unique_target->exprs,
8547 rel,
8548 rel->top_parent);
8549
8550 unique_rel->reltarget = child_unique_target;
8551
8552 sortPathkeys = rel->top_parent->unique_pathkeys;
8553 groupClause = rel->top_parent->unique_groupclause;
8554 }
8555 else
8556 {
8557 List *newtlist;
8558 int nextresno;
8559 List *sortList = NIL;
8560 ListCell *lc1;
8561 ListCell *lc2;
8562
8563 /*
8564 * The values we are supposed to unique-ify may be expressions in the
8565 * variables of the input rel's targetlist. We have to add any such
8566 * expressions to the unique rel's targetlist.
8567 *
8568 * To complicate matters, some of the values to be unique-ified may be
8569 * known redundant by the EquivalenceClass machinery (e.g., because
8570 * they have been equated to constants). There is no need to compare
8571 * such values during unique-ification, and indeed we had better not
8572 * try because the Vars involved may not have propagated as high as
8573 * the semijoin's level. We use make_pathkeys_for_sortclauses to
8574 * detect such cases, which is a tad inefficient but it doesn't seem
8575 * worth building specialized infrastructure for this.
8576 */
8579
8580 forboth(lc1, sjinfo->semi_rhs_exprs, lc2, sjinfo->semi_operators)
8581 {
8582 Expr *uniqexpr = lfirst(lc1);
8584 Oid sortop;
8586 bool made_tle = false;
8587
8589 if (!tle)
8590 {
8592 nextresno,
8593 NULL,
8594 false);
8596 nextresno++;
8597 made_tle = true;
8598 }
8599
8600 /*
8601 * Try to build an ORDER BY list to sort the input compatibly. We
8602 * do this for each sortable clause even when the clauses are not
8603 * all sortable, so that we can detect clauses that are redundant
8604 * according to the pathkey machinery.
8605 */
8607 if (OidIsValid(sortop))
8608 {
8609 Oid eqop;
8611
8612 /*
8613 * The Unique node will need equality operators. Normally
8614 * these are the same as the IN clause operators, but if those
8615 * are cross-type operators then the equality operators are
8616 * the ones for the IN clause operators' RHS datatype.
8617 */
8618 eqop = get_equality_op_for_ordering_op(sortop, NULL);
8619 if (!OidIsValid(eqop)) /* shouldn't happen */
8620 elog(ERROR, "could not find equality operator for ordering operator %u",
8621 sortop);
8622
8624 sortcl->tleSortGroupRef = assignSortGroupRef(tle, newtlist);
8625 sortcl->eqop = eqop;
8626 sortcl->sortop = sortop;
8627 sortcl->reverse_sort = false;
8628 sortcl->nulls_first = false;
8629 sortcl->hashable = false; /* no need to make this accurate */
8631
8632 /*
8633 * At each step, convert the SortGroupClause list to pathkey
8634 * form. If the just-added SortGroupClause is redundant, the
8635 * result will be shorter than the SortGroupClause list.
8636 */
8638 newtlist);
8640 {
8641 /* Drop the redundant SortGroupClause */
8644 /* Undo tlist addition, if we made one */
8645 if (made_tle)
8646 {
8648 nextresno--;
8649 }
8650 /* We need not consider this clause for hashing, either */
8651 continue;
8652 }
8653 }
8654 else if (sjinfo->semi_can_btree) /* shouldn't happen */
8655 elog(ERROR, "could not find ordering operator for equality operator %u",
8656 in_oper);
8657
8658 if (sjinfo->semi_can_hash)
8659 {
8660 /* Create a GROUP BY list for the Agg node to use */
8661 Oid eq_oper;
8663
8664 /*
8665 * Get the hashable equality operators for the Agg node to
8666 * use. Normally these are the same as the IN clause
8667 * operators, but if those are cross-type operators then the
8668 * equality operators are the ones for the IN clause
8669 * operators' RHS datatype.
8670 */
8672 elog(ERROR, "could not find compatible hash operator for operator %u",
8673 in_oper);
8674
8676 groupcl->tleSortGroupRef = assignSortGroupRef(tle, newtlist);
8677 groupcl->eqop = eq_oper;
8678 groupcl->sortop = sortop;
8679 groupcl->reverse_sort = false;
8680 groupcl->nulls_first = false;
8681 groupcl->hashable = true;
8682 groupClause = lappend(groupClause, groupcl);
8683 }
8684 }
8685
8686 /*
8687 * Done building the sortPathkeys and groupClause. But the
8688 * sortPathkeys are bogus if not all the clauses were sortable.
8689 */
8690 if (!sjinfo->semi_can_btree)
8691 sortPathkeys = NIL;
8692
8693 /*
8694 * It can happen that all the RHS columns are equated to constants.
8695 * We'd have to do something special to unique-ify in that case, and
8696 * it's such an unlikely-in-the-real-world case that it's not worth
8697 * the effort. So just punt if we found no columns to unique-ify.
8698 */
8699 if (sortPathkeys == NIL && groupClause == NIL)
8700 {
8701 MemoryContextSwitchTo(oldcontext);
8702 return NULL;
8703 }
8704
8705 /* Convert the required targetlist back to PathTarget form */
8706 unique_rel->reltarget = create_pathtarget(root, newtlist);
8707 }
8708
8709 /* build unique paths based on input rel's pathlist */
8710 create_final_unique_paths(root, rel, sortPathkeys, groupClause,
8711 sjinfo, unique_rel);
8712
8713 /* build unique paths based on input rel's partial_pathlist */
8715 sjinfo, unique_rel);
8716
8717 /* Now choose the best path(s) */
8718 set_cheapest(unique_rel);
8719
8720 /*
8721 * There shouldn't be any partial paths for the unique relation;
8722 * otherwise, we won't be able to properly guarantee uniqueness.
8723 */
8724 Assert(unique_rel->partial_pathlist == NIL);
8725
8726 /* Cache the result */
8727 rel->unique_rel = unique_rel;
8729 rel->unique_groupclause = groupClause;
8730
8731 MemoryContextSwitchTo(oldcontext);
8732
8733 return unique_rel;
8734}
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, RelOptInfo *childrel, RelOptInfo *parentrel)
Definition appendinfo.c:592
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:142
#define Assert(condition)
Definition c.h:873
#define OidIsValid(objectId)
Definition c.h:788
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
List * list_delete_last(List *list)
Definition list.c:957
bool get_compatible_hash_operators(Oid opno, Oid *lhs_opno, Oid *rhs_opno)
Definition lsyscache.c:475
Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse)
Definition lsyscache.c:324
Oid get_ordering_op_for_equality_op(Oid opno, bool use_lhs_type)
Definition lsyscache.c:362
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition makefuncs.c:289
MemoryContext GetMemoryChunkContext(void *pointer)
Definition mcxt.c:756
#define makeNode(_type_)
Definition nodes.h:161
@ JOIN_SEMI
Definition nodes.h:317
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
Index assignSortGroupRef(TargetEntry *tle, List *tlist)
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
Definition pathkeys.c:1336
void set_cheapest(RelOptInfo *parent_rel)
Definition pathnode.c:268
#define IS_OTHER_REL(rel)
Definition pathnodes.h:992
#define lfirst(lc)
Definition pg_list.h:172
static int list_length(const List *l)
Definition pg_list.h:152
#define NIL
Definition pg_list.h:68
#define forboth(cell1, list1, cell2, list2)
Definition pg_list.h:518
#define lfirst_oid(lc)
Definition pg_list.h:174
static void create_final_unique_paths(PlannerInfo *root, RelOptInfo *input_rel, List *sortPathkeys, List *groupClause, SpecialJoinInfo *sjinfo, RelOptInfo *unique_rel)
Definition planner.c:8741
static void create_partial_unique_paths(PlannerInfo *root, RelOptInfo *input_rel, List *sortPathkeys, List *groupClause, SpecialJoinInfo *sjinfo, RelOptInfo *unique_rel)
Definition planner.c:8866
unsigned int Oid
tree ctl root
Definition radixtree.h:1857
Definition pg_list.h:54
Definition nodes.h:135
List * ppilist
Definition pathnodes.h:1039
Relids relids
Definition pathnodes.h:1009
struct PathTarget * reltarget
Definition pathnodes.h:1033
List * unique_pathkeys
Definition pathnodes.h:1122
List * cheapest_parameterized_paths
Definition pathnodes.h:1043
List * pathlist
Definition pathnodes.h:1038
struct Path * cheapest_startup_path
Definition pathnodes.h:1041
struct Path * cheapest_total_path
Definition pathnodes.h:1042
List * unique_groupclause
Definition pathnodes.h:1124
List * partial_pathlist
Definition pathnodes.h:1040
struct RelOptInfo * unique_rel
Definition pathnodes.h:1120
List * semi_rhs_exprs
Definition pathnodes.h:3226
JoinType jointype
Definition pathnodes.h:3215
Relids syn_righthand
Definition pathnodes.h:3214
List * semi_operators
Definition pathnodes.h:3225
TargetEntry * tlist_member(Expr *node, List *targetlist)
Definition tlist.c:88
List * make_tlist_from_pathtarget(PathTarget *target)
Definition tlist.c:633
PathTarget * copy_pathtarget(PathTarget *src)
Definition tlist.c:666
#define create_pathtarget(root, tlist)
Definition tlist.h:58

References adjust_appendrel_attrs_multilevel(), Assert, assignSortGroupRef(), bms_equal(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, copy_pathtarget(), create_final_unique_paths(), create_partial_unique_paths(), create_pathtarget, elog, ERROR, fb(), forboth, get_compatible_hash_operators(), get_equality_op_for_ordering_op(), get_ordering_op_for_equality_op(), GetMemoryChunkContext(), IS_OTHER_REL, JOIN_SEMI, SpecialJoinInfo::jointype, lappend(), lfirst, lfirst_oid, list_delete_last(), list_length(), make_pathkeys_for_sortclauses(), make_tlist_from_pathtarget(), makeNode, makeTargetEntry(), MemoryContextSwitchTo(), NIL, OidIsValid, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, RelOptInfo::ppilist, RelOptInfo::relids, RelOptInfo::reltarget, root, SpecialJoinInfo::semi_can_btree, SpecialJoinInfo::semi_can_hash, SpecialJoinInfo::semi_operators, SpecialJoinInfo::semi_rhs_exprs, set_cheapest(), SpecialJoinInfo::syn_righthand, tlist_member(), RelOptInfo::unique_groupclause, RelOptInfo::unique_pathkeys, and RelOptInfo::unique_rel.

Referenced by join_is_legal(), and populate_joinrel_with_paths().

◆ get_cheapest_fractional_path()

Path * get_cheapest_fractional_path ( RelOptInfo rel,
double  tuple_fraction 
)
extern

Definition at line 6657 of file planner.c.

6658{
6660 ListCell *l;
6661
6662 /* If all tuples will be retrieved, just return the cheapest-total path */
6663 if (tuple_fraction <= 0.0)
6664 return best_path;
6665
6666 /* Convert absolute # of tuples to a fraction; no need to clamp to 0..1 */
6667 if (tuple_fraction >= 1.0 && best_path->rows > 0)
6668 tuple_fraction /= best_path->rows;
6669
6670 foreach(l, rel->pathlist)
6671 {
6672 Path *path = (Path *) lfirst(l);
6673
6674 if (path->param_info)
6675 continue;
6676
6677 if (path == rel->cheapest_total_path ||
6678 compare_fractional_path_costs(best_path, path, tuple_fraction) <= 0)
6679 continue;
6680
6681 best_path = path;
6682 }
6683
6684 return best_path;
6685}
int compare_fractional_path_costs(Path *path1, Path *path2, double fraction)
Definition pathnode.c:123

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

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

◆ limit_needed()

bool limit_needed ( Query parse)
extern

Definition at line 2841 of file planner.c.

2842{
2843 Node *node;
2844
2845 node = parse->limitCount;
2846 if (node)
2847 {
2848 if (IsA(node, Const))
2849 {
2850 /* NULL indicates LIMIT ALL, ie, no limit */
2851 if (!((Const *) node)->constisnull)
2852 return true; /* LIMIT with a constant value */
2853 }
2854 else
2855 return true; /* non-constant LIMIT */
2856 }
2857
2858 node = parse->limitOffset;
2859 if (node)
2860 {
2861 if (IsA(node, Const))
2862 {
2863 /* Treat NULL as no offset; the executor would too */
2864 if (!((Const *) node)->constisnull)
2865 {
2866 int64 offset = DatumGetInt64(((Const *) node)->constvalue);
2867
2868 if (offset != 0)
2869 return true; /* OFFSET with a nonzero value */
2870 }
2871 }
2872 else
2873 return true; /* non-constant OFFSET */
2874 }
2875
2876 return false; /* don't need a Limit plan node */
2877}
int64_t int64
Definition c.h:543
void parse(int)
Definition parse.c:49
#define IsA(nodeptr, _type_)
Definition nodes.h:164
static int64 DatumGetInt64(Datum X)
Definition postgres.h:413

References DatumGetInt64(), fb(), IsA, and parse().

Referenced by grouping_planner(), and set_rel_consider_parallel().

◆ mark_partial_aggref()

void mark_partial_aggref ( Aggref agg,
AggSplit  aggsplit 
)
extern

Definition at line 5818 of file planner.c.

5819{
5820 /* aggtranstype should be computed by this point */
5821 Assert(OidIsValid(agg->aggtranstype));
5822 /* ... but aggsplit should still be as the parser left it */
5823 Assert(agg->aggsplit == AGGSPLIT_SIMPLE);
5824
5825 /* Mark the Aggref with the intended partial-aggregation mode */
5826 agg->aggsplit = aggsplit;
5827
5828 /*
5829 * Adjust result type if needed. Normally, a partial aggregate returns
5830 * the aggregate's transition type; but if that's INTERNAL and we're
5831 * serializing, it returns BYTEA instead.
5832 */
5833 if (DO_AGGSPLIT_SKIPFINAL(aggsplit))
5834 {
5835 if (agg->aggtranstype == INTERNALOID && DO_AGGSPLIT_SERIALIZE(aggsplit))
5836 agg->aggtype = BYTEAOID;
5837 else
5838 agg->aggtype = agg->aggtranstype;
5839 }
5840}
#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, fb(), and OidIsValid.

Referenced by convert_combining_aggrefs(), create_rel_agg_info(), and make_partial_grouping_target().

◆ preprocess_phv_expression()

Expr * preprocess_phv_expression ( PlannerInfo root,
Expr expr 
)
extern

Definition at line 1481 of file planner.c.

1482{
1483 return (Expr *) preprocess_expression(root, (Node *) expr, EXPRKIND_PHV);
1484}
#define EXPRKIND_PHV
Definition planner.c:95
static Node * preprocess_expression(PlannerInfo *root, Node *expr, int kind)
Definition planner.c:1335

References EXPRKIND_PHV, preprocess_expression(), and root.

Referenced by extract_lateral_references().

◆ select_rowmark_type()

RowMarkType select_rowmark_type ( RangeTblEntry rte,
LockClauseStrength  strength 
)
extern

Definition at line 2590 of file planner.c.

2591{
2592 if (rte->rtekind != RTE_RELATION)
2593 {
2594 /* If it's not a table at all, use ROW_MARK_COPY */
2595 return ROW_MARK_COPY;
2596 }
2597 else if (rte->relkind == RELKIND_FOREIGN_TABLE)
2598 {
2599 /* Let the FDW select the rowmark type, if it wants to */
2600 FdwRoutine *fdwroutine = GetFdwRoutineByRelId(rte->relid);
2601
2602 if (fdwroutine->GetForeignRowMarkType != NULL)
2603 return fdwroutine->GetForeignRowMarkType(rte, strength);
2604 /* Otherwise, use ROW_MARK_COPY by default */
2605 return ROW_MARK_COPY;
2606 }
2607 else
2608 {
2609 /* Regular table, apply the appropriate lock type */
2610 switch (strength)
2611 {
2612 case LCS_NONE:
2613
2614 /*
2615 * We don't need a tuple lock, only the ability to re-fetch
2616 * the row.
2617 */
2618 return ROW_MARK_REFERENCE;
2619 break;
2620 case LCS_FORKEYSHARE:
2621 return ROW_MARK_KEYSHARE;
2622 break;
2623 case LCS_FORSHARE:
2624 return ROW_MARK_SHARE;
2625 break;
2626 case LCS_FORNOKEYUPDATE:
2628 break;
2629 case LCS_FORUPDATE:
2630 return ROW_MARK_EXCLUSIVE;
2631 break;
2632 }
2633 elog(ERROR, "unrecognized LockClauseStrength %d", (int) strength);
2634 return ROW_MARK_EXCLUSIVE; /* keep compiler quiet */
2635 }
2636}
FdwRoutine * GetFdwRoutineByRelId(Oid relid)
Definition foreign.c:420
@ 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
@ ROW_MARK_COPY
Definition plannodes.h:1558
@ ROW_MARK_REFERENCE
Definition plannodes.h:1557
@ ROW_MARK_SHARE
Definition plannodes.h:1555
@ ROW_MARK_EXCLUSIVE
Definition plannodes.h:1553
@ ROW_MARK_NOKEYEXCLUSIVE
Definition plannodes.h:1554
@ ROW_MARK_KEYSHARE
Definition plannodes.h:1556
GetForeignRowMarkType_function GetForeignRowMarkType
Definition fdwapi.h:247

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

Referenced by expand_single_inheritance_child(), and preprocess_rowmarks().

◆ standard_planner()

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

Definition at line 333 of file planner.c.

335{
336 PlannedStmt *result;
337 PlannerGlobal *glob;
338 double tuple_fraction;
342 Plan *top_plan;
343 ListCell *lp,
344 *lr;
345
346 /*
347 * Set up global state for this planner invocation. This data is needed
348 * across all levels of sub-Query that might exist in the given command,
349 * so we keep it in a separate struct that's linked to by each per-Query
350 * PlannerInfo.
351 */
352 glob = makeNode(PlannerGlobal);
353
354 glob->boundParams = boundParams;
355 glob->subplans = NIL;
356 glob->subpaths = NIL;
357 glob->subroots = NIL;
358 glob->rewindPlanIDs = NULL;
359 glob->finalrtable = NIL;
360 glob->allRelids = NULL;
361 glob->prunableRelids = NULL;
362 glob->finalrteperminfos = NIL;
363 glob->finalrowmarks = NIL;
364 glob->resultRelations = NIL;
365 glob->appendRelations = NIL;
366 glob->partPruneInfos = NIL;
367 glob->relationOids = NIL;
368 glob->invalItems = NIL;
369 glob->paramExecTypes = NIL;
370 glob->lastPHId = 0;
371 glob->lastRowMarkId = 0;
372 glob->lastPlanNodeId = 0;
373 glob->transientPlan = false;
374 glob->dependsOnRole = false;
375 glob->partition_directory = NULL;
376 glob->rel_notnullatts_hash = NULL;
377
378 /*
379 * Assess whether it's feasible to use parallel mode for this query. We
380 * can't do this in a standalone backend, or if the command will try to
381 * modify any data, or if this is a cursor operation, or if GUCs are set
382 * to values that don't permit parallelism, or if parallel-unsafe
383 * functions are present in the query tree.
384 *
385 * (Note that we do allow CREATE TABLE AS, SELECT INTO, and CREATE
386 * MATERIALIZED VIEW to use parallel plans, but this is safe only because
387 * the command is writing into a completely new table which workers won't
388 * be able to see. If the workers could see the table, the fact that
389 * group locking would cause them to ignore the leader's heavyweight GIN
390 * page locks would make this unsafe. We'll have to fix that somehow if
391 * we want to allow parallel inserts in general; updates and deletes have
392 * additional problems especially around combo CIDs.)
393 *
394 * For now, we don't try to use parallel mode if we're running inside a
395 * parallel worker. We might eventually be able to relax this
396 * restriction, but for now it seems best not to have parallel workers
397 * trying to create their own parallel workers.
398 */
399 if ((cursorOptions & CURSOR_OPT_PARALLEL_OK) != 0 &&
401 parse->commandType == CMD_SELECT &&
402 !parse->hasModifyingCTE &&
405 {
406 /* all the cheap tests pass, so scan the query tree */
409 }
410 else
411 {
412 /* skip the query tree scan, just assume it's unsafe */
414 glob->parallelModeOK = false;
415 }
416
417 /*
418 * glob->parallelModeNeeded is normally set to false here and changed to
419 * true during plan creation if a Gather or Gather Merge plan is actually
420 * created (cf. create_gather_plan, create_gather_merge_plan).
421 *
422 * However, if debug_parallel_query = on or debug_parallel_query =
423 * regress, then we impose parallel mode whenever it's safe to do so, even
424 * if the final plan doesn't use parallelism. It's not safe to do so if
425 * the query contains anything parallel-unsafe; parallelModeOK will be
426 * false in that case. Note that parallelModeOK can't change after this
427 * point. Otherwise, everything in the query is either parallel-safe or
428 * parallel-restricted, and in either case it should be OK to impose
429 * parallel-mode restrictions. If that ends up breaking something, then
430 * either some function the user included in the query is incorrectly
431 * labeled as parallel-safe or parallel-restricted when in reality it's
432 * parallel-unsafe, or else the query planner itself has a bug.
433 */
434 glob->parallelModeNeeded = glob->parallelModeOK &&
436
437 /* Determine what fraction of the plan is likely to be scanned */
438 if (cursorOptions & CURSOR_OPT_FAST_PLAN)
439 {
440 /*
441 * We have no real idea how many tuples the user will ultimately FETCH
442 * from a cursor, but it is often the case that he doesn't want 'em
443 * all, or would prefer a fast-start plan anyway so that he can
444 * process some of the tuples sooner. Use a GUC parameter to decide
445 * what fraction to optimize for.
446 */
447 tuple_fraction = cursor_tuple_fraction;
448
449 /*
450 * We document cursor_tuple_fraction as simply being a fraction, which
451 * means the edge cases 0 and 1 have to be treated specially here. We
452 * convert 1 to 0 ("all the tuples") and 0 to a very small fraction.
453 */
454 if (tuple_fraction >= 1.0)
455 tuple_fraction = 0.0;
456 else if (tuple_fraction <= 0.0)
457 tuple_fraction = 1e-10;
458 }
459 else
460 {
461 /* Default assumption is we need all the tuples */
462 tuple_fraction = 0.0;
463 }
464
465 /*
466 * Compute the initial path generation strategy mask.
467 *
468 * Some strategies, such as PGS_FOREIGNJOIN, have no corresponding enable_*
469 * GUC, and so the corresponding bits are always set in the default
470 * strategy mask.
471 *
472 * It may seem surprising that enable_indexscan sets both PGS_INDEXSCAN
473 * and PGS_INDEXONLYSCAN. However, the historical behavior of this GUC
474 * corresponds to this exactly: enable_indexscan=off disables both
475 * index-scan and index-only scan paths, whereas enable_indexonlyscan=off
476 * converts the index-only scan paths that we would have considered into
477 * index scan paths.
478 */
481 if (enable_tidscan)
483 if (enable_seqscan)
492 {
494 if (enable_material)
496 }
497 if (enable_nestloop)
498 {
500 if (enable_material)
502 if (enable_memoize)
504 }
505 if (enable_hashjoin)
511
512 /* Allow plugins to take control after we've initialized "glob" */
514 (*planner_setup_hook) (glob, parse, query_string, cursorOptions,
515 &tuple_fraction, es);
516
517 /* primary planning entry point (may recurse for subqueries) */
518 root = subquery_planner(glob, parse, NULL, NULL, false, tuple_fraction,
519 NULL);
520
521 /* Select best Path and turn it into a Plan */
524
526
527 /*
528 * If creating a plan for a scrollable cursor, make sure it can run
529 * backwards on demand. Add a Material node at the top at need.
530 */
531 if (cursorOptions & CURSOR_OPT_SCROLL)
532 {
535 }
536
537 /*
538 * Optionally add a Gather node for testing purposes, provided this is
539 * actually a safe thing to do.
540 *
541 * We can add Gather even when top_plan has parallel-safe initPlans, but
542 * then we have to move the initPlans to the Gather node because of
543 * SS_finalize_plan's limitations. That would cause cosmetic breakage of
544 * regression tests when debug_parallel_query = regress, because initPlans
545 * that would normally appear on the top_plan move to the Gather, causing
546 * them to disappear from EXPLAIN output. That doesn't seem worth kluging
547 * EXPLAIN to hide, so skip it when debug_parallel_query = regress.
548 */
550 top_plan->parallel_safe &&
551 (top_plan->initPlan == NIL ||
553 {
556 bool unsafe_initplans;
557
558 gather->plan.targetlist = top_plan->targetlist;
559 gather->plan.qual = NIL;
560 gather->plan.lefttree = top_plan;
561 gather->plan.righttree = NULL;
562 gather->num_workers = 1;
563 gather->single_copy = true;
565
566 /* Transfer any initPlans to the new top node */
567 gather->plan.initPlan = top_plan->initPlan;
568 top_plan->initPlan = NIL;
569
570 /*
571 * Since this Gather has no parallel-aware descendants to signal to,
572 * we don't need a rescan Param.
573 */
574 gather->rescan_param = -1;
575
576 /*
577 * Ideally we'd use cost_gather here, but setting up dummy path data
578 * to satisfy it doesn't seem much cleaner than knowing what it does.
579 */
580 gather->plan.startup_cost = top_plan->startup_cost +
582 gather->plan.total_cost = top_plan->total_cost +
584 gather->plan.plan_rows = top_plan->plan_rows;
585 gather->plan.plan_width = top_plan->plan_width;
586 gather->plan.parallel_aware = false;
587 gather->plan.parallel_safe = false;
588
589 /*
590 * Delete the initplans' cost from top_plan. We needn't add it to the
591 * Gather node, since the above coding already included it there.
592 */
593 SS_compute_initplan_cost(gather->plan.initPlan,
595 top_plan->startup_cost -= initplan_cost;
596 top_plan->total_cost -= initplan_cost;
597
598 /* use parallel mode for parallel plans. */
599 root->glob->parallelModeNeeded = true;
600
601 top_plan = &gather->plan;
602 }
603
604 /*
605 * If any Params were generated, run through the plan tree and compute
606 * each plan node's extParam/allParam sets. Ideally we'd merge this into
607 * set_plan_references' tree traversal, but for now it has to be separate
608 * because we need to visit subplans before not after main plan.
609 */
610 if (glob->paramExecTypes != NIL)
611 {
612 Assert(list_length(glob->subplans) == list_length(glob->subroots));
613 forboth(lp, glob->subplans, lr, glob->subroots)
614 {
615 Plan *subplan = (Plan *) lfirst(lp);
617
618 SS_finalize_plan(subroot, subplan);
619 }
621 }
622
623 /* final cleanup of the plan */
624 Assert(glob->finalrtable == NIL);
625 Assert(glob->finalrteperminfos == NIL);
626 Assert(glob->finalrowmarks == NIL);
627 Assert(glob->resultRelations == NIL);
628 Assert(glob->appendRelations == NIL);
630 /* ... and the subplans (both regular subplans and initplans) */
631 Assert(list_length(glob->subplans) == list_length(glob->subroots));
632 forboth(lp, glob->subplans, lr, glob->subroots)
633 {
634 Plan *subplan = (Plan *) lfirst(lp);
636
637 lfirst(lp) = set_plan_references(subroot, subplan);
638 }
639
640 /* build the PlannedStmt result */
641 result = makeNode(PlannedStmt);
642
643 result->commandType = parse->commandType;
644 result->queryId = parse->queryId;
646 result->hasReturning = (parse->returningList != NIL);
647 result->hasModifyingCTE = parse->hasModifyingCTE;
648 result->canSetTag = parse->canSetTag;
649 result->transientPlan = glob->transientPlan;
650 result->dependsOnRole = glob->dependsOnRole;
651 result->parallelModeNeeded = glob->parallelModeNeeded;
652 result->planTree = top_plan;
653 result->partPruneInfos = glob->partPruneInfos;
654 result->rtable = glob->finalrtable;
655 result->unprunableRelids = bms_difference(glob->allRelids,
656 glob->prunableRelids);
657 result->permInfos = glob->finalrteperminfos;
658 result->subrtinfos = glob->subrtinfos;
659 result->resultRelations = glob->resultRelations;
660 result->appendRelations = glob->appendRelations;
661 result->subplans = glob->subplans;
662 result->rewindPlanIDs = glob->rewindPlanIDs;
663 result->rowMarks = glob->finalrowmarks;
664 result->relationOids = glob->relationOids;
665 result->invalItems = glob->invalItems;
666 result->paramExecTypes = glob->paramExecTypes;
667 /* utilityStmt should be null, but we might as well copy it */
668 result->utilityStmt = parse->utilityStmt;
669 result->elidedNodes = glob->elidedNodes;
670 result->stmt_location = parse->stmt_location;
671 result->stmt_len = parse->stmt_len;
672
673 result->jitFlags = PGJIT_NONE;
674 if (jit_enabled && jit_above_cost >= 0 &&
675 top_plan->total_cost > jit_above_cost)
676 {
677 result->jitFlags |= PGJIT_PERFORM;
678
679 /*
680 * Decide how much effort should be put into generating better code.
681 */
682 if (jit_optimize_above_cost >= 0 &&
683 top_plan->total_cost > jit_optimize_above_cost)
684 result->jitFlags |= PGJIT_OPT3;
685 if (jit_inline_above_cost >= 0 &&
686 top_plan->total_cost > jit_inline_above_cost)
687 result->jitFlags |= PGJIT_INLINE;
688
689 /*
690 * Decide which operations should be JITed.
691 */
692 if (jit_expressions)
693 result->jitFlags |= PGJIT_EXPR;
695 result->jitFlags |= PGJIT_DEFORM;
696 }
697
698 /* Allow plugins to take control before we discard "glob" */
700 (*planner_shutdown_hook) (glob, parse, query_string, result);
701
702 if (glob->partition_directory != NULL)
703 DestroyPartitionDirectory(glob->partition_directory);
704
705 return result;
706}
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:346
char max_parallel_hazard(Query *parse)
Definition clauses.c:743
bool enable_seqscan
Definition costsize.c:145
int max_parallel_workers_per_gather
Definition costsize.c:143
bool enable_memoize
Definition costsize.c:155
double parallel_setup_cost
Definition costsize.c:136
bool enable_gathermerge
Definition costsize.c:158
double parallel_tuple_cost
Definition costsize.c:135
bool enable_indexonlyscan
Definition costsize.c:147
bool enable_tidscan
Definition costsize.c:149
bool enable_material
Definition costsize.c:154
bool enable_hashjoin
Definition costsize.c:157
bool enable_mergejoin
Definition costsize.c:156
bool enable_partitionwise_join
Definition costsize.c:159
bool enable_nestloop
Definition costsize.c:153
bool enable_bitmapscan
Definition costsize.c:148
bool enable_indexscan
Definition costsize.c:146
Plan * materialize_finished_plan(Plan *subplan)
Plan * create_plan(PlannerInfo *root, Path *best_path)
Definition createplan.c:338
bool ExecSupportsBackwardScan(Plan *node)
Definition execAmi.c:511
bool IsUnderPostmaster
Definition globals.c:120
#define IsParallelWorker()
Definition parallel.h:60
double jit_optimize_above_cost
Definition jit.c:41
bool jit_enabled
Definition jit.c:32
bool jit_expressions
Definition jit.c:36
bool jit_tuple_deforming
Definition jit.c:38
double jit_above_cost
Definition jit.c:39
double jit_inline_above_cost
Definition jit.c:40
#define PGJIT_OPT3
Definition jit.h:21
#define PGJIT_NONE
Definition jit.h:19
#define PGJIT_EXPR
Definition jit.h:23
#define PGJIT_DEFORM
Definition jit.h:24
#define PGJIT_INLINE
Definition jit.h:22
#define PGJIT_PERFORM
Definition jit.h:20
double Cost
Definition nodes.h:261
@ CMD_SELECT
Definition nodes.h:275
@ DEBUG_PARALLEL_REGRESS
Definition optimizer.h:98
@ DEBUG_PARALLEL_OFF
Definition optimizer.h:96
#define CURSOR_OPT_SCROLL
#define CURSOR_OPT_FAST_PLAN
#define CURSOR_OPT_PARALLEL_OK
void DestroyPartitionDirectory(PartitionDirectory pdir)
Definition partdesc.c:484
#define PGS_NESTLOOP_MEMOIZE
Definition pathnodes.h:76
#define PGS_TIDSCAN
Definition pathnodes.h:70
#define PGS_FOREIGNJOIN
Definition pathnodes.h:71
#define PGS_APPEND
Definition pathnodes.h:78
#define PGS_MERGE_APPEND
Definition pathnodes.h:79
#define PGS_SEQSCAN
Definition pathnodes.h:66
#define PGS_CONSIDER_INDEXONLY
Definition pathnodes.h:82
#define PGS_NESTLOOP_MATERIALIZE
Definition pathnodes.h:75
#define PGS_MERGEJOIN_PLAIN
Definition pathnodes.h:72
#define PGS_MERGEJOIN_MATERIALIZE
Definition pathnodes.h:73
#define PGS_HASHJOIN
Definition pathnodes.h:77
#define PGS_CONSIDER_NONPARTIAL
Definition pathnodes.h:84
#define PGS_BITMAPSCAN
Definition pathnodes.h:69
#define PGS_GATHER
Definition pathnodes.h:80
#define PGS_CONSIDER_PARTITIONWISE
Definition pathnodes.h:83
#define PGS_GATHER_MERGE
Definition pathnodes.h:81
@ UPPERREL_FINAL
Definition pathnodes.h:152
#define PGS_INDEXONLYSCAN
Definition pathnodes.h:68
#define PGS_INDEXSCAN
Definition pathnodes.h:67
#define PGS_NESTLOOP_PLAIN
Definition pathnodes.h:74
#define lfirst_node(type, lc)
Definition pg_list.h:176
double cursor_tuple_fraction
Definition planner.c:68
planner_shutdown_hook_type planner_shutdown_hook
Definition planner.c:80
PlannerInfo * subquery_planner(PlannerGlobal *glob, Query *parse, char *plan_name, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction, SetOperationStmt *setops)
Definition planner.c:743
Path * get_cheapest_fractional_path(RelOptInfo *rel, double tuple_fraction)
Definition planner.c:6657
planner_setup_hook_type planner_setup_hook
Definition planner.c:77
int debug_parallel_query
Definition planner.c:69
@ PLAN_STMT_STANDARD
Definition plannodes.h:41
e
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
Definition relnode.c:1606
Plan * set_plan_references(PlannerInfo *root, Plan *plan)
Definition setrefs.c:291
struct Plan * planTree
Definition plannodes.h:101
bool hasModifyingCTE
Definition plannodes.h:83
List * appendRelations
Definition plannodes.h:127
List * elidedNodes
Definition plannodes.h:156
List * permInfos
Definition plannodes.h:120
bool canSetTag
Definition plannodes.h:86
List * rowMarks
Definition plannodes.h:141
Bitmapset * rewindPlanIDs
Definition plannodes.h:138
int64 queryId
Definition plannodes.h:71
ParseLoc stmt_len
Definition plannodes.h:171
PlannedStmtOrigin planOrigin
Definition plannodes.h:77
bool hasReturning
Definition plannodes.h:80
ParseLoc stmt_location
Definition plannodes.h:169
List * invalItems
Definition plannodes.h:147
bool transientPlan
Definition plannodes.h:89
List * resultRelations
Definition plannodes.h:124
List * subplans
Definition plannodes.h:132
List * relationOids
Definition plannodes.h:144
List * subrtinfos
Definition plannodes.h:135
bool dependsOnRole
Definition plannodes.h:92
Bitmapset * unprunableRelids
Definition plannodes.h:115
CmdType commandType
Definition plannodes.h:68
Node * utilityStmt
Definition plannodes.h:153
List * rtable
Definition plannodes.h:109
List * partPruneInfos
Definition plannodes.h:106
List * paramExecTypes
Definition plannodes.h:150
bool parallelModeNeeded
Definition plannodes.h:95
Bitmapset * prunableRelids
Definition pathnodes.h:206
char maxParallelHazard
Definition pathnodes.h:260
List * subplans
Definition pathnodes.h:178
bool dependsOnRole
Definition pathnodes.h:251
Bitmapset * allRelids
Definition pathnodes.h:199
List * appendRelations
Definition pathnodes.h:221
List * finalrowmarks
Definition pathnodes.h:215
List * invalItems
Definition pathnodes.h:230
List * relationOids
Definition pathnodes.h:227
List * paramExecTypes
Definition pathnodes.h:233
bool parallelModeOK
Definition pathnodes.h:254
bool transientPlan
Definition pathnodes.h:248
Bitmapset * rewindPlanIDs
Definition pathnodes.h:190
List * finalrteperminfos
Definition pathnodes.h:209
List * subpaths
Definition pathnodes.h:181
Index lastRowMarkId
Definition pathnodes.h:242
List * resultRelations
Definition pathnodes.h:218
List * partPruneInfos
Definition pathnodes.h:224
List * finalrtable
Definition pathnodes.h:193
uint64 default_pgs_mask
Definition pathnodes.h:263
bool parallelModeNeeded
Definition pathnodes.h:257
void SS_finalize_plan(PlannerInfo *root, Plan *plan)
Definition subselect.c:2404
void SS_compute_initplan_cost(List *init_plans, Cost *initplan_cost_p, bool *unsafe_initplans_p)
Definition subselect.c:2348

References PlannerGlobal::allRelids, PlannerGlobal::appendRelations, PlannedStmt::appendRelations, Assert, bms_difference(), 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::default_pgs_mask, PlannerGlobal::dependsOnRole, PlannedStmt::dependsOnRole, DestroyPartitionDirectory(), PlannerGlobal::elidedNodes, PlannedStmt::elidedNodes, enable_bitmapscan, enable_gathermerge, enable_hashjoin, enable_indexonlyscan, enable_indexscan, enable_material, enable_memoize, enable_mergejoin, enable_nestloop, enable_partitionwise_join, enable_seqscan, enable_tidscan, ExecSupportsBackwardScan(), fb(), fetch_upper_rel(), PlannerGlobal::finalrowmarks, PlannerGlobal::finalrtable, PlannerGlobal::finalrteperminfos, forboth, get_cheapest_fractional_path(), PlannedStmt::hasModifyingCTE, PlannedStmt::hasReturning, PlannerGlobal::invalItems, PlannedStmt::invalItems, 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, lfirst, lfirst_node, list_length(), makeNode, materialize_finished_plan(), max_parallel_hazard(), max_parallel_workers_per_gather, PlannerGlobal::maxParallelHazard, NIL, parallel_setup_cost, parallel_tuple_cost, PlannerGlobal::parallelModeNeeded, PlannedStmt::parallelModeNeeded, PlannerGlobal::parallelModeOK, PlannerGlobal::paramExecTypes, PlannedStmt::paramExecTypes, parse(), PlannerGlobal::partPruneInfos, PlannedStmt::partPruneInfos, PlannedStmt::permInfos, PGJIT_DEFORM, PGJIT_EXPR, PGJIT_INLINE, PGJIT_NONE, PGJIT_OPT3, PGJIT_PERFORM, PGS_APPEND, PGS_BITMAPSCAN, PGS_CONSIDER_INDEXONLY, PGS_CONSIDER_NONPARTIAL, PGS_CONSIDER_PARTITIONWISE, PGS_FOREIGNJOIN, PGS_GATHER, PGS_GATHER_MERGE, PGS_HASHJOIN, PGS_INDEXONLYSCAN, PGS_INDEXSCAN, PGS_MERGE_APPEND, PGS_MERGEJOIN_MATERIALIZE, PGS_MERGEJOIN_PLAIN, PGS_NESTLOOP_MATERIALIZE, PGS_NESTLOOP_MEMOIZE, PGS_NESTLOOP_PLAIN, PGS_SEQSCAN, PGS_TIDSCAN, PLAN_STMT_STANDARD, planner_setup_hook, planner_shutdown_hook, PlannedStmt::planOrigin, PlannedStmt::planTree, PlannerGlobal::prunableRelids, PlannedStmt::queryId, PlannerGlobal::relationOids, PlannedStmt::relationOids, PlannerGlobal::resultRelations, PlannedStmt::resultRelations, PlannerGlobal::rewindPlanIDs, PlannedStmt::rewindPlanIDs, root, PlannedStmt::rowMarks, PlannedStmt::rtable, set_plan_references(), SS_compute_initplan_cost(), SS_finalize_plan(), PlannedStmt::stmt_len, PlannedStmt::stmt_location, PlannerGlobal::subpaths, PlannerGlobal::subplans, PlannedStmt::subplans, subquery_planner(), PlannerGlobal::subrtinfos, PlannedStmt::subrtinfos, PlannerGlobal::transientPlan, PlannedStmt::transientPlan, PlannedStmt::unprunableRelids, UPPERREL_FINAL, and PlannedStmt::utilityStmt.

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

◆ subquery_planner()

PlannerInfo * subquery_planner ( PlannerGlobal glob,
Query parse,
char plan_name,
PlannerInfo parent_root,
bool  hasRecursion,
double  tuple_fraction,
SetOperationStmt setops 
)
extern

Definition at line 743 of file planner.c.

746{
750 bool hasOuterJoins;
751 bool hasResultRTEs;
753 ListCell *l;
754
755 /* Create a PlannerInfo data structure for this subquery */
757 root->parse = parse;
758 root->glob = glob;
759 root->query_level = parent_root ? parent_root->query_level + 1 : 1;
760 root->plan_name = plan_name;
761 root->parent_root = parent_root;
762 root->plan_params = NIL;
763 root->outer_params = NULL;
764 root->planner_cxt = CurrentMemoryContext;
765 root->init_plans = NIL;
766 root->cte_plan_ids = NIL;
767 root->multiexpr_params = NIL;
768 root->join_domains = NIL;
769 root->eq_classes = NIL;
770 root->ec_merging_done = false;
771 root->last_rinfo_serial = 0;
772 root->all_result_relids =
773 parse->resultRelation ? bms_make_singleton(parse->resultRelation) : NULL;
774 root->leaf_result_relids = NULL; /* we'll find out leaf-ness later */
775 root->append_rel_list = NIL;
776 root->row_identity_vars = NIL;
777 root->rowMarks = NIL;
778 memset(root->upper_rels, 0, sizeof(root->upper_rels));
779 memset(root->upper_targets, 0, sizeof(root->upper_targets));
780 root->processed_groupClause = NIL;
781 root->processed_distinctClause = NIL;
782 root->processed_tlist = NIL;
783 root->update_colnos = NIL;
784 root->grouping_map = NULL;
785 root->minmax_aggs = NIL;
786 root->qual_security_level = 0;
787 root->hasPseudoConstantQuals = false;
788 root->hasAlternativeSubPlans = false;
789 root->placeholdersFrozen = false;
790 root->hasRecursion = hasRecursion;
791 root->assumeReplanning = false;
792 if (hasRecursion)
793 root->wt_param_id = assign_special_exec_param(root);
794 else
795 root->wt_param_id = -1;
796 root->non_recursive_path = NULL;
797
798 /*
799 * Create the top-level join domain. This won't have valid contents until
800 * deconstruct_jointree fills it in, but the node needs to exist before
801 * that so we can build EquivalenceClasses referencing it.
802 */
803 root->join_domains = list_make1(makeNode(JoinDomain));
804
805 /*
806 * If there is a WITH list, process each WITH query and either convert it
807 * to RTE_SUBQUERY RTE(s) or build an initplan SubPlan structure for it.
808 */
809 if (parse->cteList)
811
812 /*
813 * If it's a MERGE command, transform the joinlist as appropriate.
814 */
816
817 /*
818 * Scan the rangetable for relation RTEs and retrieve the necessary
819 * catalog information for each relation. Using this information, clear
820 * the inh flag for any relation that has no children, collect not-null
821 * attribute numbers for any relation that has column not-null
822 * constraints, and expand virtual generated columns for any relation that
823 * contains them. Note that this step does not descend into sublinks and
824 * subqueries; if we pull up any sublinks or subqueries below, their
825 * relation RTEs are processed just before pulling them up.
826 */
828
829 /*
830 * If the FROM clause is empty, replace it with a dummy RTE_RESULT RTE, so
831 * that we don't need so many special cases to deal with that situation.
832 */
834
835 /*
836 * Look for ANY and EXISTS SubLinks in WHERE and JOIN/ON clauses, and try
837 * to transform them into joins. Note that this step does not descend
838 * into subqueries; if we pull up any subqueries below, their SubLinks are
839 * processed just before pulling them up.
840 */
841 if (parse->hasSubLinks)
843
844 /*
845 * Scan the rangetable for function RTEs, do const-simplification on them,
846 * and then inline them if possible (producing subqueries that might get
847 * pulled up next). Recursion issues here are handled in the same way as
848 * for SubLinks.
849 */
851
852 /*
853 * Check to see if any subqueries in the jointree can be merged into this
854 * query.
855 */
857
858 /*
859 * If this is a simple UNION ALL query, flatten it into an appendrel. We
860 * do this now because it requires applying pull_up_subqueries to the leaf
861 * queries of the UNION ALL, which weren't touched above because they
862 * weren't referenced by the jointree (they will be after we do this).
863 */
864 if (parse->setOperations)
866
867 /*
868 * Survey the rangetable to see what kinds of entries are present. We can
869 * skip some later processing if relevant SQL features are not used; for
870 * example if there are no JOIN RTEs we can avoid the expense of doing
871 * flatten_join_alias_vars(). This must be done after we have finished
872 * adding rangetable entries, of course. (Note: actually, processing of
873 * inherited or partitioned rels can cause RTEs for their child tables to
874 * get added later; but those must all be RTE_RELATION entries, so they
875 * don't invalidate the conclusions drawn here.)
876 */
877 root->hasJoinRTEs = false;
878 root->hasLateralRTEs = false;
879 root->group_rtindex = 0;
880 hasOuterJoins = false;
881 hasResultRTEs = false;
882 foreach(l, parse->rtable)
883 {
885
886 switch (rte->rtekind)
887 {
888 case RTE_JOIN:
889 root->hasJoinRTEs = true;
890 if (IS_OUTER_JOIN(rte->jointype))
891 hasOuterJoins = true;
892 break;
893 case RTE_RESULT:
894 hasResultRTEs = true;
895 break;
896 case RTE_GROUP:
897 Assert(parse->hasGroupRTE);
898 root->group_rtindex = list_cell_number(parse->rtable, l) + 1;
899 break;
900 default:
901 /* No work here for other RTE types */
902 break;
903 }
904
905 if (rte->lateral)
906 root->hasLateralRTEs = true;
907
908 /*
909 * We can also determine the maximum security level required for any
910 * securityQuals now. Addition of inheritance-child RTEs won't affect
911 * this, because child tables don't have their own securityQuals; see
912 * expand_single_inheritance_child().
913 */
914 if (rte->securityQuals)
915 root->qual_security_level = Max(root->qual_security_level,
916 list_length(rte->securityQuals));
917 }
918
919 /*
920 * If we have now verified that the query target relation is
921 * non-inheriting, mark it as a leaf target.
922 */
923 if (parse->resultRelation)
924 {
925 RangeTblEntry *rte = rt_fetch(parse->resultRelation, parse->rtable);
926
927 if (!rte->inh)
928 root->leaf_result_relids =
929 bms_make_singleton(parse->resultRelation);
930 }
931
932 /*
933 * This would be a convenient time to check access permissions for all
934 * relations mentioned in the query, since it would be better to fail now,
935 * before doing any detailed planning. However, for historical reasons,
936 * we leave this to be done at executor startup.
937 *
938 * Note, however, that we do need to check access permissions for any view
939 * relations mentioned in the query, in order to prevent information being
940 * leaked by selectivity estimation functions, which only check view owner
941 * permissions on underlying tables (see all_rows_selectable() and its
942 * callers). This is a little ugly, because it means that access
943 * permissions for views will be checked twice, which is another reason
944 * why it would be better to do all the ACL checks here.
945 */
946 foreach(l, parse->rtable)
947 {
949
950 if (rte->perminfoindex != 0 &&
951 rte->relkind == RELKIND_VIEW)
952 {
954 bool result;
955
956 perminfo = getRTEPermissionInfo(parse->rteperminfos, rte);
958 if (!result)
960 get_rel_name(perminfo->relid));
961 }
962 }
963
964 /*
965 * Preprocess RowMark information. We need to do this after subquery
966 * pullup, so that all base relations are present.
967 */
969
970 /*
971 * Set hasHavingQual to remember if HAVING clause is present. Needed
972 * because preprocess_expression will reduce a constant-true condition to
973 * an empty qual list ... but "HAVING TRUE" is not a semantic no-op.
974 */
975 root->hasHavingQual = (parse->havingQual != NULL);
976
977 /*
978 * Do expression preprocessing on targetlist and quals, as well as other
979 * random expressions in the querytree. Note that we do not need to
980 * handle sort/group expressions explicitly, because they are actually
981 * part of the targetlist.
982 */
983 parse->targetList = (List *)
984 preprocess_expression(root, (Node *) parse->targetList,
986
988 foreach(l, parse->withCheckOptions)
989 {
991
992 wco->qual = preprocess_expression(root, wco->qual,
994 if (wco->qual != NULL)
996 }
997 parse->withCheckOptions = newWithCheckOptions;
998
999 parse->returningList = (List *)
1000 preprocess_expression(root, (Node *) parse->returningList,
1002
1003 preprocess_qual_conditions(root, (Node *) parse->jointree);
1004
1005 parse->havingQual = preprocess_expression(root, parse->havingQual,
1007
1008 foreach(l, parse->windowClause)
1009 {
1011
1012 /* partitionClause/orderClause are sort/group expressions */
1017 }
1018
1019 parse->limitOffset = preprocess_expression(root, parse->limitOffset,
1021 parse->limitCount = preprocess_expression(root, parse->limitCount,
1023
1024 if (parse->onConflict)
1025 {
1026 parse->onConflict->arbiterElems = (List *)
1028 (Node *) parse->onConflict->arbiterElems,
1030 parse->onConflict->arbiterWhere =
1032 parse->onConflict->arbiterWhere,
1034 parse->onConflict->onConflictSet = (List *)
1036 (Node *) parse->onConflict->onConflictSet,
1038 parse->onConflict->onConflictWhere =
1040 parse->onConflict->onConflictWhere,
1042 /* exclRelTlist contains only Vars, so no preprocessing needed */
1043 }
1044
1045 foreach(l, parse->mergeActionList)
1046 {
1048
1049 action->targetList = (List *)
1051 (Node *) action->targetList,
1053 action->qual =
1055 (Node *) action->qual,
1057 }
1058
1059 parse->mergeJoinCondition =
1060 preprocess_expression(root, parse->mergeJoinCondition, EXPRKIND_QUAL);
1061
1062 root->append_rel_list = (List *)
1063 preprocess_expression(root, (Node *) root->append_rel_list,
1065
1066 /* Also need to preprocess expressions within RTEs */
1067 foreach(l, parse->rtable)
1068 {
1070 int kind;
1071 ListCell *lcsq;
1072
1073 if (rte->rtekind == RTE_RELATION)
1074 {
1075 if (rte->tablesample)
1076 rte->tablesample = (TableSampleClause *)
1078 (Node *) rte->tablesample,
1080 }
1081 else if (rte->rtekind == RTE_SUBQUERY)
1082 {
1083 /*
1084 * We don't want to do all preprocessing yet on the subquery's
1085 * expressions, since that will happen when we plan it. But if it
1086 * contains any join aliases of our level, those have to get
1087 * expanded now, because planning of the subquery won't do it.
1088 * That's only possible if the subquery is LATERAL.
1089 */
1090 if (rte->lateral && root->hasJoinRTEs)
1091 rte->subquery = (Query *)
1093 (Node *) rte->subquery);
1094 }
1095 else if (rte->rtekind == RTE_FUNCTION)
1096 {
1097 /* Preprocess the function expression(s) fully */
1098 kind = rte->lateral ? EXPRKIND_RTFUNC_LATERAL : EXPRKIND_RTFUNC;
1099 rte->functions = (List *)
1100 preprocess_expression(root, (Node *) rte->functions, kind);
1101 }
1102 else if (rte->rtekind == RTE_TABLEFUNC)
1103 {
1104 /* Preprocess the function expression(s) fully */
1106 rte->tablefunc = (TableFunc *)
1107 preprocess_expression(root, (Node *) rte->tablefunc, kind);
1108 }
1109 else if (rte->rtekind == RTE_VALUES)
1110 {
1111 /* Preprocess the values lists fully */
1112 kind = rte->lateral ? EXPRKIND_VALUES_LATERAL : EXPRKIND_VALUES;
1113 rte->values_lists = (List *)
1114 preprocess_expression(root, (Node *) rte->values_lists, kind);
1115 }
1116 else if (rte->rtekind == RTE_GROUP)
1117 {
1118 /* Preprocess the groupexprs list fully */
1119 rte->groupexprs = (List *)
1120 preprocess_expression(root, (Node *) rte->groupexprs,
1122 }
1123
1124 /*
1125 * Process each element of the securityQuals list as if it were a
1126 * separate qual expression (as indeed it is). We need to do it this
1127 * way to get proper canonicalization of AND/OR structure. Note that
1128 * this converts each element into an implicit-AND sublist.
1129 */
1130 foreach(lcsq, rte->securityQuals)
1131 {
1133 (Node *) lfirst(lcsq),
1135 }
1136 }
1137
1138 /*
1139 * Now that we are done preprocessing expressions, and in particular done
1140 * flattening join alias variables, get rid of the joinaliasvars lists.
1141 * They no longer match what expressions in the rest of the tree look
1142 * like, because we have not preprocessed expressions in those lists (and
1143 * do not want to; for example, expanding a SubLink there would result in
1144 * a useless unreferenced subplan). Leaving them in place simply creates
1145 * a hazard for later scans of the tree. We could try to prevent that by
1146 * using QTW_IGNORE_JOINALIASES in every tree scan done after this point,
1147 * but that doesn't sound very reliable.
1148 */
1149 if (root->hasJoinRTEs)
1150 {
1151 foreach(l, parse->rtable)
1152 {
1154
1155 rte->joinaliasvars = NIL;
1156 }
1157 }
1158
1159 /*
1160 * Replace any Vars in the subquery's targetlist and havingQual that
1161 * reference GROUP outputs with the underlying grouping expressions.
1162 *
1163 * Note that we need to perform this replacement after we've preprocessed
1164 * the grouping expressions. This is to ensure that there is only one
1165 * instance of SubPlan for each SubLink contained within the grouping
1166 * expressions.
1167 */
1168 if (parse->hasGroupRTE)
1169 {
1170 parse->targetList = (List *)
1171 flatten_group_exprs(root, root->parse, (Node *) parse->targetList);
1172 parse->havingQual =
1173 flatten_group_exprs(root, root->parse, parse->havingQual);
1174 }
1175
1176 /* Constant-folding might have removed all set-returning functions */
1177 if (parse->hasTargetSRFs)
1178 parse->hasTargetSRFs = expression_returns_set((Node *) parse->targetList);
1179
1180 /*
1181 * If we have grouping sets, expand the groupingSets tree of this query to
1182 * a flat list of grouping sets. We need to do this before optimizing
1183 * HAVING, since we can't easily tell if there's an empty grouping set
1184 * until we have this representation.
1185 */
1186 if (parse->groupingSets)
1187 {
1188 parse->groupingSets =
1189 expand_grouping_sets(parse->groupingSets, parse->groupDistinct, -1);
1190 }
1191
1192 /*
1193 * In some cases we may want to transfer a HAVING clause into WHERE. We
1194 * cannot do so if the HAVING clause contains aggregates (obviously) or
1195 * volatile functions (since a HAVING clause is supposed to be executed
1196 * only once per group). We also can't do this if there are any grouping
1197 * sets and the clause references any columns that are nullable by the
1198 * grouping sets; the nulled values of those columns are not available
1199 * before the grouping step. (The test on groupClause might seem wrong,
1200 * but it's okay: it's just an optimization to avoid running pull_varnos
1201 * when there cannot be any Vars in the HAVING clause.)
1202 *
1203 * Also, it may be that the clause is so expensive to execute that we're
1204 * better off doing it only once per group, despite the loss of
1205 * selectivity. This is hard to estimate short of doing the entire
1206 * planning process twice, so we use a heuristic: clauses containing
1207 * subplans are left in HAVING. Otherwise, we move or copy the HAVING
1208 * clause into WHERE, in hopes of eliminating tuples before aggregation
1209 * instead of after.
1210 *
1211 * If the query has no empty grouping set then we can simply move such a
1212 * clause into WHERE; any group that fails the clause will not be in the
1213 * output because none of its tuples will reach the grouping or
1214 * aggregation stage. Otherwise we have to keep the clause in HAVING to
1215 * ensure that we don't emit a bogus aggregated row. But then the HAVING
1216 * clause must be degenerate (variable-free), so we can copy it into WHERE
1217 * so that query_planner() can use it in a gating Result node. (This could
1218 * be done better, but it seems not worth optimizing.)
1219 *
1220 * Note that a HAVING clause may contain expressions that are not fully
1221 * preprocessed. This can happen if these expressions are part of
1222 * grouping items. In such cases, they are replaced with GROUP Vars in
1223 * the parser and then replaced back after we're done with expression
1224 * preprocessing on havingQual. This is not an issue if the clause
1225 * remains in HAVING, because these expressions will be matched to lower
1226 * target items in setrefs.c. However, if the clause is moved or copied
1227 * into WHERE, we need to ensure that these expressions are fully
1228 * preprocessed.
1229 *
1230 * Note that both havingQual and parse->jointree->quals are in
1231 * implicitly-ANDed-list form at this point, even though they are declared
1232 * as Node *.
1233 */
1234 newHaving = NIL;
1235 foreach(l, (List *) parse->havingQual)
1236 {
1237 Node *havingclause = (Node *) lfirst(l);
1238
1242 (parse->groupClause && parse->groupingSets &&
1243 bms_is_member(root->group_rtindex, pull_varnos(root, havingclause))))
1244 {
1245 /* keep it in HAVING */
1247 }
1248 else if (parse->groupClause &&
1249 (parse->groupingSets == NIL ||
1250 (List *) linitial(parse->groupingSets) != NIL))
1251 {
1252 /* There is GROUP BY, but no empty grouping set */
1254
1255 /* Preprocess the HAVING clause fully */
1258 /* ... and move it to WHERE */
1259 parse->jointree->quals = (Node *)
1260 list_concat((List *) parse->jointree->quals,
1261 (List *) whereclause);
1262 }
1263 else
1264 {
1265 /* There is an empty grouping set (perhaps implicitly) */
1267
1268 /* Preprocess the HAVING clause fully */
1271 /* ... and put a copy in WHERE */
1272 parse->jointree->quals = (Node *)
1273 list_concat((List *) parse->jointree->quals,
1274 (List *) whereclause);
1275 /* ... and also keep it in HAVING */
1277 }
1278 }
1279 parse->havingQual = (Node *) newHaving;
1280
1281 /*
1282 * If we have any outer joins, try to reduce them to plain inner joins.
1283 * This step is most easily done after we've done expression
1284 * preprocessing.
1285 */
1286 if (hasOuterJoins)
1288
1289 /*
1290 * If we have any RTE_RESULT relations, see if they can be deleted from
1291 * the jointree. We also rely on this processing to flatten single-child
1292 * FromExprs underneath outer joins. This step is most effectively done
1293 * after we've done expression preprocessing and outer join reduction.
1294 */
1297
1298 /*
1299 * Do the main planning.
1300 */
1301 grouping_planner(root, tuple_fraction, setops);
1302
1303 /*
1304 * Capture the set of outer-level param IDs we have access to, for use in
1305 * extParam/allParam calculations later.
1306 */
1308
1309 /*
1310 * If any initPlans were created in this query level, adjust the surviving
1311 * Paths' costs and parallel-safety flags to account for them. The
1312 * initPlans won't actually get attached to the plan tree till
1313 * create_plan() runs, but we must include their effects now.
1314 */
1317
1318 /*
1319 * Make sure we've identified the cheapest Path for the final rel. (By
1320 * doing this here not in grouping_planner, we include initPlan costs in
1321 * the decision, though it's unlikely that will change anything.)
1322 */
1324
1325 return root;
1326}
@ ACLCHECK_NO_PRIV
Definition acl.h:184
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2654
Bitmapset * bms_make_singleton(int x)
Definition bitmapset.c:216
bool bms_is_member(int x, const Bitmapset *a)
Definition bitmapset.c:510
#define Max(x, y)
Definition c.h:991
bool contain_agg_clause(Node *clause)
Definition clauses.c:190
bool contain_subplans(Node *clause)
Definition clauses.c:339
bool contain_volatile_functions(Node *clause)
Definition clauses.c:547
bool ExecCheckOneRelPerms(RTEPermissionInfo *perminfo)
Definition execMain.c:646
List * list_concat(List *list1, const List *list2)
Definition list.c:561
char * get_rel_name(Oid relid)
Definition lsyscache.c:2078
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
bool expression_returns_set(Node *clause)
Definition nodeFuncs.c:763
#define copyObject(obj)
Definition nodes.h:232
#define IS_OUTER_JOIN(jointype)
Definition nodes.h:348
int assign_special_exec_param(PlannerInfo *root)
List * expand_grouping_sets(List *groupingSets, bool groupDistinct, int limit)
Definition parse_agg.c:1947
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
@ RTE_JOIN
@ RTE_VALUES
@ RTE_SUBQUERY
@ RTE_RESULT
@ RTE_FUNCTION
@ RTE_TABLEFUNC
@ RTE_GROUP
@ OBJECT_VIEW
#define rt_fetch(rangetable_index, rangetable)
Definition parsetree.h:31
#define list_make1(x1)
Definition pg_list.h:212
#define linitial(l)
Definition pg_list.h:178
static int list_cell_number(const List *l, const ListCell *c)
Definition pg_list.h:333
#define EXPRKIND_TABLEFUNC_LATERAL
Definition planner.c:99
#define EXPRKIND_TARGET
Definition planner.c:88
#define EXPRKIND_APPINFO
Definition planner.c:94
static void preprocess_rowmarks(PlannerInfo *root)
Definition planner.c:2478
#define EXPRKIND_TABLESAMPLE
Definition planner.c:96
#define EXPRKIND_GROUPEXPR
Definition planner.c:100
static void preprocess_qual_conditions(PlannerInfo *root, Node *jtnode)
Definition planner.c:1437
#define EXPRKIND_RTFUNC_LATERAL
Definition planner.c:90
#define EXPRKIND_VALUES_LATERAL
Definition planner.c:92
#define EXPRKIND_LIMIT
Definition planner.c:93
#define EXPRKIND_VALUES
Definition planner.c:91
#define EXPRKIND_QUAL
Definition planner.c:87
static void grouping_planner(PlannerInfo *root, double tuple_fraction, SetOperationStmt *setops)
Definition planner.c:1514
#define EXPRKIND_TABLEFUNC
Definition planner.c:98
#define EXPRKIND_RTFUNC
Definition planner.c:89
#define EXPRKIND_ARBITER_ELEM
Definition planner.c:97
void preprocess_function_rtes(PlannerInfo *root)
void flatten_simple_union_all(PlannerInfo *root)
void transform_MERGE_to_join(Query *parse)
void remove_useless_result_rtes(PlannerInfo *root)
void pull_up_sublinks(PlannerInfo *root)
void replace_empty_jointree(Query *parse)
void pull_up_subqueries(PlannerInfo *root)
Query * preprocess_relation_rtes(PlannerInfo *root)
void reduce_outer_joins(PlannerInfo *root)
Node * startOffset
Node * endOffset
void SS_process_ctes(PlannerInfo *root)
Definition subselect.c:883
void SS_identify_outer_params(PlannerInfo *root)
Definition subselect.c:2220
void SS_charge_for_initplans(PlannerInfo *root, RelOptInfo *final_rel)
Definition subselect.c:2284
Node * flatten_group_exprs(PlannerInfo *root, Query *query, Node *node)
Definition var.c:972
Relids pull_varnos(PlannerInfo *root, Node *node)
Definition var.c:114
Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)
Definition var.c:789

References aclcheck_error(), ACLCHECK_NO_PRIV, Assert, assign_special_exec_param(), bms_is_member(), bms_make_singleton(), contain_agg_clause(), contain_subplans(), contain_volatile_functions(), copyObject, CurrentMemoryContext, WindowClause::endOffset, ExecCheckOneRelPerms(), expand_grouping_sets(), expression_returns_set(), EXPRKIND_APPINFO, EXPRKIND_ARBITER_ELEM, EXPRKIND_GROUPEXPR, EXPRKIND_LIMIT, EXPRKIND_QUAL, EXPRKIND_RTFUNC, EXPRKIND_RTFUNC_LATERAL, EXPRKIND_TABLEFUNC, EXPRKIND_TABLEFUNC_LATERAL, EXPRKIND_TABLESAMPLE, EXPRKIND_TARGET, EXPRKIND_VALUES, EXPRKIND_VALUES_LATERAL, fb(), fetch_upper_rel(), flatten_group_exprs(), flatten_join_alias_vars(), flatten_simple_union_all(), get_rel_name(), getRTEPermissionInfo(), grouping_planner(), IS_OUTER_JOIN, lappend(), lfirst, lfirst_node, linitial, list_cell_number(), list_concat(), list_length(), list_make1, makeNode, Max, NIL, OBJECT_VIEW, parse(), preprocess_expression(), preprocess_function_rtes(), preprocess_qual_conditions(), preprocess_relation_rtes(), preprocess_rowmarks(), pull_up_sublinks(), pull_up_subqueries(), pull_varnos(), reduce_outer_joins(), remove_useless_result_rtes(), replace_empty_jointree(), root, rt_fetch, RTE_FUNCTION, RTE_GROUP, RTE_JOIN, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, set_cheapest(), SS_charge_for_initplans(), SS_identify_outer_params(), SS_process_ctes(), WindowClause::startOffset, transform_MERGE_to_join(), and UPPERREL_FINAL.

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

Variable Documentation

◆ create_upper_paths_hook

◆ planner_hook

PGDLLIMPORT planner_hook_type planner_hook
extern

Definition at line 74 of file planner.c.

Referenced by _PG_init(), and planner().

◆ planner_setup_hook

PGDLLIMPORT planner_setup_hook_type planner_setup_hook
extern

Definition at line 77 of file planner.c.

Referenced by standard_planner().

◆ planner_shutdown_hook

PGDLLIMPORT planner_shutdown_hook_type planner_shutdown_hook
extern

Definition at line 80 of file planner.c.

Referenced by standard_planner().