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-2021, 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 /* Test if an expression node represents a SRF call. Beware multiple eval! */
28 #define IS_SRF_CALL(node) \
29  ((IsA(node, FuncExpr) && ((FuncExpr *) (node))->funcretset) || \
30  (IsA(node, OpExpr) && ((OpExpr *) (node))->opretset))
31 
32 /*
33  * We don't want to include nodes/pathnodes.h here, because non-planner
34  * code should generally treat PlannerInfo as an opaque typedef.
35  * But we'd like such code to use that typedef name, so define the
36  * typedef either here or in pathnodes.h, whichever is read first.
37  */
38 #ifndef HAVE_PLANNERINFO_TYPEDEF
39 typedef struct PlannerInfo PlannerInfo;
40 #define HAVE_PLANNERINFO_TYPEDEF 1
41 #endif
42 
43 /* Likewise for IndexOptInfo and SpecialJoinInfo. */
44 #ifndef HAVE_INDEXOPTINFO_TYPEDEF
45 typedef struct IndexOptInfo IndexOptInfo;
46 #define HAVE_INDEXOPTINFO_TYPEDEF 1
47 #endif
48 #ifndef HAVE_SPECIALJOININFO_TYPEDEF
50 #define HAVE_SPECIALJOININFO_TYPEDEF 1
51 #endif
52 
53 /* It also seems best not to include plannodes.h, params.h, or htup.h here */
54 struct PlannedStmt;
55 struct ParamListInfoData;
56 struct HeapTupleData;
57 
58 
59 /* in path/clausesel.c: */
60 
62  Node *clause,
63  int varRelid,
64  JoinType jointype,
65  SpecialJoinInfo *sjinfo);
67  Node *clause,
68  int varRelid,
69  JoinType jointype,
70  SpecialJoinInfo *sjinfo,
71  bool use_extended_stats);
73  List *clauses,
74  int varRelid,
75  JoinType jointype,
76  SpecialJoinInfo *sjinfo);
78  List *clauses,
79  int varRelid,
80  JoinType jointype,
81  SpecialJoinInfo *sjinfo,
82  bool use_extended_stats);
83 
84 /* in path/costsize.c: */
85 
86 /* widely used cost parameters */
87 extern PGDLLIMPORT double seq_page_cost;
88 extern PGDLLIMPORT double random_page_cost;
89 extern PGDLLIMPORT double cpu_tuple_cost;
90 extern PGDLLIMPORT double cpu_index_tuple_cost;
91 extern PGDLLIMPORT double cpu_operator_cost;
92 extern PGDLLIMPORT double parallel_tuple_cost;
93 extern PGDLLIMPORT double parallel_setup_cost;
95 
96 extern double clamp_row_est(double nrows);
97 
98 /* in path/indxpath.c: */
99 
100 extern bool is_pseudo_constant_for_index(PlannerInfo *root, Node *expr,
102 
103 /* in plan/planner.c: */
104 
105 /* possible values for force_parallel_mode */
106 typedef enum
107 {
112 
113 /* GUC parameters */
114 extern int force_parallel_mode;
116 
117 extern struct PlannedStmt *planner(Query *parse, const char *query_string,
118  int cursorOptions,
119  struct ParamListInfoData *boundParams);
120 
121 extern Expr *expression_planner(Expr *expr);
123  List **relationOids,
124  List **invalItems);
125 
126 extern bool plan_cluster_use_sort(Oid tableOid, Oid indexOid);
127 extern int plan_create_index_workers(Oid tableOid, Oid indexOid);
128 
129 /* in plan/setrefs.c: */
130 
131 extern void extract_query_dependencies(Node *query,
132  List **relationOids,
133  List **invalItems,
134  bool *hasRowSecurity);
135 
136 /* in prep/prepqual.c: */
137 
138 extern Node *negate_clause(Node *node);
139 extern Expr *canonicalize_qual(Expr *qual, bool is_check);
140 
141 /* in util/clauses.c: */
142 
143 extern bool contain_mutable_functions(Node *clause);
144 extern bool contain_volatile_functions(Node *clause);
145 extern bool contain_volatile_functions_not_nextval(Node *clause);
146 
147 extern Node *eval_const_expressions(PlannerInfo *root, Node *node);
148 
149 extern void convert_saop_to_hashed_saop(Node *node);
150 
151 extern Node *estimate_expression_value(PlannerInfo *root, Node *node);
152 
153 extern Expr *evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod,
154  Oid result_collation);
155 
156 extern List *expand_function_arguments(List *args, bool include_out_arguments,
157  Oid result_type,
158  struct HeapTupleData *func_tuple);
159 
160 /* in util/predtest.c: */
161 
162 extern bool predicate_implied_by(List *predicate_list, List *clause_list,
163  bool weak);
164 extern bool predicate_refuted_by(List *predicate_list, List *clause_list,
165  bool weak);
166 
167 /* in util/tlist.c: */
168 
169 extern int count_nonjunk_tlist_entries(List *tlist);
170 extern TargetEntry *get_sortgroupref_tle(Index sortref,
171  List *targetList);
173  List *targetList);
175  List *targetList);
176 extern 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 
195 extern Bitmapset *pull_varnos(PlannerInfo *root, Node *node);
196 extern Bitmapset *pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup);
197 extern void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos);
198 extern List *pull_vars_of_level(Node *node, int levelsup);
199 extern bool contain_var_clause(Node *node);
200 extern bool contain_vars_of_level(Node *node, int levelsup);
201 extern int locate_var_of_level(Node *node, int levelsup);
202 extern List *pull_var_clause(Node *node, int flags);
203 extern Node *flatten_join_alias_vars(Query *query, Node *node);
204 
205 #endif /* OPTIMIZER_H */
bool parallel_leader_participation
Definition: planner.c:71
List * expand_function_arguments(List *args, bool include_out_arguments, Oid result_type, struct HeapTupleData *func_tuple)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2094
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:122
bool is_pseudo_constant_for_index(PlannerInfo *root, Node *expr, IndexOptInfo *index)
Definition: indxpath.c:3818
struct PlannedStmt * planner(Query *parse, const char *query_string, int cursorOptions, struct ParamListInfoData *boundParams)
Expr * expression_planner(Expr *expr)
Definition: planner.c:5806
PGDLLIMPORT double parallel_setup_cost
Definition: costsize.c:125
TargetEntry * get_sortgroupref_tle(Index sortref, List *targetList)
Definition: tlist.c:334
int plan_create_index_workers(Oid tableOid, Oid indexOid)
Definition: planner.c:6004
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
Definition: clauses.c:4785
List * relationOids
Definition: plannodes.h:80
Selectivity clauselist_selectivity_ext(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
Definition: clausesel.c:119
int force_parallel_mode
Definition: planner.c:70
Definition: nodes.h:536
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:281
PGDLLIMPORT double cpu_tuple_cost
Definition: costsize.c:121
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
Definition: tlist.c:432
double Selectivity
Definition: nodes.h:669
unsigned int Oid
Definition: postgres_ext.h:31
Node * get_sortgroupclause_expr(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:368
void convert_saop_to_hashed_saop(Node *node)
Definition: clauses.c:2126
#define PGDLLIMPORT
Definition: c.h:1317
PGDLLIMPORT double cpu_operator_cost
Definition: costsize.c:123
signed int int32
Definition: c.h:429
JoinType
Definition: nodes.h:704
List * invalItems
Definition: plannodes.h:82
Definition: type.h:89
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:151
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2234
double clamp_row_est(double nrows)
Definition: costsize.c:199
Node * flatten_join_alias_vars(Query *query, Node *node)
Definition: var.c:732
int locate_var_of_level(Node *node, int levelsup)
Definition: var.c:499
bool contain_volatile_functions_not_nextval(Node *clause)
Definition: clauses.c:559
int count_nonjunk_tlist_entries(List *tlist)
Definition: tlist.c:175
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
Definition: tlist.c:356
Bitmapset * pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup)
Definition: var.c:123
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:452
void extract_query_dependencies(Node *query, List **relationOids, List **invalItems, bool *hasRowSecurity)
Definition: setrefs.c:3044
PGDLLIMPORT int effective_cache_size
Definition: costsize.c:127
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:102
ForceParallelMode
Definition: optimizer.h:106
Expr * canonicalize_qual(Expr *qual, bool is_check)
Definition: prepqual.c:294
List * get_sortgrouplist_exprs(List *sgClauses, List *targetList)
Definition: tlist.c:381
PGDLLIMPORT double random_page_cost
Definition: costsize.c:120
bool contain_var_clause(Node *node)
Definition: var.c:393
unsigned int Index
Definition: c.h:549
List * pull_var_clause(Node *node, int flags)
Definition: var.c:597
Bitmapset * pull_varnos(PlannerInfo *root, Node *node)
Definition: var.c:97
Expr * expression_planner_with_deps(Expr *expr, List **relationOids, List **invalItems)
Definition: planner.c:5833
List * pull_vars_of_level(Node *node, int levelsup)
Definition: var.c:325
bool plan_cluster_use_sort(Oid tableOid, Oid indexOid)
Definition: planner.c:5886
PGDLLIMPORT double seq_page_cost
Definition: costsize.c:119
SortGroupClause * get_sortgroupref_clause(Index sortref, List *clauses)
Definition: tlist.c:411
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:363
Selectivity clause_selectivity(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:690
bool contain_vars_of_level(Node *node, int levelsup)
Definition: var.c:431
bool predicate_refuted_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:221
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:124
Node * negate_clause(Node *node)
Definition: prepqual.c:74
Definition: pg_list.h:50
Selectivity clause_selectivity_ext(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo, bool use_extended_stats)
Definition: clausesel.c:707
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:673