Skip to main content

uqa_sql/catalog/index/
enforced_key.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Unified descriptors for enforced table keys and standalone unique indexes.
8use crate::ast::{Expr, IndexKey, TableKeyConstraint};
9
10/// Runtime key enforcement keeps index predicates separate from SQL constraints.
11#[derive(Debug, Clone)]
12pub struct EnforcedKey {
13    pub constraint: TableKeyConstraint,
14    pub keys: Vec<IndexKey>,
15    pub index: Option<uqa_core::RelationIdentity>,
16    pub predicate: Option<Box<Expr>>,
17    pub constraint_owned: bool,
18}
19
20impl std::ops::Deref for EnforcedKey {
21    type Target = TableKeyConstraint;
22
23    fn deref(&self) -> &Self::Target {
24        &self.constraint
25    }
26}
27
28impl From<TableKeyConstraint> for EnforcedKey {
29    fn from(constraint: TableKeyConstraint) -> Self {
30        Self {
31            keys: constraint
32                .columns
33                .iter()
34                .cloned()
35                .map(IndexKey::Column)
36                .collect(),
37            index: None,
38            constraint,
39            predicate: None,
40            constraint_owned: true,
41        }
42    }
43}