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}
77
78impl NativeRecordFamily {
79    pub const fn id(self) -> u16 {
80        self as u16
81    }
82
83    pub fn from_id(id: u16) -> Option<Self> {
84        if id == Self::SequenceValues.id() {
85            return Some(Self::SequenceValues);
86        }
87        if id == Self::VectorPopulationWitnesses.id() {
88            return Some(Self::VectorPopulationWitnesses);
89        }
90        if id == Self::VectorPopulations.id() {
91            return Some(Self::VectorPopulations);
92        }
93        if id == Self::VectorChanges.id() {
94            return Some(Self::VectorChanges);
95        }
96        if id == Self::VectorOrigins.id() {
97            return Some(Self::VectorOrigins);
98        }
99        if id == Self::DiskANNRecords.id() {
100            return Some(Self::DiskANNRecords);
101        }
102        usize::from(id)
103            .checked_sub(1)
104            .and_then(|index| {
105                LAYOUTS.get(index).or_else(|| {
106                    index
107                        .checked_sub(LAYOUTS.len())
108                        .and_then(|index| super::standalone_graph::schema::LAYOUTS.get(index))
109                })
110            })
111            .map(|layout| layout.family)
112    }
113
114    pub fn layout(self) -> &'static NativeRecordLayout {
115        if self == Self::SequenceValues {
116            return &super::sequence_values::LAYOUT;
117        }
118        if self == Self::VectorPopulationWitnesses {
119            return &super::populations::schema::WITNESS;
120        }
121        if self == Self::VectorPopulations {
122            return &super::populations::schema::HEADER;
123        }
124        if self == Self::VectorChanges {
125            return &super::diskann::CHANGES_LAYOUT;
126        }
127        if self == Self::VectorOrigins {
128            return &super::diskann::ORIGINS_LAYOUT;
129        }
130        if self == Self::DiskANNRecords {
131            return &super::diskann::LAYOUT;
132        }
133        let index = usize::from(self.id()) - 1;
134        if index < LAYOUTS.len() {
135            &LAYOUTS[index]
136        } else {
137            &super::standalone_graph::schema::LAYOUTS[index - LAYOUTS.len()]
138        }
139    }
140
141    pub(crate) fn is_standalone_graph(self) -> bool {
142        (Self::StandaloneGraphScopes.id()..=Self::StandaloneGraphLookups.id()).contains(&self.id())
143    }
144
145    pub fn all() -> impl ExactSizeIterator<Item = Self> {
146        (1..=Self::SequenceValues.id()).map(|id| Self::from_id(id).expect("assigned native family"))
147    }
148}