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-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
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 /* defaults for non-Cost parameters */
34 #define DEFAULT_EFFECTIVE_CACHE_SIZE 524288 /* measured in pages */
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 */
44 /*
45  * prototypes for costsize.c
46  * routines to compute costs and sizes
47  */
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;
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, Cost input_cost, double tuples, int width,
112  Cost comparison_cost, int sort_mem,
113  double limit_tuples);
114 extern void cost_incremental_sort(Path *path,
115  PlannerInfo *root, List *pathkeys, int presorted_keys,
116  Cost input_startup_cost, Cost input_total_cost,
117  double input_tuples, int width, Cost comparison_cost, int sort_mem,
118  double limit_tuples);
119 extern void cost_append(AppendPath *apath);
120 extern void cost_merge_append(Path *path, PlannerInfo *root,
121  List *pathkeys, int n_streams,
122  Cost input_startup_cost, Cost input_total_cost,
123  double tuples);
124 extern void cost_material(Path *path,
125  Cost input_startup_cost, Cost input_total_cost,
126  double tuples, int width);
127 extern void cost_agg(Path *path, PlannerInfo *root,
128  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
129  int numGroupCols, double numGroups,
130  List *quals,
131  Cost input_startup_cost, Cost input_total_cost,
132  double input_tuples, double input_width);
133 extern void cost_windowagg(Path *path, PlannerInfo *root,
134  List *windowFuncs, WindowClause *winclause,
135  Cost input_startup_cost, Cost input_total_cost,
136  double input_tuples);
137 extern void cost_group(Path *path, PlannerInfo *root,
138  int numGroupCols, double numGroups,
139  List *quals,
140  Cost input_startup_cost, Cost input_total_cost,
141  double input_tuples);
143  JoinCostWorkspace *workspace,
144  JoinType jointype,
145  Path *outer_path, Path *inner_path,
146  JoinPathExtraData *extra);
147 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
148  JoinCostWorkspace *workspace,
149  JoinPathExtraData *extra);
151  JoinCostWorkspace *workspace,
152  JoinType jointype,
153  List *mergeclauses,
154  Path *outer_path, Path *inner_path,
155  List *outersortkeys, List *innersortkeys,
156  JoinPathExtraData *extra);
157 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
158  JoinCostWorkspace *workspace,
159  JoinPathExtraData *extra);
161  JoinCostWorkspace *workspace,
162  JoinType jointype,
163  List *hashclauses,
164  Path *outer_path, Path *inner_path,
165  JoinPathExtraData *extra,
166  bool parallel_hash);
167 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
168  JoinCostWorkspace *workspace,
169  JoinPathExtraData *extra);
170 extern void cost_gather(GatherPath *path, PlannerInfo *root,
171  RelOptInfo *rel, ParamPathInfo *param_info, double *rows);
173  RelOptInfo *rel, ParamPathInfo *param_info,
174  Cost input_startup_cost, Cost input_total_cost,
175  double *rows);
176 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
177 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
178 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
180  RelOptInfo *joinrel,
181  RelOptInfo *outerrel,
182  RelOptInfo *innerrel,
183  JoinType jointype,
184  SpecialJoinInfo *sjinfo,
185  List *restrictlist,
186  SemiAntiJoinFactors *semifactors);
189  RelOptInfo *rel,
190  List *param_clauses);
192  RelOptInfo *rel,
193  Path *outer_path,
194  Path *inner_path,
195  SpecialJoinInfo *sjinfo,
196  List *restrict_clauses);
198  RelOptInfo *outer_rel,
199  RelOptInfo *inner_rel,
200  SpecialJoinInfo *sjinfo,
201  List *restrictlist);
206  double cte_rows);
212 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
213  Path *bitmapqual, double loop_count,
214  Cost *cost_p, double *tuples_p);
216 #endif /* COST_H */
uint32 BlockNumber
Definition: block.h:31
Definition: c.h:1316
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:6002
PGDLLIMPORT bool enable_tidscan
Definition: costsize.c:138
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:148
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:4181
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:898
PGDLLIMPORT int max_parallel_workers_per_gather
Definition: costsize.c:132
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:151
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1114
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:5269
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:5350
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3745
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:3514
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:5004
PGDLLIMPORT bool enable_async_append
Definition: costsize.c:154
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5239
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:142
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1531
PGDLLIMPORT bool enable_incremental_sort
Definition: costsize.c:140
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2453
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:1013
void cost_tidrangescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidrangequals, ParamPathInfo *param_info)
Definition: costsize.c:1357
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:6256
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5872
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:2404
PGDLLIMPORT bool enable_material
Definition: costsize.c:143
PGDLLIMPORT bool enable_presorted_aggregate
Definition: costsize.c:153
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3308
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1813
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:1986
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1592
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:4073
PGDLLIMPORT bool enable_seqscan
Definition: costsize.c:134
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:361
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:436
Definition: cost.h:37
Definition: cost.h:38
Definition: cost.h:40
Definition: cost.h:39
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:145
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:5964
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:5318
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:2650
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:4666
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1739
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:284
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1648
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4640
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:3233
PGDLLIMPORT bool enable_gathermerge
Definition: costsize.c:147
void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:6035
PGDLLIMPORT bool enable_sort
Definition: costsize.c:139
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1776
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, double loop_count, Cost *cost_p, double *tuples_p)
Definition: costsize.c:6403
PGDLLIMPORT bool enable_indexscan
Definition: costsize.c:135
void cost_windowagg(Path *path, PlannerInfo *root, List *windowFuncs, WindowClause *winclause, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:3068
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1157
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5792
PGDLLIMPORT Cost disable_cost
Definition: costsize.c:130
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:6064
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:474
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition: costsize.c:149
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1249
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:56
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:4435
PGDLLIMPORT bool enable_bitmapscan
Definition: costsize.c:137
PGDLLIMPORT bool enable_indexonlyscan
Definition: costsize.c:136
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, bool trivial_pathtarget)
Definition: costsize.c:1451
void cost_append(AppendPath *apath)
Definition: costsize.c:2231
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1698
PGDLLIMPORT bool enable_hashagg
Definition: costsize.c:141
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1201
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5910
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:549
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:2124
PGDLLIMPORT bool enable_memoize
Definition: costsize.c:144
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:3163
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5932
PGDLLIMPORT bool enable_partition_pruning
Definition: costsize.c:152
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:150
PGDLLIMPORT bool enable_hashjoin
Definition: costsize.c:146
double Cost
Definition: nodes.h:251
Definition: nodes.h:352
double Selectivity
Definition: nodes.h:250
Definition: nodes.h:288
#define plan(x)
Definition: pg_regress.c:162
tree ctl root
Definition: radixtree.h:1884
Definition: pg_list.h:54
Definition: nodes.h:129