Skip to main content

uqa_sql/plan/
optimization.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! SQL-plan contract for a caller-selected executable planner.
8
9use super::UnifiedPlan;
10use crate::{binding::statements::AnalyzedResult, SQLError, SQLParam};
11
12/// Analyze and optimize a logical plan using metadata captured for this call.
13pub trait ExecutablePlanOptimizer {
14    /// Return an executable and whether its analysis inputs permit reuse across
15    /// ordinary messages. Planners without that evidence must analyze again.
16    fn plan_for_statement_cache(
17        &self,
18        plan: UnifiedPlan,
19        params: &[SQLParam],
20    ) -> Result<(UnifiedPlan, bool), SQLError> {
21        self.plan_for_execution(plan, params)
22            .map(|plan| (plan, false))
23    }
24
25    fn plan_for_execution(
26        &self,
27        plan: UnifiedPlan,
28        params: &[SQLParam],
29    ) -> Result<UnifiedPlan, SQLError>;
30
31    /// Analyze and optimize a logical plan, and return what its analysis derives about its result.
32    fn plan_with_result(
33        &self,
34        plan: UnifiedPlan,
35        params: &[SQLParam],
36    ) -> Result<(UnifiedPlan, AnalyzedResult), SQLError>;
37}