- lowering-time atom ordering and RIR construction;
- generic predicate pushdown;
- statistics-backed rewrites for recognized triangle and 4-cycle shapes;
- multiway promotion into WCOJ/Free Join candidates;
- runtime dispatch gates and counters.
Lowering-Time Planning
xlog-logic::lower::Lowerer converts frontend rules into RIR. It owns the first
join-tree shape for ordinary positive atoms and uses greedy ordering/planning
helpers when it builds scan and join nodes.
This is also where predicate names become relation IDs, schemas are inferred,
and stratum order from the dependency analyzer becomes executable SCC order.
Predicate Pushdown
xlog_logic::optimizer::Optimizer currently applies predicate pushdown as its
generic transformation. Filters are moved closer to scans when the predicate can
be evaluated on one side of a join or safely through projection.
The optimizer has a cost type, a default transfer multiplier, and a
dp_threshold configuration field, but broad dynamic-programming join ordering
is not the active generic planner. Do not document it as a universal SQL-style
join optimizer.
Selectivity Rewrites
Theselectivity_pass is shape-specific. It recognizes canonical lowered
triangle and 4-cycle bodies, estimates candidate inner pairings with
StatsManager::estimate_join_cardinality, and rewrites only when statistics
make a valid lower-cost pairing available.
Safety floors:
- unrecognized shapes are left unchanged;
- missing or zero cardinality entries leave the body unchanged;
- ties keep the existing order;
- recursive SCC bodies stay on the safe default order.
Multiway Promotion
promote_multiway identifies eligible bodies and emits RirNode::MultiWayJoin
for runtime dispatch. It coordinates with statistics, variable-order settings,
and shape rules so the runtime can decide between:
- dedicated WCOJ kernels;
- main-only Free Join routes;
- ordinary binary fallback.
Runtime Planning
The executor adds runtime information the compiler cannot know:- actual relation buffers and row counts;
- relation generations and cache state;
- available device budget;
- CUDA provider capabilities;
- kill switches;
- route-specific counters and error-decline counts.
wcoj_cost_model also plans Free Join order and
uses a factorized-loss veto so a route can decline when the known workload would
lose the intended benefit.
Statistics Layer
xlog-stats::StatsManager stores:
- relation cardinality and byte-size estimates;
- column statistics where available;
- join selectivity observations;
- heat used by adaptive indexing decisions.
Documentation Rules
When documenting optimizer behavior:- say “predicate pushdown” for the generic optimizer;
- say “shape-specific selectivity rewrite” for triangle and 4-cycle pairing;
- say “multiway promotion” for RIR conversion into dispatch candidates;
- say “runtime dispatch” for actual WCOJ, Free Join, nested-loop, or hash-join execution;
- avoid “DP optimizer” unless a concrete future implementation lands and is verified through the compile path.