Skip to main content

Module optimizer

Module optimizer 

Source
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

  1. Flattening: Collapse nested AND/OR operators

    • AND(AND(A, B), C)AND(A, B, C)
    • OR(OR(A, B), C)OR(A, B, C)
  2. 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)
  3. Selectivity Estimation: Heuristic estimates for field selectivity

    • kind: 0.1 (10%) - most selective indexed field
    • name: 0.01 (1%) - very selective
    • path: 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