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-2021, 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/pathnodes.h"
18 #include "nodes/plannodes.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.conf.sample */
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 (see also optimizer.h) */
50 extern PGDLLIMPORT bool enable_seqscan;
51 extern PGDLLIMPORT bool enable_indexscan;
53 extern PGDLLIMPORT bool enable_bitmapscan;
54 extern PGDLLIMPORT bool enable_tidscan;
55 extern PGDLLIMPORT bool enable_sort;
57 extern PGDLLIMPORT bool enable_hashagg;
58 extern PGDLLIMPORT bool enable_nestloop;
59 extern PGDLLIMPORT bool enable_material;
60 extern PGDLLIMPORT bool enable_memoize;
61 extern PGDLLIMPORT bool enable_mergejoin;
62 extern PGDLLIMPORT bool enable_hashjoin;
72 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
73  double index_pages, PlannerInfo *root);
74 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
75  ParamPathInfo *param_info);
76 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
77  ParamPathInfo *param_info);
78 extern void cost_index(IndexPath *path, PlannerInfo *root,
79  double loop_count, bool partial_path);
80 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
81  ParamPathInfo *param_info,
82  Path *bitmapqual, double loop_count);
83 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
84 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
85 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
86 extern void cost_tidscan(Path *path, PlannerInfo *root,
87  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
88 extern void cost_tidrangescan(Path *path, PlannerInfo *root,
89  RelOptInfo *baserel, List *tidrangequals,
90  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_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_resultscan(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_incremental_sort(Path *path,
111  PlannerInfo *root, List *pathkeys, int presorted_keys,
112  Cost input_startup_cost, Cost input_total_cost,
113  double input_tuples, int width, Cost comparison_cost, int sort_mem,
114  double limit_tuples);
115 extern void cost_append(AppendPath *path);
116 extern void cost_merge_append(Path *path, PlannerInfo *root,
117  List *pathkeys, int n_streams,
118  Cost input_startup_cost, Cost input_total_cost,
119  double tuples);
120 extern void cost_material(Path *path,
121  Cost input_startup_cost, Cost input_total_cost,
122  double tuples, int width);
123 extern void cost_agg(Path *path, PlannerInfo *root,
124  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
125  int numGroupCols, double numGroups,
126  List *quals,
127  Cost input_startup_cost, Cost input_total_cost,
128  double input_tuples, double input_width);
129 extern void cost_windowagg(Path *path, PlannerInfo *root,
130  List *windowFuncs, int numPartCols, int numOrderCols,
131  Cost input_startup_cost, Cost input_total_cost,
132  double input_tuples);
133 extern void cost_group(Path *path, PlannerInfo *root,
134  int numGroupCols, double numGroups,
135  List *quals,
136  Cost input_startup_cost, Cost input_total_cost,
137  double input_tuples);
138 extern void initial_cost_nestloop(PlannerInfo *root,
139  JoinCostWorkspace *workspace,
140  JoinType jointype,
141  Path *outer_path, Path *inner_path,
142  JoinPathExtraData *extra);
143 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
144  JoinCostWorkspace *workspace,
145  JoinPathExtraData *extra);
146 extern void initial_cost_mergejoin(PlannerInfo *root,
147  JoinCostWorkspace *workspace,
148  JoinType jointype,
149  List *mergeclauses,
150  Path *outer_path, Path *inner_path,
151  List *outersortkeys, List *innersortkeys,
152  JoinPathExtraData *extra);
153 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
154  JoinCostWorkspace *workspace,
155  JoinPathExtraData *extra);
156 extern void initial_cost_hashjoin(PlannerInfo *root,
157  JoinCostWorkspace *workspace,
158  JoinType jointype,
159  List *hashclauses,
160  Path *outer_path, Path *inner_path,
161  JoinPathExtraData *extra,
162  bool parallel_hash);
163 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
164  JoinCostWorkspace *workspace,
165  JoinPathExtraData *extra);
166 extern void cost_gather(GatherPath *path, PlannerInfo *root,
167  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
168 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
169  RelOptInfo *rel, ParamPathInfo *param_info,
170  Cost input_startup_cost, Cost input_total_cost,
171  double *rows);
172 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
173 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
174 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
176  RelOptInfo *joinrel,
177  RelOptInfo *outerrel,
178  RelOptInfo *innerrel,
179  JoinType jointype,
180  SpecialJoinInfo *sjinfo,
181  List *restrictlist,
182  SemiAntiJoinFactors *semifactors);
183 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
184 extern double get_parameterized_baserel_size(PlannerInfo *root,
185  RelOptInfo *rel,
186  List *param_clauses);
187 extern double get_parameterized_joinrel_size(PlannerInfo *root,
188  RelOptInfo *rel,
189  Path *outer_path,
190  Path *inner_path,
191  SpecialJoinInfo *sjinfo,
192  List *restrict_clauses);
193 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
194  RelOptInfo *outer_rel,
195  RelOptInfo *inner_rel,
196  SpecialJoinInfo *sjinfo,
197  List *restrictlist);
198 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
199 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
200 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
201 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
202  double cte_rows);
203 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
205 extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel);
206 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
208 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
209  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
211 #endif /* COST_H */
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:141
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5596
PGDLLIMPORT bool enable_async_append
Definition: costsize.c:152
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:303
void cost_append(AppendPath *path)
Definition: costsize.c:2143
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5618
PGDLLIMPORT bool enable_memoize
Definition: costsize.c:143
PGDLLIMPORT bool enable_material
Definition: costsize.c:142
Definition: nodes.h:536
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:491
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1649
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1056
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition: costsize.c:148
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:144
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3413
uint32 BlockNumber
Definition: block.h:31
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1099
double Selectivity
Definition: nodes.h:669
PGDLLIMPORT Cost disable_cost
Definition: costsize.c:129
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:2832
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4923
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:5034
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:2316
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1441
void cost_tidrangescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidrangequals, ParamPathInfo *param_info)
Definition: costsize.c:1299
Definition: c.h:1317
Definition: nodes.h:704
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:4334
PGDLLIMPORT bool enable_partition_pruning
Definition: costsize.c:151
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1608
PGDLLIMPORT bool enable_seqscan
Definition: costsize.c:133
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1191
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:2036
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:378
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1558
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:2758
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:840
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2902
PGDLLIMPORT bool enable_gathermerge
Definition: costsize.c:146
PGDLLIMPORT bool enable_hashjoin
Definition: costsize.c:145
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:5650
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:3183
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:57
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1502
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4308
PGDLLIMPORT bool enable_incremental_sort
Definition: costsize.c:139
void cost_incremental_sort(Path *path, PlannerInfo *root, List *pathkeys, int presorted_keys, Cost input_startup_cost, Cost input_total_cost, double input_tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1896
PGDLLIMPORT bool enable_indexonlyscan
Definition: costsize.c:135
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5558
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:4103
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1686
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:416
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3849
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1723
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5687
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5749
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:5002
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5478
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2365
PGDLLIMPORT bool enable_sort
Definition: costsize.c:138
PGDLLIMPORT bool enable_hashagg
Definition: costsize.c:140
PGDLLIMPORT int max_parallel_workers_per_gather
Definition: costsize.c:131
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:955
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:3741
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:150
Definition: nodes.h:766
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:5942
PGDLLIMPORT bool enable_bitmapscan
Definition: costsize.c:136
PGDLLIMPORT bool enable_tidscan
Definition: costsize.c:137
void compute_semi_anti_join_factors(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:4665
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:4953
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2977
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, double input_width)
Definition: costsize.c:2560
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:147
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1143
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:6075
PGDLLIMPORT bool enable_indexscan
Definition: costsize.c:134
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1392
Definition: pg_list.h:50
void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5720
double Cost
Definition: nodes.h:670
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:149
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:226