Expand description
Shape-based AVG(value * weight) and SUM(value * weight)
join-aggregation rewrites.
Every rewrite turns ... JOIN ... GROUP BY host, area with a single
aggregate into a join of two partial aggregates computed on one side of the
join each, with a projection above the join reconstructing the aggregate.
Admission is decided by the plan shape alone: the rule never inspects the
data its inputs will read.
AVG(value * weight) / SUM(value * weight): the aggregate over the
pairwise products is replaced by SUM(value) * SUM(weight) divided by
COUNT(value) * COUNT(weight) (AVG) or used as it is (SUM). The counts
are checked individually for zero; for AVG they are cast to Float64
before multiplication to avoid overflowing their Int64 representation.
Β§Approximation contract
The payload rewrite is opt-in rule state and shape-based: it does not inspect the payloads, so it cannot know how well they factorize.
- Floating-point reassociation means the factorized result can differ from the pairwise baseline; on inputs with heavy cancellation, intermediate overflow, or subnormal/extreme magnitudes, it can differ arbitrarily, in magnitude and in sign.
That difference is accepted in this opt-in experiment mode: the opt-in switch and this documentation are the guard, not an admission classifier. Queries whose payloads may be ill-conditioned should keep the switch off.
One difference is removed for free: a zero numerator is normalized to +0.0
(a CASE in the reconstruction), so a cancellation the baseline evaluates to
+0.0 cannot surface here as -0.0.
The rule is intentionally narrow: it matches only the join and group shapes
described by matching_payload_shape. It is registered in the optimizer but
remains inert unless enabled by config/session extension state.
StructsΒ§
- Factorized
Join πAggRule - Rewrites supported AVG/SUM payload products into partial aggregates.
- Payload
Match π - The pieces of the
AVG/SUM(<fact payload> * <dim payload>)shape the rewrite needs.
EnumsΒ§
- Payload
Function π - The payload aggregate a rewrite reconstructs from the branch statistics.
FunctionsΒ§
- column_
at π - column_
expr π - Resolve columns through projections only when they are exact pass-throughs.
- equality_
keys π - field_
type π - float_
literal π - int_
literal π - is_
scan_ πinput - is_zero π
<lhs> = <rhs>, used to detect the zero and NULL cases of theAVGreconstruction.- matching_
payload_ πshape - Matches the narrow supported
AVG(payload * payload)orSUM(payload * payload)shape and returns the join plus everything the rewrite needs from it. - partial_
aggregate π - partial_
aliases π - The four partial-aggregate output names, made collision-free against every field name the rewritten aggregates can still see.
- product_
operands π - The two operands of a payload aggregateβs argument, which must be a multiplication of two columns of the joined inputs, in either order.
- resolve_
expr_ πthrough_ projection - resolve_
through_ πprojection - rewrite_
payload π - Rewrites the matched
AVG(value * weight)orSUM(value * weight)aggregate into a join of two partial aggregates whose projection reconstructs the payload function from them.