Skip to main content

RirNode

Enum RirNode 

Source
pub enum RirNode {
Show 13 variants Unit, Scan { rel: RelId, }, Filter { input: Box<RirNode>, predicate: Expr, }, Project { input: Box<RirNode>, columns: Vec<ProjectExpr>, }, Join { left: Box<RirNode>, right: Box<RirNode>, left_keys: Vec<usize>, right_keys: Vec<usize>, join_type: JoinType, }, ChainJoin { left: Box<RirNode>, right: Box<RirNode>, left_key: usize, right_key: usize, output_columns: Vec<ProjectExpr>, fallback: Box<RirNode>, }, GroupBy { input: Box<RirNode>, key_cols: Vec<usize>, aggs: Vec<(usize, AggOp)>, }, Union { inputs: Vec<RirNode>, }, Distinct { input: Box<RirNode>, key_cols: Vec<usize>, }, Diff { left: Box<RirNode>, right: Box<RirNode>, }, Fixpoint { scc_id: u32, base: Box<RirNode>, recursive: Box<RirNode>, delta_rel: RelId, full_rel: RelId, }, MultiWayJoin { inputs: Vec<RirNode>, slot_vars: Vec<Vec<Option<u32>>>, output_columns: Vec<ProjectExpr>, fallback: Box<RirNode>, plan: Option<MultiwayPlan>, var_order: Option<VariableOrder>, }, TensorMaskedJoin { mask_name: String, schema_size: usize, left_keys: Vec<usize>, right_keys: Vec<usize>, rel_index: Vec<(RelId, String)>, head_rel_name: String, head_rel_id: RelId, max_active_rules: usize, head_projection: Vec<usize>, },
}
Expand description

Relational IR node types

Variants§

§

Unit

A 0-arity relation containing exactly one empty tuple ({()}).

This is the identity element for joins and the natural seed for rules whose bodies contain no positive atoms (e.g. p() :- not q().), allowing negation-only rules to be lowered as set difference against a unit relation.

§

Scan

Scan a base relation

Fields

§rel: RelId

Relation identifier to scan.

§

Filter

Filter rows by predicate

Fields

§input: Box<RirNode>

Input relation subtree to filter.

§predicate: Expr

Boolean predicate applied to each row.

§

Project

Project specific columns (pass-through or computed)

Fields

§input: Box<RirNode>

Input relation subtree to project from.

§columns: Vec<ProjectExpr>

Output projection expressions in result-column order.

§

Join

Join two relations

Fields

§left: Box<RirNode>

Left-hand input relation.

§right: Box<RirNode>

Right-hand input relation.

§left_keys: Vec<usize>

Column indices from the left input used as join keys.

§right_keys: Vec<usize>

Column indices from the right input used as join keys.

§join_type: JoinType

Join semantics to apply.

§

ChainJoin

Production two-atom chain join: head(...) :- left(..., Z, ...), right(..., Z, ...).

The executor MAY dispatch this node through a specialized physical route. On dispatch decline, it must execute fallback, the IR-equivalent binary join captured at promotion time.

Fields

§left: Box<RirNode>

Left relation input. The chain-join promoter emits a Scan.

§right: Box<RirNode>

Right relation input. The chain-join promoter emits a Scan.

§left_key: usize

Join key column in left.

§right_key: usize

Join key column in right.

§output_columns: Vec<ProjectExpr>

Output projection in head-tuple order.

§fallback: Box<RirNode>

IR-equivalent binary-join plan for fallback execution.

§

GroupBy

Group by with aggregation

Fields

§input: Box<RirNode>

Input relation subtree to aggregate.

§key_cols: Vec<usize>

Column indices preserved as grouping keys.

§aggs: Vec<(usize, AggOp)>

(value_column, aggregation_op)

§

Union

Union multiple inputs

Fields

§inputs: Vec<RirNode>

Input subtrees whose rows are concatenated together.

§

Distinct

Remove duplicates

Fields

§input: Box<RirNode>

Input relation subtree to deduplicate.

§key_cols: Vec<usize>

Column indices defining tuple identity.

§

Diff

Set difference (left - right)

Fields

§left: Box<RirNode>

Left-hand input relation.

§right: Box<RirNode>

Right-hand input relation whose rows are excluded from the left input.

§

Fixpoint

Fixpoint iteration for recursion

Fields

§scc_id: u32

SCC identifier

§base: Box<RirNode>

Base case computation

§recursive: Box<RirNode>

Recursive step computation

§delta_rel: RelId

Relation for delta (new tuples)

§full_rel: RelId

Relation for full result

§

MultiWayJoin

A multi-way conjunctive join that the executor MAY dispatch to a specialized physical operator (e.g. GPU WCOJ). When the dispatch declines, the executor falls through to fallback, which is the IR-equivalent binary-join plan captured at promotion time.

Invariant (upheld by xlog-logic::promote::promote_multiway): executing fallback produces the same row set as a successful specialized dispatch.

The original promoter emitted this for the triangle shape; later promoters also use it for 4-cycle and general-arity joins.

§Walker contract

Generic walkers and visitors that handle MultiWayJoin MUST be shape-agnostic over inputs, slot_vars, and output_columns — no walker may assume a fixed arity or a specific variable-class layout. Only matchers/promoters whose name carries an explicit shape qualifier (e.g. match_multiway_triangle, try_promote_triangle) may lock to a specific shape.

Fields

§inputs: Vec<RirNode>

Input scans, in physical-plan slot order. For the original triangle promoter, this is exactly [Scan(rel_xy), Scan(rel_yz), Scan(rel_xz)] for a recognized triangle. Each input MUST be RirNode::Scan { rel }.

§slot_vars: Vec<Vec<Option<u32>>>

Per-slot, per-column variable-class id. Same id across slots → join on that variable. For the canonical triangle this is [[Some(0), Some(1)], [Some(1), Some(2)], [Some(0), Some(2)]]. None is reserved for constant-bound or don’t-care columns; the v1 promoter never emits None.

§output_columns: Vec<ProjectExpr>

Output projection in head-tuple order, identical to what the equivalent Project { input: Join { ... } } carries. For the triangle: [Column(0), Column(1), Column(3)]. The executor re-validates this; a malformed or rotated projection is treated as ineligible (no dispatch).

§fallback: Box<RirNode>

IR-equivalent binary-join plan. Executed verbatim on dispatch decline. Captured from the post-optimizer tree by the promoter; never synthesized.

§plan: Option<MultiwayPlan>

Structured route for recognized multiway shapes. K-clique cost-gated hash routes are positive plans, not promoter inability to handle the shape.

§var_order: Option<VariableOrder>

Optional adaptive variable-ordering decision.

None preserves legacy triangle, 4-cycle, and recursive dispatch behavior bit-identically: dispatcher uses default leader, no col-swap, post-kernel projection is the existing output_columns.

Some(VariableOrder) instructs the dispatcher to rotate kernel inputs to put leader_idx at slot 0, apply lookup_perms col-swaps, and post-project via kernel_output_cols. output_columns is NOT consulted on the adaptive variable-ordering path; binary-fallback consumers still read it.

§

TensorMaskedJoin

Tensorized ILP super-graph join. A DLPack mask tensor selects which (body_i, body_j) → head_k rule combinations are active.

Fields

§mask_name: String

Name of the mask tensor registered in the runtime.

§schema_size: usize

Arity of the relation schema participating in the tensorized join.

§left_keys: Vec<usize>

Left-side join key columns within the body schema.

§right_keys: Vec<usize>

Right-side join key columns within the body schema.

§rel_index: Vec<(RelId, String)>

Mapping from tensor dimension index → (RelId, relation name). Sorted by RelId for deterministic ordering.

§head_rel_name: String

Head relation name for store lookup in the executor.

§head_rel_id: RelId

Head relation ID for optimizer schema lookup, keyed by RelId.

§max_active_rules: usize

Maximum active rules to process as a budget cap.

§head_projection: Vec<usize>

Column indices from the join result to project into the head schema. Maps head column i to join result column head_projection[i]. Join result columns are: [left_col_0..left_col_n, right_col_0..right_col_m].

Implementations§

Source§

impl RirNode

Source

pub fn is_leaf(&self) -> bool

Check if this node is a leaf (Scan)

Source

pub fn referenced_relations(&self) -> Vec<RelId>

Get all relation IDs referenced in this subtree

Trait Implementations§

Source§

impl Clone for RirNode

Source§

fn clone(&self) -> RirNode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RirNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,