Skip to main content

uqa_sql/
plan.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Complete SQL-to-execution-plan lowering.
8//!
9//! `OperatorTree` is the specialised algebra
10//! for posting-list, graph, and fusion operations.  It is intentionally not a
11//! relational algebra: forcing a SQL window frame or a mutation into a
12//! posting-list node would erase its row and command semantics.  This module
13//! supplies the missing super-plan.  Every SQL statement lowers to one
14//! [`UnifiedPlan`], while query-producing statements recursively own their
15//! relational children.  A physical driver can therefore use an
16//! `OperatorTree` as an access path *inside* a relational node without keeping
17//! a second top-level SQL dispatcher.
18
19use crate::ast::{
20    Expr, FrameBound, FromClause, NullsOrder, OrderBy, Projection, SelectStmt, SetOpKind,
21    Statement, WindowSpec, CTE,
22};
23use crate::ir::{ScalarExpr, ScalarFrameBound, ScalarOrder, ScalarWindowFrame, ScalarWindowSpec};
24
25mod analyzed;
26mod command_children;
27pub use analyzed::SharedAnalyzedSource;
28mod command_expressions;
29pub(crate) mod copy;
30pub mod input_projection;
31mod memory;
32mod model;
33mod mutable;
34pub use mutable::OwnedScopedPlanVisitor;
35pub use mutable::{
36    CommandAssignmentSlot, CommandQuerySlot, CommandScalarSlot, MutableCommandPlan,
37    MutableExecutablePlan, MutableExpressionPlan, MutableJoinParts, MutableJoinShell,
38    MutableQueryPlan, MutableSourcePlan, OwnedDeferredRewriteIter, OwnedProjection,
39    OwnedProjectionIter, OwnedValueRow, QueryChildSlot, QueryScalarSlot, ScalarArenaTransform,
40    ScalarQueryArena, SourceChildSlot, SourceScalarSlot,
41};
42pub(crate) use mutable::{QueryMetadataUpdate, SourceMetadataUpdate};
43mod optimization;
44pub use optimization::ExecutablePlanOptimizer;
45mod owned;
46pub use owned::{ExecutableMemory, OwnedExecutablePlan, OwnedQueryPlan, SharedExecutablePlan};
47mod query;
48mod query_visit;
49mod retained;
50pub use retained::RetainedCtePlan;
51mod retained_arena;
52pub use retained_arena::RetainedQueryArena;
53mod rewrite;
54mod scalar;
55pub use scalar::{OwnedScalarChildren, OwnedScalarExpr, ScalarNodeTransform};
56mod scoped_visit;
57pub use scoped_visit::ScopedPlanVisitor;
58mod source_metadata;
59mod source_visit;
60mod statement;
61pub mod subqueries;
62mod visit;
63pub mod windows;
64
65pub use model::*;
66pub use rewrite::rewrite_scalar_expression;
67
68#[cfg(test)]
69mod tests;
70
71mod projection;
72pub use projection::ProjectionTarget;
73
74pub mod source_projection;
75
76pub mod locking;