Module execution

Module execution 

Source
Expand description

Unified execution module for SQL statement execution

This module provides the foundation for unifying script mode and single query mode by offering a consistent execution path that:

  1. Parses SQL exactly once
  2. Applies preprocessing exactly once (if needed)
  3. Executes AST directly (no re-parsing)
  4. Manages execution context (temp tables, variables)

§Architecture

┌─────────────────────────────────────────┐
│         StatementExecutor               │
│  (Core execution engine)                │
└──────────────┬──────────────────────────┘
               │
    ┌──────────┼──────────┐
    ▼          ▼          ▼
┌────────┐ ┌────────┐ ┌─────────┐
│Context │ │Config  │ │Pipeline │
│(State) │ │(Flags) │ │(Preproc)│
└────────┘ └────────┘ └─────────┘

§Usage

use sql_cli::execution::{StatementExecutor, ExecutionContext, ExecutionConfig};
use sql_cli::sql::recursive_parser::Parser;
use std::sync::Arc;

// Create execution context with source table
let mut context = ExecutionContext::new(source_table);

// Create executor with configuration
let config = ExecutionConfig::new()
    .with_case_insensitive(true)
    .with_show_preprocessing(false);
let executor = StatementExecutor::with_config(config);

// Parse and execute
let stmt = Parser::new("SELECT * FROM test").parse()?;
let result = executor.execute(stmt, &mut context)?;

println!("Rows: {}", result.dataview.row_count());
println!("Execution time: {:.2}ms", result.stats.total_time_ms);

§Phase 0 Status

This module is part of Phase 0 of the execution mode unification plan. It provides the foundation without modifying existing code paths.

Completed:

  • ExecutionContext - manages temp tables and state
  • ExecutionConfig - controls preprocessing and behavior
  • StatementExecutor - core execution engine

Next Steps (Future Phases):

  • Phase 1: Refactor script mode to use StatementExecutor
  • Phase 2: Refactor single query mode to use StatementExecutor
  • Phase 3: Achieve feature parity
  • Phase 4: Integrate with TUI

See docs/EXECUTION_MODE_UNIFICATION_PLAN.md for complete roadmap.

Re-exports§

pub use config::ExecutionConfig;
pub use context::ExecutionContext;
pub use statement_executor::ExecutionResult;
pub use statement_executor::ExecutionStats;
pub use statement_executor::StatementExecutor;

Modules§

config
Execution configuration for controlling statement execution behavior
context
Execution context for managing state during query execution
statement_executor
Core statement executor - unified execution path for all modes