PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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
36typedef 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) */
52extern PGDLLIMPORT bool enable_seqscan;
56extern PGDLLIMPORT bool enable_tidscan;
57extern PGDLLIMPORT bool enable_sort;
59extern PGDLLIMPORT bool enable_hashagg;
63extern PGDLLIMPORT bool enable_memoize;
75
76extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
82extern void cost_index(IndexPath *path, PlannerInfo *root,
83 double loop_count, bool partial_path);
86 Path *bitmapqual, double loop_count);
89extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
90extern void cost_tidscan(Path *path, PlannerInfo *root,
92extern void cost_tidrangescan(Path *path, PlannerInfo *root,
93 RelOptInfo *baserel, List *tidrangequals,
98extern void cost_functionscan(Path *path, PlannerInfo *root,
100extern void cost_valuesscan(Path *path, PlannerInfo *root,
102extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
104extern void cost_ctescan(Path *path, PlannerInfo *root,
108extern void cost_resultscan(Path *path, PlannerInfo *root,
111extern void cost_sort(Path *path, PlannerInfo *root,
112 List *pathkeys, int input_disabled_nodes,
113 Cost input_cost, double tuples, int width,
115 double limit_tuples);
116extern void cost_incremental_sort(Path *path,
117 PlannerInfo *root, List *pathkeys, int presorted_keys,
120 double input_tuples, int width, Cost comparison_cost, int sort_mem,
121 double limit_tuples);
123extern void cost_merge_append(Path *path, PlannerInfo *root,
124 List *pathkeys, int n_streams,
127 double tuples);
128extern void cost_material(Path *path,
129 bool enabled, int input_disabled_nodes,
131 double tuples, int width);
132extern void cost_agg(Path *path, PlannerInfo *root,
133 AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
134 int numGroupCols, double numGroups,
135 List *quals,
136 int disabled_nodes,
138 double input_tuples, double input_width);
139extern void cost_windowagg(Path *path, PlannerInfo *root,
140 List *windowFuncs, WindowClause *winclause,
143 double input_tuples);
144extern void cost_group(Path *path, PlannerInfo *root,
145 int numGroupCols, double numGroups,
146 List *quals,
149 double input_tuples);
151 JoinCostWorkspace *workspace,
152 JoinType jointype, uint64 enable_mask,
154 JoinPathExtraData *extra);
155extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
156 JoinCostWorkspace *workspace,
157 JoinPathExtraData *extra);
159 JoinCostWorkspace *workspace,
160 JoinType jointype,
161 List *mergeclauses,
163 List *outersortkeys, List *innersortkeys,
164 int outer_presorted_keys,
165 JoinPathExtraData *extra);
167 JoinCostWorkspace *workspace,
168 JoinPathExtraData *extra);
170 JoinCostWorkspace *workspace,
171 JoinType jointype,
172 List *hashclauses,
174 JoinPathExtraData *extra,
175 bool parallel_hash);
176extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
177 JoinCostWorkspace *workspace,
178 JoinPathExtraData *extra);
179extern void cost_gather(GatherPath *path, PlannerInfo *root,
180 RelOptInfo *rel, ParamPathInfo *param_info, double *rows);
185 double *rows);
186extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
187extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
188extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
190 RelOptInfo *joinrel,
191 RelOptInfo *outerrel,
192 RelOptInfo *innerrel,
193 JoinType jointype,
194 SpecialJoinInfo *sjinfo,
195 List *restrictlist,
196 SemiAntiJoinFactors *semifactors);
199 RelOptInfo *rel,
202 RelOptInfo *rel,
205 SpecialJoinInfo *sjinfo,
210 SpecialJoinInfo *sjinfo,
211 List *restrictlist);
216 double cte_rows);
223 Path *bitmapqual, double loop_count,
224 Cost *cost_p, double *tuples_p);
225extern double compute_gather_rows(Path *path);
226
227#endif /* COST_H */
uint32 BlockNumber
Definition block.h:31
#define PGDLLIMPORT
Definition c.h:1478
uint64_t uint64
Definition c.h:684
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition costsize.c:6280
PGDLLIMPORT bool enable_tidscan
Definition costsize.c:150
PGDLLIMPORT bool enable_partitionwise_join
Definition costsize.c:161
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition costsize.c:4439
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:144
PGDLLIMPORT bool enable_parallel_hash
Definition costsize.c:164
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition costsize.c:1116
double get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, List *param_clauses)
Definition costsize.c:5546
double get_parameterized_joinrel_size(PlannerInfo *root, RelOptInfo *rel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, List *restrict_clauses)
Definition costsize.c:5627
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition costsize.c:3978
void cost_material(Path *path, bool enabled, int input_disabled_nodes, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition costsize.c:2584
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:5281
PGDLLIMPORT bool enable_async_append
Definition costsize.c:167
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition costsize.c:5516
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:3227
PGDLLIMPORT bool enable_nestloop
Definition costsize.c:155
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition costsize.c:1564
void initial_cost_nestloop(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, uint64 enable_mask, Path *outer_path, Path *inner_path, JoinPathExtraData *extra)
Definition costsize.c:3396
PGDLLIMPORT bool enable_incremental_sort
Definition costsize.c:152
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:1362
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition costsize.c:6150
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, int disabled_nodes, Cost input_startup_cost, Cost input_total_cost, double input_tuples, double input_width)
Definition costsize.c:2789
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, int input_disabled_nodes, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition costsize.c:2202
PGDLLIMPORT bool enable_material
Definition costsize.c:156
PGDLLIMPORT bool enable_presorted_aggregate
Definition costsize.c:166
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition costsize.c:3478
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:471
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition costsize.c:1876
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition costsize.c:1630
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:4320
PGDLLIMPORT bool enable_seqscan
Definition costsize.c:146
void initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace, JoinType jointype, List *mergeclauses, Path *outer_path, Path *inner_path, List *outersortkeys, List *innersortkeys, int outer_presorted_keys, JoinPathExtraData *extra)
Definition costsize.c:3681
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition costsize.c:350
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition costsize.c:431
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:158
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition costsize.c:6242
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition costsize.c:5595
void cost_append(AppendPath *apath, PlannerInfo *root)
Definition costsize.c:2312
double compute_gather_rows(Path *path)
Definition costsize.c:6792
void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
Definition costsize.c:4949
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition costsize.c:1792
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition costsize.c:271
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
Definition costsize.c:6534
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition costsize.c:1691
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:2054
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition costsize.c:4923
PGDLLIMPORT bool enable_gathermerge
Definition costsize.c:160
void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition costsize.c:6313
PGDLLIMPORT bool enable_sort
Definition costsize.c:151
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:3324
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition costsize.c:1834
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, double loop_count, Cost *cost_p, double *tuples_p)
Definition costsize.c:6681
PGDLLIMPORT bool enable_indexscan
Definition costsize.c:147
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition costsize.c:1159
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition costsize.c:6070
PGDLLIMPORT Cost disable_cost
Definition costsize.c:142
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition costsize.c:6342
PGDLLIMPORT bool enable_partitionwise_aggregate
Definition costsize.c:162
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition costsize.c:1252
PGDLLIMPORT int constraint_exclusion
Definition plancat.c:58
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Definition costsize.c:4700
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:2526
PGDLLIMPORT bool enable_bitmapscan
Definition costsize.c:149
PGDLLIMPORT bool enable_indexonlyscan
Definition costsize.c:148
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, bool trivial_pathtarget)
Definition costsize.c:1479
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition costsize.c:1746
PGDLLIMPORT bool enable_groupagg
Definition costsize.c:154
PGDLLIMPORT bool enable_hashagg
Definition costsize.c:153
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition costsize.c:1204
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition costsize.c:6188
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition costsize.c:546
PGDLLIMPORT bool enable_memoize
Definition costsize.c:157
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition costsize.c:6210
PGDLLIMPORT bool enable_partition_pruning
Definition costsize.c:165
PGDLLIMPORT bool enable_parallel_append
Definition costsize.c:163
PGDLLIMPORT bool enable_hashjoin
Definition costsize.c:159
double Cost
Definition nodes.h:259
AggStrategy
Definition nodes.h:361
double Selectivity
Definition nodes.h:258
JoinType
Definition nodes.h:296
#define plan(x)
Definition pg_regress.c:164
static int fb(int x)
tree ctl root
Definition radixtree.h:1857
Definition pg_list.h:54
Definition nodes.h:133