pub struct ExecutionContext { /* private fields */ }Expand description
Execution context for SQL queries
The execution context carries state and configuration for query execution, including parameters, transaction state, and cancellation support.
Note: This struct uses Arc for immutable shared data to make cloning cheap during correlated subquery processing where context is cloned per row.
Implementations§
Source§impl ExecutionContext
impl ExecutionContext
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty execution context Uses static defaults for empty collections to avoid allocations
Sourcepub fn with_params(params: ParamVec) -> Self
pub fn with_params(params: ParamVec) -> Self
Create an execution context with positional parameters
Sourcepub fn with_named_params(named_params: FxHashMap<String, Value>) -> Self
pub fn with_named_params(named_params: FxHashMap<String, Value>) -> Self
Create an execution context with named parameters
Sourcepub fn get_param(&self, index: usize) -> Option<&Value>
pub fn get_param(&self, index: usize) -> Option<&Value>
Get a positional parameter by index (1-based)
Sourcepub fn get_named_param(&self, name: &str) -> Option<&Value>
pub fn get_named_param(&self, name: &str) -> Option<&Value>
Get a named parameter by name
Sourcepub fn params_arc(&self) -> &CompactArc<ParamVec>
pub fn params_arc(&self) -> &CompactArc<ParamVec>
Get the params Arc for zero-copy sharing. Used by evaluator bridge to avoid cloning params.
Sourcepub fn named_params(&self) -> &FxHashMap<String, Value>
pub fn named_params(&self) -> &FxHashMap<String, Value>
Get all named parameters
Sourcepub fn named_params_arc(&self) -> &Arc<FxHashMap<String, Value>> ⓘ
pub fn named_params_arc(&self) -> &Arc<FxHashMap<String, Value>> ⓘ
Get the named_params Arc for zero-copy sharing. Used by evaluator bridge to avoid cloning params.
Sourcepub fn param_count(&self) -> usize
pub fn param_count(&self) -> usize
Get the number of positional parameters
Sourcepub fn set_params(&mut self, params: ParamVec)
pub fn set_params(&mut self, params: ParamVec)
Set positional parameters
Sourcepub fn set_named_param(&mut self, name: impl Into<String>, value: Value)
pub fn set_named_param(&mut self, name: impl Into<String>, value: Value)
Set a named parameter
Sourcepub fn auto_commit(&self) -> bool
pub fn auto_commit(&self) -> bool
Check if auto-commit is enabled
Sourcepub fn set_auto_commit(&mut self, auto_commit: bool)
pub fn set_auto_commit(&mut self, auto_commit: bool)
Set auto-commit mode
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if the query has been cancelled
Sourcepub fn cancellation_handle(&self) -> CancellationHandle
pub fn cancellation_handle(&self) -> CancellationHandle
Get a cancellation handle that can be used from another thread
Sourcepub fn current_database(&self) -> Option<&str>
pub fn current_database(&self) -> Option<&str>
Get the current database/schema name
Sourcepub fn set_current_database(&mut self, database: impl Into<String>)
pub fn set_current_database(&mut self, database: impl Into<String>)
Set the current database/schema name
Sourcepub const fn principal_id(&self) -> ObjectId
pub const fn principal_id(&self) -> ObjectId
Return the stable catalog Principal selected by authentication.
Sourcepub fn with_principal_id(&self, principal_id: ObjectId) -> Self
pub fn with_principal_id(&self, principal_id: ObjectId) -> Self
Derive a context for a stable Principal without carrying credentials.
Sourcepub const fn effective_principal_id(&self) -> ObjectId
pub const fn effective_principal_id(&self) -> ObjectId
Return the Principal whose privileges apply to the current execution
frame. It differs from principal_id only inside SECURITY DEFINER.
Sourcepub fn with_effective_principal_id(&self, principal_id: ObjectId) -> Self
pub fn with_effective_principal_id(&self, principal_id: ObjectId) -> Self
Derive a nested execution frame with an explicit effective Principal. Authentication identity remains unchanged.
Sourcepub fn get_session_var(&self, name: &str) -> Option<&Value>
pub fn get_session_var(&self, name: &str) -> Option<&Value>
Get a session variable
Sourcepub fn set_session_var(&mut self, name: impl Into<String>, value: Value)
pub fn set_session_var(&mut self, name: impl Into<String>, value: Value)
Set a session variable
Sourcepub fn timeout_ms(&self) -> u64
pub fn timeout_ms(&self) -> u64
Get the query timeout in milliseconds
Sourcepub fn set_timeout_ms(&mut self, timeout_ms: u64)
pub fn set_timeout_ms(&mut self, timeout_ms: u64)
Set the query timeout in milliseconds
Sourcepub fn has_timeout(&self) -> bool
pub fn has_timeout(&self) -> bool
Check if a timeout has been set
Sourcepub fn view_depth(&self) -> usize
pub fn view_depth(&self) -> usize
Get the current view nesting depth
Sourcepub fn with_incremented_view_depth(&self) -> Self
pub fn with_incremented_view_depth(&self) -> Self
Create a new context with incremented view depth. Used when executing nested views to track recursion depth. Also increments query_depth since views are nested queries.
Sourcepub fn with_incremented_query_depth(&self) -> Self
pub fn with_incremented_query_depth(&self) -> Self
Create a new context with incremented query depth. Used when executing subqueries to ensure TimeoutGuard is only created at the top level.
Sourcepub fn outer_row(&self) -> Option<&FxHashMap<CompactArc<str>, Value>>
pub fn outer_row(&self) -> Option<&FxHashMap<CompactArc<str>, Value>>
Get the outer row context for correlated subqueries
Sourcepub fn outer_columns(&self) -> Option<&[String]>
pub fn outer_columns(&self) -> Option<&[String]>
Get the outer row columns for correlated subqueries
Sourcepub fn with_outer_row(
&self,
outer_row: FxHashMap<CompactArc<str>, Value>,
outer_columns: CompactArc<Vec<String>>,
) -> Self
pub fn with_outer_row( &self, outer_row: FxHashMap<CompactArc<str>, Value>, outer_columns: CompactArc<Vec<String>>, ) -> Self
Create a new context with outer row context for correlated subqueries.
The outer row maps lowercase column names (as CompactArc<str>) to their values.
NOTE: This is now cheap to clone due to Arc wrapping of immutable fields.
Sourcepub fn get_cte(&self, name: &str) -> Option<&CteData>
pub fn get_cte(&self, name: &str) -> Option<&CteData>
Get CTE data by name (case-insensitive) Returns Arc references to enable zero-copy sharing with joins
Sourcepub fn get_cte_by_lower(&self, name_lower: &str) -> Option<&CteData>
pub fn get_cte_by_lower(&self, name_lower: &str) -> Option<&CteData>
Get CTE data by name that is already lowercase. Use this when the name is known to be lowercase (e.g., from value_lower fields) to avoid redundant to_lowercase() allocation.
Sourcepub fn has_cte_by_lower(&self, name_lower: &str) -> bool
pub fn has_cte_by_lower(&self, name_lower: &str) -> bool
Check if context has CTE data by name that is already lowercase. Use this when the name is known to be lowercase to avoid allocation.
Sourcepub fn with_cte_data(&self, cte_data: Arc<CteDataMap>) -> Self
pub fn with_cte_data(&self, cte_data: Arc<CteDataMap>) -> Self
Create a new context with CTE data for subqueries to reference Takes an Arc to avoid cloning large CTE datasets
Sourcepub fn transaction_id(&self) -> Option<u64>
pub fn transaction_id(&self) -> Option<u64>
Get the current transaction ID
Sourcepub fn set_transaction_id(&mut self, txn_id: u64)
pub fn set_transaction_id(&mut self, txn_id: u64)
Set the transaction ID
Sourcepub fn with_transaction_id(&self, txn_id: u64) -> Self
pub fn with_transaction_id(&self, txn_id: u64) -> Self
Create a new context with a transaction ID
Sourcepub fn check_cancelled(&self) -> Result<()>
pub fn check_cancelled(&self) -> Result<()>
Check for cancellation and return an error if cancelled
Trait Implementations§
Source§impl Clone for ExecutionContext
impl Clone for ExecutionContext
Source§fn clone(&self) -> ExecutionContext
fn clone(&self) -> ExecutionContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more