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 bool enable_partition_wise_join;
71 extern int constraint_exclusion;
73 extern double clamp_row_est(double nrows);
74 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
75  double index_pages, PlannerInfo *root);
76 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
77  ParamPathInfo *param_info);
78 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
79  ParamPathInfo *param_info);
80 extern void cost_index(IndexPath *path, PlannerInfo *root,
81  double loop_count, bool partial_path);
82 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
83  ParamPathInfo *param_info,
84  Path *bitmapqual, double loop_count);
85 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
86 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
87 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
88 extern void cost_tidscan(Path *path, PlannerInfo *root,
89  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
90 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
91  RelOptInfo *baserel, ParamPathInfo *param_info);
92 extern void cost_functionscan(Path *path, PlannerInfo *root,
93  RelOptInfo *baserel, ParamPathInfo *param_info);
94 extern void cost_tableexprscan(Path *path, PlannerInfo *root,
95  RelOptInfo *baserel, ParamPathInfo *param_info);
96 extern void cost_valuesscan(Path *path, PlannerInfo *root,
97  RelOptInfo *baserel, ParamPathInfo *param_info);
98 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
99  RelOptInfo *baserel, ParamPathInfo *param_info);
100 extern void cost_ctescan(Path *path, PlannerInfo *root,
101  RelOptInfo *baserel, ParamPathInfo *param_info);
102 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
103  RelOptInfo *baserel, ParamPathInfo *param_info);
104 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
105 extern void cost_sort(Path *path, PlannerInfo *root,
106  List *pathkeys, Cost input_cost, double tuples, int width,
107  Cost comparison_cost, int sort_mem,
108  double limit_tuples);
109 extern void cost_merge_append(Path *path, PlannerInfo *root,
110  List *pathkeys, int n_streams,
111  Cost input_startup_cost, Cost input_total_cost,
112  double tuples);
113 extern void cost_material(Path *path,
114  Cost input_startup_cost, Cost input_total_cost,
115  double tuples, int width);
116 extern void cost_agg(Path *path, PlannerInfo *root,
117  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
118  int numGroupCols, double numGroups,
119  Cost input_startup_cost, Cost input_total_cost,
120  double input_tuples);
121 extern void cost_windowagg(Path *path, PlannerInfo *root,
122  List *windowFuncs, int numPartCols, int numOrderCols,
123  Cost input_startup_cost, Cost input_total_cost,
124  double input_tuples);
125 extern void cost_group(Path *path, PlannerInfo *root,
126  int numGroupCols, double numGroups,
127  Cost input_startup_cost, Cost input_total_cost,
128  double input_tuples);
129 extern void initial_cost_nestloop(PlannerInfo *root,
130  JoinCostWorkspace *workspace,
131  JoinType jointype,
132  Path *outer_path, Path *inner_path,
133  JoinPathExtraData *extra);
134 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
135  JoinCostWorkspace *workspace,
136  JoinPathExtraData *extra);
137 extern void initial_cost_mergejoin(PlannerInfo *root,
138  JoinCostWorkspace *workspace,
139  JoinType jointype,
140  List *mergeclauses,
141  Path *outer_path, Path *inner_path,
142  List *outersortkeys, List *innersortkeys,
143  JoinPathExtraData *extra);
144 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
145  JoinCostWorkspace *workspace,
146  JoinPathExtraData *extra);
147 extern void initial_cost_hashjoin(PlannerInfo *root,
148  JoinCostWorkspace *workspace,
149  JoinType jointype,
150  List *hashclauses,
151  Path *outer_path, Path *inner_path,
152  JoinPathExtraData *extra);
153 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
154  JoinCostWorkspace *workspace,
155  JoinPathExtraData *extra);
156 extern void cost_gather(GatherPath *path, PlannerInfo *root,
157  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
158 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
159 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
160 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
162  RelOptInfo *outerrel,
163  RelOptInfo *innerrel,
164  JoinType jointype,
165  SpecialJoinInfo *sjinfo,
166  List *restrictlist,
167  SemiAntiJoinFactors *semifactors);
168 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
169 extern double get_parameterized_baserel_size(PlannerInfo *root,
170  RelOptInfo *rel,
171  List *param_clauses);
172 extern double get_parameterized_joinrel_size(PlannerInfo *root,
173  RelOptInfo *rel,
174  Path *outer_path,
175  Path *inner_path,
176  SpecialJoinInfo *sjinfo,
177  List *restrict_clauses);
178 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
179  RelOptInfo *outer_rel,
180  RelOptInfo *inner_rel,
181  SpecialJoinInfo *sjinfo,
182  List *restrictlist);
183 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
184 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
185 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
186 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
187  double cte_rows);
188 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:4671
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:275
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:4693
bool enable_material
Definition: costsize.c:126
Definition: nodes.h:510
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:463
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1525
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1030
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2600
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:1073
double Selectivity
Definition: nodes.h:640
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:4041
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4152
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:1769
bool enable_sort
Definition: costsize.c:123
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1317
Definition: c.h:1069
Definition: nodes.h:674
double clamp_row_est(double nrows)
Definition: costsize.c:174
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:3490
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1484
bool enable_seqscan
Definition: costsize.c:118
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1165
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:1645
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:350
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1434
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:1971
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:814
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2088
bool enable_indexonlyscan
Definition: costsize.c:120
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:4725
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:2370
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1378
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3464
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:107
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4633
bool enable_bitmapscan
Definition: costsize.c:121
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3264
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:388
void compute_semi_anti_join_factors(PlannerInfo *root, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:3784
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3013
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:2041
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1565
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4762
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4801
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4121
int constraint_exclusion
Definition: plancat.c:54
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4553
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1820
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:1874
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:929
int max_parallel_workers_per_gather
Definition: costsize.c:116
PGDLLIMPORT double parallel_tuple_cost
Definition: costsize.c:109
Definition: nodes.h:736
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:4994
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:4071
PGDLLIMPORT double random_page_cost
Definition: costsize.c:105
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2163
bool enable_partition_wise_join
Definition: costsize.c:130
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1117
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5122
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1268
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:2921
double Cost
Definition: nodes.h:641
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:198