pub struct MLQueryOptimizer { /* private fields */ }Expand description
ML-based query optimizer with adaptive learning
Uses SciRS2-core features for advanced query optimization:
- Statistical cardinality prediction with continuous learning
- Adaptive join ordering based on execution feedback
- Pattern-based optimization strategies
- Continuous learning from execution feedback
This is a foundation for future ML integration including:
- GPU-accelerated histogram processing
- Neural architecture search for join ordering
- Quantum-inspired graph optimization
Implementations§
Source§impl MLQueryOptimizer
impl MLQueryOptimizer
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ML query optimizer
Initializes GPU context (if available), ML pipeline, neural architecture search, and quantum optimizer for advanced query optimization.
Sourcepub fn with_config(config: MLOptimizerConfig) -> Self
pub fn with_config(config: MLOptimizerConfig) -> Self
Create with custom configuration
Sourcepub fn predict_cardinality(&self, features: &PatternFeatures) -> Result<usize>
pub fn predict_cardinality(&self, features: &PatternFeatures) -> Result<usize>
Predict query cardinality using trained model
Uses learned weights for cardinality prediction. Falls back to heuristic if ML model not yet trained.
Sourcepub fn optimize_join_order(
&self,
pattern_count: usize,
features: &PatternFeatures,
) -> Result<Vec<usize>>
pub fn optimize_join_order( &self, pattern_count: usize, features: &PatternFeatures, ) -> Result<Vec<usize>>
Optimize join order using adaptive strategy
Uses learned heuristics to determine optimal join ordering for the given query pattern. Returns recommended join order based on selectivity.
Sourcepub fn train_from_execution(
&mut self,
features: PatternFeatures,
actual_cardinality: usize,
execution_time_ms: f64,
) -> Result<()>
pub fn train_from_execution( &mut self, features: PatternFeatures, actual_cardinality: usize, execution_time_ms: f64, ) -> Result<()>
Train the optimizer from execution feedback
Adds execution data to training buffer and triggers retraining when sufficient samples are collected. This enables continuous learning and adaptation to workload characteristics.
Sourcepub fn optimize(
&mut self,
features: PatternFeatures,
) -> Result<MLOptimizationResult>
pub fn optimize( &mut self, features: PatternFeatures, ) -> Result<MLOptimizationResult>
Get comprehensive optimization recommendation
Combines ML techniques (cardinality prediction, adaptive join ordering) to provide comprehensive optimization guidance for query execution.
Sourcepub fn training_stats(&self) -> Result<TrainingStats>
pub fn training_stats(&self) -> Result<TrainingStats>
Get training statistics
Sourcepub fn performance_metrics(&self) -> PerformanceMetrics
pub fn performance_metrics(&self) -> PerformanceMetrics
Get performance metrics for the ML optimizer
Returns comprehensive performance statistics including:
- Number of predictions made
- Number of training operations
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MLQueryOptimizer
impl RefUnwindSafe for MLQueryOptimizer
impl Send for MLQueryOptimizer
impl Sync for MLQueryOptimizer
impl Unpin for MLQueryOptimizer
impl UnsafeUnpin for MLQueryOptimizer
impl UnwindSafe for MLQueryOptimizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more