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, validate_partition_constraint,
13        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;
46use super::row_membership::PhysicalRowLookup as DeletedRowLookup;
47use actions::defer_deleted_key_checks_excluding;
48pub use actions::{defer_deleted_key_checks, defer_updated_key_checks};
49pub use delete::prepare_document_delete;
50pub(crate) use delete::prepare_document_delete_excluding;
51pub use references::{
52    apply_set_action_to_child, lock_referencing_child, referencing_rows, ReferencingChildLock,
53};
54pub use rewrite::{
55    prepare_document_rewrite, prepare_partition_update_route, prepare_referential_document_rewrite,
56    prepare_routed_document_rewrite, refresh_updated_generated_columns, reject_partition_rewrite,
57};
58pub enum PartitionUpdateRoute {
59    Rewrite {
60        document: Document,
61        destination: Option<String>,
62        /// 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.
63        moved_through: Option<String>,
64    },
65    Delete {
66        attempted_document: Document,
67    },
68}