aegis-query
SQL query engine for the Aegis Database Platform.
Overview
aegis-query provides a complete SQL query pipeline including parsing, semantic analysis, query planning, and execution. It supports standard SQL with extensions for time series and document queries.
Features
- SQL Parser - Full SQL syntax support via
sqlparser - Semantic Analyzer - Type checking and schema validation
- Query Planner - Cost-based optimization with rule transformations
- Query Executor - Vectorized execution engine
Architecture
SQL Query
│
▼
┌─────────────┐
│ Parser │ SQL text → AST
└──────┬──────┘
│
▼
┌─────────────┐
│ Analyzer │ AST → Validated AST (types, schema)
└──────┬──────┘
│
▼
┌─────────────┐
│ Planner │ Validated AST → Optimized Plan
└──────┬──────┘
│
▼
┌─────────────┐
│ Executor │ Plan → Results
└─────────────┘
Modules
| Module | Description |
|---|---|
parser |
SQL parsing and tokenization |
ast |
Abstract syntax tree definitions |
analyzer |
Semantic analysis and type checking |
planner |
Query planning and optimization |
executor |
Query execution engine |
Usage
[]
= { = "../aegis-query" }
Example
use ;
let engine = new?;
// Execute a query
let result = engine.execute?;
// Iterate results
for row in result.rows
Supported SQL
DDL:
(
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
users;
users ADD COLUMN status VARCHAR(20);
DML:
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
UPDATE users SET status = 'active' WHERE id = 1;
DELETE FROM users WHERE status = 'inactive';
Queries:
SELECT u.name, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.created_at > '2024-01-01'
GROUP BY u.name
HAVING COUNT(o.id) > 5
ORDER BY order_count DESC
LIMIT 10;
Query Optimization
The planner applies several optimization rules:
- Predicate Pushdown - Move filters closer to data source
- Projection Pruning - Only read needed columns
- Join Reordering - Optimize join order based on cardinality
- Index Selection - Choose optimal indexes for predicates
- Constant Folding - Evaluate constant expressions at plan time
Tests
Test count: 17 tests
License
Apache-2.0