Expand description
Query optimizer for efficient execution
This module provides query optimization through clause reordering and AST transformations to maximize index usage and minimize evaluation cost.
§Optimization Strategies
-
Flattening: Collapse nested AND/OR operators
AND(AND(A, B), C)→AND(A, B, C)OR(OR(A, B), C)→OR(A, B, C)
-
Clause Reordering: Order AND clauses for optimal execution
- Indexed fields first (can use index lookups)
- Within indexed fields, order by selectivity (most selective first)
- Non-indexed fields last (require full scans)
-
Selectivity Estimation: Heuristic estimates for field selectivity
kind: 0.1 (10%) - most selective indexed fieldname: 0.01 (1%) - very selectivepath: 0.3 (30%)lang: 0.4 (40%)text: 0.5 (50%) - least selective, not indexed
§Example
ⓘ
use sqry_core::query::optimizer::Optimizer;
use sqry_core::query::registry::FieldRegistry;
let registry = FieldRegistry::with_core_fields();
let optimizer = Optimizer::new(registry);
// Optimize: text:TODO AND kind:function
// Result: kind:function AND text:TODO (indexed first)
let optimized = optimizer.optimize(ast);Structs§
- Optimizer
- Query optimizer that reorders clauses for efficient execution