Skip to main content

uqa_sql/plan/mutable/sources/
metadata.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use super::{MutableSourcePlan, SourcePlan};
8use crate::{plan::JoinExecutionStrategy, SQLError};
9use uqa_core::memory::ProductionControl;
10
11impl MutableSourcePlan {
12    /// Retain the selected join's lateral namespace when a function input expands into a derived table.
13    pub fn set_join_lateral(
14        mut self,
15        lateral: bool,
16        control: &ProductionControl<'_>,
17    ) -> Result<Self, SQLError> {
18        self.assert_owner(control);
19        control.check()?;
20        let SourcePlan::Join {
21            lateral: target, ..
22        } = &mut self.source
23        else {
24            return Err(SQLError::Internal(
25                "lateral join decision requires a join source".into(),
26            ));
27        };
28        *target = lateral;
29        Ok(self)
30    }
31
32    /// Install the planner's allocation-free join execution decision.
33    pub fn set_join_strategy(
34        mut self,
35        strategy: JoinExecutionStrategy,
36        control: &ProductionControl<'_>,
37    ) -> Result<Self, SQLError> {
38        self.assert_owner(control);
39        control.check()?;
40        let SourcePlan::Join {
41            strategy: target, ..
42        } = &mut self.source
43        else {
44            return Err(SQLError::Internal(
45                "join strategy requires a join source".into(),
46            ));
47        };
48        *target = strategy;
49        Ok(self)
50    }
51}
52
53impl MutableSourcePlan {
54    /// Null-rejection changes only join-kind decisions; every source constructor and child keeps its existing owner.
55    pub fn reduce_null_rejected_outer_joins(
56        mut self,
57        routines: &dyn crate::routines::RoutineResolution,
58        predicate: Option<&crate::ScalarExpr>,
59        params: &[crate::SQLParam],
60        context: &crate::binding::production::ControlledBindingContext<'_>,
61        control: &ProductionControl<'_>,
62    ) -> Result<Self, SQLError> {
63        self.assert_owner(control);
64        crate::semantics::locking::null_rejection::reduce_null_rejected_outer_joins_with_control(
65            routines,
66            &mut self.source,
67            predicate,
68            params,
69            context,
70            control,
71        )?;
72        Ok(self)
73    }
74}