Range of Possibilities
Release Notes
New Feature: Temporary Ranges (Subqueries)
ObjectQuel now supports temporary ranges, enabling inline subqueries that create intermediate result sets for advanced query composition.
What's New
Temporary Range Syntax
- Define subqueries inline using the familiar range syntax
- Create intermediate result sets that can be joined with other ranges
- Compute derived values, perform aggregations, or pre-filter data before joining
Intelligent JOIN Optimization
- Automatic nullability analysis determines optimal JOIN types
- LEFT JOIN for potentially NULL fields (aggregates, nullable columns)
- INNER JOIN for guaranteed non-NULL fields (performance optimization)
- Aggregate functions (MAX, MIN, AVG, etc.) correctly handled as nullable
Example Usage
// Find products priced above their category average
$results = $entityManager->executeQuery("
range of avgPrices is (
range of p is App\\Entity\\ProductEntity
retrieve (categoryId=p.categoryId, avg=AVG(p.price))
)
range of p is App\\Entity\\ProductEntity via p.categoryId=avgPrices.categoryId
retrieve (p.name, p.price, avgPrices.avg)
where p.price > avgPrices.avg
");Technical Details
- Subqueries execute first, creating temporary tables in the database
- JOIN type selection based on field nullability from source columns
- Complex expressions conservatively treated as nullable
- Automatic removal of unreferenced temporary ranges during optimization
Use Cases
- Pre-filtering large datasets before joining
- Computing derived values (profit margins, percentages, ratios)
- Combining aggregated data with detail records
- Multi-stage data transformations
Performance Considerations
- Each temporary range creates a database temporary table
- Use appropriate indexes on joined columns
- Keep subqueries focused for optimal performance
- Very large result sets may impact memory usage