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::{executor::ExecutionFamily, query::explain::ExplainPlan};
7
8///
9/// TraceExecutionFamily
10///
11/// Trace-surface execution-family label derived from executor family selection.
12/// Keeps high-level route shape visible without exposing executor internals.
13///
14pub type TraceExecutionFamily = ExecutionFamily;
15
16///
17/// QueryTracePlan
18///
19/// Lightweight trace payload for one planned query.
20/// Includes plan hash, selected access strategy summary, and logical explain output.
21///
22#[derive(Clone, Debug, Eq, PartialEq)]
23pub struct QueryTracePlan {
24 pub(crate) plan_hash: String,
25 pub(crate) access_strategy: String,
26 pub(crate) execution_family: Option<TraceExecutionFamily>,
27 pub(crate) explain: ExplainPlan,
28}
29
30impl QueryTracePlan {
31 /// Construct one query trace payload.
32 #[must_use]
33 pub const fn new(
34 plan_hash: String,
35 access_strategy: String,
36 execution_family: Option<TraceExecutionFamily>,
37 explain: ExplainPlan,
38 ) -> Self {
39 Self {
40 plan_hash,
41 access_strategy,
42 execution_family,
43 explain,
44 }
45 }
46
47 /// Borrow the canonical explain fingerprint hash.
48 #[must_use]
49 pub const fn plan_hash(&self) -> &str {
50 self.plan_hash.as_str()
51 }
52
53 /// Borrow the rendered access strategy summary.
54 #[must_use]
55 pub const fn access_strategy(&self) -> &str {
56 self.access_strategy.as_str()
57 }
58
59 /// Return the selected execution family classification.
60 #[must_use]
61 pub const fn execution_family(&self) -> Option<TraceExecutionFamily> {
62 self.execution_family
63 }
64
65 /// Borrow planner explain output carried in this trace payload.
66 #[must_use]
67 pub const fn explain(&self) -> &ExplainPlan {
68 &self.explain
69 }
70}