Skip to content

Commit b826e3d

Browse files
committed
move filter-related constants to stats crate
1 parent 5ed4553 commit b826e3d

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

optd-cost-model/src/cost/filter.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,13 @@ use crate::{
2222
values::Value,
2323
},
2424
cost_model::CostModelImpl,
25-
stats::{AttributeCombValue, AttributeCombValueStats},
25+
stats::{
26+
AttributeCombValue, AttributeCombValueStats, DEFAULT_EQ_SEL, DEFAULT_INEQ_SEL,
27+
FIXED_CHAR_SEL_FACTOR, FULL_WILDCARD_SEL_FACTOR, UNIMPLEMENTED_SEL,
28+
},
2629
CostModelResult, EstimatedStatistic,
2730
};
2831

29-
// A placeholder for unimplemented!() for codepaths which are accessed by plannertest
30-
const UNIMPLEMENTED_SEL: f64 = 0.01;
31-
// Default statistics. All are from selfuncs.h in Postgres unless specified otherwise
32-
// Default selectivity estimate for equalities such as "A = b"
33-
const DEFAULT_EQ_SEL: f64 = 0.005;
34-
// Default selectivity estimate for inequalities such as "A < b"
35-
const DEFAULT_INEQ_SEL: f64 = 0.3333333333333333;
36-
// Used for estimating pattern selectivity character-by-character. These numbers
37-
// are not used on their own. Depending on the characters in the pattern, the
38-
// selectivity is multiplied by these factors.
39-
//
40-
// See `FULL_WILDCARD_SEL` and `FIXED_CHAR_SEL` in Postgres.
41-
const FULL_WILDCARD_SEL_FACTOR: f64 = 5.0;
42-
const FIXED_CHAR_SEL_FACTOR: f64 = 0.2;
43-
4432
impl<S: CostModelStorageLayer> CostModelImpl<S> {
4533
// TODO: is it a good design to pass table_id here? I think it needs to be refactored.
4634
// Consider to remove table_id.

optd-cost-model/src/stats/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ use serde::{Deserialize, Serialize};
1010

1111
// Default n-distinct estimate for derived columns or columns lacking statistics
1212
pub const DEFAULT_NUM_DISTINCT: u64 = 200;
13+
// A placeholder for unimplemented!() for codepaths which are accessed by plannertest
14+
pub const UNIMPLEMENTED_SEL: f64 = 0.01;
15+
// Default statistics. All are from selfuncs.h in Postgres unless specified otherwise
16+
// Default selectivity estimate for equalities such as "A = b"
17+
pub const DEFAULT_EQ_SEL: f64 = 0.005;
18+
// Default selectivity estimate for inequalities such as "A < b"
19+
pub const DEFAULT_INEQ_SEL: f64 = 0.3333333333333333;
20+
// Used for estimating pattern selectivity character-by-character. These numbers
21+
// are not used on their own. Depending on the characters in the pattern, the
22+
// selectivity is multiplied by these factors.
23+
//
24+
// See `FULL_WILDCARD_SEL` and `FIXED_CHAR_SEL` in Postgres.
25+
pub const FULL_WILDCARD_SEL_FACTOR: f64 = 5.0;
26+
pub const FIXED_CHAR_SEL_FACTOR: f64 = 0.2;
1327

1428
pub type AttributeCombValue = Vec<Option<Value>>;
1529

0 commit comments

Comments
 (0)