#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) enum InstrumentationLevel {
#[default]
Disabled,
PhaseOnly,
Full,
}
impl InstrumentationLevel {
pub fn phase_span_enabled(&self) -> bool {
matches!(self, Self::PhaseOnly | Self::Full)
}
pub fn rule_spans_enabled(&self) -> bool {
matches!(self, Self::Full)
}
}
#[derive(Clone, Debug)]
pub struct RuleInstrumentationOptions {
pub(crate) plan_diff: bool,
pub(crate) analyzer: InstrumentationLevel,
pub(crate) optimizer: InstrumentationLevel,
pub(crate) physical_optimizer: InstrumentationLevel,
}
impl Default for RuleInstrumentationOptions {
fn default() -> Self {
Self {
plan_diff: false,
analyzer: InstrumentationLevel::Disabled,
optimizer: InstrumentationLevel::Disabled,
physical_optimizer: InstrumentationLevel::Disabled,
}
}
}
impl RuleInstrumentationOptions {
pub fn builder() -> RuleInstrumentationOptionsBuilder {
RuleInstrumentationOptionsBuilder::default()
}
pub fn full() -> Self {
Self {
plan_diff: false,
analyzer: InstrumentationLevel::Full,
optimizer: InstrumentationLevel::Full,
physical_optimizer: InstrumentationLevel::Full,
}
}
pub fn phase_only() -> Self {
Self {
plan_diff: false,
analyzer: InstrumentationLevel::PhaseOnly,
optimizer: InstrumentationLevel::PhaseOnly,
physical_optimizer: InstrumentationLevel::PhaseOnly,
}
}
pub fn with_plan_diff(mut self) -> Self {
self.plan_diff = true;
self
}
}
#[derive(Default)]
pub struct RuleInstrumentationOptionsBuilder {
plan_diff: bool,
analyzer: InstrumentationLevel,
optimizer: InstrumentationLevel,
physical_optimizer: InstrumentationLevel,
}
impl RuleInstrumentationOptionsBuilder {
pub fn plan_diff(mut self) -> Self {
self.plan_diff = true;
self
}
pub fn all(mut self) -> Self {
self.analyzer = InstrumentationLevel::Full;
self.optimizer = InstrumentationLevel::Full;
self.physical_optimizer = InstrumentationLevel::Full;
self
}
pub fn all_phase_only(mut self) -> Self {
self.analyzer = InstrumentationLevel::PhaseOnly;
self.optimizer = InstrumentationLevel::PhaseOnly;
self.physical_optimizer = InstrumentationLevel::PhaseOnly;
self
}
pub fn analyzer(mut self) -> Self {
self.analyzer = InstrumentationLevel::Full;
self
}
pub fn analyzer_phase_only(mut self) -> Self {
self.analyzer = InstrumentationLevel::PhaseOnly;
self
}
pub fn optimizer(mut self) -> Self {
self.optimizer = InstrumentationLevel::Full;
self
}
pub fn optimizer_phase_only(mut self) -> Self {
self.optimizer = InstrumentationLevel::PhaseOnly;
self
}
pub fn physical_optimizer(mut self) -> Self {
self.physical_optimizer = InstrumentationLevel::Full;
self
}
pub fn physical_optimizer_phase_only(mut self) -> Self {
self.physical_optimizer = InstrumentationLevel::PhaseOnly;
self
}
pub fn build(self) -> RuleInstrumentationOptions {
RuleInstrumentationOptions {
plan_diff: self.plan_diff,
analyzer: self.analyzer,
optimizer: self.optimizer,
physical_optimizer: self.physical_optimizer,
}
}
}