datalog_ir
Intermediate Representation (IR) types for Datalog query plans.
This library provides a canonical IR definition for representing Datalog query execution plans, suitable for use in query optimizers and execution engines.
Features
- IRNode - Query plan operators (Scan, Map, Filter, Join, Distinct, Union)
- Predicate - Filter conditions with support for comparisons and logical operators
- Schema tracking - Automatic schema propagation through the query tree
- Predicate utilities - Column reference tracking, simplification, and projection adjustment
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
// Create a scan of the "edge" relation
let scan = Scan ;
// Add a filter: x > 5
let filtered = Filter ;
// Project to just the "y" column
let projected = Map ;
// Get the output schema
assert_eq!;
// Pretty print for debugging
println!;
IR Node Types
| Node | Description |
|---|---|
Scan |
Read from a relation (EDB or IDB) |
Map |
Project/transform columns |
Filter |
Select rows matching a predicate |
Join |
Multi-column equi-join of two inputs |
Distinct |
Remove duplicate rows |
Union |
Combine multiple inputs |
Predicate Types
| Predicate | Description |
|---|---|
ColumnEqConst |
Column equals constant |
ColumnNeConst |
Column not equals constant |
ColumnGtConst |
Column greater than constant |
ColumnLtConst |
Column less than constant |
ColumnGeConst |
Column greater or equal |
ColumnLeConst |
Column less or equal |
ColumnsEq |
Two columns are equal |
ColumnsNe |
Two columns are not equal |
And |
Logical AND |
Or |
Logical OR |
True |
Always true (optimization) |
False |
Always false (optimization) |
Example: Building a Join Query
use IRNode;
// Scan two relations
let edges = Scan ;
let nodes = Scan ;
// Join edge.b = node.id
let joined = Join ;
Example: Predicate Manipulation
use Predicate;
// Build a compound predicate: (x > 5) AND (y = z)
let predicate = And;
// Find referenced columns
let columns = predicate.referenced_columns;
assert!;
assert!;
assert!;
// Simplify predicates with constant folding
let with_true = And;
let simplified = with_true.simplify;
assert_eq!;
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.