ROADMAP v0.3.0 - Multi-plan generation for cost-based optimization (see ROADMAP.md §5)
(
&mut self,
document: &Document,
)
| 320 | /// Plan a query with multiple alternatives for comparison |
| 321 | #[allow(dead_code)] // ROADMAP v0.3.0 - Multi-plan generation for cost-based optimization (see ROADMAP.md §5) |
| 322 | pub fn plan_query_with_alternatives( |
| 323 | &mut self, |
| 324 | document: &Document, |
| 325 | ) -> Result<QueryPlanAlternatives, PlanningError> { |
| 326 | let _start_time = std::time::Instant::now(); |
| 327 | |
| 328 | // Extract query from document |
| 329 | let query = match &document.statement { |
| 330 | crate::ast::Statement::Query(q) => q, |
| 331 | _ => { |
| 332 | return Err(PlanningError::InvalidQuery( |
| 333 | "Document does not contain a query statement".to_string(), |
| 334 | )) |
| 335 | } |
| 336 | }; |
| 337 | |
| 338 | // Generate logical plan |
| 339 | let logical_plan = self.create_logical_plan(query)?; |
| 340 | |
| 341 | // Generate multiple physical plan alternatives |
| 342 | let mut physical_plans = Vec::new(); |
| 343 | |
| 344 | // Plan 1: Basic plan without heavy optimization |
| 345 | let basic_physical = PhysicalPlan::from_logical(&logical_plan); |
| 346 | physical_plans.push(basic_physical.clone()); |
| 347 | |
| 348 | // Plan 2: Optimized plan |
| 349 | let optimized_logical = self.optimize_logical_plan(logical_plan.clone())?; |
| 350 | let optimized_physical = self.create_physical_plan(optimized_logical)?; |
| 351 | physical_plans.push(optimized_physical.clone()); |
| 352 | |
| 353 | // Plan 3: Alternative join orders (if applicable) |
| 354 | if matches!( |
| 355 | self.optimization_level, |
| 356 | OptimizationLevel::Advanced | OptimizationLevel::Aggressive |
| 357 | ) { |
| 358 | if let Ok(alternative) = self.generate_join_alternatives(&logical_plan) { |
| 359 | physical_plans.push(alternative); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // Select best plan based on cost |
| 364 | let best_plan = self.select_best_plan(&physical_plans)?; |
| 365 | |
| 366 | let planning_time = _start_time.elapsed().as_millis() as u64; |
| 367 | |
| 368 | Ok(QueryPlanAlternatives { |
| 369 | plans: physical_plans, |
| 370 | best_plan, |
| 371 | planning_time_ms: planning_time, |
| 372 | }) |
| 373 | } |
| 374 | |
| 375 | /// Create logical plan from query AST |
| 376 | fn create_logical_plan(&mut self, query: &Query) -> Result<LogicalPlan, PlanningError> { |
nothing calls this directly
no test coverage detected