Skip to content

Commit bdd1c10

Browse files
TimelordUKclaude
andcommitted
fix: Restore temp table persistence in --execute-statement mode
Fixes critical regression where temp tables created with SELECT INTO were not persisting between statements in dependency-aware execution (\sx mode in nvim plugin). ## Problem After the execution mode unification refactor (commit e3ec558), temp tables stopped working in --execute-statement mode. When executing: ```sql SELECT * FROM web_cte INTO #temp; GO SELECT * FROM #temp; GO ``` Statement #2 would return DUMMY table instead of the temp table data. ## Root Cause The StatementExecutor.execute() method was removing the INTO clause during preprocessing (line 175) before execution, so the QueryEngine never knew to store the result as a temp table. The INTO clause was being stripped by IntoClauseRemover but the result was never captured. ## Solution Modified StatementExecutor.execute() to: 1. Capture INTO table name BEFORE preprocessing removes it (Step 0) 2. Execute the query normally 3. If INTO clause was present, materialize the result and store it in the ExecutionContext's temp_tables registry (Step 4) This ensures temp tables persist within a single --execute-statement invocation across multiple dependent statements. ## Changes **src/execution/statement_executor.rs:** - Added Step 0: Capture into_table_name before preprocessing - Added Step 4: Materialize and store result if INTO clause was present - Uses QueryEngine.materialize_view() to convert DataView to DataTable - Stores in context.temp_tables for subsequent statement access ## Testing All 10 statement_executor tests pass. User scenario now works: 1. \sx on statement #1: Creates #temp with 72,888 rows ✓ 2. \sx on statement #2: Queries #temp, returns actual data ✓ Fixes regression introduced in execution mode unification. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b972e4e commit bdd1c10

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/execution/statement_executor.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ impl StatementExecutor {
114114
let total_start = Instant::now();
115115
let mut stats = ExecutionStats::new();
116116

117+
// Step 0: Check if this statement has an INTO clause (before preprocessing removes it!)
118+
let into_table_name = stmt.into_table.as_ref().map(|it| it.name.clone());
119+
117120
// Step 1: Determine source table
118121
let source_table = if let Some(ref from_table) = stmt.from_table {
119122
context.resolve_table(from_table)
@@ -133,7 +136,18 @@ impl StatementExecutor {
133136
let result_view = self.execute_ast(transformed_stmt.clone(), source_table, context)?;
134137
stats.execution_time_ms = exec_start.elapsed().as_secs_f64() * 1000.0;
135138

136-
// Step 4: Collect statistics
139+
// Step 4: If this was a SELECT INTO statement, store the result as a temp table
140+
if let Some(table_name) = into_table_name {
141+
// Materialize the view into a DataTable using QueryEngine's method
142+
let engine = QueryEngine::with_case_insensitive(self.config.case_insensitive);
143+
let temp_table = engine.materialize_view(result_view.clone())?;
144+
145+
// Store in temp table registry
146+
context.store_temp_table(table_name.clone(), Arc::new(temp_table))?;
147+
tracing::debug!("Stored temp table: {}", table_name);
148+
}
149+
150+
// Step 5: Collect statistics
137151
stats.total_time_ms = total_start.elapsed().as_secs_f64() * 1000.0;
138152
stats.row_count = result_view.row_count();
139153
stats.column_count = result_view.column_count();

0 commit comments

Comments
 (0)