Skip to main content

uqa_storage_sqlite/mvcc/native/
family.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Native physical family IDs are durable format assignments. Append new IDs; never reorder or reuse an existing assignment.
8
9use super::layout::{NativeRecordLayout, LAYOUTS};
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq)]
12#[repr(u16)]
13pub enum NativeRecordFamily {
14    Analyzers = 1,
15    BtreeIndexEntries = 2,
16    BtreeIndexRepairs = 3,
17    BtreeIndexes = 4,
18    CacheRevisions = 5,
19    CatalogIndexes = 6,
20    ColumnStats = 7,
21    DocLengths = 8,
22    DocumentBlobs = 9,
23    Documents = 10,
24    FieldStats = 11,
25    ForeignServers = 12,
26    ForeignTables = 13,
27    GraphEdges = 14,
28    GraphMembership = 15,
29    GraphPathIndexState = 16,
30    GraphPathPairs = 17,
31    GraphVertices = 18,
32    HNSWEdges = 19,
33    HNSWIndexes = 20,
34    HNSWNodes = 21,
35    IVFAssignments = 22,
36    IVFCentroids = 23,
37    IVFIndexes = 24,
38    Metadata = 25,
39    Models = 26,
40    NamedGraphs = 27,
41    OccurrenceClusters = 28,
42    OccurrenceDocuments = 29,
43    OccurrenceFields = 30,
44    OccurrenceFormats = 31,
45    OccurrenceLengths = 32,
46    PathIndexes = 33,
47    PostingClusters = 34,
48    PostingDocuments = 35,
49    Relations = 36,
50    Schemas = 37,
51    ScoringParams = 38,
52    Sequences = 39,
53    TableFieldAnalyzers = 40,
54    Tables = 41,
55    Vectors = 42,
56    Views = 43,
57    TableOwners = 44,
58    GraphLookups = 45,
59    OccurrenceSkips = 46,
60    OccurrenceBlockMax = 47,
61    OccurrenceGuards = 48,
62    VectorGuards = 49,
63    StandaloneGraphScopes = 50,
64    StandaloneGraphMetadata = 51,
65    StandaloneGraphCatalog = 52,
66    StandaloneGraphVertices = 53,
67    StandaloneGraphEdges = 54,
68    StandaloneGraphMembership = 55,
69    StandaloneGraphLookups = 56,
70    DiskANNRecords = 57,
71    VectorOrigins = 58,
72    VectorChanges = 59,
73    VectorPopulations = 60,
74    VectorPopulationWitnesses = 61,
75    SequenceValues = 62,
76    ForeignServerMetadata = 63,
77}
78
79impl NativeRecordFamily {
80    pub const fn id(self) -> u16 {
81        self as u16
82    }
83
84    pub fn from_id(id: u16) -> Option<Self> {
85        if id == Self::ForeignServerMetadata.id() {
86            return Some(Self::ForeignServerMetadata);
87        }
88        if id == Self::SequenceValues.id() {
89            return Some(Self::SequenceValues);
90        }
91        if id == Self::VectorPopulationWitnesses.id() {
92            return Some(Self::VectorPopulationWitnesses);
93        }
94        if id == Self::VectorPopulations.id() {
95            return Some(Self::VectorPopulations);
96        }
97        if id == Self::VectorChanges.id() {
98            return Some(Self::VectorChanges);
99        }
100        if id == Self::VectorOrigins.id() {
101            return Some(Self::VectorOrigins);
102        }
103        if id == Self::DiskANNRecords.id() {
104            return Some(Self::DiskANNRecords);
105        }
106        usize::from(id)
107            .checked_sub(1)
108            .and_then(|index| {
109                LAYOUTS.get(index).or_else(|| {
110                    index
111                        .checked_sub(LAYOUTS.len())
112                        .and_then(|index| super::standalone_graph::schema::LAYOUTS.get(index))
113                })
114            })
115            .map(|layout| layout.family)
116    }
117
118    pub fn layout(self) -> &'static NativeRecordLayout {
119        if self == Self::ForeignServerMetadata {
120            return &super::foreign_servers::LAYOUT;
121        }
122        if self == Self::SequenceValues {
123            return &super::sequence_values::LAYOUT;
124        }
125        if self == Self::VectorPopulationWitnesses {
126            return &super::populations::schema::WITNESS;
127        }
128        if self == Self::VectorPopulations {
129            return &super::populations::schema::HEADER;
130        }
131        if self == Self::VectorChanges {
132            return &super::diskann::CHANGES_LAYOUT;
133        }
134        if self == Self::VectorOrigins {
135            return &super::diskann::ORIGINS_LAYOUT;
136        }
137        if self == Self::DiskANNRecords {
138            return &super::diskann::LAYOUT;
139        }
140        let index = usize::from(self.id()) - 1;
141        if index < LAYOUTS.len() {
142            &LAYOUTS[index]
143        } else {
144            &super::standalone_graph::schema::LAYOUTS[index - LAYOUTS.len()]
145        }
146    }
147
148    pub(crate) fn is_standalone_graph(self) -> bool {
149        (Self::StandaloneGraphScopes.id()..=Self::StandaloneGraphLookups.id()).contains(&self.id())
150    }
151
152    pub fn all() -> impl ExactSizeIterator<Item = Self> {
153        (1..=Self::ForeignServerMetadata.id())
154            .map(|id| Self::from_id(id).expect("assigned native family"))
155    }
156}