Struct coord::catalog::Catalog [−][src]
pub struct Catalog {
state: CatalogState,
storage: Arc<Mutex<Connection>>,
oid_counter: u32,
transient_revision: u64,
config: CatalogConfig,
}
Expand description
A Catalog
keeps track of the SQL objects known to the planner.
For each object, it keeps track of both forward and reverse dependencies: i.e., which objects are depended upon by the object, and which objects depend upon the object. It enforces the SQL rules around dropping: an object cannot be dropped until all of the objects that depend upon it are dropped. It also enforces uniqueness of names.
SQL mandates a hierarchy of exactly three layers. A catalog contains databases, databases contain schemas, and schemas contain catalog items, like sources, sinks, view, and indexes.
To the outside world, databases, schemas, and items are all identified by
name. Items can be referred to by their FullName
, which fully and
unambiguously specifies the item, or a PartialName
, which can omit the
database name and/or the schema name. Partial names can be converted into
full names via a complicated resolution process documented by the
Catalog::resolve
method.
The catalog also maintains special “ambient schemas”: virtual schemas,
implicitly present in all databases, that house various system views.
The big examples of ambient schemas are pg_catalog
and mz_catalog
.
Fields
state: CatalogState
storage: Arc<Mutex<Connection>>
oid_counter: u32
transient_revision: u64
config: CatalogConfig
Implementations
Opens or creates a catalog that stores data at path
.
Returns the catalog and a list of updates to builtin tables that describe the initial state of the catalog.
Retuns the catalog’s transient revision, which starts at 1 and is incremented on every change. This is not persisted to disk, and will restart on every load.
Takes a catalog which only has items in its on-disk storage (“unloaded”) and cannot yet resolve names, and returns a catalog loaded with those items.
This function requires transactions to support loading a catalog with the transaction’s currently in-flight updates to existing catalog objects, which is necessary for at least one catalog migration.
TODO(justin): it might be nice if these were two different types.
Opens the catalog at path
with parameters set appropriately for debug
contexts, like in tests.
WARNING! This function can arbitrarily fail because it does not make any effort to adjust the catalog’s contents’ structure or semantics to the currently running version, i.e. it does not apply any migrations.
This function should not be called in production contexts. Use
Catalog::open
with appropriately set configuration parameters
instead.
pub fn resolve_schema(
&self,
current_database: &str,
database: Option<String>,
schema_name: &str,
conn_id: u32
) -> Result<&Schema, SqlCatalogError>
pub fn resolve_item(
&self,
current_database: &str,
search_path: &[&str],
name: &PartialName,
conn_id: u32
) -> Result<&CatalogEntry, SqlCatalogError>
pub fn resolve_item(
&self,
current_database: &str,
search_path: &[&str],
name: &PartialName,
conn_id: u32
) -> Result<&CatalogEntry, SqlCatalogError>
Resolves name
to a non-function CatalogEntry
.
pub fn resolve_function(
&self,
current_database: &str,
search_path: &[&str],
name: &PartialName,
conn_id: u32
) -> Result<&CatalogEntry, SqlCatalogError>
pub fn resolve_function(
&self,
current_database: &str,
search_path: &[&str],
name: &PartialName,
conn_id: u32
) -> Result<&CatalogEntry, SqlCatalogError>
Resolves name
to a function CatalogEntry
.
Resolves PartialName
into a FullName
.
If name
does not specify a database, the current_database
is used.
If name
does not specify a schema, then the schemas in search_path
are searched in order.
Returns the named catalog item, if it exists.
Creates a new schema in the Catalog
for temporary items
indicated by the TEMPORARY or TEMP keywords.
pub fn drop_temp_item_ops(&mut self, conn_id: u32) -> Vec<Op>ⓘ
fn get_schema(
&self,
database_spec: &DatabaseSpecifier,
schema_name: &str,
conn_id: u32
) -> Option<&Schema>
pub fn drop_database_ops(&mut self, name: String) -> Vec<Op>ⓘ
pub fn drop_schema_ops(&mut self, name: SchemaName) -> Vec<Op>ⓘ
fn drop_schema_items(
schema: &Schema,
by_id: &BTreeMap<GlobalId, CatalogEntry>,
ops: &mut Vec<Op>,
seen: &mut HashSet<GlobalId>
)
fn drop_item_cascade(
id: GlobalId,
by_id: &BTreeMap<GlobalId, CatalogEntry>,
ops: &mut Vec<Op>,
seen: &mut HashSet<GlobalId>
)
Returns the Op
s necessary to enable an index.
Panics
Panics if id
is not the id
of a CatalogItem::Index
.
Gets GlobalIds of temporary items to be created, checks for name collisions within a connection id.
Insert timestamp bindings into SQLite, and ignores duplicate timestamp bindings.
Each individual binding is listed as (source_id, partition_id, timestamp, offset)
and it indicates that all data from (source, partition) for offsets < offset
, can
be assigned timestamp
iff offset
is the minimal such offset (this is a way to encode
a [start, end) offset interval without having to duplicate adjacent starts and ends in
storage).
TODO: we intentionally ignore duplicates because BYO sources can send multiple
copies of the same timestamp.
Read all available timestamp bindings for a source
Returns its output sorted by (partition, timestamp)
Compact timestamp bindings for a source
In practice this ends up being “remove all bindings less than a given timestamp” because all offsets are then assigned to the next available binding.
pub fn transact<F, T>(
&mut self,
ops: Vec<Op>,
f: F
) -> Result<(Vec<BuiltinTableUpdate>, T), CoordError> where
F: FnOnce(&CatalogState) -> Result<T, CoordError>,
fn serialize_item(&self, item: &CatalogItem) -> Vec<u8>ⓘ
fn parse_item(
&self,
id: GlobalId,
create_sql: String,
pcx: Option<&PlanContext>,
table_persist_name: Option<String>,
source_persist_details: Option<SerializedSourcePersistDetails>
) -> Result<CatalogItem, Error>
Returns the default value for an Index
’s enabled
field.
Note that it is the caller’s responsibility to ensure that the id
is
used for an Index
.
Returns a mapping that indicates all indices that are available for each item in the catalog.
Note that when self.config.disable_user_indexes
is true
, this does
not include any user indexes.
Returns whether or not an index is enabled.
Panics
Panics if id
does not belong to a CatalogItem::Index
.
Returns all indexes on this object known in the catalog.
Returns the default index for the specified id
.
Panics if id
does not exist, or if id
is not an object on which
indexes can be built.
Returns an error if the object’s default index is disabled.
Note that this function is really only meant to be used with tables.
Panics
Panics if the object identified with id
does not have a default index.
Serializes the catalog’s in-memory state.
There are no guarantees about the format of the serialized state, except that the serialized state for two identical catalogs will compare identically.
Returns all tables, views, and sources in the same schemas as a set of input ids. The indexes of all relations are included.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Catalog
impl !UnwindSafe for Catalog
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more