use std::collections::BTreeMap;
use lora_compiler::PlanTree;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlanShape {
ReadOnly,
Mutating,
}
impl PlanShape {
pub fn is_mutating(self) -> bool {
matches!(self, PlanShape::Mutating)
}
pub fn as_str(self) -> &'static str {
match self {
PlanShape::ReadOnly => "readOnly",
PlanShape::Mutating => "mutating",
}
}
}
impl From<lora_executor::StreamShape> for PlanShape {
fn from(value: lora_executor::StreamShape) -> Self {
match value {
lora_executor::StreamShape::ReadOnly => PlanShape::ReadOnly,
lora_executor::StreamShape::Mutating => PlanShape::Mutating,
}
}
}
#[derive(Debug, Clone)]
pub struct QueryPlan {
pub query: String,
pub tree: PlanTree,
pub shape: PlanShape,
pub result_columns: Vec<String>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ProfileMetrics {
pub total_elapsed_ns: u64,
pub total_rows: u64,
pub mutated: bool,
pub per_operator: BTreeMap<usize, OperatorMetrics>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct OperatorMetrics {
pub rows: u64,
pub db_hits: u64,
pub elapsed_ns: u64,
pub next_calls: u64,
}
#[derive(Debug, Clone)]
pub struct QueryProfile {
pub plan: QueryPlan,
pub metrics: ProfileMetrics,
}