Skip to main content

uqa_execution/catalog/
production.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Immutable catalog capture admits the shared payloads before constructing their owners.
8
9use super::{CatalogReadSnapshot, CatalogReadView};
10use std::sync::Arc;
11use uqa_core::memory::{Produced, ProductionControl};
12use uqa_sql::SQLError;
13
14impl CatalogReadView {
15    pub fn new_with_control(
16        snapshot: Produced<CatalogReadSnapshot>,
17        control: &ProductionControl<'_>,
18    ) -> Result<Self, SQLError> {
19        control.check()?;
20        let range_descriptors = if snapshot.definitions.ranges.is_empty() {
21            None
22        } else {
23            Some(default_shared(control)?)
24        };
25        Ok(Self {
26            snapshot: snapshot.into_shared(control)?,
27            relation_descriptors: default_shared(control)?,
28            range_descriptors,
29            dependencies: default_shared(control)?,
30            index_relations: default_shared(control)?,
31            constraint_definitions: default_shared(control)?,
32            event_definitions: default_shared(control)?,
33            routine_definitions: default_shared(control)?,
34            alias_output: default_shared(control)?,
35            graph_reads: None,
36            prepared_catalog: None,
37            physical_catalog: None,
38            sequence_positions: None,
39            latest_sequence_values: None,
40        })
41    }
42}
43
44// These caches' default constructors contain only empty containers and synchronization fields.
45fn default_shared<T: Default>(
46    control: &ProductionControl<'_>,
47) -> Result<Arc<Produced<T>>, SQLError> {
48    let memory = control.reserve(size_of::<Produced<T>>())?;
49    Ok(Arc::new(control.finish(T::default(), memory)?))
50}