pub struct PlanObservation {
pub template_hash: String,
pub plan_fingerprint: String,
pub features: CorrectionFeatures,
pub actual_rows: u64,
pub latency_ms: Option<f64>,
}Expand description
An observation captured together with the plan-shape features the corrector will be handed at inference time.
§Why this exists alongside Observation
Observation records only est_rows and actual_rows. Training from
it forces the trainer to synthesise a feature vector with
baseline_estimate set and the other six slots zeroed — while at
inference time an adapter fills all seven. A tree model never splits on
a feature that was constant during training, so six of the seven
features are dead weight and the corrector is effectively
one-dimensional. That is a silent train/serve skew, not a crash, which
is why it survived so long.
PlanObservation closes it by recording what the corrector will
actually see. Prefer it for anything that will be trained on.
§Examples
use samkhya_core::feedback::PlanObservation;
use samkhya_core::residual::CorrectionFeatures;
let obs = PlanObservation {
template_hash: "q7".into(),
plan_fingerprint: "hash-join#1".into(),
features: CorrectionFeatures { baseline_estimate: 10, ..Default::default() },
actual_rows: 100,
latency_ms: None,
};
// 10x under-estimate.
assert!((obs.q_error() - 10.0).abs() < 1e-9);Fields§
§template_hash: String§plan_fingerprint: String§features: CorrectionFeaturesThe feature vector the corrector saw, including baseline_estimate.
actual_rows: u64§latency_ms: Option<f64>Implementations§
Source§impl PlanObservation
impl PlanObservation
Sourcepub fn q_error(&self) -> f64
pub fn q_error(&self) -> f64
Multiplicative q-error against the baseline estimate. f64::INFINITY
when either side is zero, matching Observation::q_error.
Sourcepub fn to_observation(&self) -> Observation
pub fn to_observation(&self) -> Observation
Reduce to the legacy shape, discarding the plan features.
Trait Implementations§
Source§impl Clone for PlanObservation
impl Clone for PlanObservation
Source§fn clone(&self) -> PlanObservation
fn clone(&self) -> PlanObservation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more