1 | /*------------------------------------------------------------------------- |
2 | * |
3 | * cost.h |
4 | * prototypes for costsize.c and clausesel.c. |
5 | * |
6 | * |
7 | * Portions Copyright (c) 1996-2019, 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 */ |
39 | } ConstraintExclusionType; |
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) */ |
48 | extern PGDLLIMPORT Cost disable_cost; |
49 | extern PGDLLIMPORT int max_parallel_workers_per_gather; |
50 | extern PGDLLIMPORT bool enable_seqscan; |
51 | extern PGDLLIMPORT bool enable_indexscan; |
52 | extern PGDLLIMPORT bool enable_indexonlyscan; |
53 | extern PGDLLIMPORT bool enable_bitmapscan; |
54 | extern PGDLLIMPORT bool enable_tidscan; |
55 | extern PGDLLIMPORT bool enable_sort; |
56 | extern PGDLLIMPORT bool enable_hashagg; |
57 | extern PGDLLIMPORT bool enable_nestloop; |
58 | extern PGDLLIMPORT bool enable_material; |
59 | extern PGDLLIMPORT bool enable_mergejoin; |
60 | extern PGDLLIMPORT bool enable_hashjoin; |
61 | extern PGDLLIMPORT bool enable_gathermerge; |
62 | extern PGDLLIMPORT bool enable_partitionwise_join; |
63 | extern PGDLLIMPORT bool enable_partitionwise_aggregate; |
64 | extern PGDLLIMPORT bool enable_parallel_append; |
65 | extern PGDLLIMPORT bool enable_parallel_hash; |
66 | extern PGDLLIMPORT bool enable_partition_pruning; |
67 | extern PGDLLIMPORT int constraint_exclusion; |
68 | |
69 | extern double index_pages_fetched(double tuples_fetched, BlockNumber pages, |
70 | double index_pages, PlannerInfo *root); |
71 | extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, |
72 | ParamPathInfo *param_info); |
73 | extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, |
74 | ParamPathInfo *param_info); |
75 | extern void cost_index(IndexPath *path, PlannerInfo *root, |
76 | double loop_count, bool partial_path); |
77 | extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, |
78 | ParamPathInfo *param_info, |
79 | Path *bitmapqual, double loop_count); |
80 | extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root); |
81 | extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root); |
82 | extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec); |
83 | extern void cost_tidscan(Path *path, PlannerInfo *root, |
84 | RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info); |
85 | extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, |
86 | RelOptInfo *baserel, ParamPathInfo *param_info); |
87 | extern void cost_functionscan(Path *path, PlannerInfo *root, |
88 | RelOptInfo *baserel, ParamPathInfo *param_info); |
89 | extern void cost_valuesscan(Path *path, PlannerInfo *root, |
90 | RelOptInfo *baserel, ParamPathInfo *param_info); |
91 | extern void cost_tablefuncscan(Path *path, PlannerInfo *root, |
92 | RelOptInfo *baserel, ParamPathInfo *param_info); |
93 | extern void cost_ctescan(Path *path, PlannerInfo *root, |
94 | RelOptInfo *baserel, ParamPathInfo *param_info); |
95 | extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root, |
96 | RelOptInfo *baserel, ParamPathInfo *param_info); |
97 | extern void cost_resultscan(Path *path, PlannerInfo *root, |
98 | RelOptInfo *baserel, ParamPathInfo *param_info); |
99 | extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm); |
100 | extern void cost_sort(Path *path, PlannerInfo *root, |
101 | List *pathkeys, Cost input_cost, double tuples, int width, |
102 | Cost comparison_cost, int sort_mem, |
103 | double limit_tuples); |
104 | extern void cost_append(AppendPath *path); |
105 | extern void cost_merge_append(Path *path, PlannerInfo *root, |
106 | List *pathkeys, int n_streams, |
107 | Cost input_startup_cost, Cost input_total_cost, |
108 | double tuples); |
109 | extern void cost_material(Path *path, |
110 | Cost input_startup_cost, Cost input_total_cost, |
111 | double tuples, int width); |
112 | extern void cost_agg(Path *path, PlannerInfo *root, |
113 | AggStrategy aggstrategy, const AggClauseCosts *aggcosts, |
114 | int numGroupCols, double numGroups, |
115 | List *quals, |
116 | Cost input_startup_cost, Cost input_total_cost, |
117 | double input_tuples); |
118 | extern void cost_windowagg(Path *path, PlannerInfo *root, |
119 | List *windowFuncs, int numPartCols, int numOrderCols, |
120 | Cost input_startup_cost, Cost input_total_cost, |
121 | double input_tuples); |
122 | extern void cost_group(Path *path, PlannerInfo *root, |
123 | int numGroupCols, double numGroups, |
124 | List *quals, |
125 | Cost input_startup_cost, Cost input_total_cost, |
126 | double input_tuples); |
127 | extern void initial_cost_nestloop(PlannerInfo *root, |
128 | JoinCostWorkspace *workspace, |
129 | JoinType jointype, |
130 | Path *outer_path, Path *inner_path, |
131 | JoinPathExtraData *); |
132 | extern void final_cost_nestloop(PlannerInfo *root, NestPath *path, |
133 | JoinCostWorkspace *workspace, |
134 | JoinPathExtraData *); |
135 | extern void initial_cost_mergejoin(PlannerInfo *root, |
136 | JoinCostWorkspace *workspace, |
137 | JoinType jointype, |
138 | List *mergeclauses, |
139 | Path *outer_path, Path *inner_path, |
140 | List *outersortkeys, List *innersortkeys, |
141 | JoinPathExtraData *); |
142 | extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path, |
143 | JoinCostWorkspace *workspace, |
144 | JoinPathExtraData *); |
145 | extern void initial_cost_hashjoin(PlannerInfo *root, |
146 | JoinCostWorkspace *workspace, |
147 | JoinType jointype, |
148 | List *hashclauses, |
149 | Path *outer_path, Path *inner_path, |
150 | JoinPathExtraData *, |
151 | bool parallel_hash); |
152 | extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path, |
153 | JoinCostWorkspace *workspace, |
154 | JoinPathExtraData *); |
155 | extern void cost_gather(GatherPath *path, PlannerInfo *root, |
156 | RelOptInfo *baserel, ParamPathInfo *param_info, double *rows); |
157 | extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root, |
158 | RelOptInfo *rel, ParamPathInfo *param_info, |
159 | Cost input_startup_cost, Cost input_total_cost, |
160 | double *rows); |
161 | extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan); |
162 | extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root); |
163 | extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root); |
164 | extern void compute_semi_anti_join_factors(PlannerInfo *root, |
165 | RelOptInfo *joinrel, |
166 | RelOptInfo *outerrel, |
167 | RelOptInfo *innerrel, |
168 | JoinType jointype, |
169 | SpecialJoinInfo *sjinfo, |
170 | List *restrictlist, |
171 | SemiAntiJoinFactors *semifactors); |
172 | extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel); |
173 | extern double get_parameterized_baserel_size(PlannerInfo *root, |
174 | RelOptInfo *rel, |
175 | List *param_clauses); |
176 | extern double get_parameterized_joinrel_size(PlannerInfo *root, |
177 | RelOptInfo *rel, |
178 | Path *outer_path, |
179 | Path *inner_path, |
180 | SpecialJoinInfo *sjinfo, |
181 | List *restrict_clauses); |
182 | extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, |
183 | RelOptInfo *outer_rel, |
184 | RelOptInfo *inner_rel, |
185 | SpecialJoinInfo *sjinfo, |
186 | List *restrictlist); |
187 | extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel); |
188 | extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel); |
189 | extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel); |
190 | extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, |
191 | double cte_rows); |
192 | extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel); |
193 | extern void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel); |
194 | extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel); |
195 | extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel); |
196 | extern PathTarget *set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target); |
197 | extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, |
198 | Path *bitmapqual, int loop_count, Cost *cost, double *tuple); |
199 | |
200 | #endif /* COST_H */ |
201 | |