Module fuse

Module fuse 

Source
Expand description

Query fusion: a plan rewritten into a smaller plan that computes the same thing.

docs/05-tier-lowering.md §5.3:

Query fusion still matters (a for over a view of a view should become one plan, not N+1 lookups); it is a plan-rewrite on symbolic Query nodes, kept symbolic in Core precisely for this.

crate::plan decomposes a view into operators one construct at a time, so it produces the operators the source names: concat_lists(map_list(xs, f)) is a map_list whose arrangement holds one list per element and a flatten that takes them apart again. Nothing reads the arrangement in between. This module is the pass that says so.

§What a rewrite has to preserve, and it is not only the values

An arrangement’s key is what makes iteration order a consequence of the plan rather than of a sort at the end (crate::plan), and the order reaches the rendered page and the replay digest. So a rewrite here has three obligations, not one: the same values, in the same order, and the same deltas — a fused operator has to move exactly the entries the pair moved, or a subscriber woken late updates by a delta that does not describe what happened.

Every rule below is stated with the property that makes it sound, and each is a local rewrite of one consumer and its producer. 38 §38.2 points at equality saturation (egg, egglog) as the machinery for this, and it is not used: equality saturation earns its keep when rewrites conflict and the phase order would decide the answer. None of these conflict — every one removes an operator and none adds one — so the extraction that an e-graph would do by cost is done here by applying rules to a fixed point. §89.6 names what would need one.

§The three conditions, and the second is the interesting one

A producer may be fused into its consumer only when:

  1. nothing else reads itconsumers == 1. An arrangement read twice is 26’s shared prefix, and fusing it into one consumer computes it twice;
  2. the fusion does not cross §5.3’s session cut. A shared operator fused into a per-session one stops being shared: its work moves from once per event to once per event per subscriber, which on a 256-subscriber feed is the 55× that report measured, spent rather than saved. A local rewrite that is an improvement everywhere else is a pessimisation here, and nothing but the cut can tell;
  3. no name points at it. A declared signal is projected as a read-model table (88), so an operator a developer named is observable to a SQL client even when the page does not read it.

Structs§

Fusion
One rewrite that fired.
Fusions
What one run of the pass did.
Refusal
One rewrite that matched a shape and was refused, with the condition that refused it.

Constants§

RULES
Every rule this pass has, by name.

Functions§

fuse
Rewrite a plan to a fixed point.
report
The fusion half of beck explain query.