mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-11 11:14:21 +01:00
preallocate plan.result_columns according to AST
This commit is contained in:
@@ -48,9 +48,30 @@ pub fn prepare_select_plan(
|
||||
// Parse the FROM clause into a vec of TableReferences. Fold all the join conditions expressions into the WHERE clause.
|
||||
let table_references = parse_from(schema, from, syms, &mut where_predicates)?;
|
||||
|
||||
// Preallocate space for the result columns
|
||||
let result_columns = Vec::with_capacity(
|
||||
columns
|
||||
.iter()
|
||||
.map(|c| match c {
|
||||
// Allocate space for all columns in all tables
|
||||
ResultColumn::Star => {
|
||||
table_references.iter().map(|t| t.columns().len()).sum()
|
||||
}
|
||||
// Guess 5 columns if we can't find the table using the identifier (maybe it's in [brackets] or `tick_quotes`, or miXeDcAse)
|
||||
ResultColumn::TableStar(n) => table_references
|
||||
.iter()
|
||||
.find(|t| t.identifier == n.0)
|
||||
.map(|t| t.columns().len())
|
||||
.unwrap_or(5),
|
||||
// Otherwise allocate space for 1 column
|
||||
ResultColumn::Expr(_, _) => 1,
|
||||
})
|
||||
.sum(),
|
||||
);
|
||||
|
||||
let mut plan = SelectPlan {
|
||||
table_references,
|
||||
result_columns: vec![],
|
||||
result_columns,
|
||||
where_clause: where_predicates,
|
||||
group_by: None,
|
||||
order_by: None,
|
||||
|
||||
Reference in New Issue
Block a user