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
34typedef 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) */
48extern PGDLLIMPORT Cost disable_cost;
49extern PGDLLIMPORT int max_parallel_workers_per_gather;
50extern PGDLLIMPORT bool enable_seqscan;
51extern PGDLLIMPORT bool enable_indexscan;
52extern PGDLLIMPORT bool enable_indexonlyscan;
53extern PGDLLIMPORT bool enable_bitmapscan;
54extern PGDLLIMPORT bool enable_tidscan;
55extern PGDLLIMPORT bool enable_sort;
56extern PGDLLIMPORT bool enable_hashagg;
57extern PGDLLIMPORT bool enable_nestloop;
58extern PGDLLIMPORT bool enable_material;
59extern PGDLLIMPORT bool enable_mergejoin;
60extern PGDLLIMPORT bool enable_hashjoin;
61extern PGDLLIMPORT bool enable_gathermerge;
62extern PGDLLIMPORT bool enable_partitionwise_join;
63extern PGDLLIMPORT bool enable_partitionwise_aggregate;
64extern PGDLLIMPORT bool enable_parallel_append;
65extern PGDLLIMPORT bool enable_parallel_hash;
66extern PGDLLIMPORT bool enable_partition_pruning;
67extern PGDLLIMPORT int constraint_exclusion;
68
69extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
70 double index_pages, PlannerInfo *root);
71extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
72 ParamPathInfo *param_info);
73extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
74 ParamPathInfo *param_info);
75extern void cost_index(IndexPath *path, PlannerInfo *root,
76 double loop_count, bool partial_path);
77extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
78 ParamPathInfo *param_info,
79 Path *bitmapqual, double loop_count);
80extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
81extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
82extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
83extern void cost_tidscan(Path *path, PlannerInfo *root,
84 RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
85extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
86 RelOptInfo *baserel, ParamPathInfo *param_info);
87extern void cost_functionscan(Path *path, PlannerInfo *root,
88 RelOptInfo *baserel, ParamPathInfo *param_info);
89extern void cost_valuesscan(Path *path, PlannerInfo *root,
90 RelOptInfo *baserel, ParamPathInfo *param_info);
91extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
92 RelOptInfo *baserel, ParamPathInfo *param_info);
93extern void cost_ctescan(Path *path, PlannerInfo *root,
94 RelOptInfo *baserel, ParamPathInfo *param_info);
95extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root,
96 RelOptInfo *baserel, ParamPathInfo *param_info);
97extern void cost_resultscan(Path *path, PlannerInfo *root,
98 RelOptInfo *baserel, ParamPathInfo *param_info);
99extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
100extern 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);
104extern void cost_append(AppendPath *path);
105extern 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);
109extern void cost_material(Path *path,
110 Cost input_startup_cost, Cost input_total_cost,
111 double tuples, int width);
112extern 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);
118extern 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);
122extern 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);
127extern void initial_cost_nestloop(PlannerInfo *root,
128 JoinCostWorkspace *workspace,
129 JoinType jointype,
130 Path *outer_path, Path *inner_path,
131 JoinPathExtraData *extra);
132extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
133 JoinCostWorkspace *workspace,
134 JoinPathExtraData *extra);
135extern 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 *extra);
142extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
143 JoinCostWorkspace *workspace,
144 JoinPathExtraData *extra);
145extern void initial_cost_hashjoin(PlannerInfo *root,
146 JoinCostWorkspace *workspace,
147 JoinType jointype,
148 List *hashclauses,
149 Path *outer_path, Path *inner_path,
150 JoinPathExtraData *extra,
151 bool parallel_hash);
152extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
153 JoinCostWorkspace *workspace,
154 JoinPathExtraData *extra);
155extern void cost_gather(GatherPath *path, PlannerInfo *root,
156 RelOptInfo *baserel, ParamPathInfo *param_info, double *rows);
157extern 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);
161extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
162extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
163extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
164extern 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);
172extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
173extern double get_parameterized_baserel_size(PlannerInfo *root,
174 RelOptInfo *rel,
175 List *param_clauses);
176extern 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);
182extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
183 RelOptInfo *outer_rel,
184 RelOptInfo *inner_rel,
185 SpecialJoinInfo *sjinfo,
186 List *restrictlist);
187extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
188extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
189extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
190extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
191 double cte_rows);
192extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
193extern void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel);
194extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel);
195extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
196extern PathTarget *set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target);
197extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
198 Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
199
200#endif /* COST_H */
201