Skip to main content

uqa_storage/
value_index_key.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Physical B-tree namespaces distinguish column accelerators from named SQL indexes.
8
9/// A stored evaluated key distinguishes an unbuilt index, an absent row and a present SQL NULL. Consumers must not recompute an old expression against a newer routine definition.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum ValueIndexEntry {
12    Unbuilt,
13    Absent,
14    Present(uqa_core::Value),
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
18pub enum ValueIndexKey {
19    Column(String),
20    Index(String),
21}
22
23impl ValueIndexKey {
24    #[must_use]
25    pub fn name(&self) -> &str {
26        match self {
27            Self::Column(name) | Self::Index(name) => name,
28        }
29    }
30}
31
32impl From<&str> for ValueIndexKey {
33    fn from(name: &str) -> Self {
34        Self::Column(name.into())
35    }
36}
37
38impl From<String> for ValueIndexKey {
39    fn from(name: String) -> Self {
40        Self::Column(name)
41    }
42}
43
44impl std::fmt::Display for ValueIndexKey {
45    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        match self {
47            Self::Column(name) => write!(formatter, "column {name}"),
48            Self::Index(name) => write!(formatter, "index {name}"),
49        }
50    }
51}