Skip to content

Commit 8fb462c

Browse files
committed
Refine store_cost in the ORM layer
1 parent 23c444d commit 8fb462c

File tree

1 file changed

+14
-3
lines changed
  • optd-persistent/src/cost_model

1 file changed

+14
-3
lines changed

optd-persistent/src/cost_model/orm.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,27 @@ impl CostModelStorageLayer for BackendManager {
580580

581581
if valid_cost.is_some() {
582582
let mut new_cost: plan_cost::ActiveModel = valid_cost.unwrap().into();
583+
let mut update = false;
583584
if cost.is_some() {
584-
new_cost.cost = sea_orm::ActiveValue::Set(Some(json!({
585+
let input_cost = sea_orm::ActiveValue::Set(Some(json!({
585586
"compute_cost": cost.clone().unwrap().compute_cost,
586587
"io_cost": cost.clone().unwrap().io_cost
587588
})));
589+
if new_cost.cost != input_cost {
590+
update = true;
591+
new_cost.cost = input_cost;
592+
}
588593
}
589594
if estimated_statistic.is_some() {
590-
new_cost.estimated_statistic = sea_orm::ActiveValue::Set(estimated_statistic);
595+
let input_estimated_statistic = sea_orm::ActiveValue::Set(estimated_statistic);
596+
if new_cost.estimated_statistic != input_estimated_statistic {
597+
update = true;
598+
new_cost.estimated_statistic = input_estimated_statistic;
599+
}
600+
}
601+
if update {
602+
let _ = PlanCost::update(new_cost).exec(&transaction).await?;
591603
}
592-
let _ = PlanCost::update(new_cost).exec(&transaction).await?;
593604
} else {
594605
let new_cost = plan_cost::ActiveModel {
595606
physical_expression_id: sea_orm::ActiveValue::Set(physical_expression_id),

0 commit comments

Comments
 (0)