oxigdal-query
A high-performance SQL-like query language and cost-based optimizer for geospatial data processing. This crate provides a complete query engine with parsing, optimization, parallel execution, and result caching designed for efficient data filtering and transformation.
Features
- SQL-like Query Language: Parse and execute SQL queries with full support for SELECT, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT, and OFFSET clauses
- Cost-Based Query Optimizer: Intelligent query optimization using cost models for join reordering, predicate pushdown, and constant folding
- Parallel Query Execution: Built-in support for parallelized query execution using Rayon with efficient data batching
- Result Caching: Configurable query result caching with TTL and size limits using DashMap for concurrent access
- Index Selection: Automatic index selection for optimized query execution
- Geospatial Support: Full support for spatial predicates including ST_Intersects and other PostGIS-compatible functions
- Async/Await: Non-blocking asynchronous query execution with Tokio integration
- Error Handling: Comprehensive error types with detailed position information for parsing errors
- Pure Rust: 100% Pure Rust implementation with no C/Fortran dependencies
- Performance: Benchmarked query parser, optimizer, and executor for baseline performance metrics
Installation
Add to your Cargo.toml:
[]
= "0.1.2"
= "0.1.2"
= { = "1", = ["full"] }
Quick Start
Basic Query Parsing and Optimization
use *;
Query Engine with Execution
use *;
async
Query Explanation
use *;
Usage
Basic Query Execution
use *;
async
With Custom Optimizer Configuration
use *;
Query Result Caching
use *;
use Duration;
async
Geospatial Queries
use *;
API Overview
| Module | Description |
|---|---|
parser |
SQL query parsing with AST generation - supports standard SQL SELECT statements |
optimizer |
Cost-based query optimization with configurable rules and heuristics |
executor |
Query execution engine with support for scans, filters, joins, aggregations, and sorting |
cache |
Query result caching with TTL and size management |
index |
Index selection and management for optimized data access |
explain |
Query plan explanation and visualization with cost estimates |
parallel |
Parallel execution utilities for distributed query processing |
error |
Comprehensive error types with detailed diagnostics |
Optimization Rules
The optimizer implements the following optimization strategies:
- Predicate Pushdown: Push filter predicates down to reduce data earlier
- Join Reordering: Reorder joins for optimal execution
- Constant Folding: Pre-compute constant expressions
- Common Subexpression Elimination: Eliminate redundant computations
- Filter Fusion: Combine multiple filters into single operations
- Projection Pushdown: Push column selections down the tree
Performance
Benchmarks on standard hardware demonstrate:
| Operation | Dataset Size | Time |
|---|---|---|
| Parse simple SELECT | N/A | ~10 µs |
| Parse complex query | N/A | ~50 µs |
| Optimize query | N/A | ~100 µs |
| Full table scan | 100k rows | ~1 ms |
| Filtered scan | 100k rows | ~2 ms |
| Aggregate query | 100k rows | ~5 ms |
Run benchmarks locally:
Examples
See the tests directory for comprehensive examples:
parser_test.rs- SQL parsing examples (simple select, joins, aggregates, spatial queries)executor_test.rs- Query execution patternsoptimizer_test.rs- Optimization strategiesend_to_end_test.rs- Complete workflows
Error Handling
This library follows the "no unwrap" policy. All fallible operations return Result<T, QueryError> with specific error variants:
use *;
Documentation
Full documentation is available at docs.rs.
Generate and view local documentation:
Pure Rust
This library is 100% Pure Rust with no C/Fortran dependencies. All functionality works out of the box without external system libraries.
Related Projects
- oxigdal-core - Core geospatial data structures and types
- oxigdal-algorithms - Spatial algorithms and operations
- oxigdal-drivers - Data source drivers (GeoTIFF, GeoJSON, Parquet, etc.)
Contributing
Contributions are welcome! Please ensure:
- No use of
unwrap()- useResult<T, E>instead - All tests pass:
cargo test --all-features - No clippy warnings:
cargo clippy - Code follows COOLJAPAN ecosystem policies
License
Licensed under Apache-2.0.
See LICENSE file for details.
Part of the COOLJAPAN ecosystem for high-performance geospatial and scientific computing in Pure Rust.