Catalog

Trait Catalog 

Source
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 &self and return references or copies
  • Write methods take &mut self and return Result<(), PlannerError>
  • The Planner only uses read methods; Executor performs writes
  • ID generation is done via next_table_id() / next_index_id() at execute time

§Error Handling

  • create_table: Returns TableAlreadyExists if table exists
  • drop_table: Returns TableNotFound if table doesn’t exist
  • create_index: Returns IndexAlreadyExists if index exists
  • drop_index: Returns IndexNotFound if index doesn’t exist

Required Methods§

Source

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.

Source

fn get_table(&self, name: &str) -> Option<&TableMetadata>

Get a table by name.

Returns None if the table doesn’t exist.

Source

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.

Source

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.

Source

fn get_index(&self, name: &str) -> Option<&IndexMetadata>

Get an index by name.

Returns None if the index doesn’t exist.

Source

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.

Source

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.

Source

fn table_exists(&self, name: &str) -> bool

Check if a table exists.

Source

fn index_exists(&self, name: &str) -> bool

Check if an index exists.

Source

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.

Source

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.

Implementors§