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_namedtuplestorescan(Path *path, PlannerInfo *root,
102  RelOptInfo *baserel, ParamPathInfo *param_info);
103 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
104 extern void cost_sort(Path *path, PlannerInfo *root,
105  List *pathkeys, Cost input_cost, double tuples, int width,
106  Cost comparison_cost, int sort_mem,
107  double limit_tuples);
108 extern void cost_merge_append(Path *path, PlannerInfo *root,
109  List *pathkeys, int n_streams,
110  Cost input_startup_cost, Cost input_total_cost,
111  double tuples);
112 extern void cost_material(Path *path,
113  Cost input_startup_cost, Cost input_total_cost,
114  double tuples, int width);
115 extern void cost_agg(Path *path, PlannerInfo *root,
116  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
117  int numGroupCols, double numGroups,
118  Cost input_startup_cost, Cost input_total_cost,
119  double input_tuples);
120 extern void cost_windowagg(Path *path, PlannerInfo *root,
121  List *windowFuncs, int numPartCols, int numOrderCols,
122  Cost input_startup_cost, Cost input_total_cost,
123  double input_tuples);
124 extern void cost_group(Path *path, PlannerInfo *root,
125  int numGroupCols, double numGroups,
126  Cost input_startup_cost, Cost input_total_cost,
127  double input_tuples);
128 extern void initial_cost_nestloop(PlannerInfo *root,
129  JoinCostWorkspace *workspace,
130  JoinType jointype,
131  Path *outer_path, Path *inner_path,
132  JoinPathExtraData *extra);
133 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
134  JoinCostWorkspace *workspace,
135  JoinPathExtraData *extra);
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  JoinPathExtraData *extra);
143 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
144  JoinCostWorkspace *workspace,
145  JoinPathExtraData *extra);
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  JoinPathExtraData *extra);
152 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
153  JoinCostWorkspace *workspace,
154  JoinPathExtraData *extra);
155 extern void cost_gather(GatherPath *path, PlannerInfo *root,
156  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
157 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
158 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
159 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
161  RelOptInfo *outerrel,
162  RelOptInfo *innerrel,
163  JoinType jointype,
164  SpecialJoinInfo *sjinfo,
165  List *restrictlist,
166  SemiAntiJoinFactors *semifactors);
167 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
168 extern double get_parameterized_baserel_size(PlannerInfo *root,
169  RelOptInfo *rel,
170  List *param_clauses);
171 extern double get_parameterized_joinrel_size(PlannerInfo *root,
172  RelOptInfo *rel,
173  Path *outer_path,
174  Path *inner_path,
175  SpecialJoinInfo *sjinfo,
176  List *restrict_clauses);
177 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
178  RelOptInfo *outer_rel,
179  RelOptInfo *inner_rel,
180  SpecialJoinInfo *sjinfo,
181  List *restrictlist);
182 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
183 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
184 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
185 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
186  double cte_rows);
187 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
189 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
191 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
192  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
194 /*
195  * prototypes for clausesel.c
196  * routines to compute clause selectivities
197  */
199  List *clauses,
200  int varRelid,
201  JoinType jointype,
202  SpecialJoinInfo *sjinfo);
204  Node *clause,
205  int varRelid,
206  JoinType jointype,
207  SpecialJoinInfo *sjinfo);
208 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
209  RelOptInfo *rel, ParamPathInfo *param_info,
210  Cost input_startup_cost, Cost input_total_cost,
211  double *rows);
213 #endif /* COST_H */
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4637
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:572
bool enable_tidscan
Definition: costsize.c:122
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4664
bool enable_material
Definition: costsize.c:126
Definition: nodes.h:509
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:462
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1524
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1029
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2599
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:1072
double Selectivity
Definition: nodes.h:639
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:4003
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4114
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:1768
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:673
double clamp_row_est(double nrows)
Definition: costsize.c:173
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:3464
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
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:1644
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:1970
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:813
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2087
bool enable_indexonlyscan
Definition: costsize.c:120
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:4696
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:2369
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:3438
PGDLLIMPORT double cpu_index_tuple_cost
Definition: costsize.c:107
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4599
bool enable_bitmapscan
Definition: costsize.c:121
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3238
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:3746
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3012
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:2040
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1564
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4733
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4772
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4083
int constraint_exclusion
Definition: plancat.c:54
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4515
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1819
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:1873
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:735
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:4965
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:4033
PGDLLIMPORT double random_page_cost
Definition: costsize.c:105
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2162
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:5093
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1267
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:2920
Definition: relation.h:948
double Cost
Definition: nodes.h:640
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:197