Skip to content

Commit b900ee7

Browse files
committed
fix: improve the statistic type
1 parent 472ad48 commit b900ee7

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
@@ -113,23 +113,23 @@ impl MockCatalog {
113113
let statistics: Vec<MockStatistic> = vec![
114114
MockStatistic {
115115
id: 1,
116-
stat_type: StatType::Count as i32,
116+
stat_type: StatType::NotNullCount as i32,
117117
stat_value: json!(100),
118118
attr_ids: vec![1],
119119
table_id: None,
120120
name: "CountAttr1".to_string(),
121121
},
122122
MockStatistic {
123123
id: 2,
124-
stat_type: StatType::Count as i32,
124+
stat_type: StatType::NotNullCount as i32,
125125
stat_value: json!(200),
126126
attr_ids: vec![2],
127127
table_id: None,
128128
name: "CountAttr2".to_string(),
129129
},
130130
MockStatistic {
131131
id: 3,
132-
stat_type: StatType::Count as i32,
132+
stat_type: StatType::TableRowCount as i32,
133133
stat_value: json!(300),
134134
attr_ids: vec![],
135135
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
@@ -41,15 +41,9 @@ pub enum ConstraintType {
4141

4242
/// TODO: documentation
4343
pub enum StatType {
44-
// TODO(lanlou): I am not sure which way to represent the type is better.
45-
// 1. `Count` means row count, (i.e. record count), and it only applies to
46-
// table statistics. In this way, we should introduce `NotNullCount` for attribute
47-
// statistics to indicate the number of non-null values.
48-
// 2. `Count` means the number of non-null values, and it applies to both table
49-
// and attribute statistics. (Will a table have a record with null values in all
50-
// attributes?)
51-
// For now, we just use the second way for simplicity.
52-
Count,
44+
/// `TableRowCount` only applies to table statistics.
45+
TableRowCount,
46+
NotNullCount,
5347
Cardinality,
5448
Min,
5549
Max,

optd-persistent/src/cost_model/orm.rs

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

601601
let stat_res = backend_manager
602-
.get_stats_for_table(1, StatType::Count as i32, Some(epoch_id))
602+
.get_stats_for_table(1, StatType::TableRowCount as i32, Some(epoch_id))
603603
.await;
604604
assert!(stat_res.is_ok());
605605
assert_eq!(stat_res.unwrap().unwrap(), json!(300));
606606
let stat_res = backend_manager
607-
.get_stats_for_attr([2].to_vec(), StatType::Count as i32, None)
607+
.get_stats_for_attr([2].to_vec(), StatType::NotNullCount as i32, None)
608608
.await;
609609
assert!(stat_res.is_ok());
610610
assert_eq!(stat_res.unwrap().unwrap(), json!(200));
@@ -624,7 +624,7 @@ mod tests {
624624
.await
625625
.unwrap();
626626
let stat = Stat {
627-
stat_type: StatType::Count as i32,
627+
stat_type: StatType::NotNullCount as i32,
628628
stat_value: json!(100),
629629
attr_ids: vec![1],
630630
table_id: None,
@@ -643,7 +643,7 @@ mod tests {
643643
println!("{:?}", stat_res);
644644
assert_eq!(stat_res[0].number_of_attributes, 1);
645645
assert_eq!(stat_res[0].description, "1".to_string());
646-
assert_eq!(stat_res[0].variant_tag, StatType::Count as i32);
646+
assert_eq!(stat_res[0].variant_tag, StatType::NotNullCount as i32);
647647
let stat_attr_res = StatisticToAttributeJunction::find()
648648
.filter(statistic_to_attribute_junction::Column::StatisticId.eq(stat_res[0].id))
649649
.all(&backend_manager.db)
@@ -696,7 +696,7 @@ mod tests {
696696
.await
697697
.unwrap();
698698
let stat2 = Stat {
699-
stat_type: StatType::Count as i32,
699+
stat_type: StatType::NotNullCount as i32,
700700
stat_value: json!(200),
701701
attr_ids: vec![1],
702702
table_id: None,
@@ -750,7 +750,7 @@ mod tests {
750750
// 3. Update existed stat with the same value
751751
let epoch_num = Event::find().all(&backend_manager.db).await.unwrap().len();
752752
let stat3 = Stat {
753-
stat_type: StatType::Count as i32,
753+
stat_type: StatType::NotNullCount as i32,
754754
stat_value: json!(200),
755755
attr_ids: vec![1],
756756
table_id: None,
@@ -791,21 +791,21 @@ mod tests {
791791

792792
let statistics: Vec<Stat> = vec![
793793
Stat {
794-
stat_type: StatType::Count as i32,
794+
stat_type: StatType::TableRowCount as i32,
795795
stat_value: json!(0),
796796
attr_ids: vec![],
797797
table_id: Some(1),
798798
name: "row_count".to_string(),
799799
},
800800
Stat {
801-
stat_type: StatType::Count as i32,
801+
stat_type: StatType::TableRowCount as i32,
802802
stat_value: json!(20),
803803
attr_ids: vec![],
804804
table_id: Some(1),
805805
name: "row_count".to_string(),
806806
},
807807
Stat {
808-
stat_type: StatType::Count as i32,
808+
stat_type: StatType::TableRowCount as i32,
809809
stat_value: json!(100),
810810
attr_ids: vec![],
811811
table_id: Some(table_inserted_res.last_insert_id),
@@ -969,7 +969,7 @@ mod tests {
969969
let backend_manager = binding.as_mut().unwrap();
970970
let epoch_id = 1;
971971
let table_id = 1;
972-
let stat_type = StatType::Count as i32;
972+
let stat_type = StatType::TableRowCount as i32;
973973

974974
// Get initial stats
975975
let res = backend_manager
@@ -986,7 +986,7 @@ mod tests {
986986
.await
987987
.unwrap();
988988
let stat = Stat {
989-
stat_type: StatType::Count as i32,
989+
stat_type: StatType::TableRowCount as i32,
990990
stat_value: json!(100),
991991
attr_ids: vec![],
992992
table_id: Some(table_id),

optd-persistent/src/db/init.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)