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_mergejoin;
61 extern PGDLLIMPORT bool enable_hashjoin;
70 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
71  double index_pages, PlannerInfo *root);
72 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
73  ParamPathInfo *param_info);
74 extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
75  ParamPathInfo *param_info);
76 extern void cost_index(IndexPath *path, PlannerInfo *root,
77  double loop_count, bool partial_path);
78 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
79  ParamPathInfo *param_info,
80  Path *bitmapqual, double loop_count);
81 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
82 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
83 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
84 extern void cost_tidscan(Path *path, PlannerInfo *root,
85  RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
86 extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
87  RelOptInfo *baserel, ParamPathInfo *param_info);
88 extern void cost_functionscan(Path *path, PlannerInfo *root,
89  RelOptInfo *baserel, ParamPathInfo *param_info);
90 extern void cost_valuesscan(Path *path, PlannerInfo *root,
91  RelOptInfo *baserel, ParamPathInfo *param_info);
92 extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
93  RelOptInfo *baserel, ParamPathInfo *param_info);
94 extern void cost_ctescan(Path *path, PlannerInfo *root,
95  RelOptInfo *baserel, ParamPathInfo *param_info);
96 extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
97  RelOptInfo *baserel, ParamPathInfo *param_info);
98 extern void cost_resultscan(Path *path, PlannerInfo *root,
99  RelOptInfo *baserel, ParamPathInfo *param_info);
100 extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
101 extern void cost_sort(Path *path, PlannerInfo *root,
102  List *pathkeys, Cost input_cost, double tuples, int width,
103  Cost comparison_cost, int sort_mem,
104  double limit_tuples);
105 extern void cost_incremental_sort(Path *path,
106  PlannerInfo *root, List *pathkeys, int presorted_keys,
107  Cost input_startup_cost, Cost input_total_cost,
108  double input_tuples, int width, Cost comparison_cost, int sort_mem,
109  double limit_tuples);
110 extern void cost_append(AppendPath *path);
111 extern void cost_merge_append(Path *path, PlannerInfo *root,
112  List *pathkeys, int n_streams,
113  Cost input_startup_cost, Cost input_total_cost,
114  double tuples);
115 extern void cost_material(Path *path,
116  Cost input_startup_cost, Cost input_total_cost,
117  double tuples, int width);
118 extern void cost_agg(Path *path, PlannerInfo *root,
119  AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
120  int numGroupCols, double numGroups,
121  List *quals,
122  Cost input_startup_cost, Cost input_total_cost,
123  double input_tuples, double input_width);
124 extern void cost_windowagg(Path *path, PlannerInfo *root,
125  List *windowFuncs, int numPartCols, int numOrderCols,
126  Cost input_startup_cost, Cost input_total_cost,
127  double input_tuples);
128 extern void cost_group(Path *path, PlannerInfo *root,
129  int numGroupCols, double numGroups,
130  List *quals,
131  Cost input_startup_cost, Cost input_total_cost,
132  double input_tuples);
133 extern void initial_cost_nestloop(PlannerInfo *root,
134  JoinCostWorkspace *workspace,
135  JoinType jointype,
136  Path *outer_path, Path *inner_path,
137  JoinPathExtraData *extra);
138 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
139  JoinCostWorkspace *workspace,
140  JoinPathExtraData *extra);
141 extern void initial_cost_mergejoin(PlannerInfo *root,
142  JoinCostWorkspace *workspace,
143  JoinType jointype,
144  List *mergeclauses,
145  Path *outer_path, Path *inner_path,
146  List *outersortkeys, List *innersortkeys,
147  JoinPathExtraData *extra);
148 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
149  JoinCostWorkspace *workspace,
150  JoinPathExtraData *extra);
151 extern void initial_cost_hashjoin(PlannerInfo *root,
152  JoinCostWorkspace *workspace,
153  JoinType jointype,
154  List *hashclauses,
155  Path *outer_path, Path *inner_path,
156  JoinPathExtraData *extra,
157  bool parallel_hash);
158 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
159  JoinCostWorkspace *workspace,
160  JoinPathExtraData *extra);
161 extern void cost_gather(GatherPath *path, PlannerInfo *root,
162  RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
163 extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root,
164  RelOptInfo *rel, ParamPathInfo *param_info,
165  Cost input_startup_cost, Cost input_total_cost,
166  double *rows);
167 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
168 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
169 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
171  RelOptInfo *joinrel,
172  RelOptInfo *outerrel,
173  RelOptInfo *innerrel,
174  JoinType jointype,
175  SpecialJoinInfo *sjinfo,
176  List *restrictlist,
177  SemiAntiJoinFactors *semifactors);
178 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
179 extern double get_parameterized_baserel_size(PlannerInfo *root,
180  RelOptInfo *rel,
181  List *param_clauses);
182 extern double get_parameterized_joinrel_size(PlannerInfo *root,
183  RelOptInfo *rel,
184  Path *outer_path,
185  Path *inner_path,
186  SpecialJoinInfo *sjinfo,
187  List *restrict_clauses);
188 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
189  RelOptInfo *outer_rel,
190  RelOptInfo *inner_rel,
191  SpecialJoinInfo *sjinfo,
192  List *restrictlist);
193 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
194 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
195 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
196 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
197  double cte_rows);
198 extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
200 extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel);
201 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
203 extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
204  Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
206 #endif /* COST_H */
PGDLLIMPORT bool enable_nestloop
Definition: costsize.c:140
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5324
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:300
void cost_append(AppendPath *path)
Definition: costsize.c:2044
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5346
PGDLLIMPORT bool enable_material
Definition: costsize.c:141
Definition: nodes.h:528
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:488
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1551
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1053
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition: costsize.c:146
PGDLLIMPORT bool enable_mergejoin
Definition: costsize.c:142
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3173
uint32 BlockNumber
Definition: block.h:31
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1096
double Selectivity
Definition: nodes.h:661
PGDLLIMPORT Cost disable_cost
Definition: costsize.c:128
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:2592
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4651
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition: costsize.c:4762
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:2217
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1343
Definition: c.h:1305
Definition: nodes.h:695
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition: costsize.c:4092
PGDLLIMPORT bool enable_partition_pruning
Definition: costsize.c:149
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1510
PGDLLIMPORT bool enable_seqscan
Definition: costsize.c:132
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1188
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:1937
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:375
Definition: cost.h:34
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1460
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:2518
double index_pages_fetched(double tuples_fetched, BlockNumber pages, double index_pages, PlannerInfo *root)
Definition: costsize.c:837
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition: costsize.c:2662
PGDLLIMPORT bool enable_gathermerge
Definition: costsize.c:144
PGDLLIMPORT bool enable_hashjoin
Definition: costsize.c:143
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:5378
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:2943
PGDLLIMPORT int constraint_exclusion
Definition: plancat.c:57
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1404
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4066
PGDLLIMPORT bool enable_incremental_sort
Definition: costsize.c:138
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:1798
PGDLLIMPORT bool enable_indexonlyscan
Definition: costsize.c:134
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5286
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition: costsize.c:3866
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1588
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:413
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3609
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1625
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5415
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5477
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4730
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5206
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2266
PGDLLIMPORT bool enable_sort
Definition: costsize.c:137
PGDLLIMPORT bool enable_hashagg
Definition: costsize.c:139
PGDLLIMPORT int max_parallel_workers_per_gather
Definition: costsize.c:130
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:952
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:3501
PGDLLIMPORT bool enable_parallel_hash
Definition: costsize.c:148
Definition: nodes.h:757
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition: costsize.c:5670
PGDLLIMPORT bool enable_bitmapscan
Definition: costsize.c:135
PGDLLIMPORT bool enable_tidscan
Definition: costsize.c:136
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:4394
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition: costsize.c:4681
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2737
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:2320
PGDLLIMPORT bool enable_partitionwise_join
Definition: costsize.c:145
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1140
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5802
PGDLLIMPORT bool enable_indexscan
Definition: costsize.c:133
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1294
Definition: pg_list.h:50
void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5448
double Cost
Definition: nodes.h:662
PGDLLIMPORT bool enable_parallel_append
Definition: costsize.c:147
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:223