PostgreSQL Source Code  git master
cost.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * cost.h
4  * prototypes for costsize.c and clausesel.c.
5  *
6  *
7  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/optimizer/cost.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef COST_H
15 #define COST_H
16 
17 #include "nodes/pathnodes.h"
18 #include "nodes/plannodes.h"
19 
20 
21 /* defaults for costsize.c's Cost parameters */
22 /* NB: cost-estimation code should use the variables, not these constants! */
23 /* If you change these, update backend/utils/misc/postgresql.sample.conf */
24 #define DEFAULT_SEQ_PAGE_COST 1.0
25 #define DEFAULT_RANDOM_PAGE_COST 4.0
26 #define DEFAULT_CPU_TUPLE_COST 0.01
27 #define DEFAULT_CPU_INDEX_TUPLE_COST 0.005
28 #define DEFAULT_CPU_OPERATOR_COST 0.0025
29 #define DEFAULT_PARALLEL_TUPLE_COST 0.1
30 #define DEFAULT_PARALLEL_SETUP_COST 1000.0
31 
32 #define DEFAULT_EFFECTIVE_CACHE_SIZE 524288 /* measured in pages */
33 
34 typedef enum
35 {
36  CONSTRAINT_EXCLUSION_OFF, /* do not use c_e */
37  CONSTRAINT_EXCLUSION_ON, /* apply c_e to all rels */
38  CONSTRAINT_EXCLUSION_PARTITION /* apply c_e to otherrels only */
40 
41 
42 /*
43  * prototypes for costsize.c
44  * routines to compute costs and sizes
45  */
46 
47 /* parameter variables and flags (see also optimizer.h) */
50 extern PGDLLIMPORT bool enable_seqscan;
51 extern PGDLLIMPORT bool enable_indexscan;
53 extern PGDLLIMPORT bool enable_bitmapscan;
54 extern PGDLLIMPORT bool enable_tidscan;
55 extern PGDLLIMPORT bool enable_sort;
56 extern PGDLLIMPORT bool enable_hashagg;
57 extern PGDLLIMPORT bool enable_nestloop;
58 extern PGDLLIMPORT bool enable_material;
59 extern PGDLLIMPORT bool enable_mergejoin;
60 extern PGDLLIMPORT bool enable_hashjoin;
68 
69 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
70  double index_pages, PlannerInfo *root);
71 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
72  ParamPathInfo *param_info);
73 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
74  ParamPathInfo *param_info);
75 extern void cost_index(IndexPath *path, PlannerInfo *root,
76  double loop_count, bool partial_path);
77 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
78  ParamPathInfo *param_info,
79  Path *bitmapqual, double loop_count);
80 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
81 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
82 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
83 extern void cost_tidscan(Path *path, PlannerInfo *root,
84  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
85 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
86  RelOptInfo *baserel, ParamPathInfo *param_info);
87 extern void cost_functionscan(Path *path, PlannerInfo *root,
88  RelOptInfo *baserel, ParamPathInfo *param_info);
89 extern void cost_valuesscan(Path *path, PlannerInfo *root,
90  RelOptInfo *baserel, ParamPathInfo *param_info);
91 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
92  RelOptInfo *baserel, ParamPathInfo *param_info);
93 extern void cost_ctescan(Path *path, PlannerInfo *root,
94  RelOptInfo *baserel, ParamPathInfo *param_info);
95 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
96  RelOptInfo *baserel, ParamPathInfo *param_info);
97 extern void cost_resultscan(Path *path, PlannerInfo *root,
98  RelOptInfo *baserel, ParamPathInfo *param_info);
99 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
100 extern void cost_sort(Path *path, PlannerInfo *root,
101  List *pathkeys, Cost input_cost, double tuples, int width,
102  Cost comparison_cost, int sort_mem,
103  double limit_tuples);
104 extern void cost_append(AppendPath *path);
105 extern void cost_merge_append(Path *path, PlannerInfo *root,
106  List *pathkeys, int n_streams,
107  Cost input_startup_cost, Cost input_total_cost,
108  double tuples);
109 extern void cost_material(Path *path,
110  Cost input_startup_cost, Cost input_total_cost,
111  double tuples, int width);
112 extern void cost_agg(Path *path, PlannerInfo *root,
113  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
114  int numGroupCols, double numGroups,
115  List *quals,
116  Cost input_startup_cost, Cost input_total_cost,
117  double input_tuples);
118 extern void cost_windowagg(Path *path, PlannerInfo *root,
119  List *windowFuncs, int numPartCols, int numOrderCols,
120  Cost input_startup_cost, Cost input_total_cost,
121  double input_tuples);
122 extern void cost_group(Path *path, PlannerInfo *root,
123  int numGroupCols, double numGroups,
124  List *quals,
125  Cost input_startup_cost, Cost input_total_cost,
126  double input_tuples);
127 extern void initial_cost_nestloop(PlannerInfo *root,
128  JoinCostWorkspace *workspace,
129  JoinType jointype,
130  Path *outer_path, Path *inner_path,
131  JoinPathExtraData *extra);
132 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
133  JoinCostWorkspace *workspace,
134  JoinPathExtraData *extra);
135 extern void initial_cost_mergejoin(PlannerInfo *root,
136  JoinCostWorkspace *workspace,
137  JoinType jointype,
138  List *mergeclauses,
139  Path *outer_path, Path *inner_path,
140  List *outersortkeys, List *innersortkeys,
141  JoinPathExtraData *extra);
142 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
143  JoinCostWorkspace *workspace,
144  JoinPathExtraData *extra);
145 extern void initial_cost_hashjoin(PlannerInfo *root,
146  JoinCostWorkspace *workspace,
147  JoinType jointype,
148  List *hashclauses,
149  Path *outer_path, Path *inner_path,
150  JoinPathExtraData *extra,
151  bool parallel_hash);
152 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
153  JoinCostWorkspace *workspace,
154  JoinPathExtraData *extra);
155 extern void cost_gather(GatherPath *path, PlannerInfo *root,
156  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
157 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
158  RelOptInfo *rel, ParamPathInfo *param_info,
159  Cost input_startup_cost, Cost input_total_cost,
160  double *rows);
161 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
162 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
163 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
165  RelOptInfo *joinrel,
166  RelOptInfo *outerrel,
167  RelOptInfo *innerrel,
168  JoinType jointype,
169  SpecialJoinInfo *sjinfo,
170  List *restrictlist,
171  SemiAntiJoinFactors *semifactors);
172 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
173 extern double get_parameterized_baserel_size(PlannerInfo *root,
174  RelOptInfo *rel,
175  List *param_clauses);
176 extern double get_parameterized_joinrel_size(PlannerInfo *root,
177  RelOptInfo *rel,
178  Path *outer_path,
179  Path *inner_path,
180  SpecialJoinInfo *sjinfo,
181  List *restrict_clauses);
182 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
183  RelOptInfo *outer_rel,
184  RelOptInfo *inner_rel,
185  SpecialJoinInfo *sjinfo,
186  List *restrictlist);
187 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
188 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
189 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
190 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
191  double cte_rows);
192 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
194 extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel);
195 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
197 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
198  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
199 
200 #endif /* COST_H */
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:131
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5030
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2151
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:288
void cost_append(AppendPath *path)
Definition: costsize.c:1875
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5052
PGDLLIMPORT bool enable_material
Definition: costsize.c:132
Definition: nodes.h:525
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:476
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1539
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1041
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition: costsize.c:137
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:133
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2928
uint32 BlockNumber
Definition: block.h:31
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1084
double Selectivity
Definition: nodes.h:658
PGDLLIMPORT Cost disable_cost
Definition: costsize.c:120
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2346
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4404
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4515
void cost_merge_append(Path *path, PlannerInfo *root, List *pathkeys, int n_streams, Cost input_startup_cost, Cost input_total_cost, double tuples)
Definition: costsize.c:2048
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1331
#define PGDLLIMPORT
Definition: c.h:1266
JoinType
Definition: nodes.h:692
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:3845
PGDLLIMPORT bool enable_partition_pruning
Definition: costsize.c:140
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1498
PGDLLIMPORT bool enable_seqscan
Definition: costsize.c:124
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1176
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1693
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:363
ConstraintExclusionType
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1448
void cost_windowagg(Path *path, PlannerInfo *root, List *windowFuncs, int numPartCols, int numOrderCols, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2272
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:825
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2416
PGDLLIMPORT bool enable_gathermerge
Definition: costsize.c:135
PGDLLIMPORT bool enable_hashjoin
Definition: costsize.c:134
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:5084
void initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *mergeclauses, Path *outer_path, Path *inner_path, List *outersortkeys, List *innersortkeys, JoinPathExtraData *extra)
Definition: costsize.c:2698
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:57
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1392
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3819
PGDLLIMPORT bool enable_indexonlyscan
Definition: costsize.c:126
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4992
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3619
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1576
void cost_gather_merge(GatherMergePath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, Cost input_startup_cost, Cost input_total_cost, double *rows)
Definition: costsize.c:401
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3364
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1613
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5121
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5183
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4483
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4912
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2097
PGDLLIMPORT bool enable_sort
Definition: costsize.c:129
PGDLLIMPORT bool enable_hashagg
Definition: costsize.c:130
PGDLLIMPORT int max_parallel_workers_per_gather
Definition: costsize.c:122
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:940
void initial_cost_hashjoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *hashclauses, Path *outer_path, Path *inner_path, JoinPathExtraData *extra, bool parallel_hash)
Definition: costsize.c:3256
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:139
AggStrategy
Definition: nodes.h:754
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:5376
PGDLLIMPORT bool enable_bitmapscan
Definition: costsize.c:127
PGDLLIMPORT bool enable_tidscan
Definition: costsize.c:128
void compute_semi_anti_join_factors(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:4147
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:4434
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2491
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:136
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1128
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5508
PGDLLIMPORT bool enable_indexscan
Definition: costsize.c:125
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1282
Definition: pg_list.h:50
void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5154
double Cost
Definition: nodes.h:659
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:138
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:211