Skip to main content

hawdb_optimizer_graph/
trace.rs

1// Copyright 2026 Nowledge
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::cost::{PlanCost, PlanCostBreakdown};
16use crate::properties::PhysicalProperties;
17use crate::search::{RuleEvent, SearchMode};
18use crate::stage::StageTrace;
19use hawdb_plan_cypher::{PhysicalOperatorId, PhysicalPlanKind};
20use std::collections::BTreeMap;
21
22pub use hawdb_cascades::OptimizerConfig;
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct OptimizerTrace {
26    pub groups: usize,
27    pub search_mode: SearchMode,
28    pub query_digest: Option<String>,
29    pub selected_plan: String,
30    /// The physical operator-tree shape. Bound values are intentionally absent.
31    pub selected_plan_fingerprint: String,
32    pub selected_plan_cost: PlanCost,
33    pub selected_plan_cost_breakdown: PlanCostBreakdown,
34    pub selected_plan_properties: PhysicalProperties,
35    /// Per-operator cardinalities keyed by stable, plan-local pre-order identities.
36    pub selected_plan_cardinality_estimates: Vec<OperatorCardinalityEstimate>,
37    pub selected_plan_operator_counts: BTreeMap<String, usize>,
38    pub selected_plan_class_counts: BTreeMap<String, usize>,
39    pub warnings: Vec<String>,
40    pub decisions: Vec<String>,
41    pub rule_events: Vec<RuleEvent>,
42    pub stage_events: Vec<StageTrace>,
43}
44
45/// The optimizer's output-cardinality estimate for one physical operator.
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
47pub struct OperatorCardinalityEstimate {
48    pub operator_id: PhysicalOperatorId,
49    pub operator: PhysicalPlanKind,
50    pub estimated_rows: u64,
51}