Skip to main content

Module wcoj_var_ordering

Module wcoj_var_ordering 

Source
Expand description

Variable-ordering cost model for WCOJ dispatch.

The trait WcojVariableOrderingModel picks the kernel leader slot (slot 0) for triangle and 4-cycle WCOJ shapes. The leader is the input that drives the outer iteration; smaller leaders mean fewer iterations.

The default implementation LeaderCardinalityModel picks the min-cardinality input as leader IFF the ratio min_card / default_leader_card ≤ config.effective_wcoj_var_ordering_threshold(). Marginal cases (above threshold) return None so the promoter leaves var_order = None and default WCOJ dispatch behavior is preserved.

The trait returns only the leader index in the promoter’s canonical input order — the promoter is responsible for building the full [xlog_ir::rir::VariableOrder] using the canonical permutation tables (because computing kernel_output_cols requires the rule’s head-variable order, which only the promoter has).

§Canonical permutation tables

Triangle (canonical inputs [e_xy, e_yz, e_xz], vars {X, Y, Z}):

LeaderSlot 0Slot 1Slot 2Lookup col-swapsKernel-direct output
e_xy 0e_xye_yze_xznone(X, Y, Z)
e_yz 1e_yze_xz↔e_xy↔e_xz, e_xy(Y, Z, X)
e_xz 2e_xze_yz↔e_xye_yz(X, Z, Y)

4-cycle (canonical inputs [e_wx, e_xy, e_yz, e_zw], vars {W, X, Y, Z}) — all rotation-only, no col-swaps:

LeaderSlot 0Slot 1Slot 2Slot 3Kernel-direct output
e_wx 0e_wxe_xye_yze_zw(W, X, Y, Z)
e_xy 1e_xye_yze_zwe_wx(X, Y, Z, W)
e_yz 2e_yze_zwe_wxe_xy(Y, Z, W, X)
e_zw 3e_zwe_wxe_xye_yz(Z, W, X, Y)

Structs§

HeatAwareLeaderModel
Heat-aware cost model: combines cardinality, access heat, and observed join selectivity into a fixed composite score formula. Higher score = more expensive to iterate over → demote from the leader (slot 0). The model picks argmin(score) as leader, gated by the same effective_wcoj_var_ordering_threshold as the leader-cardinality model.
LeaderCardinalityModel
Default implementation: pick the min-cardinality input as leader, gated by the configurable wcoj_var_ordering_threshold ratio.
WcojCostGateParams
Named K-clique WCOJ-vs-hash gate parameters.

Constants§

WCOJ_COST_GATE_PARAMS
Default K-clique cost-gate policy.

Traits§

WcojVariableOrderingModel
Trait that picks a leader slot for triangle / 4-cycle WCOJ.

Functions§

build_cycle4_var_order
Promoter helper: build a complete VariableOrder for a 4-cycle from the cost model’s leader_idx decision.
build_triangle_var_order
Promoter helper: build a complete VariableOrder for a triangle from the cost model’s leader_idx decision.
cycle4_kernel_output_cols
Promoter helper: 4-cycle canonical head-projection table.
cycle4_lookup_perms
Promoter helper: 4-cycle canonical permutation table.
triangle_kernel_output_cols
Promoter helper: triangle canonical head-projection table.
triangle_lookup_perms
Promoter helper: triangle canonical permutation table.
wcoj_cost_gate_predicts_wcoj
Returns true when the named K-clique cost-gate policy routes WCOJ.