PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2024, 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.conf.sample */
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 /* defaults for non-Cost parameters */
33 #define DEFAULT_RECURSIVE_WORKTABLE_FACTOR 10.0
34 #define DEFAULT_EFFECTIVE_CACHE_SIZE 524288 /* measured in pages */
35 
36 typedef enum
37 {
38  CONSTRAINT_EXCLUSION_OFF, /* do not use c_e */
39  CONSTRAINT_EXCLUSION_ON, /* apply c_e to all rels */
40  CONSTRAINT_EXCLUSION_PARTITION, /* apply c_e to otherrels only */
42 
43 
44 /*
45  * prototypes for costsize.c
46  * routines to compute costs and sizes
47  */
48 
49 /* parameter variables and flags (see also optimizer.h) */
52 extern PGDLLIMPORT bool enable_seqscan;
53 extern PGDLLIMPORT bool enable_indexscan;
55 extern PGDLLIMPORT bool enable_bitmapscan;
56 extern PGDLLIMPORT bool enable_tidscan;
57 extern PGDLLIMPORT bool enable_sort;
59 extern PGDLLIMPORT bool enable_hashagg;
60 extern PGDLLIMPORT bool enable_nestloop;
61 extern PGDLLIMPORT bool enable_material;
62 extern PGDLLIMPORT bool enable_memoize;
63 extern PGDLLIMPORT bool enable_mergejoin;
64 extern PGDLLIMPORT bool enable_hashjoin;
74 
75 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
76  double index_pages, PlannerInfo *root);
77 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
78  ParamPathInfo *param_info);
79 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
80  ParamPathInfo *param_info);
81 extern void cost_index(IndexPath *path, PlannerInfo *root,
82  double loop_count, bool partial_path);
83 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
84  ParamPathInfo *param_info,
85  Path *bitmapqual, double loop_count);
88 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
89 extern void cost_tidscan(Path *path, PlannerInfo *root,
90  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
91 extern void cost_tidrangescan(Path *path, PlannerInfo *root,
92  RelOptInfo *baserel, List *tidrangequals,
93  ParamPathInfo *param_info);
95  RelOptInfo *baserel, ParamPathInfo *param_info,
96  bool trivial_pathtarget);
97 extern void cost_functionscan(Path *path, PlannerInfo *root,
98  RelOptInfo *baserel, ParamPathInfo *param_info);
99 extern void cost_valuesscan(Path *path, PlannerInfo *root,
100  RelOptInfo *baserel, ParamPathInfo *param_info);
101 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
102  RelOptInfo *baserel, ParamPathInfo *param_info);
103 extern void cost_ctescan(Path *path, PlannerInfo *root,
104  RelOptInfo *baserel, ParamPathInfo *param_info);
105 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
106  RelOptInfo *baserel, ParamPathInfo *param_info);
107 extern void cost_resultscan(Path *path, PlannerInfo *root,
108  RelOptInfo *baserel, ParamPathInfo *param_info);
109 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
110 extern void cost_sort(Path *path, PlannerInfo *root,
111  List *pathkeys, int disabled_nodes,
112  Cost input_cost, double tuples, int width,
113  Cost comparison_cost, int sort_mem,
114  double limit_tuples);
115 extern void cost_incremental_sort(Path *path,
116  PlannerInfo *root, List *pathkeys, int presorted_keys,
117  int input_disabled_nodes,
118  Cost input_startup_cost, Cost input_total_cost,
119  double input_tuples, int width, Cost comparison_cost, int sort_mem,
120  double limit_tuples);
121 extern void cost_append(AppendPath *apath);
122 extern void cost_merge_append(Path *path, PlannerInfo *root,
123  List *pathkeys, int n_streams,
124  int input_disabled_nodes,
125  Cost input_startup_cost, Cost input_total_cost,
126  double tuples);
127 extern void cost_material(Path *path,
128  int input_disabled_nodes,
129  Cost input_startup_cost, Cost input_total_cost,
130  double tuples, int width);
131 extern void cost_agg(Path *path, PlannerInfo *root,
132  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
133  int numGroupCols, double numGroups,
134  List *quals,
135  int input_disabled_nodes,
136  Cost input_startup_cost, Cost input_total_cost,
137  double input_tuples, double input_width);
138 extern void cost_windowagg(Path *path, PlannerInfo *root,
139  List *windowFuncs, WindowClause *winclause,
140  int input_disabled_nodes,
141  Cost input_startup_cost, Cost input_total_cost,
142  double input_tuples);
143 extern void cost_group(Path *path, PlannerInfo *root,
144  int numGroupCols, double numGroups,
145  List *quals,
146  int input_disabled_nodes,
147  Cost input_startup_cost, Cost input_total_cost,
148  double input_tuples);
150  JoinCostWorkspace *workspace,
151  JoinType jointype,
152  Path *outer_path, Path *inner_path,
153  JoinPathExtraData *extra);
154 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
155  JoinCostWorkspace *workspace,
156  JoinPathExtraData *extra);
158  JoinCostWorkspace *workspace,
159  JoinType jointype,
160  List *mergeclauses,
161  Path *outer_path, Path *inner_path,
162  List *outersortkeys, List *innersortkeys,
163  JoinPathExtraData *extra);
164 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
165  JoinCostWorkspace *workspace,
166  JoinPathExtraData *extra);
168  JoinCostWorkspace *workspace,
169  JoinType jointype,
170  List *hashclauses,
171  Path *outer_path, Path *inner_path,
172  JoinPathExtraData *extra,
173  bool parallel_hash);
174 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
175  JoinCostWorkspace *workspace,
176  JoinPathExtraData *extra);
177 extern void cost_gather(GatherPath *path, PlannerInfo *root,
178  RelOptInfo *rel, ParamPathInfo *param_info, double *rows);
180  RelOptInfo *rel, ParamPathInfo *param_info,
181  int input_disabled_nodes,
182  Cost input_startup_cost, Cost input_total_cost,
183  double *rows);
184 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
185 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
186 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
188  RelOptInfo *joinrel,
189  RelOptInfo *outerrel,
190  RelOptInfo *innerrel,
191  JoinType jointype,
192  SpecialJoinInfo *sjinfo,
193  List *restrictlist,
194  SemiAntiJoinFactors *semifactors);
197  RelOptInfo *rel,
198  List *param_clauses);
200  RelOptInfo *rel,
201  Path *outer_path,
202  Path *inner_path,
203  SpecialJoinInfo *sjinfo,
204  List *restrict_clauses);
206  RelOptInfo *outer_rel,
207  RelOptInfo *inner_rel,
208  SpecialJoinInfo *sjinfo,
209  List *restrictlist);
214  double cte_rows);
220 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
221  Path *bitmapqual, double loop_count,
222  Cost *cost_p, double *tuples_p);
223 extern double compute_gather_rows(Path *path);
224 
225 #endif /* COST_H */
uint32 BlockNumber
Definition: block.h:31
#define PGDLLIMPORT
Definition: c.h:1321
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:6089
PGDLLIMPORT bool enable_tidscan
Definition: costsize.c:149
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:159
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:4275
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:908
PGDLLIMPORT int max_parallel_workers_per_gather
Definition: costsize.c:143
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:162
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1122
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:5356
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:5437
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3837
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:3552
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, int input_disabled_nodes, Cost input_startup_cost, Cost input_total_cost, double input_tuples, double input_width)
Definition: costsize.c:2682
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:5091
PGDLLIMPORT bool enable_async_append
Definition: costsize.c:165
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5326
void cost_windowagg(Path *path, PlannerInfo *root, List *windowFuncs, WindowClause *winclause, int input_disabled_nodes, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:3099
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:153
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1538
void cost_material(Path *path, int input_disabled_nodes, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2483
PGDLLIMPORT bool enable_incremental_sort
Definition: costsize.c:151
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:1023
void cost_tidrangescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidrangequals, ParamPathInfo *param_info)
Definition: costsize.c:1363
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:6343
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5959
PGDLLIMPORT bool enable_material
Definition: costsize.c:154
PGDLLIMPORT bool enable_presorted_aggregate
Definition: costsize.c:164
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3350
void cost_gather_merge(GatherMergePath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, int input_disabled_nodes, Cost input_startup_cost, Cost input_total_cost, double *rows)
Definition: costsize.c:485
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1826
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1600
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, int disabled_nodes, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:2144
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:4160
PGDLLIMPORT bool enable_seqscan
Definition: costsize.c:145
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:370
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:446
ConstraintExclusionType
Definition: cost.h:37
@ CONSTRAINT_EXCLUSION_OFF
Definition: cost.h:38
@ CONSTRAINT_EXCLUSION_PARTITION
Definition: cost.h:40
@ CONSTRAINT_EXCLUSION_ON
Definition: cost.h:39
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:156
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:6051
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:5405
double compute_gather_rows(Path *path)
Definition: costsize.c:6601
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:4758
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1750
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:295
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1657
void cost_incremental_sort(Path *path, PlannerInfo *root, List *pathkeys, int presorted_keys, int input_disabled_nodes, 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:2000
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4732
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:3268
PGDLLIMPORT bool enable_gathermerge
Definition: costsize.c:158
void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:6122
PGDLLIMPORT bool enable_sort
Definition: costsize.c:150
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, List *quals, int input_disabled_nodes, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:3196
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1788
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, double loop_count, Cost *cost_p, double *tuples_p)
Definition: costsize.c:6490
PGDLLIMPORT bool enable_indexscan
Definition: costsize.c:146
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1165
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5879
PGDLLIMPORT Cost disable_cost
Definition: costsize.c:141
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:6151
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition: costsize.c:160
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1258
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:57
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:4524
void cost_merge_append(Path *path, PlannerInfo *root, List *pathkeys, int n_streams, int input_disabled_nodes, Cost input_startup_cost, Cost input_total_cost, double tuples)
Definition: costsize.c:2432
PGDLLIMPORT bool enable_bitmapscan
Definition: costsize.c:148
PGDLLIMPORT bool enable_indexonlyscan
Definition: costsize.c:147
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, bool trivial_pathtarget)
Definition: costsize.c:1457
void cost_append(AppendPath *apath)
Definition: costsize.c:2250
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1708
PGDLLIMPORT bool enable_hashagg
Definition: costsize.c:152
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1210
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5997
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:560
PGDLLIMPORT bool enable_memoize
Definition: costsize.c:155
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:6019
PGDLLIMPORT bool enable_partition_pruning
Definition: costsize.c:163
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:161
PGDLLIMPORT bool enable_hashjoin
Definition: costsize.c:157
double Cost
Definition: nodes.h:251
AggStrategy
Definition: nodes.h:353
double Selectivity
Definition: nodes.h:250
JoinType
Definition: nodes.h:288
#define plan(x)
Definition: pg_regress.c:161
tree ctl root
Definition: radixtree.h:1886
Definition: pg_list.h:54
Definition: nodes.h:129