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-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
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;
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;
75 extern double clamp_row_est(double nrows);
76 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
77  double index_pages, PlannerInfo *root);
78 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
79  ParamPathInfo *param_info);
80 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
81  ParamPathInfo *param_info);
82 extern void cost_index(IndexPath *path, PlannerInfo *root,
83  double loop_count, bool partial_path);
84 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
85  ParamPathInfo *param_info,
86  Path *bitmapqual, double loop_count);
87 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
88 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
89 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
90 extern void cost_tidscan(Path *path, PlannerInfo *root,
91  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
92 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
93  RelOptInfo *baserel, ParamPathInfo *param_info);
94 extern void cost_functionscan(Path *path, PlannerInfo *root,
95  RelOptInfo *baserel, ParamPathInfo *param_info);
96 extern void cost_tableexprscan(Path *path, PlannerInfo *root,
97  RelOptInfo *baserel, ParamPathInfo *param_info);
98 extern void cost_valuesscan(Path *path, PlannerInfo *root,
99  RelOptInfo *baserel, ParamPathInfo *param_info);
100 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
101  RelOptInfo *baserel, ParamPathInfo *param_info);
102 extern void cost_ctescan(Path *path, PlannerInfo *root,
103  RelOptInfo *baserel, ParamPathInfo *param_info);
104 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
105  RelOptInfo *baserel, ParamPathInfo *param_info);
106 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
107 extern void cost_sort(Path *path, PlannerInfo *root,
108  List *pathkeys, Cost input_cost, double tuples, int width,
109  Cost comparison_cost, int sort_mem,
110  double limit_tuples);
111 extern void cost_append(AppendPath *path);
112 extern void cost_merge_append(Path *path, PlannerInfo *root,
113  List *pathkeys, int n_streams,
114  Cost input_startup_cost, Cost input_total_cost,
115  double tuples);
116 extern void cost_material(Path *path,
117  Cost input_startup_cost, Cost input_total_cost,
118  double tuples, int width);
119 extern void cost_agg(Path *path, PlannerInfo *root,
120  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
121  int numGroupCols, double numGroups,
122  List *quals,
123  Cost input_startup_cost, Cost input_total_cost,
124  double input_tuples);
125 extern void cost_windowagg(Path *path, PlannerInfo *root,
126  List *windowFuncs, int numPartCols, int numOrderCols,
127  Cost input_startup_cost, Cost input_total_cost,
128  double input_tuples);
129 extern void cost_group(Path *path, PlannerInfo *root,
130  int numGroupCols, double numGroups,
131  List *quals,
132  Cost input_startup_cost, Cost input_total_cost,
133  double input_tuples);
134 extern void initial_cost_nestloop(PlannerInfo *root,
135  JoinCostWorkspace *workspace,
136  JoinType jointype,
137  Path *outer_path, Path *inner_path,
138  JoinPathExtraData *extra);
139 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
140  JoinCostWorkspace *workspace,
141  JoinPathExtraData *extra);
142 extern void initial_cost_mergejoin(PlannerInfo *root,
143  JoinCostWorkspace *workspace,
144  JoinType jointype,
145  List *mergeclauses,
146  Path *outer_path, Path *inner_path,
147  List *outersortkeys, List *innersortkeys,
148  JoinPathExtraData *extra);
149 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
150  JoinCostWorkspace *workspace,
151  JoinPathExtraData *extra);
152 extern void initial_cost_hashjoin(PlannerInfo *root,
153  JoinCostWorkspace *workspace,
154  JoinType jointype,
155  List *hashclauses,
156  Path *outer_path, Path *inner_path,
157  JoinPathExtraData *extra,
158  bool parallel_hash);
159 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
160  JoinCostWorkspace *workspace,
161  JoinPathExtraData *extra);
162 extern void cost_gather(GatherPath *path, PlannerInfo *root,
163  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
164 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
165 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
166 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
168  RelOptInfo *outerrel,
169  RelOptInfo *innerrel,
170  JoinType jointype,
171  SpecialJoinInfo *sjinfo,
172  List *restrictlist,
173  SemiAntiJoinFactors *semifactors);
174 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
175 extern double get_parameterized_baserel_size(PlannerInfo *root,
176  RelOptInfo *rel,
177  List *param_clauses);
178 extern double get_parameterized_joinrel_size(PlannerInfo *root,
179  RelOptInfo *rel,
180  Path *outer_path,
181  Path *inner_path,
182  SpecialJoinInfo *sjinfo,
183  List *restrict_clauses);
184 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
185  RelOptInfo *outer_rel,
186  RelOptInfo *inner_rel,
187  SpecialJoinInfo *sjinfo,
188  List *restrictlist);
189 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
190 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
191 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
192 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
193  double cte_rows);
194 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
196 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
198 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
199  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
201 /*
202  * prototypes for clausesel.c
203  * routines to compute clause selectivities
204  */
206  List *clauses,
207  int varRelid,
208  JoinType jointype,
209  SpecialJoinInfo *sjinfo);
211  Node *clause,
212  int varRelid,
213  JoinType jointype,
214  SpecialJoinInfo *sjinfo);
215 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
216  RelOptInfo *rel, ParamPathInfo *param_info,
217  Cost input_startup_cost, Cost input_total_cost,
218  double *rows);
220 #endif /* COST_H */
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:132
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4920
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:2057
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:286
void cost_append(AppendPath *path)
Definition: costsize.c:1840
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:4942
PGDLLIMPORT bool enable_material
Definition: costsize.c:133
Definition: nodes.h:513
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:474
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1538
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1043
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:134
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2827
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:1086
double Selectivity
Definition: nodes.h:643
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:2245
PGDLLIMPORT int effective_cache_size
Definition: costsize.c:119
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4290
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4401
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:1954
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1330
Definition: c.h:1094
Definition: nodes.h:677
double clamp_row_est(double nrows)
Definition: costsize.c:185
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:3739
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1497
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:1658
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:361
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1447
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:2175
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:2315
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:4974
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:2597
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:54
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1391
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3713
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:4882
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3513
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:399
void compute_semi_anti_join_factors(PlannerInfo *root, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:4033
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3258
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1578
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5011
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5050
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4370
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4802
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2003
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: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:3150
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:139
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:116
Definition: nodes.h:739
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:5243
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
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:4320
PGDLLIMPORT double random_page_cost
Definition: costsize.c:112
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2390
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:137
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:5375
PGDLLIMPORT bool enable_indexscan
Definition: costsize.c:126
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1281
Definition: pg_list.h:45
double Cost
Definition: nodes.h:644
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:138
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:209