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-2020, 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;
57 extern PGDLLIMPORT bool enable_hashagg;
58 extern PGDLLIMPORT bool enable_nestloop;
59 extern PGDLLIMPORT bool enable_material;
60 extern PGDLLIMPORT bool enable_mergejoin;
61 extern PGDLLIMPORT bool enable_hashjoin;
69 
70 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
71  double index_pages, PlannerInfo *root);
72 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
73  ParamPathInfo *param_info);
74 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
75  ParamPathInfo *param_info);
76 extern void cost_index(IndexPath *path, PlannerInfo *root,
77  double loop_count, bool partial_path);
78 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
79  ParamPathInfo *param_info,
80  Path *bitmapqual, double loop_count);
81 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
82 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
83 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
84 extern void cost_tidscan(Path *path, PlannerInfo *root,
85  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
86 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
87  RelOptInfo *baserel, ParamPathInfo *param_info);
88 extern void cost_functionscan(Path *path, PlannerInfo *root,
89  RelOptInfo *baserel, ParamPathInfo *param_info);
90 extern void cost_valuesscan(Path *path, PlannerInfo *root,
91  RelOptInfo *baserel, ParamPathInfo *param_info);
92 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
93  RelOptInfo *baserel, ParamPathInfo *param_info);
94 extern void cost_ctescan(Path *path, PlannerInfo *root,
95  RelOptInfo *baserel, ParamPathInfo *param_info);
96 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
97  RelOptInfo *baserel, ParamPathInfo *param_info);
98 extern void cost_resultscan(Path *path, PlannerInfo *root,
99  RelOptInfo *baserel, ParamPathInfo *param_info);
100 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
101 extern void cost_sort(Path *path, PlannerInfo *root,
102  List *pathkeys, Cost input_cost, double tuples, int width,
103  Cost comparison_cost, int sort_mem,
104  double limit_tuples);
105 extern void cost_incremental_sort(Path *path,
106  PlannerInfo *root, List *pathkeys, int presorted_keys,
107  Cost input_startup_cost, Cost input_total_cost,
108  double input_tuples, int width, Cost comparison_cost, int sort_mem,
109  double limit_tuples);
110 extern void cost_append(AppendPath *path);
111 extern void cost_merge_append(Path *path, PlannerInfo *root,
112  List *pathkeys, int n_streams,
113  Cost input_startup_cost, Cost input_total_cost,
114  double tuples);
115 extern void cost_material(Path *path,
116  Cost input_startup_cost, Cost input_total_cost,
117  double tuples, int width);
118 extern void cost_agg(Path *path, PlannerInfo *root,
119  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
120  int numGroupCols, double numGroups,
121  List *quals,
122  Cost input_startup_cost, Cost input_total_cost,
123  double input_tuples, double input_width);
124 extern void cost_windowagg(Path *path, PlannerInfo *root,
125  List *windowFuncs, int numPartCols, int numOrderCols,
126  Cost input_startup_cost, Cost input_total_cost,
127  double input_tuples);
128 extern void cost_group(Path *path, PlannerInfo *root,
129  int numGroupCols, double numGroups,
130  List *quals,
131  Cost input_startup_cost, Cost input_total_cost,
132  double input_tuples);
133 extern void initial_cost_nestloop(PlannerInfo *root,
134  JoinCostWorkspace *workspace,
135  JoinType jointype,
136  Path *outer_path, Path *inner_path,
137  JoinPathExtraData *extra);
138 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
139  JoinCostWorkspace *workspace,
140  JoinPathExtraData *extra);
141 extern void initial_cost_mergejoin(PlannerInfo *root,
142  JoinCostWorkspace *workspace,
143  JoinType jointype,
144  List *mergeclauses,
145  Path *outer_path, Path *inner_path,
146  List *outersortkeys, List *innersortkeys,
147  JoinPathExtraData *extra);
148 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
149  JoinCostWorkspace *workspace,
150  JoinPathExtraData *extra);
151 extern void initial_cost_hashjoin(PlannerInfo *root,
152  JoinCostWorkspace *workspace,
153  JoinType jointype,
154  List *hashclauses,
155  Path *outer_path, Path *inner_path,
156  JoinPathExtraData *extra,
157  bool parallel_hash);
158 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
159  JoinCostWorkspace *workspace,
160  JoinPathExtraData *extra);
161 extern void cost_gather(GatherPath *path, PlannerInfo *root,
162  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
163 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
164  RelOptInfo *rel, ParamPathInfo *param_info,
165  Cost input_startup_cost, Cost input_total_cost,
166  double *rows);
167 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
168 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
169 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
171  RelOptInfo *joinrel,
172  RelOptInfo *outerrel,
173  RelOptInfo *innerrel,
174  JoinType jointype,
175  SpecialJoinInfo *sjinfo,
176  List *restrictlist,
177  SemiAntiJoinFactors *semifactors);
178 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
179 extern double get_parameterized_baserel_size(PlannerInfo *root,
180  RelOptInfo *rel,
181  List *param_clauses);
182 extern double get_parameterized_joinrel_size(PlannerInfo *root,
183  RelOptInfo *rel,
184  Path *outer_path,
185  Path *inner_path,
186  SpecialJoinInfo *sjinfo,
187  List *restrict_clauses);
188 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
189  RelOptInfo *outer_rel,
190  RelOptInfo *inner_rel,
191  SpecialJoinInfo *sjinfo,
192  List *restrictlist);
193 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
194 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
195 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
196 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
197  double cte_rows);
198 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
200 extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel);
201 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
203 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
204  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
205 
206 #endif /* COST_H */
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:133
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5254
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:290
void cost_append(AppendPath *path)
Definition: costsize.c:2034
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5276
PGDLLIMPORT bool enable_material
Definition: costsize.c:134
Definition: nodes.h:529
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:478
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1541
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1043
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition: costsize.c:139
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:135
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3150
uint32 BlockNumber
Definition: block.h:31
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1086
double Selectivity
Definition: nodes.h:662
PGDLLIMPORT Cost disable_cost
Definition: costsize.c:121
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:2568
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4628
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4739
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:2207
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1333
#define PGDLLIMPORT
Definition: c.h:1286
JoinType
Definition: nodes.h:696
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:4069
PGDLLIMPORT bool enable_partition_pruning
Definition: costsize.c:142
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1500
PGDLLIMPORT bool enable_seqscan
Definition: costsize.c:125
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1178
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:1927
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:365
ConstraintExclusionType
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1450
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:2494
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:827
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2638
PGDLLIMPORT bool enable_gathermerge
Definition: costsize.c:137
PGDLLIMPORT bool enable_hashjoin
Definition: costsize.c:136
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:5308
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:2920
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:57
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1394
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4043
PGDLLIMPORT bool enable_incremental_sort
Definition: costsize.c:131
void cost_incremental_sort(Path *path, PlannerInfo *root, List *pathkeys, int presorted_keys, Cost input_startup_cost, Cost input_total_cost, double input_tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1788
PGDLLIMPORT bool enable_indexonlyscan
Definition: costsize.c:127
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5216
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3843
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1578
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:403
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3586
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1615
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5345
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5407
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4707
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5136
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2256
PGDLLIMPORT bool enable_sort
Definition: costsize.c:130
PGDLLIMPORT bool enable_hashagg
Definition: costsize.c:132
PGDLLIMPORT int max_parallel_workers_per_gather
Definition: costsize.c:123
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:942
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:3478
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:141
AggStrategy
Definition: nodes.h:758
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:5600
PGDLLIMPORT bool enable_bitmapscan
Definition: costsize.c:128
PGDLLIMPORT bool enable_tidscan
Definition: costsize.c:129
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:4371
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:4658
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2713
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, double input_width)
Definition: costsize.c:2310
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:138
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1130
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5732
PGDLLIMPORT bool enable_indexscan
Definition: costsize.c:126
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1284
Definition: pg_list.h:50
void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5378
double Cost
Definition: nodes.h:663
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:140
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:213