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}
71
72impl NativeRecordFamily {
73    pub const fn id(self) -> u16 {
74        self as u16
75    }
76
77    pub fn from_id(id: u16) -> Option<Self> {
78        usize::from(id)
79            .checked_sub(1)
80            .and_then(|index| {
81                LAYOUTS.get(index).or_else(|| {
82                    index
83                        .checked_sub(LAYOUTS.len())
84                        .and_then(|index| super::standalone_graph::schema::LAYOUTS.get(index))
85                })
86            })
87            .map(|layout| layout.family)
88    }
89
90    pub fn layout(self) -> &'static NativeRecordLayout {
91        let index = usize::from(self.id()) - 1;
92        if index < LAYOUTS.len() {
93            &LAYOUTS[index]
94        } else {
95            &super::standalone_graph::schema::LAYOUTS[index - LAYOUTS.len()]
96        }
97    }
98
99    pub(crate) fn is_standalone_graph(self) -> bool {
100        self.id() >= Self::StandaloneGraphScopes.id()
101    }
102
103    pub fn all() -> impl ExactSizeIterator<Item = Self> {
104        (1..=Self::StandaloneGraphLookups.id())
105            .map(|id| Self::from_id(id).expect("assigned native family"))
106    }
107}