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-2018, 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/plannodes.h"
18 #include "nodes/relation.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 */
48 extern PGDLLIMPORT double seq_page_cost;
49 extern PGDLLIMPORT double random_page_cost;
50 extern PGDLLIMPORT double cpu_tuple_cost;
51 extern PGDLLIMPORT double cpu_index_tuple_cost;
52 extern PGDLLIMPORT double cpu_operator_cost;
53 extern PGDLLIMPORT double parallel_tuple_cost;
54 extern PGDLLIMPORT double parallel_setup_cost;
58 extern PGDLLIMPORT bool enable_seqscan;
59 extern PGDLLIMPORT bool enable_indexscan;
61 extern PGDLLIMPORT bool enable_bitmapscan;
62 extern PGDLLIMPORT bool enable_tidscan;
63 extern PGDLLIMPORT bool enable_sort;
64 extern PGDLLIMPORT bool enable_hashagg;
65 extern PGDLLIMPORT bool enable_nestloop;
66 extern PGDLLIMPORT bool enable_material;
67 extern PGDLLIMPORT bool enable_mergejoin;
68 extern PGDLLIMPORT bool enable_hashjoin;
76 
77 extern double clamp_row_est(double nrows);
78 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
79  double index_pages, PlannerInfo *root);
80 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
81  ParamPathInfo *param_info);
82 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
83  ParamPathInfo *param_info);
84 extern void cost_index(IndexPath *path, PlannerInfo *root,
85  double loop_count, bool partial_path);
86 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
87  ParamPathInfo *param_info,
88  Path *bitmapqual, double loop_count);
89 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
90 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
91 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
92 extern void cost_tidscan(Path *path, PlannerInfo *root,
93  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
94 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
95  RelOptInfo *baserel, ParamPathInfo *param_info);
96 extern void cost_functionscan(Path *path, PlannerInfo *root,
97  RelOptInfo *baserel, ParamPathInfo *param_info);
98 extern void cost_tableexprscan(Path *path, PlannerInfo *root,
99  RelOptInfo *baserel, ParamPathInfo *param_info);
100 extern void cost_valuesscan(Path *path, PlannerInfo *root,
101  RelOptInfo *baserel, ParamPathInfo *param_info);
102 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
103  RelOptInfo *baserel, ParamPathInfo *param_info);
104 extern void cost_ctescan(Path *path, PlannerInfo *root,
105  RelOptInfo *baserel, ParamPathInfo *param_info);
106 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
107  RelOptInfo *baserel, ParamPathInfo *param_info);
108 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
109 extern void cost_sort(Path *path, PlannerInfo *root,
110  List *pathkeys, Cost input_cost, double tuples, int width,
111  Cost comparison_cost, int sort_mem,
112  double limit_tuples);
113 extern void cost_append(AppendPath *path);
114 extern void cost_merge_append(Path *path, PlannerInfo *root,
115  List *pathkeys, int n_streams,
116  Cost input_startup_cost, Cost input_total_cost,
117  double tuples);
118 extern void cost_material(Path *path,
119  Cost input_startup_cost, Cost input_total_cost,
120  double tuples, int width);
121 extern void cost_agg(Path *path, PlannerInfo *root,
122  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
123  int numGroupCols, double numGroups,
124  List *quals,
125  Cost input_startup_cost, Cost input_total_cost,
126  double input_tuples);
127 extern void cost_windowagg(Path *path, PlannerInfo *root,
128  List *windowFuncs, int numPartCols, int numOrderCols,
129  Cost input_startup_cost, Cost input_total_cost,
130  double input_tuples);
131 extern void cost_group(Path *path, PlannerInfo *root,
132  int numGroupCols, double numGroups,
133  List *quals,
134  Cost input_startup_cost, Cost input_total_cost,
135  double input_tuples);
136 extern void initial_cost_nestloop(PlannerInfo *root,
137  JoinCostWorkspace *workspace,
138  JoinType jointype,
139  Path *outer_path, Path *inner_path,
140  JoinPathExtraData *extra);
141 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
142  JoinCostWorkspace *workspace,
143  JoinPathExtraData *extra);
144 extern void initial_cost_mergejoin(PlannerInfo *root,
145  JoinCostWorkspace *workspace,
146  JoinType jointype,
147  List *mergeclauses,
148  Path *outer_path, Path *inner_path,
149  List *outersortkeys, List *innersortkeys,
150  JoinPathExtraData *extra);
151 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
152  JoinCostWorkspace *workspace,
153  JoinPathExtraData *extra);
154 extern void initial_cost_hashjoin(PlannerInfo *root,
155  JoinCostWorkspace *workspace,
156  JoinType jointype,
157  List *hashclauses,
158  Path *outer_path, Path *inner_path,
159  JoinPathExtraData *extra,
160  bool parallel_hash);
161 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
162  JoinCostWorkspace *workspace,
163  JoinPathExtraData *extra);
164 extern void cost_gather(GatherPath *path, PlannerInfo *root,
165  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
166 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
167 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
168 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
170  RelOptInfo *joinrel,
171  RelOptInfo *outerrel,
172  RelOptInfo *innerrel,
173  JoinType jointype,
174  SpecialJoinInfo *sjinfo,
175  List *restrictlist,
176  SemiAntiJoinFactors *semifactors);
177 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
178 extern double get_parameterized_baserel_size(PlannerInfo *root,
179  RelOptInfo *rel,
180  List *param_clauses);
181 extern double get_parameterized_joinrel_size(PlannerInfo *root,
182  RelOptInfo *rel,
183  Path *outer_path,
184  Path *inner_path,
185  SpecialJoinInfo *sjinfo,
186  List *restrict_clauses);
187 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
188  RelOptInfo *outer_rel,
189  RelOptInfo *inner_rel,
190  SpecialJoinInfo *sjinfo,
191  List *restrictlist);
192 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
193 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
194 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
195 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
196  double cte_rows);
197 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
199 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
201 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
202  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
203 
204 /*
205  * prototypes for clausesel.c
206  * routines to compute clause selectivities
207  */
209  List *clauses,
210  int varRelid,
211  JoinType jointype,
212  SpecialJoinInfo *sjinfo);
214  Node *clause,
215  int varRelid,
216  JoinType jointype,
217  SpecialJoinInfo *sjinfo);
218 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
219  RelOptInfo *rel, ParamPathInfo *param_info,
220  Cost input_startup_cost, Cost input_total_cost,
221  double *rows);
222 
223 #endif /* COST_H */
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:132
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4928
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:2060
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:289
void cost_append(AppendPath *path)
Definition: costsize.c:1843
PGDLLIMPORT double cpu_operator_cost
Definition: costsize.c:115
Selectivity clause_selectivity(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:574
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4950
PGDLLIMPORT bool enable_material
Definition: costsize.c:133
Definition: nodes.h:517
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:477
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:1046
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition: costsize.c:138
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:134
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2830
uint32 BlockNumber
Definition: block.h:31
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:99
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1089
double Selectivity
Definition: nodes.h:647
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:2248
PGDLLIMPORT int effective_cache_size
Definition: costsize.c:119
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4295
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4407
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:1957
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1333
#define PGDLLIMPORT
Definition: c.h:1140
JoinType
Definition: nodes.h:681
double clamp_row_est(double nrows)
Definition: costsize.c:188
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:3742
PGDLLIMPORT bool enable_partition_pruning
Definition: costsize.c:141
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:1181
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:1661
void cost_tableexprscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:364
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:2178
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:830
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2318
PGDLLIMPORT bool enable_gathermerge
Definition: costsize.c:136
PGDLLIMPORT bool enable_hashjoin
Definition: costsize.c:135
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:4982
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:2600
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:56
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:3716
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:114
PGDLLIMPORT bool enable_indexonlyscan
Definition: costsize.c:127
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4890
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3516
PGDLLIMPORT double cpu_tuple_cost
Definition: costsize.c:113
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:402
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3261
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1581
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5019
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5058
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4375
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4810
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2006
PGDLLIMPORT bool enable_sort
Definition: costsize.c:130
PGDLLIMPORT bool enable_hashagg
Definition: costsize.c:131
PGDLLIMPORT double parallel_setup_cost
Definition: costsize.c:117
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:945
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:3153
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:140
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:116
AggStrategy
Definition: nodes.h:743
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:5251
PGDLLIMPORT bool enable_bitmapscan
Definition: costsize.c:128
PGDLLIMPORT double seq_page_cost
Definition: costsize.c:111
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:4037
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:4325
PGDLLIMPORT double random_page_cost
Definition: costsize.c:112
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2393
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:137
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1133
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5383
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:45
double Cost
Definition: nodes.h:648
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:139
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:212