00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef COST_H
00015 #define COST_H
00016
00017 #include "nodes/plannodes.h"
00018 #include "nodes/relation.h"
00019
00020
00021
00022
00023
00024 #define DEFAULT_SEQ_PAGE_COST 1.0
00025 #define DEFAULT_RANDOM_PAGE_COST 4.0
00026 #define DEFAULT_CPU_TUPLE_COST 0.01
00027 #define DEFAULT_CPU_INDEX_TUPLE_COST 0.005
00028 #define DEFAULT_CPU_OPERATOR_COST 0.0025
00029
00030 #define DEFAULT_EFFECTIVE_CACHE_SIZE 16384
00031
00032 typedef enum
00033 {
00034 CONSTRAINT_EXCLUSION_OFF,
00035 CONSTRAINT_EXCLUSION_ON,
00036 CONSTRAINT_EXCLUSION_PARTITION
00037 } ConstraintExclusionType;
00038
00039
00040
00041
00042
00043
00044
00045
00046 extern PGDLLIMPORT double seq_page_cost;
00047 extern PGDLLIMPORT double random_page_cost;
00048 extern PGDLLIMPORT double cpu_tuple_cost;
00049 extern PGDLLIMPORT double cpu_index_tuple_cost;
00050 extern PGDLLIMPORT double cpu_operator_cost;
00051 extern PGDLLIMPORT int effective_cache_size;
00052 extern Cost disable_cost;
00053 extern bool enable_seqscan;
00054 extern bool enable_indexscan;
00055 extern bool enable_indexonlyscan;
00056 extern bool enable_bitmapscan;
00057 extern bool enable_tidscan;
00058 extern bool enable_sort;
00059 extern bool enable_hashagg;
00060 extern bool enable_nestloop;
00061 extern bool enable_material;
00062 extern bool enable_mergejoin;
00063 extern bool enable_hashjoin;
00064 extern int constraint_exclusion;
00065
00066 extern double clamp_row_est(double nrows);
00067 extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
00068 double index_pages, PlannerInfo *root);
00069 extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
00070 ParamPathInfo *param_info);
00071 extern void cost_index(IndexPath *path, PlannerInfo *root,
00072 double loop_count);
00073 extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
00074 ParamPathInfo *param_info,
00075 Path *bitmapqual, double loop_count);
00076 extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
00077 extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
00078 extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
00079 extern void cost_tidscan(Path *path, PlannerInfo *root,
00080 RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info);
00081 extern void cost_subqueryscan(Path *path, PlannerInfo *root,
00082 RelOptInfo *baserel, ParamPathInfo *param_info);
00083 extern void cost_functionscan(Path *path, PlannerInfo *root,
00084 RelOptInfo *baserel, ParamPathInfo *param_info);
00085 extern void cost_valuesscan(Path *path, PlannerInfo *root,
00086 RelOptInfo *baserel, ParamPathInfo *param_info);
00087 extern void cost_ctescan(Path *path, PlannerInfo *root,
00088 RelOptInfo *baserel, ParamPathInfo *param_info);
00089 extern void cost_recursive_union(Plan *runion, Plan *nrterm, Plan *rterm);
00090 extern void cost_sort(Path *path, PlannerInfo *root,
00091 List *pathkeys, Cost input_cost, double tuples, int width,
00092 Cost comparison_cost, int sort_mem,
00093 double limit_tuples);
00094 extern void cost_merge_append(Path *path, PlannerInfo *root,
00095 List *pathkeys, int n_streams,
00096 Cost input_startup_cost, Cost input_total_cost,
00097 double tuples);
00098 extern void cost_material(Path *path,
00099 Cost input_startup_cost, Cost input_total_cost,
00100 double tuples, int width);
00101 extern void cost_agg(Path *path, PlannerInfo *root,
00102 AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
00103 int numGroupCols, double numGroups,
00104 Cost input_startup_cost, Cost input_total_cost,
00105 double input_tuples);
00106 extern void cost_windowagg(Path *path, PlannerInfo *root,
00107 List *windowFuncs, int numPartCols, int numOrderCols,
00108 Cost input_startup_cost, Cost input_total_cost,
00109 double input_tuples);
00110 extern void cost_group(Path *path, PlannerInfo *root,
00111 int numGroupCols, double numGroups,
00112 Cost input_startup_cost, Cost input_total_cost,
00113 double input_tuples);
00114 extern void initial_cost_nestloop(PlannerInfo *root,
00115 JoinCostWorkspace *workspace,
00116 JoinType jointype,
00117 Path *outer_path, Path *inner_path,
00118 SpecialJoinInfo *sjinfo,
00119 SemiAntiJoinFactors *semifactors);
00120 extern void final_cost_nestloop(PlannerInfo *root, NestPath *path,
00121 JoinCostWorkspace *workspace,
00122 SpecialJoinInfo *sjinfo,
00123 SemiAntiJoinFactors *semifactors);
00124 extern void initial_cost_mergejoin(PlannerInfo *root,
00125 JoinCostWorkspace *workspace,
00126 JoinType jointype,
00127 List *mergeclauses,
00128 Path *outer_path, Path *inner_path,
00129 List *outersortkeys, List *innersortkeys,
00130 SpecialJoinInfo *sjinfo);
00131 extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path,
00132 JoinCostWorkspace *workspace,
00133 SpecialJoinInfo *sjinfo);
00134 extern void initial_cost_hashjoin(PlannerInfo *root,
00135 JoinCostWorkspace *workspace,
00136 JoinType jointype,
00137 List *hashclauses,
00138 Path *outer_path, Path *inner_path,
00139 SpecialJoinInfo *sjinfo,
00140 SemiAntiJoinFactors *semifactors);
00141 extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path,
00142 JoinCostWorkspace *workspace,
00143 SpecialJoinInfo *sjinfo,
00144 SemiAntiJoinFactors *semifactors);
00145 extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
00146 extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
00147 extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
00148 extern void compute_semi_anti_join_factors(PlannerInfo *root,
00149 RelOptInfo *outerrel,
00150 RelOptInfo *innerrel,
00151 JoinType jointype,
00152 SpecialJoinInfo *sjinfo,
00153 List *restrictlist,
00154 SemiAntiJoinFactors *semifactors);
00155 extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
00156 extern double get_parameterized_baserel_size(PlannerInfo *root,
00157 RelOptInfo *rel,
00158 List *param_clauses);
00159 extern double get_parameterized_joinrel_size(PlannerInfo *root,
00160 RelOptInfo *rel,
00161 double outer_rows,
00162 double inner_rows,
00163 SpecialJoinInfo *sjinfo,
00164 List *restrict_clauses);
00165 extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
00166 RelOptInfo *outer_rel,
00167 RelOptInfo *inner_rel,
00168 SpecialJoinInfo *sjinfo,
00169 List *restrictlist);
00170 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel);
00171 extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
00172 extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
00173 extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
00174 Plan *cteplan);
00175 extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
00176
00177
00178
00179
00180
00181 extern Selectivity clauselist_selectivity(PlannerInfo *root,
00182 List *clauses,
00183 int varRelid,
00184 JoinType jointype,
00185 SpecialJoinInfo *sjinfo);
00186 extern Selectivity clause_selectivity(PlannerInfo *root,
00187 Node *clause,
00188 int varRelid,
00189 JoinType jointype,
00190 SpecialJoinInfo *sjinfo);
00191
00192 #endif