Skip to main content

uqa_sql/catalog/graph_oids/
label.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! The public OIDs of one AGE label's catalog objects.
8
9use std::collections::BTreeMap;
10
11use serde::{Deserialize, Serialize};
12
13use crate::catalog::relation_oids::RelationCatalogOids;
14
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16#[serde(deny_unknown_fields)]
17pub struct LabelCatalogOids {
18    /// `<label>_id_seq`.
19    pub sequence: u32,
20    /// The label's relation with its array and row types.
21    pub relation: RelationCatalogOids,
22    /// `pg_attrdef` of the `id` column.
23    pub id_default: u32,
24    /// `pg_attrdef` of the `properties` column.
25    pub properties_default: u32,
26    /// The NOT NULL constraints by column name.
27    pub not_null: BTreeMap<String, u32>,
28    /// The TOAST table the `agtype` properties column needs, and its index.
29    pub toast_table: u32,
30    pub toast_index: u32,
31    /// The primary key's index and constraint: every vertex label and the default edge label have one.
32    #[serde(default, skip_serializing_if = "Option::is_none")]
33    pub primary_key: Option<IndexConstraintOids>,
34    /// The `start_id` and `end_id` indexes of an edge label.
35    #[serde(default, skip_serializing_if = "Option::is_none")]
36    pub endpoint_indexes: Option<EndpointIndexOids>,
37    /// The `_age_cache_invalidate` trigger.
38    pub trigger: u32,
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
42#[serde(deny_unknown_fields)]
43pub struct IndexConstraintOids {
44    pub index: u32,
45    pub constraint: u32,
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
49#[serde(deny_unknown_fields)]
50pub struct EndpointIndexOids {
51    pub start_id: u32,
52    pub end_id: u32,
53}
54
55impl LabelCatalogOids {
56    /// Every OID the label's objects claim, for occupancy checks.
57    pub fn claimed(&self) -> impl Iterator<Item = u32> + '_ {
58        [
59            self.sequence,
60            self.id_default,
61            self.properties_default,
62            self.toast_table,
63            self.toast_index,
64            self.trigger,
65        ]
66        .into_iter()
67        .chain(self.relation.claimed())
68        .chain(self.not_null.values().copied())
69        .chain(
70            self.primary_key
71                .iter()
72                .flat_map(|key| [key.index, key.constraint]),
73        )
74        .chain(
75            self.endpoint_indexes
76                .iter()
77                .flat_map(|indexes| [indexes.start_id, indexes.end_id]),
78        )
79    }
80}