Skip to main content

hawdb_optimizer/
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
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct OptimizerConfig {
24    pub max_groups: usize,
25}
26
27impl Default for OptimizerConfig {
28    fn default() -> Self {
29        Self { max_groups: 128 }
30    }
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct OptimizerTrace {
35    pub groups: usize,
36    pub search_mode: SearchMode,
37    pub query_digest: Option<String>,
38    pub selected_plan: String,
39    /// The physical operator-tree shape. Bound values are intentionally absent.
40    pub selected_plan_fingerprint: String,
41    pub selected_plan_cost: PlanCost,
42    pub selected_plan_cost_breakdown: PlanCostBreakdown,
43    pub selected_plan_properties: PhysicalProperties,
44    /// Per-operator cardinalities keyed by stable, plan-local pre-order identities.
45    pub selected_plan_cardinality_estimates: Vec<OperatorCardinalityEstimate>,
46    pub selected_plan_operator_counts: BTreeMap<String, usize>,
47    pub selected_plan_class_counts: BTreeMap<String, usize>,
48    pub warnings: Vec<String>,
49    pub decisions: Vec<String>,
50    pub rule_events: Vec<RuleEvent>,
51    pub stage_events: Vec<StageTrace>,
52}
53
54/// The optimizer's output-cardinality estimate for one physical operator.
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub struct OperatorCardinalityEstimate {
57    pub operator_id: PhysicalOperatorId,
58    pub operator: PhysicalPlanKind,
59    pub estimated_rows: u64,
60}