PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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
17 #include "nodes/plannodes.h"
18 #include "nodes/relation.h"
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
26 #define DEFAULT_CPU_TUPLE_COST 0.01
32 #define DEFAULT_EFFECTIVE_CACHE_SIZE 524288 /* measured in pages */
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 */
42 /*
43  * prototypes for costsize.c
44  * routines to compute costs and sizes
45  */
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 bool enable_gathermerge;
70 extern int constraint_exclusion;
72 extern double clamp_row_est(double nrows);
73 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
74  double index_pages, PlannerInfo *root);
75 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
76  ParamPathInfo *param_info);
77 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
78  ParamPathInfo *param_info);
79 extern void cost_index(IndexPath *path, PlannerInfo *root,
80  double loop_count, bool partial_path);
81 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
82  ParamPathInfo *param_info,
83  Path *bitmapqual, double loop_count);
84 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
85 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
86 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
87 extern void cost_tidscan(Path *path, PlannerInfo *root,
88  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
89 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
90  RelOptInfo *baserel, ParamPathInfo *param_info);
91 extern void cost_functionscan(Path *path, PlannerInfo *root,
92  RelOptInfo *baserel, ParamPathInfo *param_info);
93 extern void cost_tableexprscan(Path *path, PlannerInfo *root,
94  RelOptInfo *baserel, ParamPathInfo *param_info);
95 extern void cost_valuesscan(Path *path, PlannerInfo *root,
96  RelOptInfo *baserel, ParamPathInfo *param_info);
97 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
98  RelOptInfo *baserel, ParamPathInfo *param_info);
99 extern void cost_ctescan(Path *path, PlannerInfo *root,
100  RelOptInfo *baserel, ParamPathInfo *param_info);
101 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
102 extern void cost_sort(Path *path, PlannerInfo *root,
103  List *pathkeys, Cost input_cost, double tuples, int width,
104  Cost comparison_cost, int sort_mem,
105  double limit_tuples);
106 extern void cost_merge_append(Path *path, PlannerInfo *root,
107  List *pathkeys, int n_streams,
108  Cost input_startup_cost, Cost input_total_cost,
109  double tuples);
110 extern void cost_material(Path *path,
111  Cost input_startup_cost, Cost input_total_cost,
112  double tuples, int width);
113 extern void cost_agg(Path *path, PlannerInfo *root,
114  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
115  int numGroupCols, double numGroups,
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  Cost input_startup_cost, Cost input_total_cost,
125  double input_tuples);
126 extern void initial_cost_nestloop(PlannerInfo *root,
127  JoinCostWorkspace *workspace,
128  JoinType jointype,
129  Path *outer_path, Path *inner_path,
130  SpecialJoinInfo *sjinfo,
131  SemiAntiJoinFactors *semifactors);
132 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
133  JoinCostWorkspace *workspace,
134  SpecialJoinInfo *sjinfo,
135  SemiAntiJoinFactors *semifactors);
136 extern void initial_cost_mergejoin(PlannerInfo *root,
137  JoinCostWorkspace *workspace,
138  JoinType jointype,
139  List *mergeclauses,
140  Path *outer_path, Path *inner_path,
141  List *outersortkeys, List *innersortkeys,
142  SpecialJoinInfo *sjinfo);
143 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
144  JoinCostWorkspace *workspace,
145  SpecialJoinInfo *sjinfo);
146 extern void initial_cost_hashjoin(PlannerInfo *root,
147  JoinCostWorkspace *workspace,
148  JoinType jointype,
149  List *hashclauses,
150  Path *outer_path, Path *inner_path,
151  SpecialJoinInfo *sjinfo,
152  SemiAntiJoinFactors *semifactors);
153 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
154  JoinCostWorkspace *workspace,
155  SpecialJoinInfo *sjinfo,
156  SemiAntiJoinFactors *semifactors);
157 extern void cost_gather(GatherPath *path, PlannerInfo *root,
158  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
159 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
160 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
161 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
163  RelOptInfo *outerrel,
164  RelOptInfo *innerrel,
165  JoinType jointype,
166  SpecialJoinInfo *sjinfo,
167  List *restrictlist,
168  SemiAntiJoinFactors *semifactors);
169 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
170 extern double get_parameterized_baserel_size(PlannerInfo *root,
171  RelOptInfo *rel,
172  List *param_clauses);
173 extern double get_parameterized_joinrel_size(PlannerInfo *root,
174  RelOptInfo *rel,
175  Path *outer_path,
176  Path *inner_path,
177  SpecialJoinInfo *sjinfo,
178  List *restrict_clauses);
179 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
180  RelOptInfo *outer_rel,
181  RelOptInfo *inner_rel,
182  SpecialJoinInfo *sjinfo,
183  List *restrictlist);
184 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
185 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
186 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
187 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
188  double cte_rows);
189 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
190 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
192 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
193  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
195 /*
196  * prototypes for clausesel.c
197  * routines to compute clause selectivities
198  */
200  List *clauses,
201  int varRelid,
202  JoinType jointype,
203  SpecialJoinInfo *sjinfo);
205  Node *clause,
206  int varRelid,
207  JoinType jointype,
208  SpecialJoinInfo *sjinfo);
209 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
210  RelOptInfo *rel, ParamPathInfo *param_info,
211  Cost input_startup_cost, Cost input_total_cost,
212  double *rows);
214 #endif /* COST_H */
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4596
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:274
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:4623
bool enable_material
Definition: costsize.c:126
Definition: nodes.h:522
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:462
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1029
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:1072
double Selectivity
Definition: nodes.h:645
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:3925
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4036
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:1731
bool enable_sort
Definition: costsize.c:123
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1316
Definition: c.h:1063
Definition: nodes.h:679
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:2935
double clamp_row_est(double nrows)
Definition: costsize.c:173
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:3385
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1483
bool enable_seqscan
Definition: costsize.c:118
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1164
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo)
Definition: costsize.c:2540
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:1607
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:349
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1433
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:1928
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:813
bool enable_indexonlyscan
Definition: costsize.c:120
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:4655
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:2841
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1377
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3359
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:2046
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:107
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4558
bool enable_bitmapscan
Definition: costsize.c:121
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3159
PGDLLIMPORT double cpu_tuple_cost
Definition: costsize.c:106
bool enable_hashagg
Definition: costsize.c:124
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:387
void compute_semi_anti_join_factors(PlannerInfo *root, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:3666
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:1998
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1527
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4698
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4005
int constraint_exclusion
Definition: plancat.c:54
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4474
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1782
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:1836
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:928
int max_parallel_workers_per_gather
Definition: costsize.c:116
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:109
Definition: nodes.h:741
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:4891
bool enable_gathermerge
Definition: costsize.c:129
PGDLLIMPORT double seq_page_cost
Definition: costsize.c:104
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:3955
PGDLLIMPORT double random_page_cost
Definition: costsize.c:105
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1116
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5019
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1267
Definition: pg_list.h:45
Definition: relation.h:911
double Cost
Definition: nodes.h:646
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:2317
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:197
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:2121