Skip to main content

hawdb_storage/relational_index_view/
constraint_qualification.rs

1// Copyright 2026 Nowledge
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Relational constraint qualification report contracts.
16
17use crate::relational::RelationalKey;
18use crate::relational_index_view::RelationalIndexReadViewReport;
19
20pub const RELATIONAL_CONSTRAINT_QUALIFICATION_PROTOCOL: &str =
21    "hawdb-relational-constraint-qualification-v1";
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
24pub enum RelationalConstraintQualificationUse {
25    PrimaryKeyIdentity,
26    UniqueEnforcement,
27    UpsertConflict,
28    ForeignKeyTarget,
29    ForeignKeyReferrers,
30    NullableUniqueNoConflict,
31    AbsentKeyNoConflict,
32}
33
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct RelationalConstraintQualificationProbeReport {
36    pub ordinal: usize,
37    pub table: String,
38    pub index: String,
39    pub uses: Vec<RelationalConstraintQualificationUse>,
40    pub key_digest: String,
41    pub candidate_rows: usize,
42    pub oracle_rows: usize,
43    pub candidate_digest: String,
44    pub oracle_digest: String,
45    pub semantic_valid: bool,
46    pub matched: bool,
47    pub read: RelationalIndexReadViewReport,
48}
49
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub struct RelationalConstraintQualificationReport {
52    pub protocol: &'static str,
53    pub base_generation: u64,
54    pub delta_generation: Option<u64>,
55    pub base_commit_epoch: u64,
56    pub visible_commit_epoch: u64,
57    pub root_set_digest: String,
58    pub tables_discovered: usize,
59    pub tables_sampled: usize,
60    pub rows_sampled: usize,
61    pub unique_targets_discovered: usize,
62    pub nullable_unique_targets_discovered: usize,
63    pub foreign_keys_discovered: usize,
64    pub probes: Vec<RelationalConstraintQualificationProbeReport>,
65    pub uses_covered: usize,
66    pub mismatches: usize,
67    pub truncated: bool,
68    pub ready: bool,
69}
70
71#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
72pub struct ConstraintProbeIdentity {
73    pub table: String,
74    pub index: String,
75    pub key: RelationalKey,
76}