PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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;
56 extern Cost disable_cost;
58 extern bool enable_seqscan;
59 extern bool enable_indexscan;
60 extern bool enable_indexonlyscan;
61 extern bool enable_bitmapscan;
62 extern bool enable_tidscan;
63 extern bool enable_sort;
64 extern bool enable_hashagg;
65 extern bool enable_nestloop;
66 extern bool enable_material;
67 extern bool enable_mergejoin;
68 extern bool enable_hashjoin;
69 extern int constraint_exclusion;
70 
71 extern double clamp_row_est(double nrows);
72 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
73  double index_pages, PlannerInfo *root);
74 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
75  ParamPathInfo *param_info);
76 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
77  ParamPathInfo *param_info);
78 extern void cost_index(IndexPath *path, PlannerInfo *root,
79  double loop_count, bool partial_path);
80 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
81  ParamPathInfo *param_info,
82  Path *bitmapqual, double loop_count);
83 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
84 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
85 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
86 extern void cost_tidscan(Path *path, PlannerInfo *root,
87  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
88 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
89  RelOptInfo *baserel, ParamPathInfo *param_info);
90 extern void cost_functionscan(Path *path, PlannerInfo *root,
91  RelOptInfo *baserel, ParamPathInfo *param_info);
92 extern void cost_valuesscan(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_recursive_union(Path *runion, Path *nrterm, Path *rterm);
97 extern void cost_sort(Path *path, PlannerInfo *root,
98  List *pathkeys, Cost input_cost, double tuples, int width,
99  Cost comparison_cost, int sort_mem,
100  double limit_tuples);
101 extern void cost_merge_append(Path *path, PlannerInfo *root,
102  List *pathkeys, int n_streams,
103  Cost input_startup_cost, Cost input_total_cost,
104  double tuples);
105 extern void cost_material(Path *path,
106  Cost input_startup_cost, Cost input_total_cost,
107  double tuples, int width);
108 extern void cost_agg(Path *path, PlannerInfo *root,
109  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
110  int numGroupCols, double numGroups,
111  Cost input_startup_cost, Cost input_total_cost,
112  double input_tuples);
113 extern void cost_windowagg(Path *path, PlannerInfo *root,
114  List *windowFuncs, int numPartCols, int numOrderCols,
115  Cost input_startup_cost, Cost input_total_cost,
116  double input_tuples);
117 extern void cost_group(Path *path, PlannerInfo *root,
118  int numGroupCols, double numGroups,
119  Cost input_startup_cost, Cost input_total_cost,
120  double input_tuples);
121 extern void initial_cost_nestloop(PlannerInfo *root,
122  JoinCostWorkspace *workspace,
123  JoinType jointype,
124  Path *outer_path, Path *inner_path,
125  SpecialJoinInfo *sjinfo,
126  SemiAntiJoinFactors *semifactors);
127 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
128  JoinCostWorkspace *workspace,
129  SpecialJoinInfo *sjinfo,
130  SemiAntiJoinFactors *semifactors);
131 extern void initial_cost_mergejoin(PlannerInfo *root,
132  JoinCostWorkspace *workspace,
133  JoinType jointype,
134  List *mergeclauses,
135  Path *outer_path, Path *inner_path,
136  List *outersortkeys, List *innersortkeys,
137  SpecialJoinInfo *sjinfo);
138 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
139  JoinCostWorkspace *workspace,
140  SpecialJoinInfo *sjinfo);
141 extern void initial_cost_hashjoin(PlannerInfo *root,
142  JoinCostWorkspace *workspace,
143  JoinType jointype,
144  List *hashclauses,
145  Path *outer_path, Path *inner_path,
146  SpecialJoinInfo *sjinfo,
147  SemiAntiJoinFactors *semifactors);
148 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
149  JoinCostWorkspace *workspace,
150  SpecialJoinInfo *sjinfo,
151  SemiAntiJoinFactors *semifactors);
152 extern void cost_gather(GatherPath *path, PlannerInfo *root,
153  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
154 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
155 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
156 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
158  RelOptInfo *outerrel,
159  RelOptInfo *innerrel,
160  JoinType jointype,
161  SpecialJoinInfo *sjinfo,
162  List *restrictlist,
163  SemiAntiJoinFactors *semifactors);
164 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
165 extern double get_parameterized_baserel_size(PlannerInfo *root,
166  RelOptInfo *rel,
167  List *param_clauses);
168 extern double get_parameterized_joinrel_size(PlannerInfo *root,
169  RelOptInfo *rel,
170  Path *outer_path,
171  Path *inner_path,
172  SpecialJoinInfo *sjinfo,
173  List *restrict_clauses);
174 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
175  RelOptInfo *outer_rel,
176  RelOptInfo *inner_rel,
177  SpecialJoinInfo *sjinfo,
178  List *restrictlist);
179 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
180 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
181 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
182 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
183  double cte_rows);
184 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
186 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
187  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
188 
189 /*
190  * prototypes for clausesel.c
191  * routines to compute clause selectivities
192  */
194  List *clauses,
195  int varRelid,
196  JoinType jointype,
197  SpecialJoinInfo *sjinfo);
199  Node *clause,
200  int varRelid,
201  JoinType jointype,
202  SpecialJoinInfo *sjinfo);
203 
204 #endif /* COST_H */
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:273
PGDLLIMPORT double cpu_operator_cost
Definition: costsize.c:108
bool enable_hashjoin
Definition: costsize.c:128
Selectivity clause_selectivity(PlannerInfo *root, Node *clause, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:483
bool enable_tidscan
Definition: costsize.c:122
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4442
bool enable_material
Definition: costsize.c:126
Definition: nodes.h:508
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:394
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:941
uint32 BlockNumber
Definition: block.h:31
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:92
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:984
double Selectivity
Definition: nodes.h:631
PGDLLIMPORT int effective_cache_size
Definition: costsize.c:112
Cost disable_cost
Definition: costsize.c:114
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:3771
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:3882
bool enable_nestloop
Definition: costsize.c:125
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:1587
bool enable_sort
Definition: costsize.c:123
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1228
#define PGDLLIMPORT
Definition: c.h:1062
JoinType
Definition: nodes.h:665
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:2783
double clamp_row_est(double nrows)
Definition: costsize.c:172
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:3230
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1339
bool enable_seqscan
Definition: costsize.c:118
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1076
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo)
Definition: costsize.c:2393
bool enable_mergejoin
Definition: costsize.c:127
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:1463
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:348
ConstraintExclusionType
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1289
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:1784
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:739
bool enable_indexonlyscan
Definition: costsize.c:120
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:4474
void initial_cost_hashjoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *hashclauses, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:2689
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3204
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:1904
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:107
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4404
bool enable_bitmapscan
Definition: costsize.c:121
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3004
PGDLLIMPORT double cpu_tuple_cost
Definition: costsize.c:106
bool enable_hashagg
Definition: costsize.c:124
void compute_semi_anti_join_factors(PlannerInfo *root, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:3511
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1856
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1383
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4517
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:3851
int constraint_exclusion
Definition: plancat.c:50
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4321
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1638
PGDLLIMPORT double parallel_setup_cost
Definition: costsize.c:110
bool enable_indexscan
Definition: costsize.c:119
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1692
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:854
int max_parallel_workers_per_gather
Definition: costsize.c:116
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:109
AggStrategy
Definition: nodes.h:727
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:4710
PGDLLIMPORT double seq_page_cost
Definition: costsize.c:104
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:3801
PGDLLIMPORT double random_page_cost
Definition: costsize.c:105
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1028
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:4838
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1179
Definition: pg_list.h:45
Definition: relation.h:888
double Cost
Definition: nodes.h:632
void initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *mergeclauses, Path *outer_path, Path *inner_path, List *outersortkeys, List *innersortkeys, SpecialJoinInfo *sjinfo)
Definition: costsize.c:2170
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:196
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:1979