From db8829d55a37c1bb7d270eb28ef239e5b2684a99 Mon Sep 17 00:00:00 2001
From: Lan Lou <62441979+lanlou1554@users.noreply.github.com>
Date: Wed, 13 Nov 2024 12:32:44 -0500
Subject: [PATCH] fix(cost-model): add more cost types and raw estimated
statistic into ORM (#30)
* fix(cost-model): add more cost types and raw estimated statistic into ORM
* Add comments
---
optd-persistent/src/bin/init.rs | 3 +-
optd-persistent/src/cost_model/interface.rs | 15 ++-
optd-persistent/src/cost_model/orm.rs | 101 ++++++++++++++----
optd-persistent/src/db/init.db | Bin 147456 -> 147456 bytes
optd-persistent/src/entities/constraint.rs | 68 ------------
optd-persistent/src/entities/index.rs | 48 ---------
optd-persistent/src/entities/plan_cost.rs | 3 +-
.../cost_model/m20241029_000001_plan_cost.rs | 6 +-
schema/all_tables.dbml | 5 +-
9 files changed, 107 insertions(+), 142 deletions(-)
delete mode 100644 optd-persistent/src/entities/constraint.rs
delete mode 100644 optd-persistent/src/entities/index.rs
diff --git a/optd-persistent/src/bin/init.rs b/optd-persistent/src/bin/init.rs
index c2291d7..e39bd56 100644
--- a/optd-persistent/src/bin/init.rs
+++ b/optd-persistent/src/bin/init.rs
@@ -355,7 +355,8 @@ async fn init_all_tables() -> Result<(), sea_orm::error::DbErr> {
id: Set(1),
physical_expression_id: Set(1),
epoch_id: Set(1),
- cost: Set(10),
+ cost: Set(json!({"compute_cost":10, "io_cost":10})),
+ estimated_statistic: Set(10),
is_valid: Set(true),
};
plan_cost::Entity::insert(plan_cost)
diff --git a/optd-persistent/src/cost_model/interface.rs b/optd-persistent/src/cost_model/interface.rs
index d896ec1..92d7e44 100644
--- a/optd-persistent/src/cost_model/interface.rs
+++ b/optd-persistent/src/cost_model/interface.rs
@@ -67,6 +67,15 @@ pub struct Stat {
pub name: String,
}
+/// TODO: documentation
+#[derive(Clone, Debug, PartialEq)]
+pub struct Cost {
+ pub compute_cost: i32,
+ pub io_cost: i32,
+ // Raw estimated output row count of targeted expression.
+ pub estimated_statistic: i32,
+}
+
/// TODO: documentation
#[trait_variant::make(Send)]
pub trait CostModelStorageLayer {
@@ -91,7 +100,7 @@ pub trait CostModelStorageLayer {
async fn store_cost(
&self,
expr_id: Self::ExprId,
- cost: i32,
+ cost: Cost,
epoch_id: Self::EpochId,
) -> StorageResult<()>;
@@ -126,7 +135,7 @@ pub trait CostModelStorageLayer {
&self,
expr_id: Self::ExprId,
epoch_id: Self::EpochId,
- ) -> StorageResult