Skip to main content

SqlCatalog

Trait SqlCatalog 

Source
pub trait SqlCatalog {
    // Required method
    fn get_collection(
        &self,
        database_id: DatabaseId,
        name: &str,
    ) -> Result<Option<CollectionInfo>, SqlCatalogError>;

    // Provided methods
    fn resolve_relation(
        &self,
        database_id: DatabaseId,
        name: &str,
    ) -> Result<Option<CollectionInfo>, SqlCatalogError> { ... }
    fn lookup_array(&self, _name: &str) -> Option<ArrayCatalogView> { ... }
    fn array_exists(&self, name: &str) -> bool { ... }
    fn resolve_regclass(
        &self,
        _database_id: DatabaseId,
        _tenant_id: u64,
        _name: &str,
    ) -> Option<i64> { ... }
    fn resolve_regtype(&self, _name: &str) -> Option<i64> { ... }
    fn sequence_nextval(
        &self,
        _database_id: DatabaseId,
        _tenant_id: u64,
        _name: &str,
    ) -> Result<i64, SqlError> { ... }
    fn sequence_currval(
        &self,
        _database_id: DatabaseId,
        _tenant_id: u64,
        _name: &str,
    ) -> Result<i64, SqlError> { ... }
    fn sequence_setval(
        &self,
        _database_id: DatabaseId,
        _tenant_id: u64,
        _name: &str,
        _value: i64,
    ) -> Result<i64, SqlError> { ... }
}
Expand description

Trait for looking up collection metadata during planning.

Both Origin (via CredentialStore) and Lite (via the embedded redb catalog) implement this trait.

The return type is Result<Option<CollectionInfo>, _> with a three-way semantics:

  • Ok(Some(info)) — the collection exists and is usable. An Origin implementation will have acquired a descriptor lease at the current version before returning; subsequent planning against the same collection within the lease window is drain-safe.
  • Ok(None) — the collection does not exist. Callers should surface this as SqlError::UnknownTable.
  • Err(SqlCatalogError::RetryableSchemaChanged { .. }) — the collection exists but a DDL drain is in progress. Callers propagate this up so the pgwire layer can retry the whole statement.

Required Methods§

Provided Methods§

Source

fn resolve_relation( &self, database_id: DatabaseId, name: &str, ) -> Result<Option<CollectionInfo>, SqlCatalogError>

Resolve ANY relation name to planner metadata. Catalog tables override this to surface synthetic relations by name; the default resolves only stored collections, identical to get_collection.

Source

fn lookup_array(&self, _name: &str) -> Option<ArrayCatalogView>

Look up an array by name. Returns None if no array with that name is registered. The default implementation returns None so that catalog adapters predating array support compile without change — the array DML planner falls back to “array not found” in that case.

Source

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

Cheap existence check; the default delegates to lookup_array.

Source

fn resolve_regclass( &self, _database_id: DatabaseId, _tenant_id: u64, _name: &str, ) -> Option<i64>

Resolve a relation name to its catalog OID for 'name'::regclass. Returns None when the name is not found. The default returns None so existing impls compile without change.

Source

fn resolve_regtype(&self, _name: &str) -> Option<i64>

Resolve a type name to its catalog OID for 'name'::regtype. Returns None when the name is not found. The default returns None so existing impls compile without change.

Source

fn sequence_nextval( &self, _database_id: DatabaseId, _tenant_id: u64, _name: &str, ) -> Result<i64, SqlError>

Advance a sequence and return the allocated value, recording it as this session’s currval. Scoping mirrors resolve_regclass.

An unknown name returns [SqlError::UndefinedObject] (SQLSTATE 42704). The default returns “sequence access unavailable” so implementors with no sequence state compile without change.

Source

fn sequence_currval( &self, _database_id: DatabaseId, _tenant_id: u64, _name: &str, ) -> Result<i64, SqlError>

Return the last value this session obtained from sequence_nextval.

A sequence this session never advanced returns [SqlError::ObjectNotInPrerequisiteState] (SQLSTATE 55000).

Source

fn sequence_setval( &self, _database_id: DatabaseId, _tenant_id: u64, _name: &str, _value: i64, ) -> Result<i64, SqlError>

Position a sequence so the next sequence_nextval returns value + increment. Returns value.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§