sochdb-query
Query planning and execution engine for SochDB.
Overview
sochdb-query provides the query layer for SochDB, featuring:
- Query Builder: Fluent API for constructing queries
- Query Optimizer: Cost-based optimization for efficient execution
- Projection Pushdown: Only read columns you need
- Filter Pushdown: Apply filters at storage layer
- TOON Output: Token-optimized format (40-66% fewer tokens than JSON)
Features
- SQL-like Queries: Familiar query patterns without SQL parsing overhead
- Path-based Access: O(|path|) resolution independent of data size
- Aggregations: COUNT, SUM, AVG, MIN, MAX with efficient execution
- Sorting & Pagination: ORDER BY, LIMIT, OFFSET support
- Join Support: Nested loop and hash joins
Installation
[]
= "0.2.5"
Usage
Most users should use the high-level sochdb crate:
use ;
let db = open?;
// Query with builder pattern
let results = db.query
.filter
.select
.order_by
.limit
.execute?;
// Results in token-efficient TOON format
println!;
// users[3]{name,email}: Alice,alice@...|Bob,bob@...|Carol,carol@...
Query Execution Pipeline
┌──────────────┐
│ Query │ User query (builder or path)
└──────┬───────┘
│
▼
┌──────────────┐
│ Parse │ Validate and normalize
└──────┬───────┘
│
▼
┌──────────────┐
│ Optimize │ Pushdown filters, projections
└──────┬───────┘
│
▼
┌──────────────┐
│ Execute │ Scan, filter, project, sort
└──────┬───────┘
│
▼
┌──────────────┐
│ Format │ TOON or JSON output
└──────────────┘
Crate Structure
| Crate | Purpose |
|---|---|
sochdb |
High-level client API (start here) |
sochdb-core |
Core types and traits |
sochdb-storage |
Storage engine with WAL |
sochdb-index |
HNSW vector indexing |
sochdb-query |
Query execution (this crate) |
License
Apache-2.0 - see LICENSE for details.