Skip to content

Commit c5ee2c7

Browse files
committed
fix: improve the statistic type
1 parent 02407a5 commit c5ee2c7

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

optd-persistent/src/bin/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async fn init_all_tables() -> Result<(), sea_orm::error::DbErr> {
105105
table_id: Set(Some(1)),
106106
creation_time: Set(Utc::now()),
107107
number_of_attributes: Set(0),
108-
variant_tag: Set(StatType::Count as i32),
108+
variant_tag: Set(StatType::TableRowCount as i32),
109109
description: Set("".to_owned()),
110110
};
111111
let table_versioned_statistic = versioned_statistic::ActiveModel {

optd-persistent/src/cost_model/catalog/mock_catalog.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,23 @@ impl MockCatalog {
112112
let statistics: Vec<MockStatistic> = vec![
113113
MockStatistic {
114114
id: 1,
115-
stat_type: StatType::Count as i32,
115+
stat_type: StatType::NotNullCount as i32,
116116
stat_value: json!(100),
117117
attr_ids: vec![1],
118118
table_id: None,
119119
name: "CountAttr1".to_string(),
120120
},
121121
MockStatistic {
122122
id: 2,
123-
stat_type: StatType::Count as i32,
123+
stat_type: StatType::NotNullCount as i32,
124124
stat_value: json!(200),
125125
attr_ids: vec![2],
126126
table_id: None,
127127
name: "CountAttr2".to_string(),
128128
},
129129
MockStatistic {
130130
id: 3,
131-
stat_type: StatType::Count as i32,
131+
stat_type: StatType::TableRowCount as i32,
132132
stat_value: json!(300),
133133
attr_ids: vec![],
134134
table_id: Some(1),

optd-persistent/src/cost_model/interface.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,9 @@ pub enum ConstraintType {
3636
}
3737

3838
pub enum StatType {
39-
// TODO(lanlou): I am not sure which way to represent the type is better.
40-
// 1. `Count` means row count, (i.e. record count), and it only applies to
41-
// table statistics. In this way, we should introduce `NotNullCount` for attribute
42-
// statistics to indicate the number of non-null values.
43-
// 2. `Count` means the number of non-null values, and it applies to both table
44-
// and attribute statistics. (Will a table have a record with null values in all
45-
// attributes?)
46-
// For now, we just use the second way for simplicity.
47-
Count,
39+
/// `TableRowCount` only applies to table statistics.
40+
TableRowCount,
41+
NotNullCount,
4842
Cardinality,
4943
Min,
5044
Max,

optd-persistent/src/cost_model/orm.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,12 @@ mod tests {
611611
assert_eq!(lookup_res.len(), 3);
612612

613613
let stat_res = backend_manager
614-
.get_stats_for_table(1, StatType::Count as i32, Some(epoch_id))
614+
.get_stats_for_table(1, StatType::TableRowCount as i32, Some(epoch_id))
615615
.await;
616616
assert!(stat_res.is_ok());
617617
assert_eq!(stat_res.unwrap().unwrap(), json!(300));
618618
let stat_res = backend_manager
619-
.get_stats_for_attr([2].to_vec(), StatType::Count as i32, None)
619+
.get_stats_for_attr([2].to_vec(), StatType::NotNullCount as i32, None)
620620
.await;
621621
assert!(stat_res.is_ok());
622622
assert_eq!(stat_res.unwrap().unwrap(), json!(200));
@@ -636,7 +636,7 @@ mod tests {
636636
.await
637637
.unwrap();
638638
let stat = Stat {
639-
stat_type: StatType::Count as i32,
639+
stat_type: StatType::NotNullCount as i32,
640640
stat_value: json!(100),
641641
attr_ids: vec![1],
642642
table_id: None,
@@ -655,7 +655,7 @@ mod tests {
655655
println!("{:?}", stat_res);
656656
assert_eq!(stat_res[0].number_of_attributes, 1);
657657
assert_eq!(stat_res[0].description, "1".to_string());
658-
assert_eq!(stat_res[0].variant_tag, StatType::Count as i32);
658+
assert_eq!(stat_res[0].variant_tag, StatType::NotNullCount as i32);
659659
let stat_attr_res = StatisticToAttributeJunction::find()
660660
.filter(statistic_to_attribute_junction::Column::StatisticId.eq(stat_res[0].id))
661661
.all(&backend_manager.db)
@@ -708,7 +708,7 @@ mod tests {
708708
.await
709709
.unwrap();
710710
let stat2 = Stat {
711-
stat_type: StatType::Count as i32,
711+
stat_type: StatType::NotNullCount as i32,
712712
stat_value: json!(200),
713713
attr_ids: vec![1],
714714
table_id: None,
@@ -762,7 +762,7 @@ mod tests {
762762
// 3. Update existed stat with the same value
763763
let epoch_num = Event::find().all(&backend_manager.db).await.unwrap().len();
764764
let stat3 = Stat {
765-
stat_type: StatType::Count as i32,
765+
stat_type: StatType::NotNullCount as i32,
766766
stat_value: json!(200),
767767
attr_ids: vec![1],
768768
table_id: None,
@@ -803,21 +803,21 @@ mod tests {
803803

804804
let statistics: Vec<Stat> = vec![
805805
Stat {
806-
stat_type: StatType::Count as i32,
806+
stat_type: StatType::TableRowCount as i32,
807807
stat_value: json!(0),
808808
attr_ids: vec![],
809809
table_id: Some(1),
810810
name: "row_count".to_string(),
811811
},
812812
Stat {
813-
stat_type: StatType::Count as i32,
813+
stat_type: StatType::TableRowCount as i32,
814814
stat_value: json!(20),
815815
attr_ids: vec![],
816816
table_id: Some(1),
817817
name: "row_count".to_string(),
818818
},
819819
Stat {
820-
stat_type: StatType::Count as i32,
820+
stat_type: StatType::TableRowCount as i32,
821821
stat_value: json!(100),
822822
attr_ids: vec![],
823823
table_id: Some(table_inserted_res.last_insert_id),
@@ -981,7 +981,7 @@ mod tests {
981981
let backend_manager = binding.as_mut().unwrap();
982982
let epoch_id = 1;
983983
let table_id = 1;
984-
let stat_type = StatType::Count as i32;
984+
let stat_type = StatType::TableRowCount as i32;
985985

986986
// Get initial stats
987987
let res = backend_manager
@@ -998,7 +998,7 @@ mod tests {
998998
.await
999999
.unwrap();
10001000
let stat = Stat {
1001-
stat_type: StatType::Count as i32,
1001+
stat_type: StatType::TableRowCount as i32,
10021002
stat_value: json!(100),
10031003
attr_ids: vec![],
10041004
table_id: Some(table_id),

optd-persistent/src/db/init.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)