pub struct RuntimeContext<P>{ /* private fields */ }Expand description
In-memory execution context shared by plan-based queries.
Important: “lazy loading” here refers to table metadata only (schema, executor-side column descriptors, and a small next-row-id counter). We do NOT eagerly load or materialize the table’s row data into memory. All row/column data remains on the ColumnStore and is streamed in chunks during query execution. This keeps the memory footprint low even for very large tables.
Typical resource usage:
- Metadata per table: ~100s of bytes to a few KB (schema + field ids)
- ExecutorTable struct: small (handles + counters)
- Actual table rows: streamed from disk in chunks (never fully resident)
Implementations§
Source§impl<P> RuntimeContext<P>
impl<P> RuntimeContext<P>
Sourcepub fn rename_column(
&self,
table_name: &str,
old_column_name: &str,
new_column_name: &str,
) -> Result<()>
pub fn rename_column( &self, table_name: &str, old_column_name: &str, new_column_name: &str, ) -> Result<()>
Renames a column in a table by delegating to the catalog layer.
Source§impl<P> RuntimeContext<P>
impl<P> RuntimeContext<P>
Sourcepub fn lookup_table(
&self,
canonical_name: &str,
) -> Result<Arc<ExecutorTable<P>>>
pub fn lookup_table( &self, canonical_name: &str, ) -> Result<Arc<ExecutorTable<P>>>
Looks up a table in the executor cache, lazily loading it from metadata if not already cached. This is the primary method for obtaining table references for query execution.
Source§impl<P> RuntimeContext<P>
impl<P> RuntimeContext<P>
Sourcepub fn create_table<C, I>(
self: &Arc<Self>,
name: &str,
columns: I,
) -> Result<RuntimeTableHandle<P>>where
C: IntoPlanColumnSpec,
I: IntoIterator<Item = C>,
pub fn create_table<C, I>(
self: &Arc<Self>,
name: &str,
columns: I,
) -> Result<RuntimeTableHandle<P>>where
C: IntoPlanColumnSpec,
I: IntoIterator<Item = C>,
Create a new table with the given columns.
Public API method for table creation.
Sourcepub fn create_table_if_not_exists<C, I>(
self: &Arc<Self>,
name: &str,
columns: I,
) -> Result<RuntimeTableHandle<P>>where
C: IntoPlanColumnSpec,
I: IntoIterator<Item = C>,
pub fn create_table_if_not_exists<C, I>(
self: &Arc<Self>,
name: &str,
columns: I,
) -> Result<RuntimeTableHandle<P>>where
C: IntoPlanColumnSpec,
I: IntoIterator<Item = C>,
Create a new table if it doesn’t already exist.
Public API method for conditional table creation.
Sourcepub fn create_table_builder(
&self,
name: &str,
) -> RuntimeCreateTableBuilder<'_, P>
pub fn create_table_builder( &self, name: &str, ) -> RuntimeCreateTableBuilder<'_, P>
Creates a fluent builder for defining and creating a new table with columns and constraints.
Public API method for advanced table creation with constraints.
Source§impl<P> RuntimeContext<P>
impl<P> RuntimeContext<P>
Sourcepub fn is_table_marked_dropped(&self, canonical_name: &str) -> bool
pub fn is_table_marked_dropped(&self, canonical_name: &str) -> bool
Check if a table is marked as dropped.
Source§impl<P> RuntimeContext<P>
impl<P> RuntimeContext<P>
pub fn new(pager: Arc<P>) -> Self
pub fn new_with_catalog(pager: Arc<P>, catalog: Arc<TableCatalog>) -> Self
Sourcepub fn txn_manager(&self) -> Arc<TxnIdManager>
pub fn txn_manager(&self) -> Arc<TxnIdManager>
Return the transaction ID manager shared with sessions.
Sourcepub fn store(&self) -> &Arc<ColumnStore<P>>
pub fn store(&self) -> &Arc<ColumnStore<P>>
Return the column store for catalog operations.
Sourcepub fn with_fallback_lookup(self, fallback: Arc<RuntimeContext<P>>) -> Self
pub fn with_fallback_lookup(self, fallback: Arc<RuntimeContext<P>>) -> Self
Set a fallback context for cross-pager table lookups. The fallback uses BoxedPager to enable access across different underlying pager types (e.g., temporary MemPager can fall back to persistent disk pager).
Sourcepub fn register_type(&self, name: String, data_type: DataType)
pub fn register_type(&self, name: String, data_type: DataType)
Register a custom type alias (CREATE TYPE/DOMAIN).
Sourcepub fn ensure_next_table_id_at_least(&self, minimum: TableId) -> Result<()>
pub fn ensure_next_table_id_at_least(&self, minimum: TableId) -> Result<()>
Ensure the catalog’s next_table_id counter is at least minimum.
Sourcepub fn create_view(
self: &Arc<Self>,
display_name: &str,
view_definition: String,
select_plan: SelectPlan,
if_not_exists: bool,
) -> Result<()>
pub fn create_view( self: &Arc<Self>, display_name: &str, view_definition: String, select_plan: SelectPlan, if_not_exists: bool, ) -> Result<()>
Create a view by executing its SELECT definition to derive projected columns and persisting the metadata into the catalog. The view is registered as a catalog entry with column names so subsequent binding can succeed without reparsing the stored SQL in higher layers.
pub fn create_trigger( self: &Arc<Self>, trigger_display_name: &str, canonical_trigger_name: &str, table_display_name: &str, canonical_table_name: &str, timing: TriggerTimingMeta, event: TriggerEventMeta, for_each_row: bool, condition: Option<String>, body_sql: String, if_not_exists: bool, ) -> Result<bool>
pub fn drop_trigger( self: &Arc<Self>, trigger_display_name: &str, canonical_trigger_name: &str, table_hint_display: Option<&str>, table_hint_canonical: Option<&str>, if_exists: bool, ) -> Result<bool>
Sourcepub fn view_definition(&self, canonical_name: &str) -> Result<Option<String>>
pub fn view_definition(&self, canonical_name: &str) -> Result<Option<String>>
Return the stored SQL definition for a view, if it exists.
Sourcepub fn is_view(&self, table_id: TableId) -> Result<bool>
pub fn is_view(&self, table_id: TableId) -> Result<bool>
Check if a table is actually a view by looking at its metadata. Returns true if the table exists and has a view_definition.
Sourcepub fn drop_view(&self, name: &str, if_exists: bool) -> Result<()>
pub fn drop_view(&self, name: &str, if_exists: bool) -> Result<()>
Drop a view, ignoring missing views when if_exists is true.
Sourcepub fn resolve_type(&self, data_type: &DataType) -> DataType
pub fn resolve_type(&self, data_type: &DataType) -> DataType
Resolve a type name to its base DataType, recursively following aliases.
Sourcepub fn persist_next_txn_id(&self, next_txn_id: TxnId) -> Result<()>
pub fn persist_next_txn_id(&self, next_txn_id: TxnId) -> Result<()>
Persist the next_txn_id to the catalog.
Sourcepub fn default_snapshot(&self) -> TransactionSnapshot
pub fn default_snapshot(&self) -> TransactionSnapshot
Construct the default snapshot for auto-commit operations.
Sourcepub fn table_catalog(&self) -> Arc<TableCatalog>
pub fn table_catalog(&self) -> Arc<TableCatalog>
Get the table catalog for schema and table name management.
Sourcepub fn catalog(&self) -> &CatalogManager<P>
pub fn catalog(&self) -> &CatalogManager<P>
Access the catalog manager for type registry, view management, and metadata operations.
Sourcepub fn table(self: &Arc<Self>, name: &str) -> Result<RuntimeTableHandle<P>>
pub fn table(self: &Arc<Self>, name: &str) -> Result<RuntimeTableHandle<P>>
Get a handle to an existing table by name.
Sourcepub fn table_names(self: &Arc<Self>) -> Vec<String>
pub fn table_names(self: &Arc<Self>) -> Vec<String>
Create a table with explicit column definitions - Programmatic API.
This is a convenience method for programmatically creating tables with explicit column definitions. Use this when you’re writing Rust code that needs to create tables directly, rather than executing SQL.
§When to use create_table vs CatalogDdl::create_table
Use create_table:
- You’re writing Rust code (not parsing SQL)
- You have explicit column definitions
- You want a simple, ergonomic API:
ctx.create_table("users", vec![...]) - You want a
RuntimeTableHandleto work with immediately - Does NOT support: CREATE TABLE AS SELECT, foreign keys, namespaces
- You’re implementing SQL execution (already have a parsed
CreateTablePlan) - You need CREATE TABLE AS SELECT support
- You need foreign key constraints
- You need namespace support (temporary tables)
- You need IF NOT EXISTS / OR REPLACE semantics
- You’re working within the transaction system
§Usage Comparison
Programmatic API (this method):
ctx.create_table("users", vec![("id", DataType::Int64, false), ...])?- Returns
RuntimeTableHandlefor immediate use - Simple, ergonomic, no plan construction needed
SQL execution API (CatalogDdl::create_table):
- Construct a
CreateTablePlanwith all SQL features - Delegates to the
CatalogDdltrait for catalog-aware creation - Support for CTAS, foreign keys, namespaces, transactions
- Returns
RuntimeStatementResultfor consistency with other SQL operations
§Returns
Returns a RuntimeTableHandle that provides immediate access to the table.
Use this for further programmatic operations on the table.
Returns all table names currently registered in the catalog.
Source§impl RuntimeContext<BoxedPager>
impl RuntimeContext<BoxedPager>
Sourcepub fn create_session(self: &Arc<Self>) -> RuntimeSession
pub fn create_session(self: &Arc<Self>) -> RuntimeSession
Create a new session for transaction management. Each session can have its own independent transaction.
Trait Implementations§
Source§impl<P> CatalogDdl for RuntimeContext<P>
impl<P> CatalogDdl for RuntimeContext<P>
Source§type CreateTableOutput = RuntimeStatementResult<P>
type CreateTableOutput = RuntimeStatementResult<P>
Source§type DropTableOutput = ()
type DropTableOutput = ()
Source§type RenameTableOutput = ()
type RenameTableOutput = ()
Source§type AlterTableOutput = RuntimeStatementResult<P>
type AlterTableOutput = RuntimeStatementResult<P>
Source§type CreateIndexOutput = RuntimeStatementResult<P>
type CreateIndexOutput = RuntimeStatementResult<P>
Source§type DropIndexOutput = Option<SingleColumnIndexDescriptor>
type DropIndexOutput = Option<SingleColumnIndexDescriptor>
Source§fn create_table(&self, plan: CreateTablePlan) -> Result<Self::CreateTableOutput>
fn create_table(&self, plan: CreateTablePlan) -> Result<Self::CreateTableOutput>
Source§fn drop_table(&self, plan: DropTablePlan) -> Result<Self::DropTableOutput>
fn drop_table(&self, plan: DropTablePlan) -> Result<Self::DropTableOutput>
Source§fn rename_table(&self, plan: RenameTablePlan) -> Result<Self::RenameTableOutput>
fn rename_table(&self, plan: RenameTablePlan) -> Result<Self::RenameTableOutput>
Source§fn alter_table(&self, plan: AlterTablePlan) -> Result<Self::AlterTableOutput>
fn alter_table(&self, plan: AlterTablePlan) -> Result<Self::AlterTableOutput>
Source§fn create_index(&self, plan: CreateIndexPlan) -> Result<Self::CreateIndexOutput>
fn create_index(&self, plan: CreateIndexPlan) -> Result<Self::CreateIndexOutput>
Source§fn drop_index(&self, plan: DropIndexPlan) -> Result<Self::DropIndexOutput>
fn drop_index(&self, plan: DropIndexPlan) -> Result<Self::DropIndexOutput>
Source§fn create_view(&self, _plan: CreateViewPlan) -> Result<()>
fn create_view(&self, _plan: CreateViewPlan) -> Result<()>
Auto Trait Implementations§
impl<P> !Freeze for RuntimeContext<P>
impl<P> RefUnwindSafe for RuntimeContext<P>where
P: RefUnwindSafe,
impl<P> Send for RuntimeContext<P>
impl<P> Sync for RuntimeContext<P>
impl<P> Unpin for RuntimeContext<P>
impl<P> UnwindSafe for RuntimeContext<P>where
P: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more