PostgreSQL Source Code  git master
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-2022, 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 
27 /*
28  * We don't want to include nodes/pathnodes.h here, because non-planner
29  * code should generally treat PlannerInfo as an opaque typedef.
30  * But we'd like such code to use that typedef name, so define the
31  * typedef either here or in pathnodes.h, whichever is read first.
32  */
33 #ifndef HAVE_PLANNERINFO_TYPEDEF
34 typedef struct PlannerInfo PlannerInfo;
35 #define HAVE_PLANNERINFO_TYPEDEF 1
36 #endif
37 
38 /* Likewise for IndexOptInfo and SpecialJoinInfo. */
39 #ifndef HAVE_INDEXOPTINFO_TYPEDEF
40 typedef struct IndexOptInfo IndexOptInfo;
41 #define HAVE_INDEXOPTINFO_TYPEDEF 1
42 #endif
43 #ifndef HAVE_SPECIALJOININFO_TYPEDEF
44 typedef struct SpecialJoinInfo SpecialJoinInfo;
45 #define HAVE_SPECIALJOININFO_TYPEDEF 1
46 #endif
47 
48 /* It also seems best not to include plannodes.h, params.h, or htup.h here */
49 struct PlannedStmt;
50 struct ParamListInfoData;
51 struct HeapTupleData;
52 
53 
54 /* in path/clausesel.c: */
55 
57  Node *clause,
58  int varRelid,
59  JoinType jointype,
60  SpecialJoinInfo *sjinfo);
62  Node *clause,
63  int varRelid,
64  JoinType jointype,
65  SpecialJoinInfo *sjinfo,
66  bool use_extended_stats);
68  List *clauses,
69  int varRelid,
70  JoinType jointype,
71  SpecialJoinInfo *sjinfo);
73  List *clauses,
74  int varRelid,
75  JoinType jointype,
76  SpecialJoinInfo *sjinfo,
77  bool use_extended_stats);
78 
79 /* in path/costsize.c: */
80 
81 /* widely used cost parameters */
82 extern PGDLLIMPORT double seq_page_cost;
83 extern PGDLLIMPORT double random_page_cost;
84 extern PGDLLIMPORT double cpu_tuple_cost;
85 extern PGDLLIMPORT double cpu_index_tuple_cost;
86 extern PGDLLIMPORT double cpu_operator_cost;
87 extern PGDLLIMPORT double parallel_tuple_cost;
88 extern PGDLLIMPORT double parallel_setup_cost;
91 
92 extern double clamp_row_est(double nrows);
94 
95 /* in path/indxpath.c: */
96 
97 extern bool is_pseudo_constant_for_index(PlannerInfo *root, Node *expr,
99 
100 /* in plan/planner.c: */
101 
102 /* possible values for force_parallel_mode */
103 typedef enum
104 {
109 
110 /* GUC parameters */
113 
114 extern struct PlannedStmt *planner(Query *parse, const char *query_string,
115  int cursorOptions,
116  struct ParamListInfoData *boundParams);
117 
118 extern Expr *expression_planner(Expr *expr);
120  List **relationOids,
121  List **invalItems);
122 
123 extern bool plan_cluster_use_sort(Oid tableOid, Oid indexOid);
124 extern int plan_create_index_workers(Oid tableOid, Oid indexOid);
125 
126 /* in plan/setrefs.c: */
127 
128 extern void extract_query_dependencies(Node *query,
129  List **relationOids,
130  List **invalItems,
131  bool *hasRowSecurity);
132 
133 /* in prep/prepqual.c: */
134 
135 extern Node *negate_clause(Node *node);
136 extern Expr *canonicalize_qual(Expr *qual, bool is_check);
137 
138 /* in util/clauses.c: */
139 
140 extern bool contain_mutable_functions(Node *clause);
141 extern bool contain_volatile_functions(Node *clause);
142 extern bool contain_volatile_functions_not_nextval(Node *clause);
143 
144 extern Node *eval_const_expressions(PlannerInfo *root, Node *node);
145 
146 extern void convert_saop_to_hashed_saop(Node *node);
147 
148 extern Node *estimate_expression_value(PlannerInfo *root, Node *node);
149 
150 extern Expr *evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod,
151  Oid result_collation);
152 
153 extern List *expand_function_arguments(List *args, bool include_out_arguments,
154  Oid result_type,
155  struct HeapTupleData *func_tuple);
156 
157 /* in util/predtest.c: */
158 
159 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
160  bool weak);
161 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
162  bool weak);
163 
164 /* in util/tlist.c: */
165 
166 extern int count_nonjunk_tlist_entries(List *tlist);
167 extern TargetEntry *get_sortgroupref_tle(Index sortref,
168  List *targetList);
170  List *targetList);
172  List *targetList);
173 extern List *get_sortgrouplist_exprs(List *sgClauses,
174  List *targetList);
176  List *clauses);
178  List *clauses);
179 
180 /* in util/var.c: */
181 
182 /* Bits that can be OR'd into the flags argument of pull_var_clause() */
183 #define PVC_INCLUDE_AGGREGATES 0x0001 /* include Aggrefs in output list */
184 #define PVC_RECURSE_AGGREGATES 0x0002 /* recurse into Aggref arguments */
185 #define PVC_INCLUDE_WINDOWFUNCS 0x0004 /* include WindowFuncs in output list */
186 #define PVC_RECURSE_WINDOWFUNCS 0x0008 /* recurse into WindowFunc arguments */
187 #define PVC_INCLUDE_PLACEHOLDERS 0x0010 /* include PlaceHolderVars in
188  * output list */
189 #define PVC_RECURSE_PLACEHOLDERS 0x0020 /* recurse into PlaceHolderVar
190  * arguments */
191 
192 extern Bitmapset *pull_varnos(PlannerInfo *root, Node *node);
193 extern Bitmapset *pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup);
194 extern void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos);
195 extern List *pull_vars_of_level(Node *node, int levelsup);
196 extern bool contain_var_clause(Node *node);
197 extern bool contain_vars_of_level(Node *node, int levelsup);
198 extern int locate_var_of_level(Node *node, int levelsup);
199 extern List *pull_var_clause(Node *node, int flags);
200 extern Node *flatten_join_alias_vars(Query *query, Node *node);
201 
202 #endif /* OPTIMIZER_H */
#define PGDLLIMPORT
Definition: c.h:1252
signed int int32
Definition: c.h:430
unsigned int Index
Definition: c.h:550
int x
Definition: isn.c:71
double Cardinality
Definition: nodes.h:252
double Selectivity
Definition: nodes.h:250
JoinType
Definition: nodes.h:288
PGDLLIMPORT double cpu_operator_cost
Definition: costsize.c:124
bool contain_volatile_functions_not_nextval(Node *clause)
Definition: clauses.c:555
PGDLLIMPORT bool parallel_leader_participation
Definition: planner.c:72
Expr * expression_planner(Expr *expr)
Definition: planner.c:6147
struct PlannedStmt * planner(Query *parse, const char *query_string, int cursorOptions, struct ParamListInfoData *boundParams)
List * get_sortgrouplist_exprs(List *sgClauses, List *targetList)
Definition: tlist.c:392
List * pull_vars_of_level(Node *node, int levelsup)
Definition: var.c:325
TargetEntry * get_sortgroupref_tle(Index sortref, List *targetList)
Definition: tlist.c:345
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
Definition: clauses.c:4807
Selectivity clause_selectivity_ext(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
Definition: clausesel.c:707
bool predicate_refuted_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:222
bool contain_vars_of_level(Node *node, int levelsup)
Definition: var.c:431
List * pull_var_clause(Node *node, int flags)
Definition: var.c:597
bool contain_var_clause(Node *node)
Definition: var.c:393
bool is_pseudo_constant_for_index(PlannerInfo *root, Node *expr, IndexOptInfo *index)
Definition: indxpath.c:3801
bool plan_cluster_use_sort(Oid tableOid, Oid indexOid)
Definition: planner.c:6227
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:125
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:365
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
Definition: tlist.c:443
int plan_create_index_workers(Oid tableOid, Oid indexOid)
Definition: planner.c:6345
PGDLLIMPORT double parallel_setup_cost
Definition: costsize.c:126
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:102
ForceParallelMode
Definition: optimizer.h:104
@ FORCE_PARALLEL_ON
Definition: optimizer.h:106
@ FORCE_PARALLEL_OFF
Definition: optimizer.h:105
@ FORCE_PARALLEL_REGRESS
Definition: optimizer.h:107
Node * negate_clause(Node *node)
Definition: prepqual.c:74
Selectivity clauselist_selectivity_ext(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
Definition: clausesel.c:119
Bitmapset * pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup)
Definition: var.c:126
Node * get_sortgroupclause_expr(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:379
Bitmapset * pull_varnos(PlannerInfo *root, Node *node)
Definition: var.c:100
void convert_saop_to_hashed_saop(Node *node)
Definition: clauses.c:2165
PGDLLIMPORT double cpu_tuple_cost
Definition: costsize.c:122
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:367
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:152
PGDLLIMPORT double recursive_worktable_factor
Definition: costsize.c:127
List * expand_function_arguments(List *args, bool include_out_arguments, Oid result_type, struct HeapTupleData *func_tuple)
void extract_query_dependencies(Node *query, List **relationOids, List **invalItems, bool *hasRowSecurity)
Definition: setrefs.c:3297
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:123
int count_nonjunk_tlist_entries(List *tlist)
Definition: tlist.c:186
PGDLLIMPORT int force_parallel_mode
Definition: planner.c:71
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:281
PGDLLIMPORT double seq_page_cost
Definition: costsize.c:120
Expr * expression_planner_with_deps(Expr *expr, List **relationOids, List **invalItems)
Definition: planner.c:6174
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2132
int locate_var_of_level(Node *node, int levelsup)
Definition: var.c:499
SortGroupClause * get_sortgroupref_clause(Index sortref, List *clauses)
Definition: tlist.c:422
double clamp_row_est(double nrows)
Definition: costsize.c:201
Node * flatten_join_alias_vars(Query *query, Node *node)
Definition: var.c:726
PGDLLIMPORT int effective_cache_size
Definition: costsize.c:129
long clamp_cardinality_to_long(Cardinality x)
Definition: costsize.c:224
PGDLLIMPORT double random_page_cost
Definition: costsize.c:121
Expr * canonicalize_qual(Expr *qual, bool is_check)
Definition: prepqual.c:294
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:448
Selectivity clause_selectivity(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:690
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2273
unsigned int Oid
Definition: postgres_ext.h:31
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:52
Definition: nodes.h:118
List * invalItems
Definition: plannodes.h:92
List * relationOids
Definition: plannodes.h:90
Definition: type.h:95