-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redefine FieldName as (TableId, ColId)
#1165
Conversation
7d231a5
to
d96e452
Compare
@@ -351,7 +349,7 @@ impl InstanceEnv { | |||
let tx = &mut *self.tx.get()?; | |||
|
|||
let schema = stdb.schema_for_table_mut(tx, table_id)?; | |||
let row_type = ProductType::from(&*schema); | |||
let row_type = schema.get_row_type(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive-by optimization
let mut iter = ident.rsplit('.'); | ||
let field = iter.next(); | ||
let table = iter.next(); | ||
let more = iter.next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoids allocation now.
if let Some(f_table) = f_table { | ||
// Qualified field `{f_table}.{f_field}`. | ||
// Narrow search to first table with name `f_table`. | ||
return if let Some(col) = tables | ||
.find(|t| &*t.table_name == f_table) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoids allocation in the qualified path now.
@@ -626,10 +630,9 @@ fn compile_select_item(from: &From, select_item: SelectItem) -> Result<Column, P | |||
fn compile_select<T: TableSchemaView>(db: &RelationalDB, tx: &T, select: Select) -> Result<SqlAst, PlanError> { | |||
let from = compile_from(db, tx, &select.from)?; | |||
// SELECT ... | |||
let mut project = Vec::new(); | |||
let mut project = Vec::with_capacity(select.projection.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by optimization
fn check_field(table: &From, field: &FieldExpr) -> Result<(), PlanError> { | ||
if let FieldExpr::Name(field) = field { | ||
table.find_field(&field.to_string())?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn check_field_column(table: &From, field: &ColumnOp) -> Result<(), PlanError> { | ||
if let ColumnOp::Field(field) = field { | ||
check_field(table, field)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Verify the `fields` inside the `expr` are valid | ||
fn check_cmp_expr(table: &From, expr: &ColumnOp) -> Result<(), PlanError> { | ||
match expr { | ||
ColumnOp::Field(field) => check_field(table, field)?, | ||
ColumnOp::Cmp { op: _, lhs, rhs } => { | ||
check_field_column(table, lhs)?; | ||
check_field_column(table, rhs)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By having FieldName
we've already verified, so no need to do it again.
@@ -529,7 +532,8 @@ fn compile_from<T: TableSchemaView>(db: &RelationalDB, tx: &T, from: &[TableWith | |||
|
|||
match constraint { | |||
JoinConstraint::On(x) => { | |||
let expr = compile_expr_value(&base, None, x.clone())?; | |||
let tables = base.iter_tables().chain([&*join]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the reason find_field
had to become a free function.
We must extend the context with the joined table before adding it to the returned base.
af99b17
to
5b5274a
Compare
let result = run_for_testing( | ||
&db, | ||
"insert into inventory (id, name) values (1, 'Kiley'); | ||
insert into inventory (id, name) values (2, 'Terza'); | ||
insert into inventory (id, name) values (3, 'Alvie'); | ||
"insert into inventory (inventory_id, name) values (1, 'Kiley'); | ||
insert into inventory (inventory_id, name) values (2, 'Terza'); | ||
insert into inventory (inventory_id, name) values (3, 'Alvie'); | ||
SELECT * FROM inventory", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we have a bug in master as the column name is inventory_id
and not id
.
.iter() | ||
.map(|x| { | ||
let ty = x.algebraic_type.clone(); | ||
let name = translate_col(tx, x.field); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to do this to match the old output as the header no longer contains the column names.
5b5274a
to
dc59598
Compare
dc59598
to
1ce322c
Compare
578bd6c
to
4b99880
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look cleaner, column accesses look more efficient.
Description of Changes
Do not store table names and field names in
FieldName
.Rather, store the table id and the column id which is substantially cheaper (8 bytes).
Fixes a bug in
fn column_pos
along the way and does some drive-by cleanup.The second commit adds both necessary changes to tests and refactoring around them, and similar changes which I had to do to understand and be confident in the changes to the tests. The diff got larger than I wanted, but once merged, I think it will help us long term.
Fixes #1118.
Fixes #1117.
API and ABI breaking changes
None
Expected complexity level and risk
2