diff --git a/optd-persistent/src/bin/init.rs b/optd-persistent/src/bin/init.rs index 9cc07e2..b21f6f0 100644 --- a/optd-persistent/src/bin/init.rs +++ b/optd-persistent/src/bin/init.rs @@ -276,6 +276,7 @@ async fn init_all_tables() -> Result<(), sea_orm::error::DbErr> { latest_winner: Set(None), in_progress: Set(true), is_optimized: Set(false), + parent_id: Set(None), }; cascades_group::Entity::insert(cascades_group) .exec(&db) @@ -288,7 +289,6 @@ async fn init_all_tables() -> Result<(), sea_orm::error::DbErr> { group_id: Set(1), fingerprint: Set(12345), variant_tag: Set(0), - data: Set(json!(r#"{"expr": "index_scan"}"#)), }; logical_expression::Entity::insert(logical_expression) .exec(&db) @@ -301,7 +301,6 @@ async fn init_all_tables() -> Result<(), sea_orm::error::DbErr> { group_id: Set(1), fingerprint: Set(12345), variant_tag: Set(0), - data: Set(json!(r#"{"expr": "index_scan"}"#)), }; physical_expression::Entity::insert(physical_expression) .exec(&db) diff --git a/optd-persistent/src/entities/attribute.rs b/optd-persistent/src/entities/attribute.rs index aa312c0..f45d04a 100644 --- a/optd-persistent/src/entities/attribute.rs +++ b/optd-persistent/src/entities/attribute.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/attribute_constraint_junction.rs b/optd-persistent/src/entities/attribute_constraint_junction.rs index 7c61c72..e1d8052 100644 --- a/optd-persistent/src/entities/attribute_constraint_junction.rs +++ b/optd-persistent/src/entities/attribute_constraint_junction.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/attribute_foreign_constraint_junction.rs b/optd-persistent/src/entities/attribute_foreign_constraint_junction.rs index f219a39..c2f0b61 100644 --- a/optd-persistent/src/entities/attribute_foreign_constraint_junction.rs +++ b/optd-persistent/src/entities/attribute_foreign_constraint_junction.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/cascades_group.rs b/optd-persistent/src/entities/cascades_group.rs index 9ea79d1..8be9f4f 100644 --- a/optd-persistent/src/entities/cascades_group.rs +++ b/optd-persistent/src/entities/cascades_group.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; @@ -10,10 +10,19 @@ pub struct Model { pub latest_winner: Option, pub in_progress: bool, pub is_optimized: bool, + pub parent_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { + #[sea_orm( + belongs_to = "Entity", + from = "Column::ParentId", + to = "Column::Id", + on_update = "Cascade", + on_delete = "SetNull" + )] + SelfRef, #[sea_orm(has_many = "super::group_winner::Entity")] GroupWinner, #[sea_orm(has_many = "super::logical_children::Entity")] diff --git a/optd-persistent/src/entities/constraint_metadata.rs b/optd-persistent/src/entities/constraint_metadata.rs index 8adf1d7..5630e3e 100644 --- a/optd-persistent/src/entities/constraint_metadata.rs +++ b/optd-persistent/src/entities/constraint_metadata.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/database_metadata.rs b/optd-persistent/src/entities/database_metadata.rs index 98106d6..190bc73 100644 --- a/optd-persistent/src/entities/database_metadata.rs +++ b/optd-persistent/src/entities/database_metadata.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/event.rs b/optd-persistent/src/entities/event.rs index ad9157d..c26c7b1 100644 --- a/optd-persistent/src/entities/event.rs +++ b/optd-persistent/src/entities/event.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/group_winner.rs b/optd-persistent/src/entities/group_winner.rs index 32cbcb4..efd8661 100644 --- a/optd-persistent/src/entities/group_winner.rs +++ b/optd-persistent/src/entities/group_winner.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/index_metadata.rs b/optd-persistent/src/entities/index_metadata.rs index 47263b7..49a1ea2 100644 --- a/optd-persistent/src/entities/index_metadata.rs +++ b/optd-persistent/src/entities/index_metadata.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/logical_children.rs b/optd-persistent/src/entities/logical_children.rs index 120641f..92d53bd 100644 --- a/optd-persistent/src/entities/logical_children.rs +++ b/optd-persistent/src/entities/logical_children.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/logical_expression.rs b/optd-persistent/src/entities/logical_expression.rs index 6beff04..818c3ff 100644 --- a/optd-persistent/src/entities/logical_expression.rs +++ b/optd-persistent/src/entities/logical_expression.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; @@ -10,7 +10,6 @@ pub struct Model { pub group_id: i32, pub fingerprint: i64, pub variant_tag: i16, - pub data: Json, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -25,6 +24,8 @@ pub enum Relation { CascadesGroup, #[sea_orm(has_many = "super::logical_children::Entity")] LogicalChildren, + #[sea_orm(has_many = "super::predicate_logical_expression_junction::Entity")] + PredicateLogicalExpressionJunction, } impl Related for Entity { @@ -33,6 +34,12 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::PredicateLogicalExpressionJunction.def() + } +} + impl Related for Entity { fn to() -> RelationDef { super::logical_children::Relation::CascadesGroup.def() @@ -46,4 +53,17 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + super::predicate_logical_expression_junction::Relation::Predicate.def() + } + fn via() -> Option { + Some( + super::predicate_logical_expression_junction::Relation::LogicalExpression + .def() + .rev(), + ) + } +} + impl ActiveModelBehavior for ActiveModel {} diff --git a/optd-persistent/src/entities/logical_property.rs b/optd-persistent/src/entities/logical_property.rs index 755575c..f42ffdd 100644 --- a/optd-persistent/src/entities/logical_property.rs +++ b/optd-persistent/src/entities/logical_property.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/mod.rs b/optd-persistent/src/entities/mod.rs index 9434c2a..ab7c8f4 100644 --- a/optd-persistent/src/entities/mod.rs +++ b/optd-persistent/src/entities/mod.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 pub mod prelude; @@ -20,6 +20,10 @@ pub mod physical_expression; pub mod physical_expression_to_statistic_junction; pub mod physical_property; pub mod plan_cost; +pub mod predicate; +pub mod predicate_children; +pub mod predicate_logical_expression_junction; +pub mod predicate_physical_expression_junction; pub mod statistic; pub mod statistic_to_attribute_junction; pub mod table_metadata; diff --git a/optd-persistent/src/entities/namespace_metadata.rs b/optd-persistent/src/entities/namespace_metadata.rs index 8f63146..f3f3f37 100644 --- a/optd-persistent/src/entities/namespace_metadata.rs +++ b/optd-persistent/src/entities/namespace_metadata.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/physical_children.rs b/optd-persistent/src/entities/physical_children.rs index d8f9db0..18c1794 100644 --- a/optd-persistent/src/entities/physical_children.rs +++ b/optd-persistent/src/entities/physical_children.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/physical_expression.rs b/optd-persistent/src/entities/physical_expression.rs index 4876d35..be75e3a 100644 --- a/optd-persistent/src/entities/physical_expression.rs +++ b/optd-persistent/src/entities/physical_expression.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; @@ -10,7 +10,6 @@ pub struct Model { pub group_id: i32, pub fingerprint: i64, pub variant_tag: i16, - pub data: Json, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -33,6 +32,8 @@ pub enum Relation { PhysicalProperty, #[sea_orm(has_many = "super::plan_cost::Entity")] PlanCost, + #[sea_orm(has_many = "super::predicate_physical_expression_junction::Entity")] + PredicatePhysicalExpressionJunction, } impl Related for Entity { @@ -65,6 +66,12 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::PredicatePhysicalExpressionJunction.def() + } +} + impl Related for Entity { fn to() -> RelationDef { super::physical_children::Relation::CascadesGroup.def() @@ -78,6 +85,19 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + super::predicate_physical_expression_junction::Relation::Predicate.def() + } + fn via() -> Option { + Some( + super::predicate_physical_expression_junction::Relation::PhysicalExpression + .def() + .rev(), + ) + } +} + impl Related for Entity { fn to() -> RelationDef { super::physical_expression_to_statistic_junction::Relation::Statistic.def() diff --git a/optd-persistent/src/entities/physical_expression_to_statistic_junction.rs b/optd-persistent/src/entities/physical_expression_to_statistic_junction.rs index f8020bd..0332f02 100644 --- a/optd-persistent/src/entities/physical_expression_to_statistic_junction.rs +++ b/optd-persistent/src/entities/physical_expression_to_statistic_junction.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/physical_property.rs b/optd-persistent/src/entities/physical_property.rs index 51d98dc..944a94d 100644 --- a/optd-persistent/src/entities/physical_property.rs +++ b/optd-persistent/src/entities/physical_property.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/plan_cost.rs b/optd-persistent/src/entities/plan_cost.rs index 1acf101..a78083e 100644 --- a/optd-persistent/src/entities/plan_cost.rs +++ b/optd-persistent/src/entities/plan_cost.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/predicate_children.rs b/optd-persistent/src/entities/predicate_children.rs index 93ef3eb..a30e2d9 100644 --- a/optd-persistent/src/entities/predicate_children.rs +++ b/optd-persistent/src/entities/predicate_children.rs @@ -31,4 +31,19 @@ pub enum Relation { Predicate1, } +pub struct PredicateChildrenLink; + +impl Linked for PredicateChildrenLink { + type FromEntity = super::predicate::Entity; + + type ToEntity = super::predicate::Entity; + + fn link(&self) -> Vec { + vec![ + super::predicate_children::Relation::Predicate2.def(), + super::predicate_children::Relation::Predicate1.def(), + ] + } +} + impl ActiveModelBehavior for ActiveModel {} diff --git a/optd-persistent/src/entities/prelude.rs b/optd-persistent/src/entities/prelude.rs index 753e58b..4f84202 100644 --- a/optd-persistent/src/entities/prelude.rs +++ b/optd-persistent/src/entities/prelude.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 pub use super::attribute::Entity as Attribute; pub use super::attribute_constraint_junction::Entity as AttributeConstraintJunction; @@ -18,6 +18,10 @@ pub use super::physical_expression::Entity as PhysicalExpression; pub use super::physical_expression_to_statistic_junction::Entity as PhysicalExpressionToStatisticJunction; pub use super::physical_property::Entity as PhysicalProperty; pub use super::plan_cost::Entity as PlanCost; +pub use super::predicate::Entity as Predicate; +pub use super::predicate_children::Entity as PredicateChildren; +pub use super::predicate_logical_expression_junction::Entity as PredicateLogicalExpressionJunction; +pub use super::predicate_physical_expression_junction::Entity as PredicatePhysicalExpressionJunction; pub use super::statistic::Entity as Statistic; pub use super::statistic_to_attribute_junction::Entity as StatisticToAttributeJunction; pub use super::table_metadata::Entity as TableMetadata; diff --git a/optd-persistent/src/entities/statistic.rs b/optd-persistent/src/entities/statistic.rs index 1eaf96b..303dc0c 100644 --- a/optd-persistent/src/entities/statistic.rs +++ b/optd-persistent/src/entities/statistic.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/statistic_to_attribute_junction.rs b/optd-persistent/src/entities/statistic_to_attribute_junction.rs index 63d23fb..4581dd0 100644 --- a/optd-persistent/src/entities/statistic_to_attribute_junction.rs +++ b/optd-persistent/src/entities/statistic_to_attribute_junction.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/table_metadata.rs b/optd-persistent/src/entities/table_metadata.rs index 35ea923..c31140c 100644 --- a/optd-persistent/src/entities/table_metadata.rs +++ b/optd-persistent/src/entities/table_metadata.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/trigger.rs b/optd-persistent/src/entities/trigger.rs index a5f9de8..1e3c763 100644 --- a/optd-persistent/src/entities/trigger.rs +++ b/optd-persistent/src/entities/trigger.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/entities/versioned_statistic.rs b/optd-persistent/src/entities/versioned_statistic.rs index c4533bf..112cc59 100644 --- a/optd-persistent/src/entities/versioned_statistic.rs +++ b/optd-persistent/src/entities/versioned_statistic.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.1 use sea_orm::entity::prelude::*; diff --git a/optd-persistent/src/main.rs b/optd-persistent/src/main.rs index 165189e..13ea27f 100644 --- a/optd-persistent/src/main.rs +++ b/optd-persistent/src/main.rs @@ -46,11 +46,11 @@ async fn basic_demo() { group_id: group.id.clone(), fingerprint: ActiveValue::Set(42), // Example fingerprint variant_tag: ActiveValue::Set(1), // Example variant tag - data: ActiveValue::Set(json!({ // Example operator - "type": "Scan", - "table": "lineitem", - "predicate": "l_quantity < 10", - })), + // data: ActiveValue::Set(json!({ // Example operator + // "type": "Scan", + // "table": "lineitem", + // "predicate": "l_quantity < 10", + // })), ..Default::default() } .save(&db) diff --git a/optd-persistent/src/memo/expression.rs b/optd-persistent/src/memo/expression.rs index ff1590c..09e213d 100644 --- a/optd-persistent/src/memo/expression.rs +++ b/optd-persistent/src/memo/expression.rs @@ -31,43 +31,43 @@ pub enum PhysicalOperator { /// expressions are equivalent. /// /// TODO actually make efficient. -fn fingerprint(variant_tag: i16, data: &serde_json::Value) -> i64 { +fn fingerprint(variant_tag: i16) -> i64 { let mut hasher = DefaultHasher::new(); variant_tag.hash(&mut hasher); - data.hash(&mut hasher); + // data.hash(&mut hasher); hasher.finish() as i64 } impl logical_expression::Model { /// Creates a new logical expression with an unset `id` and `group_id`. - pub fn new(variant_tag: LogicalOperator, data: serde_json::Value) -> Self { + pub fn new(variant_tag: LogicalOperator) -> Self { let tag = variant_tag as i16; - let fingerprint = fingerprint(tag, &data); + let fingerprint = fingerprint(tag); Self { id: 0, group_id: 0, fingerprint, variant_tag: tag, - data, + // data, } } } impl physical_expression::Model { /// Creates a new physical expression with an unset `id` and `group_id`. - pub fn new(variant_tag: PhysicalOperator, data: serde_json::Value) -> Self { + pub fn new(variant_tag: PhysicalOperator) -> Self { let tag = variant_tag as i16; - let fingerprint = fingerprint(tag, &data); + let fingerprint = fingerprint(tag); Self { id: 0, group_id: 0, fingerprint, variant_tag: tag, - data, + // data, } } } diff --git a/optd-persistent/src/migrator/memo/m20241029_000001_predicate_children.rs b/optd-persistent/src/migrator/memo/m20241029_000001_predicate_children.rs index f3c0d10..073d968 100644 --- a/optd-persistent/src/migrator/memo/m20241029_000001_predicate_children.rs +++ b/optd-persistent/src/migrator/memo/m20241029_000001_predicate_children.rs @@ -31,6 +31,7 @@ impl MigrationTrait for Migration { .foreign_key( ForeignKey::create() .from(PredicateChildren::Table, PredicateChildren::ParentId) + .name("ParentId") .to(Predicate::Table, Predicate::Id) .on_delete(ForeignKeyAction::Cascade) .on_update(ForeignKeyAction::Cascade), @@ -39,6 +40,7 @@ impl MigrationTrait for Migration { .foreign_key( ForeignKey::create() .from(PredicateChildren::Table, PredicateChildren::ChildId) + .name("ChildId") .to(Predicate::Table, Predicate::Id) .on_delete(ForeignKeyAction::Cascade) .on_update(ForeignKeyAction::Cascade),