PostgreSQL Source Code  git master
cost.h
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-2020, 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
16 
17 #include "nodes/pathnodes.h"
18 #include "nodes/plannodes.h"
19 
20 
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
25 #define DEFAULT_RANDOM_PAGE_COST 4.0
26 #define DEFAULT_CPU_TUPLE_COST 0.01
27 #define DEFAULT_CPU_INDEX_TUPLE_COST 0.005
28 #define DEFAULT_CPU_OPERATOR_COST 0.0025
29 #define DEFAULT_PARALLEL_TUPLE_COST 0.1
30 #define DEFAULT_PARALLEL_SETUP_COST 1000.0
31 
32 #define DEFAULT_EFFECTIVE_CACHE_SIZE 524288 /* measured in pages */
33 
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 */
40 
41 
42 /*
43  * prototypes for costsize.c
44  * routines to compute costs and sizes
45  */
46 
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;
60 extern PGDLLIMPORT bool enable_nestloop;
61 extern PGDLLIMPORT bool enable_material;
62 extern PGDLLIMPORT bool enable_mergejoin;
63 extern PGDLLIMPORT bool enable_hashjoin;
71 
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_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
89  RelOptInfo *baserel, ParamPathInfo *param_info);
90 extern void cost_functionscan(Path *path, PlannerInfo *root,
91  RelOptInfo *baserel, ParamPathInfo *param_info);
92 extern void cost_valuesscan(Path *path, PlannerInfo *root,
93  RelOptInfo *baserel, ParamPathInfo *param_info);
94 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
95  RelOptInfo *baserel, ParamPathInfo *param_info);
96 extern void cost_ctescan(Path *path, PlannerInfo *root,
97  RelOptInfo *baserel, ParamPathInfo *param_info);
98 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
99  RelOptInfo *baserel, ParamPathInfo *param_info);
100 extern void cost_resultscan(Path *path, PlannerInfo *root,
101  RelOptInfo *baserel, ParamPathInfo *param_info);
102 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
103 extern void cost_sort(Path *path, PlannerInfo *root,
104  List *pathkeys, Cost input_cost, double tuples, int width,
105  Cost comparison_cost, int sort_mem,
106  double limit_tuples);
107 extern void cost_incremental_sort(Path *path,
108  PlannerInfo *root, List *pathkeys, int presorted_keys,
109  Cost input_startup_cost, Cost input_total_cost,
110  double input_tuples, int width, Cost comparison_cost, int sort_mem,
111  double limit_tuples);
112 extern void cost_append(AppendPath *path);
113 extern void cost_merge_append(Path *path, PlannerInfo *root,
114  List *pathkeys, int n_streams,
115  Cost input_startup_cost, Cost input_total_cost,
116  double tuples);
117 extern void cost_material(Path *path,
118  Cost input_startup_cost, Cost input_total_cost,
119  double tuples, int width);
120 extern void cost_agg(Path *path, PlannerInfo *root,
121  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
122  int numGroupCols, double numGroups,
123  List *quals,
124  Cost input_startup_cost, Cost input_total_cost,
125  double input_tuples, double input_width);
126 extern void cost_windowagg(Path *path, PlannerInfo *root,
127  List *windowFuncs, int numPartCols, int numOrderCols,
128  Cost input_startup_cost, Cost input_total_cost,
129  double input_tuples);
130 extern void cost_group(Path *path, PlannerInfo *root,
131  int numGroupCols, double numGroups,
132  List *quals,
133  Cost input_startup_cost, Cost input_total_cost,
134  double input_tuples);
135 extern void initial_cost_nestloop(PlannerInfo *root,
136  JoinCostWorkspace *workspace,
137  JoinType jointype,
138  Path *outer_path, Path *inner_path,
139  JoinPathExtraData *extra);
140 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
141  JoinCostWorkspace *workspace,
142  JoinPathExtraData *extra);
143 extern void initial_cost_mergejoin(PlannerInfo *root,
144  JoinCostWorkspace *workspace,
145  JoinType jointype,
146  List *mergeclauses,
147  Path *outer_path, Path *inner_path,
148  List *outersortkeys, List *innersortkeys,
149  JoinPathExtraData *extra);
150 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
151  JoinCostWorkspace *workspace,
152  JoinPathExtraData *extra);
153 extern void initial_cost_hashjoin(PlannerInfo *root,
154  JoinCostWorkspace *workspace,
155  JoinType jointype,
156  List *hashclauses,
157  Path *outer_path, Path *inner_path,
158  JoinPathExtraData *extra,
159  bool parallel_hash);
160 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
161  JoinCostWorkspace *workspace,
162  JoinPathExtraData *extra);
163 extern void cost_gather(GatherPath *path, PlannerInfo *root,
164  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
165 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
166  RelOptInfo *rel, ParamPathInfo *param_info,
167  Cost input_startup_cost, Cost input_total_cost,
168  double *rows);
169 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
170 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
171 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
173  RelOptInfo *joinrel,
174  RelOptInfo *outerrel,
175  RelOptInfo *innerrel,
176  JoinType jointype,
177  SpecialJoinInfo *sjinfo,
178  List *restrictlist,
179  SemiAntiJoinFactors *semifactors);
180 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
181 extern double get_parameterized_baserel_size(PlannerInfo *root,
182  RelOptInfo *rel,
183  List *param_clauses);
184 extern double get_parameterized_joinrel_size(PlannerInfo *root,
185  RelOptInfo *rel,
186  Path *outer_path,
187  Path *inner_path,
188  SpecialJoinInfo *sjinfo,
189  List *restrict_clauses);
190 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
191  RelOptInfo *outer_rel,
192  RelOptInfo *inner_rel,
193  SpecialJoinInfo *sjinfo,
194  List *restrictlist);
195 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
196 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
197 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
198 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
199  double cte_rows);
200 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
202 extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel);
203 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
205 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
206  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
207 
208 #endif /* COST_H */
PGDLLIMPORT bool enable_incrementalsort
Definition: costsize.c:131
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:135
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5254
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:292
void cost_append(AppendPath *path)
Definition: costsize.c:2036
PGDLLIMPORT bool enable_groupingsets_hash_disk
Definition: costsize.c:134
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5276
PGDLLIMPORT bool enable_material
Definition: costsize.c:136
Definition: nodes.h:529
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:480
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1543
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1045
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition: costsize.c:141
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:137
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3152
uint32 BlockNumber
Definition: block.h:31
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1088
double Selectivity
Definition: nodes.h:662
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:2570
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4628
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4739
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:2209
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1335
#define PGDLLIMPORT
Definition: c.h:1280
JoinType
Definition: nodes.h:696
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:4069
PGDLLIMPORT bool enable_partition_pruning
Definition: costsize.c:144
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1502
PGDLLIMPORT bool enable_seqscan
Definition: costsize.c:125
PGDLLIMPORT bool enable_hashagg_disk
Definition: costsize.c:133
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1180
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:1929
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:367
ConstraintExclusionType
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1452
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:2496
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:829
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2640
PGDLLIMPORT bool enable_gathermerge
Definition: costsize.c:139
PGDLLIMPORT bool enable_hashjoin
Definition: costsize.c:138
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:5308
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:2922
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:57
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1396
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4043
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:1790
PGDLLIMPORT bool enable_indexonlyscan
Definition: costsize.c:127
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5216
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3843
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1580
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:405
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3588
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1617
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5345
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5407
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4707
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5136
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2258
PGDLLIMPORT bool enable_sort
Definition: costsize.c:130
PGDLLIMPORT bool enable_hashagg
Definition: costsize.c:132
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:944
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:3480
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:143
AggStrategy
Definition: nodes.h:758
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:5600
PGDLLIMPORT bool enable_bitmapscan
Definition: costsize.c:128
PGDLLIMPORT bool enable_tidscan
Definition: costsize.c:129
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:4371
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:4658
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2715
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:2312
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:140
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1132
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5732
PGDLLIMPORT bool enable_indexscan
Definition: costsize.c:126
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1286
Definition: pg_list.h:50
void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5378
double Cost
Definition: nodes.h:663
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:142
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:215