Skip to content

Commit cfb1d58

Browse files
authored
make columns nullable for cost model (#21)
1 parent e1523ce commit cfb1d58

File tree

5 files changed

+17
-32
lines changed

5 files changed

+17
-32
lines changed

optd-persistent/src/entities/constraint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ pub struct Model {
99
pub id: i32,
1010
pub name: String,
1111
pub variant_tag: i32,
12-
pub table_id: i32,
13-
pub index_id: i32,
14-
pub foreign_ref_id: i32,
12+
pub table_id: Option<i32>,
13+
pub index_id: Option<i32>,
14+
pub foreign_ref_id: Option<i32>,
1515
pub check_src: String,
1616
}
1717

optd-persistent/src/entities/statistic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub struct Model {
88
#[sea_orm(primary_key)]
99
pub id: i32,
1010
pub name: String,
11-
pub table_id: i32,
11+
pub table_id: Option<i32>,
1212
pub created_time: DateTimeUtc,
1313
pub number_of_attributes: i32,
14-
pub statistic_type: i32,
14+
pub variant_tag: i32,
1515
pub description: String,
1616
}
1717

optd-persistent/src/migrator/catalog/m20241029_000001_constraint.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
/*
2-
// Not-null is handled directly in `attribute`. See `is_not_null` field.
3-
// Constraint trigger is handled directly in `trigger`.
4-
Table constraint {
5-
id integer PK
6-
name varchar
7-
constraint_type integer // pk, fk, unique, check, exclusion
8-
table_id integer [ref: > table_metadata.id] // 0 if not a table constraint
9-
index_id integer [ref: > index.id] // The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else 0
10-
foreign_ref_id integer [ref: > table_metadata.id] // If a foreign key, the referenced table; else 0
11-
check_src varchar // the expression tree for a check constraint, which provides a textual representation of the constraint expression
12-
} */
13-
141
use crate::migrator::catalog::{index::Index, table_metadata::TableMetadata};
152
use sea_orm_migration::{prelude::*, schema::*};
163

@@ -40,23 +27,23 @@ impl MigrationTrait for Migration {
4027
.col(pk_auto(Constraint::Id))
4128
.col(string(Constraint::Name))
4229
.col(integer(Constraint::VariantTag))
43-
.col(integer(Constraint::TableId))
30+
.col(integer_null(Constraint::TableId))
4431
.foreign_key(
4532
ForeignKey::create()
4633
.from(Constraint::Table, Constraint::TableId)
4734
.to(TableMetadata::Table, TableMetadata::Id)
4835
.on_delete(ForeignKeyAction::Cascade)
4936
.on_update(ForeignKeyAction::Cascade),
5037
)
51-
.col(integer(Constraint::IndexId))
38+
.col(integer_null(Constraint::IndexId))
5239
.foreign_key(
5340
ForeignKey::create()
5441
.from(Constraint::Table, Constraint::IndexId)
5542
.to(Index::Table, Index::Id)
5643
.on_delete(ForeignKeyAction::Cascade)
5744
.on_update(ForeignKeyAction::Cascade),
5845
)
59-
.col(integer(Constraint::ForeignRefId))
46+
.col(integer_null(Constraint::ForeignRefId))
6047
.foreign_key(
6148
ForeignKey::create()
6249
.from(Constraint::Table, Constraint::ForeignRefId)

optd-persistent/src/migrator/cost_model/m20241029_000001_statistic.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ pub enum Statistic {
1818
CreatedTime,
1919
// 0 if a table statistic.
2020
NumberOfAttributes,
21-
// TODO(lanlou): Should we make another table to explain the type mapping?
22-
#[allow(clippy::enum_variant_names)]
23-
StatisticType,
21+
VariantTag,
2422
// Store the sorted attribute ids of this statistic, to support quick lookup (OR we can use junction table to look up)
2523
// For example, if we want to store the statistic of attributes [1, 2, 3], we can store it as "1,2,3".
2624
// During lookup, we should first sort the attribute ids, and then look up.
@@ -41,7 +39,7 @@ impl MigrationTrait for Migration {
4139
.if_not_exists()
4240
.col(pk_auto(Statistic::Id))
4341
.col(string(Statistic::Name))
44-
.col(integer(Statistic::TableId))
42+
.col(integer_null(Statistic::TableId))
4543
.foreign_key(
4644
ForeignKey::create()
4745
.from(Statistic::Table, Statistic::TableId)
@@ -51,7 +49,7 @@ impl MigrationTrait for Migration {
5149
)
5250
.col(timestamp(Statistic::CreatedTime))
5351
.col(integer(Statistic::NumberOfAttributes))
54-
.col(integer(Statistic::StatisticType))
52+
.col(integer(Statistic::VariantTag))
5553
.col(string(Statistic::Description))
5654
.to_owned(),
5755
)

schema/all_tables.dbml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ Table attribute {
3333
Table statistic {
3434
id integer PK
3535
name varchar
36-
table_id integer [ref: > table_metadata.id] // null if not a table statistic
36+
table_id integer [ref: > table_metadata.id, null] // null if not a table statistic
3737
created_time timestamp
3838
number_of_attributes integer // 0 if a table statistic
39-
statistic_type integer // Should we make another table to explain the type mapping?
39+
variant_tag integer // Should we make another table to explain the type mapping?
4040
description varchar // Store the sorted attribute ids of this statistic, to support quick lookup (OR we can use junction table to look up)
4141
}
4242

@@ -98,10 +98,10 @@ Table trigger {
9898
Table constraint {
9999
id integer PK
100100
name varchar
101-
constraint_type integer // pk, fk, unique, check, exclusion
102-
table_id integer [ref: > table_metadata.id] // null if not a table constraint
103-
index_id integer [ref: > index.id] // The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else null
104-
foreign_ref_id integer [ref: > table_metadata.id] // If a foreign key, the referenced table; else null
101+
variant_tag integer // pk, fk, unique, check, exclusion
102+
table_id integer [ref: > table_metadata.id, null] // null if not a table constraint
103+
index_id integer [ref: > index.id, null] // The index supporting this constraint, if it's a unique, primary key, foreign key, or exclusion constraint; else null
104+
foreign_ref_id integer [ref: > table_metadata.id, null] // If a foreign key, the referenced table; else null
105105
check_src varchar // the expression tree for a check constraint, which provides a textual representation of the constraint expression
106106
}
107107

0 commit comments

Comments
 (0)