Skip to main content

uqa_sql/prepared/
planning.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Prepared-plan selection contract and identity-checked cache updates.
8
9use super::ownership::SharedPreparedInput;
10use crate::{SQLError, SQLParam};
11
12pub trait PreparedPlanProvider {
13    fn plan_for_execution(
14        &self,
15        name: &str,
16        parameters: &[SQLParam],
17    ) -> Result<Option<crate::plan::SharedExecutablePlan>, SQLError>;
18}
19
20/// A successful replacement analysis and the namespace it used, published together against the original definition identity.
21pub struct PreparedPlanAnalysis {
22    pub logical_plan: crate::plan::SharedExecutablePlan,
23    pub effective_search_path:
24        SharedPreparedInput<Option<crate::catalog::resolution::EffectiveSearchPath>>,
25    pub dependencies: SharedPreparedInput<super::dependencies::PreparedAnalysisDependencies>,
26    pub dependency_snapshot:
27        SharedPreparedInput<Option<super::dependencies::PreparedDependencySnapshot>>,
28}
29
30pub struct PreparedPlanUpdate {
31    pub composite_inputs: super::composites::CompositeInputs,
32    pub reanalyzed: Option<PreparedPlanAnalysis>,
33    pub generic_plan: Option<crate::plan::SharedExecutablePlan>,
34    pub generic_cost: Option<f64>,
35    pub custom_cost: Option<f64>,
36}
37
38/// A selected immutable executable and its cache update. Reuse shares the cached executable; custom specialization and composite projection retain separate plans. The owner publishes the update only against the definition it supplied to selection.
39pub struct PreparedPlanSelection {
40    pub plan: crate::plan::SharedExecutablePlan,
41    pub update: PreparedPlanUpdate,
42}