PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
optimizer.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * optimizer.h
4 * External API for the Postgres planner.
5 *
6 * This header is meant to define everything that the core planner
7 * exposes for use by non-planner modules.
8 *
9 * Note that there are files outside src/backend/optimizer/ that are
10 * considered planner modules, because they're too much in bed with
11 * planner operations to be treated otherwise. FDW planning code is an
12 * example. For the most part, however, code outside the core planner
13 * should not need to include any optimizer/ header except this one.
14 *
15 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
16 * Portions Copyright (c) 1994, Regents of the University of California
17 *
18 * src/include/optimizer/optimizer.h
19 *
20 *-------------------------------------------------------------------------
21 */
22#ifndef OPTIMIZER_H
23#define OPTIMIZER_H
24
25#include "nodes/parsenodes.h"
26
27typedef struct ExplainState ExplainState; /* defined in explain_state.h */
28
29/*
30 * We don't want to include nodes/pathnodes.h here, because non-planner
31 * code should generally treat PlannerInfo as an opaque typedef.
32 * But we'd like such code to use that typedef name, so define the
33 * typedef both here and in pathnodes.h.
34 */
35typedef struct PlannerInfo PlannerInfo;
38
39/* It also seems best not to include plannodes.h, params.h, or htup.h here */
40typedef struct PlannedStmt PlannedStmt;
42typedef struct HeapTupleData *HeapTuple;
43
44
45/* in path/clausesel.c: */
46
48 Node *clause,
49 int varRelid,
50 JoinType jointype,
51 SpecialJoinInfo *sjinfo);
53 Node *clause,
54 int varRelid,
55 JoinType jointype,
56 SpecialJoinInfo *sjinfo,
57 bool use_extended_stats);
59 List *clauses,
60 int varRelid,
61 JoinType jointype,
62 SpecialJoinInfo *sjinfo);
64 List *clauses,
65 int varRelid,
66 JoinType jointype,
67 SpecialJoinInfo *sjinfo,
68 bool use_extended_stats);
69
70/* in path/costsize.c: */
71
72/* widely used cost parameters */
73extern PGDLLIMPORT double seq_page_cost;
74extern PGDLLIMPORT double random_page_cost;
75extern PGDLLIMPORT double cpu_tuple_cost;
77extern PGDLLIMPORT double cpu_operator_cost;
82
83extern double clamp_row_est(double nrows);
84extern int32 clamp_width_est(int64 tuple_width);
86
87/* in path/indxpath.c: */
88
91
92/* in plan/planner.c: */
93
94/* possible values for debug_parallel_query */
95typedef enum
96{
101
102/* GUC parameters */
106
107extern PlannedStmt *planner(Query *parse, const char *query_string,
108 int cursorOptions,
109 ParamListInfo boundParams,
110 ExplainState *es);
111
112extern Expr *expression_planner(Expr *expr);
114 List **relationOids,
115 List **invalItems);
116
117extern bool plan_cluster_use_sort(Oid tableOid, Oid indexOid);
118extern int plan_create_index_workers(Oid tableOid, Oid indexOid);
119
120/* in plan/setrefs.c: */
121
122extern void extract_query_dependencies(Node *query,
123 List **relationOids,
124 List **invalItems,
125 bool *hasRowSecurity);
126
127/* in prep/prepqual.c: */
128
129extern Node *negate_clause(Node *node);
130extern Expr *canonicalize_qual(Expr *qual, bool is_check);
131
132/* in util/clauses.c: */
133
134extern bool contain_mutable_functions(Node *clause);
136extern bool contain_volatile_functions(Node *clause);
139
141
142extern void convert_saop_to_hashed_saop(Node *node);
143
145
146extern Expr *evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod,
147 Oid result_collation);
148
149extern bool var_is_nonnullable(PlannerInfo *root, Var *var, bool use_rel_info);
150
151extern List *expand_function_arguments(List *args, bool include_out_arguments,
152 Oid result_type,
153 HeapTuple func_tuple);
154
155extern ScalarArrayOpExpr *make_SAOP_expr(Oid oper, Node *leftexpr,
156 Oid coltype, Oid arraycollid,
157 Oid inputcollid, List *exprs,
158 bool haveNonConst);
159
160/* in util/predtest.c: */
161
162extern bool predicate_implied_by(List *predicate_list, List *clause_list,
163 bool weak);
164extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
165 bool weak);
166
167/* in util/tlist.c: */
168
169extern int count_nonjunk_tlist_entries(List *tlist);
171 List *targetList);
173 List *targetList);
175 List *targetList);
176extern List *get_sortgrouplist_exprs(List *sgClauses,
177 List *targetList);
179 List *clauses);
181 List *clauses);
182
183/* in util/var.c: */
184
185/* Bits that can be OR'd into the flags argument of pull_var_clause() */
186#define PVC_INCLUDE_AGGREGATES 0x0001 /* include Aggrefs in output list */
187#define PVC_RECURSE_AGGREGATES 0x0002 /* recurse into Aggref arguments */
188#define PVC_INCLUDE_WINDOWFUNCS 0x0004 /* include WindowFuncs in output list */
189#define PVC_RECURSE_WINDOWFUNCS 0x0008 /* recurse into WindowFunc arguments */
190#define PVC_INCLUDE_PLACEHOLDERS 0x0010 /* include PlaceHolderVars in
191 * output list */
192#define PVC_RECURSE_PLACEHOLDERS 0x0020 /* recurse into PlaceHolderVar
193 * arguments */
194#define PVC_INCLUDE_CONVERTROWTYPES 0x0040 /* include ConvertRowtypeExprs in
195 * output list */
196
197extern Bitmapset *pull_varnos(PlannerInfo *root, Node *node);
198extern Bitmapset *pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup);
199extern void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos);
200extern List *pull_vars_of_level(Node *node, int levelsup);
201extern bool contain_var_clause(Node *node);
202extern bool contain_vars_of_level(Node *node, int levelsup);
203extern bool contain_vars_returning_old_or_new(Node *node);
204extern int locate_var_of_level(Node *node, int levelsup);
205extern List *pull_var_clause(Node *node, int flags);
206extern Node *flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node);
207extern Node *flatten_group_exprs(PlannerInfo *root, Query *query, Node *node);
208
209#endif /* OPTIMIZER_H */
#define PGDLLIMPORT
Definition: c.h:1319
int64_t int64
Definition: c.h:535
int32_t int32
Definition: c.h:534
unsigned int Index
Definition: c.h:619
int x
Definition: isn.c:75
double Cardinality
Definition: nodes.h:262
double Selectivity
Definition: nodes.h:260
JoinType
Definition: nodes.h:298
PGDLLIMPORT double cpu_operator_cost
Definition: costsize.c:134
bool contain_volatile_functions_not_nextval(Node *clause)
Definition: clauses.c:677
PGDLLIMPORT bool parallel_leader_participation
Definition: planner.c:70
Expr * canonicalize_qual(Expr *qual, bool is_check)
Definition: prepqual.c:293
Expr * expression_planner_with_deps(Expr *expr, List **relationOids, List **invalItems)
Definition: planner.c:6773
struct HeapTupleData * HeapTuple
Definition: optimizer.h:42
Selectivity clause_selectivity_ext(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
Definition: clausesel.c:684
bool predicate_refuted_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:222
PlannedStmt * planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams, ExplainState *es)
Definition: planner.c:315
Bitmapset * pull_varnos(PlannerInfo *root, Node *node)
Definition: var.c:114
bool contain_vars_of_level(Node *node, int levelsup)
Definition: var.c:444
Node * flatten_group_exprs(PlannerInfo *root, Query *query, Node *node)
Definition: var.c:968
PGDLLIMPORT bool enable_distinct_reordering
Definition: planner.c:71
bool contain_var_clause(Node *node)
Definition: var.c:406
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
Definition: tlist.c:443
bool is_pseudo_constant_for_index(PlannerInfo *root, Node *expr, IndexOptInfo *index)
Definition: indxpath.c:4456
bool plan_cluster_use_sort(Oid tableOid, Oid indexOid)
Definition: planner.c:6826
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:135
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:374
SortGroupClause * get_sortgroupref_clause(Index sortref, List *clauses)
Definition: tlist.c:422
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2403
int plan_create_index_workers(Oid tableOid, Oid indexOid)
Definition: planner.c:6948
PGDLLIMPORT double parallel_setup_cost
Definition: costsize.c:136
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:100
List * pull_vars_of_level(Node *node, int levelsup)
Definition: var.c:339
List * pull_var_clause(Node *node, int flags)
Definition: var.c:653
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2262
bool contain_volatile_functions_after_planning(Expr *expr)
Definition: clauses.c:663
Bitmapset * pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup)
Definition: var.c:140
PGDLLIMPORT int debug_parallel_query
Definition: planner.c:69
bool contain_mutable_functions_after_planning(Expr *expr)
Definition: clauses.c:494
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:367
Selectivity clauselist_selectivity_ext(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
Definition: clausesel.c:117
Node * flatten_join_alias_vars(PlannerInfo *root, Query *query, Node *node)
Definition: var.c:789
DebugParallelMode
Definition: optimizer.h:96
@ DEBUG_PARALLEL_REGRESS
Definition: optimizer.h:99
@ DEBUG_PARALLEL_ON
Definition: optimizer.h:98
@ DEBUG_PARALLEL_OFF
Definition: optimizer.h:97
struct ParamListInfoData * ParamListInfo
Definition: optimizer.h:41
Node * negate_clause(Node *node)
Definition: prepqual.c:73
void convert_saop_to_hashed_saop(Node *node)
Definition: clauses.c:2295
PGDLLIMPORT double cpu_tuple_cost
Definition: costsize.c:132
List * get_sortgrouplist_exprs(List *sgClauses, List *targetList)
Definition: tlist.c:392
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:152
List * expand_function_arguments(List *args, bool include_out_arguments, Oid result_type, HeapTuple func_tuple)
Definition: clauses.c:4279
PGDLLIMPORT double recursive_worktable_factor
Definition: costsize.c:137
TargetEntry * get_sortgroupref_tle(Index sortref, List *targetList)
Definition: tlist.c:345
void extract_query_dependencies(Node *query, List **relationOids, List **invalItems, bool *hasRowSecurity)
Definition: setrefs.c:3656
Expr * expression_planner(Expr *expr)
Definition: planner.c:6746
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:133
int count_nonjunk_tlist_entries(List *tlist)
Definition: tlist.c:186
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:296
PGDLLIMPORT double seq_page_cost
Definition: costsize.c:130
int locate_var_of_level(Node *node, int levelsup)
Definition: var.c:555
double clamp_row_est(double nrows)
Definition: costsize.c:213
PGDLLIMPORT int effective_cache_size
Definition: costsize.c:139
long clamp_cardinality_to_long(Cardinality x)
Definition: costsize.c:265
PGDLLIMPORT double random_page_cost
Definition: costsize.c:131
ScalarArrayOpExpr * make_SAOP_expr(Oid oper, Node *leftexpr, Oid coltype, Oid arraycollid, Oid inputcollid, List *exprs, bool haveNonConst)
Definition: clauses.c:5553
bool contain_vars_returning_old_or_new(Node *node)
Definition: var.c:511
int32 clamp_width_est(int64 tuple_width)
Definition: costsize.c:242
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
Definition: clauses.c:5076
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:542
bool var_is_nonnullable(PlannerInfo *root, Var *var, bool use_rel_info)
Definition: clauses.c:4207
Node * get_sortgroupclause_expr(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:379
Selectivity clause_selectivity(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:667
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:371
unsigned int Oid
Definition: postgres_ext.h:32
tree ctl root
Definition: radixtree.h:1857
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
Definition: regcomp.c:717
Definition: pg_list.h:54
Definition: nodes.h:135
Definition: primnodes.h:262
Definition: type.h:96