Skip to main content

Module factorized_join_agg

Module factorized_join_agg 

Source
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Β§

FactorizedJoinAggRule πŸ”’
Rewrites supported AVG/SUM payload products into partial aggregates.
PayloadMatch πŸ”’
The pieces of the AVG/SUM(<fact payload> * <dim payload>) shape the rewrite needs.

EnumsΒ§

PayloadFunction πŸ”’
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 the AVG reconstruction.
matching_payload_shape πŸ”’
Matches the narrow supported AVG(payload * payload) or SUM(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) or SUM(value * weight) aggregate into a join of two partial aggregates whose projection reconstructs the payload function from them.