Skip to main content

uqa_execution/mutation/
referential.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Prepare referential actions and partition rewrites before publishing row changes.
8use super::{
9    assignment::refresh_stored_generated_columns,
10    candidate::{MutationLockTarget, PhysicalDocumentIdentity, PhysicalMutationLockTarget},
11    constraints::{
12        lock_document_key_dependencies, partition_insert_target,
13        period::period_foreign_key_coverage, validate_partition_constraint, ConstraintStatement,
14    },
15    errors::{dml_storage_error, missing_document_error},
16    events::ReferentialRewritePreparation,
17    identity::{arriving_key_identity, key_relocation},
18    locking::{lock_mutation_row, lock_mutation_target, lock_physical_mutation_target},
19    prepared::{PreparedDocumentDelete, PreparedDocumentRewrite, ReferentialRewrite},
20};
21use crate::query::locking::context::update_lock_strength;
22use std::collections::BTreeSet;
23use uqa_core::{DocId, Value};
24use uqa_sql::{
25    ast::{ForeignKey, ForeignKeyAction},
26    semantics::{
27        foreign_keys::{
28            foreign_key_comparison_types, foreign_key_lookup_values, ForeignKeyComparison,
29        },
30        referential::referrers_to_for_actions,
31    },
32    SQLError, SQLParam,
33};
34use uqa_storage::document_store::Document;
35mod context;
36pub use context::{
37    ReferentialContext, ReferentialDeferrals, ReferentialReadSnapshot, ReferentialSnapshots,
38};
39mod actions;
40mod cascades;
41pub mod checks;
42mod delete;
43mod references;
44mod rewrite;
45mod snapshots;
46pub use actions::{defer_deleted_key_checks, defer_updated_key_checks};
47pub use delete::prepare_document_delete;
48pub use references::{
49    apply_set_action_to_child, lock_referencing_child, referencing_rows, ReferencingChildLock,
50};
51pub use rewrite::{
52    prepare_document_rewrite, prepare_partition_update_route, prepare_referential_document_rewrite,
53    prepare_routed_document_rewrite, refresh_updated_generated_columns, reject_partition_rewrite,
54};
55pub enum PartitionUpdateRoute {
56    Rewrite {
57        document: Document,
58        destination: Option<String>,
59        /// The relation the `UPDATE` names when the row moves to another partition, whose constraints a change to a referenced key fires, as `PostgreSQL` fires the update triggers of the update's root for a moved row.
60        moved_through: Option<String>,
61    },
62    Delete {
63        attempted_document: Document,
64    },
65}