pub trait Catalog {
// Required methods
fn create_table(&mut self, table: TableMetadata) -> Result<(), PlannerError>;
fn get_table(&self, name: &str) -> Option<&TableMetadata>;
fn drop_table(&mut self, name: &str) -> Result<(), PlannerError>;
fn create_index(&mut self, index: IndexMetadata) -> Result<(), PlannerError>;
fn get_index(&self, name: &str) -> Option<&IndexMetadata>;
fn get_indexes_for_table(&self, table: &str) -> Vec<&IndexMetadata>;
fn drop_index(&mut self, name: &str) -> Result<(), PlannerError>;
fn table_exists(&self, name: &str) -> bool;
fn index_exists(&self, name: &str) -> bool;
fn next_table_id(&mut self) -> u32;
fn next_index_id(&mut self) -> u32;
}Expand description
Trait for catalog implementations.
A catalog manages metadata for tables and indexes. This trait abstracts the storage mechanism, allowing both in-memory and persistent implementations.
§Design Notes
- Read methods take
&selfand return references or copies - Write methods take
&mut selfand returnResult<(), PlannerError> - The
Planneronly uses read methods;Executorperforms writes - ID generation is done via
next_table_id()/next_index_id()at execute time
§Error Handling
create_table: ReturnsTableAlreadyExistsif table existsdrop_table: ReturnsTableNotFoundif table doesn’t existcreate_index: ReturnsIndexAlreadyExistsif index existsdrop_index: ReturnsIndexNotFoundif index doesn’t exist
Required Methods§
Sourcefn create_table(&mut self, table: TableMetadata) -> Result<(), PlannerError>
fn create_table(&mut self, table: TableMetadata) -> Result<(), PlannerError>
Create a new table in the catalog.
§Errors
Returns PlannerError::TableAlreadyExists if a table with the same name exists.
Sourcefn get_table(&self, name: &str) -> Option<&TableMetadata>
fn get_table(&self, name: &str) -> Option<&TableMetadata>
Get a table by name.
Returns None if the table doesn’t exist.
Sourcefn drop_table(&mut self, name: &str) -> Result<(), PlannerError>
fn drop_table(&mut self, name: &str) -> Result<(), PlannerError>
Drop a table from the catalog.
§Errors
Returns PlannerError::TableNotFound if the table doesn’t exist.
Sourcefn create_index(&mut self, index: IndexMetadata) -> Result<(), PlannerError>
fn create_index(&mut self, index: IndexMetadata) -> Result<(), PlannerError>
Create a new index in the catalog.
§Errors
Returns PlannerError::IndexAlreadyExists if an index with the same name exists.
Sourcefn get_index(&self, name: &str) -> Option<&IndexMetadata>
fn get_index(&self, name: &str) -> Option<&IndexMetadata>
Get an index by name.
Returns None if the index doesn’t exist.
Sourcefn get_indexes_for_table(&self, table: &str) -> Vec<&IndexMetadata>
fn get_indexes_for_table(&self, table: &str) -> Vec<&IndexMetadata>
Get all indexes for a table.
Returns an empty vector if the table has no indexes.
Sourcefn drop_index(&mut self, name: &str) -> Result<(), PlannerError>
fn drop_index(&mut self, name: &str) -> Result<(), PlannerError>
Drop an index from the catalog.
§Errors
Returns PlannerError::IndexNotFound if the index doesn’t exist.
Sourcefn table_exists(&self, name: &str) -> bool
fn table_exists(&self, name: &str) -> bool
Check if a table exists.
Sourcefn index_exists(&self, name: &str) -> bool
fn index_exists(&self, name: &str) -> bool
Check if an index exists.
Sourcefn next_table_id(&mut self) -> u32
fn next_table_id(&mut self) -> u32
Generate the next unique table ID.
Called by the Executor when creating a new table. IDs start from 1 and increment monotonically.
Sourcefn next_index_id(&mut self) -> u32
fn next_index_id(&mut self) -> u32
Generate the next unique index ID.
Called by the Executor when creating a new index. IDs start from 1 and increment monotonically.