Expand description
Adaptive query execution with runtime cardinality feedback.
This module provides adaptive execution capabilities that allow the query engine to adjust its execution strategy based on actual runtime cardinalities.
The key insight is that cardinality estimates can be significantly wrong, especially for complex predicates or skewed data. By tracking actual row counts during execution, we can detect when our estimates are off and potentially re-optimize the remaining query plan.
§Architecture
┌─────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Optimizer │────>│ Estimated Cards │ │ CardinalityFeed │
└─────────────┘ └──────────────────┘ │ back │
│ └────────┬────────┘
v │
┌──────────────────┐ │
│ AdaptiveContext │<─────────────┘
└────────┬─────────┘
│
┌────────v─────────┐
│ ReoptimizeCheck │
└──────────────────┘§Example
ⓘ
use grafeo_core::execution::adaptive::{AdaptiveContext, CardinalityCheckpoint};
// Set up adaptive context with estimated cardinalities
let mut ctx = AdaptiveContext::new();
ctx.set_estimate("scan_1", 1000.0);
ctx.set_estimate("filter_1", 100.0); // Expected 10% selectivity
// During execution, record actuals
ctx.record_actual("scan_1", 1000);
ctx.record_actual("filter_1", 500); // Actual 50% selectivity!
// Check if re-optimization is warranted
if ctx.should_reoptimize() {
// Re-plan remaining operators with updated statistics
}Structs§
- Adaptive
Checkpoint - A checkpoint during adaptive execution where plan switching can occur.
- Adaptive
Context - Context for adaptive query execution.
- Adaptive
Execution Config - Configuration for adaptive execution, built by
AdaptivePipelineBuilder. - Adaptive
Execution Result - Result of executing an adaptive pipeline.
- Adaptive
Pipeline Builder - Builder for creating adaptive pipelines.
- Adaptive
Pipeline Config - Configuration for adaptive pipeline execution.
- Adaptive
Pipeline Executor - High-level adaptive pipeline that executes a pull-based operator with cardinality tracking using push-based infrastructure.
- Adaptive
Summary - Summary of adaptive execution statistics.
- Cardinality
Checkpoint - A checkpoint for tracking cardinality at a specific point in the plan.
- Cardinality
Feedback - Feedback from runtime execution about actual cardinalities.
- Cardinality
Tracking Operator - A wrapper operator that tracks cardinality and reports to an adaptive context.
- Cardinality
Tracking Sink - A sink that tracks cardinality of data flowing through it.
- Cardinality
Tracking Wrapper - A wrapper that tracks cardinality for pull-based operators.
- Shared
Adaptive Context - Thread-safe wrapper for
AdaptiveContext.
Enums§
- Adaptive
Event - Event emitted during adaptive execution.
- Reoptimization
Decision - Decision about whether to re-optimize a query.
Constants§
- DEFAULT_
REOPTIMIZATION_ THRESHOLD - Threshold for deviation that triggers re-optimization consideration. A value of 2.0 means actual cardinality is 2x or 0.5x the estimate.
- MIN_
ROWS_ FOR_ REOPTIMIZATION - Minimum number of rows before considering re-optimization. Helps avoid thrashing on small result sets.
Functions§
- evaluate_
reoptimization - Evaluates whether re-optimization should occur based on context.
- execute_
adaptive - Convenience function to execute a pull-based operator with adaptive tracking.
Type Aliases§
- Adaptive
Event Callback - Callback for observing adaptive execution events.
- Plan
Factory - Callback for creating a new plan based on observed cardinalities.