mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-26 11:24:32 +01:00
Store Cow<&Expr> in expr_to_reg_cache
We will be storing owned expressions in it for RETURNING in a later commit.
This commit is contained in:
@@ -38,10 +38,10 @@ pub fn emit_ungrouped_aggregation<'a>(
|
||||
// we need to call translate_expr on each result column, but replace the expr with a register copy in case any part of the
|
||||
// result column expression matches a) a group by column or b) an aggregation result.
|
||||
for (i, agg) in plan.aggregates.iter().enumerate() {
|
||||
t_ctx
|
||||
.resolver
|
||||
.expr_to_reg_cache
|
||||
.push((&agg.original_expr, agg_start_reg + i));
|
||||
t_ctx.resolver.expr_to_reg_cache.push((
|
||||
std::borrow::Cow::Borrowed(&agg.original_expr),
|
||||
agg_start_reg + i,
|
||||
));
|
||||
}
|
||||
t_ctx.resolver.enable_expr_to_reg_cache();
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ pub struct Resolver<'a> {
|
||||
pub schema: &'a Schema,
|
||||
pub symbol_table: &'a SymbolTable,
|
||||
pub expr_to_reg_cache_enabled: bool,
|
||||
pub expr_to_reg_cache: Vec<(&'a ast::Expr, usize)>,
|
||||
pub expr_to_reg_cache: Vec<(std::borrow::Cow<'a, ast::Expr>, usize)>,
|
||||
}
|
||||
|
||||
impl<'a> Resolver<'a> {
|
||||
|
||||
@@ -646,7 +646,10 @@ pub fn group_by_process_single_group(
|
||||
{
|
||||
if *in_result {
|
||||
program.emit_column_or_rowid(*pseudo_cursor, sorter_column_index, next_reg);
|
||||
t_ctx.resolver.expr_to_reg_cache.push((expr, next_reg));
|
||||
t_ctx
|
||||
.resolver
|
||||
.expr_to_reg_cache
|
||||
.push((std::borrow::Cow::Borrowed(expr), next_reg));
|
||||
next_reg += 1;
|
||||
}
|
||||
}
|
||||
@@ -669,7 +672,10 @@ pub fn group_by_process_single_group(
|
||||
dest_reg,
|
||||
&t_ctx.resolver,
|
||||
)?;
|
||||
t_ctx.resolver.expr_to_reg_cache.push((expr, dest_reg));
|
||||
t_ctx
|
||||
.resolver
|
||||
.expr_to_reg_cache
|
||||
.push((std::borrow::Cow::Borrowed(expr), dest_reg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -792,10 +798,10 @@ pub fn group_by_emit_row_phase<'a>(
|
||||
register: agg_result_reg,
|
||||
func: agg.func.clone(),
|
||||
});
|
||||
t_ctx
|
||||
.resolver
|
||||
.expr_to_reg_cache
|
||||
.push((&agg.original_expr, agg_result_reg));
|
||||
t_ctx.resolver.expr_to_reg_cache.push((
|
||||
std::borrow::Cow::Borrowed(&agg.original_expr),
|
||||
agg_result_reg,
|
||||
));
|
||||
}
|
||||
|
||||
t_ctx.resolver.enable_expr_to_reg_cache();
|
||||
|
||||
@@ -526,10 +526,10 @@ pub fn init_window<'a>(
|
||||
let reg_acc_start = program.alloc_registers(window_function_count);
|
||||
let reg_acc_result_start = program.alloc_registers(window_function_count);
|
||||
for (i, func) in window.functions.iter().enumerate() {
|
||||
t_ctx
|
||||
.resolver
|
||||
.expr_to_reg_cache
|
||||
.push((&func.original_expr, reg_acc_result_start + i));
|
||||
t_ctx.resolver.expr_to_reg_cache.push((
|
||||
std::borrow::Cow::Borrowed(&func.original_expr),
|
||||
reg_acc_result_start + i,
|
||||
));
|
||||
}
|
||||
|
||||
// The same approach applies to expressions referencing the subquery (columns).
|
||||
@@ -543,7 +543,7 @@ pub fn init_window<'a>(
|
||||
t_ctx
|
||||
.resolver
|
||||
.expr_to_reg_cache
|
||||
.push((expr, reg_col_start + i));
|
||||
.push((std::borrow::Cow::Borrowed(expr), reg_col_start + i));
|
||||
}
|
||||
|
||||
t_ctx.meta_window = Some(WindowMetadata {
|
||||
|
||||
Reference in New Issue
Block a user