Skip to main content

icydb_core/db/query/
trace.rs

1//! Module: query::trace
2//! Responsibility: lightweight, deterministic trace projections for planned queries.
3//! Does not own: query semantics, plan hashing primitives, or executor routing policy.
4//! Boundary: read-only diagnostics surface assembled at query/session boundaries.
5
6use crate::db::query::explain::ExplainPlan;
7
8///
9/// TraceExecutionStrategy
10///
11/// Trace-surface execution-shape label derived from executor strategy selection.
12/// Keeps high-level route shape visible without exposing executor internals.
13///
14#[derive(Clone, Copy, Debug, Eq, PartialEq)]
15pub enum TraceExecutionStrategy {
16    PrimaryKey,
17    Ordered,
18    Grouped,
19}
20
21///
22/// QueryTracePlan
23///
24/// Lightweight trace payload for one planned query.
25/// Includes plan hash, selected access strategy summary, and logical explain output.
26///
27#[derive(Clone, Debug, Eq, PartialEq)]
28pub struct QueryTracePlan {
29    pub(crate) plan_hash: String,
30    pub(crate) access_strategy: String,
31    pub(crate) execution_strategy: Option<TraceExecutionStrategy>,
32    pub(crate) explain: ExplainPlan,
33}
34
35impl QueryTracePlan {
36    /// Construct one query trace payload.
37    #[must_use]
38    pub const fn new(
39        plan_hash: String,
40        access_strategy: String,
41        execution_strategy: Option<TraceExecutionStrategy>,
42        explain: ExplainPlan,
43    ) -> Self {
44        Self {
45            plan_hash,
46            access_strategy,
47            execution_strategy,
48            explain,
49        }
50    }
51
52    /// Borrow the canonical explain fingerprint hash.
53    #[must_use]
54    pub const fn plan_hash(&self) -> &str {
55        self.plan_hash.as_str()
56    }
57
58    /// Borrow the rendered access strategy summary.
59    #[must_use]
60    pub const fn access_strategy(&self) -> &str {
61        self.access_strategy.as_str()
62    }
63
64    /// Return the selected execution strategy classification.
65    #[must_use]
66    pub const fn execution_strategy(&self) -> Option<TraceExecutionStrategy> {
67        self.execution_strategy
68    }
69
70    /// Borrow planner explain output carried in this trace payload.
71    #[must_use]
72    pub const fn explain(&self) -> &ExplainPlan {
73        &self.explain
74    }
75}