PostgreSQL Source Code  git master
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 bool enable_partition_wise_join;
71 extern bool enable_parallel_append;
72 extern int constraint_exclusion;
74 extern double clamp_row_est(double nrows);
75 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
76  double index_pages, PlannerInfo *root);
77 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
78  ParamPathInfo *param_info);
79 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
80  ParamPathInfo *param_info);
81 extern void cost_index(IndexPath *path, PlannerInfo *root,
82  double loop_count, bool partial_path);
83 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
84  ParamPathInfo *param_info,
85  Path *bitmapqual, double loop_count);
86 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
87 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
88 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
89 extern void cost_tidscan(Path *path, PlannerInfo *root,
90  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
91 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
92  RelOptInfo *baserel, ParamPathInfo *param_info);
93 extern void cost_functionscan(Path *path, PlannerInfo *root,
94  RelOptInfo *baserel, ParamPathInfo *param_info);
95 extern void cost_tableexprscan(Path *path, PlannerInfo *root,
96  RelOptInfo *baserel, ParamPathInfo *param_info);
97 extern void cost_valuesscan(Path *path, PlannerInfo *root,
98  RelOptInfo *baserel, ParamPathInfo *param_info);
99 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
100  RelOptInfo *baserel, ParamPathInfo *param_info);
101 extern void cost_ctescan(Path *path, PlannerInfo *root,
102  RelOptInfo *baserel, ParamPathInfo *param_info);
103 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
104  RelOptInfo *baserel, ParamPathInfo *param_info);
105 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
106 extern void cost_sort(Path *path, PlannerInfo *root,
107  List *pathkeys, Cost input_cost, double tuples, int width,
108  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);
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 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
158  JoinCostWorkspace *workspace,
159  JoinPathExtraData *extra);
160 extern void cost_gather(GatherPath *path, PlannerInfo *root,
161  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
162 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
163 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
164 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
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_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
196 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
197  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
199 /*
200  * prototypes for clausesel.c
201  * routines to compute clause selectivities
202  */
204  List *clauses,
205  int varRelid,
206  JoinType jointype,
207  SpecialJoinInfo *sjinfo);
209  Node *clause,
210  int varRelid,
211  JoinType jointype,
212  SpecialJoinInfo *sjinfo);
213 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
214  RelOptInfo *rel, ParamPathInfo *param_info,
215  Cost input_startup_cost, Cost input_total_cost,
216  double *rows);
218 #endif /* COST_H */
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4879
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:2038
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:278
void cost_append(AppendPath *path)
Definition: costsize.c:1834
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:574
bool enable_tidscan
Definition: costsize.c:122
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4901
bool enable_material
Definition: costsize.c:126
bool enable_parallel_append
Definition: costsize.c:131
Definition: nodes.h:512
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:466
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1528
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1033
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2808
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:1076
double Selectivity
Definition: nodes.h:642
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:2226
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:4249
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4360
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:1933
bool enable_sort
Definition: costsize.c:123
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1320
Definition: c.h:1060
Definition: nodes.h:676
double clamp_row_est(double nrows)
Definition: costsize.c:177
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:3698
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1487
bool enable_seqscan
Definition: costsize.c:118
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1168
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:1648
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:353
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1437
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:2156
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:817
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2296
bool enable_indexonlyscan
Definition: costsize.c:120
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:4933
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:2578
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1381
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3672
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:107
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4841
bool enable_bitmapscan
Definition: costsize.c:121
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3472
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:391
void compute_semi_anti_join_factors(PlannerInfo *root, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:3992
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3221
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1568
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4970
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5009
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4329
int constraint_exclusion
Definition: plancat.c:54
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4761
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1984
PGDLLIMPORT double parallel_setup_cost
Definition: costsize.c:110
bool enable_indexscan
Definition: costsize.c:119
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:932
int max_parallel_workers_per_gather
Definition: costsize.c:116
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:109
Definition: nodes.h:738
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:5202
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:4279
PGDLLIMPORT double random_page_cost
Definition: costsize.c:105
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2371
bool enable_partition_wise_join
Definition: costsize.c:130
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1120
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5334
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1271
Definition: pg_list.h:45
void initial_cost_hashjoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *hashclauses, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:3129
double Cost
Definition: nodes.h:643
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:201