Module prepared_statement

Module prepared_statement 

Source
Expand description

Prepared statement caching for optimized query execution

Caches parsed AST statements to avoid repeated parsing overhead. This provides significant performance benefits for repeated queries by:

  • Caching the parsed AST for identical SQL strings
  • Avoiding expensive parsing for each query execution
  • Supporting ? placeholders with AST-level parameter binding

§Parameterized Queries

The parser supports ? placeholders which are converted to Placeholder(index) expressions in the AST. Parameter binding replaces these placeholders with literal values directly in the AST, avoiding re-parsing entirely.

Example:

let stmt = session.prepare("SELECT * FROM users WHERE id = ?")?;
// First execution - fast (no re-parsing)
let result1 = session.execute_prepared(&stmt, &[SqlValue::Integer(1)])?;
// Second execution - equally fast (still no re-parsing)
let result2 = session.execute_prepared(&stmt, &[SqlValue::Integer(2)])?;

Re-exports§

pub use plan::CachedPlan;
pub use plan::ColumnProjection;
pub use plan::PkDeletePlan;
pub use plan::PkPointLookupPlan;
pub use plan::ProjectionPlan;
pub use plan::ResolvedProjection;
pub use plan::SimpleFastPathPlan;

Modules§

arena_prepared
Arena-based prepared statement for zero-allocation execution
plan
Query plan caching for prepared statements

Structs§

PreparedStatement
A prepared statement with cached AST and optional execution plan
PreparedStatementCache
Thread-safe cache for prepared statements with LRU eviction
PreparedStatementCacheStats
Statistics for prepared statement cache

Enums§

PreparedStatementError
Errors that can occur during prepared statement operations