Files

39 lines
11 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Shape-based `AVG(value * weight)` and `SUM(value * weight)` join-aggregation rewrites."><title>query::optimizer::factorized_join_agg - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-1ed95124.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="query" data-themes="" data-resource-suffix="" data-rustdoc-version="1.98.1 (48a229cea 2026-09-01)" data-channel="1.98.1" data-search-js="search-9944d736.js" data-stringdex-js="stringdex-2da4960a.js" data-settings-js="settings-170eb4bf.js" ><script src="../../../static.files/storage-41dd4d93.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-417ebf0a.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-f7c3ffd8.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><a class="skip-main-content" href="#main-content">Skip to main content</a><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Module factorized_join_agg</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../query/index.html">query</a><span class="version">1.4.0-alpha.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module factorized_<wbr>join_<wbr>agg</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#approximation-contract" title="Approximation contract">Approximation contract</a></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In query::<wbr>optimizer</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content" tabindex="-1"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../index.html">query</a>::<wbr><a href="../index.html">optimizer</a></div><h1>Module <span>factorized_<wbr>join_<wbr>agg</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/query/optimizer/factorized_join_agg.rs.html#15-561">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Shape-based <code>AVG(value * weight)</code> and <code>SUM(value * weight)</code>
join-aggregation rewrites.</p>
<p>Every rewrite turns <code>... JOIN ... GROUP BY host, area</code> 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.</p>
<p><code>AVG(value * weight)</code> / <code>SUM(value * weight)</code>: the aggregate over the
pairwise products is replaced by <code>SUM(value) * SUM(weight)</code> divided by
<code>COUNT(value) * COUNT(weight)</code> (<code>AVG</code>) or used as it is (<code>SUM</code>). The counts
are checked individually for zero; for <code>AVG</code> they are cast to <code>Float64</code>
before multiplication to avoid overflowing their <code>Int64</code> representation.</p>
<h2 id="approximation-contract"><a class="doc-anchor" href="#approximation-contract">§</a>Approximation contract</h2>
<p>The payload rewrite is opt-in rule state and <strong>shape-based</strong>: it does not
inspect the payloads, so it cannot know how well they factorize.</p>
<ul>
<li>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.</li>
</ul>
<p>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.</p>
<p>One difference is removed for free: a zero numerator is normalized to <code>+0.0</code>
(a <code>CASE</code> in the reconstruction), so a cancellation the baseline evaluates to
<code>+0.0</code> cannot surface here as <code>-0.0</code>.</p>
<p>The rule is intentionally narrow: it matches only the join and group shapes
described by <code>matching_payload_shape</code>. It is registered in the optimizer but
remains inert unless enabled by config/session extension state.</p>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.FactorizedJoinAggRule.html" title="struct query::optimizer::factorized_join_agg::FactorizedJoinAggRule">Factorized<wbr>Join<wbr>AggRule</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd>Rewrites supported AVG/SUM payload products into partial aggregates.</dd><dt><a class="struct" href="struct.PayloadMatch.html" title="struct query::optimizer::factorized_join_agg::PayloadMatch">Payload<wbr>Match</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd>The pieces of the <code>AVG</code>/<code>SUM(&lt;fact payload&gt; * &lt;dim payload&gt;)</code> shape the
rewrite needs.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.PayloadFunction.html" title="enum query::optimizer::factorized_join_agg::PayloadFunction">Payload<wbr>Function</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd>The payload aggregate a rewrite reconstructs from the branch statistics.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.column_at.html" title="fn query::optimizer::factorized_join_agg::column_at">column_<wbr>at</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.column_expr.html" title="fn query::optimizer::factorized_join_agg::column_expr">column_<wbr>expr</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd>Resolve columns through projections only when they are exact pass-throughs.</dd><dt><a class="fn" href="fn.equality_keys.html" title="fn query::optimizer::factorized_join_agg::equality_keys">equality_<wbr>keys</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.field_type.html" title="fn query::optimizer::factorized_join_agg::field_type">field_<wbr>type</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.float_literal.html" title="fn query::optimizer::factorized_join_agg::float_literal">float_<wbr>literal</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.int_literal.html" title="fn query::optimizer::factorized_join_agg::int_literal">int_<wbr>literal</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.is_scan_input.html" title="fn query::optimizer::factorized_join_agg::is_scan_input">is_<wbr>scan_<wbr>input</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.is_zero.html" title="fn query::optimizer::factorized_join_agg::is_zero">is_zero</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd><code>&lt;lhs&gt; = &lt;rhs&gt;</code>, used to detect the zero and NULL cases of the <code>AVG</code>
reconstruction.</dd><dt><a class="fn" href="fn.matching_payload_shape.html" title="fn query::optimizer::factorized_join_agg::matching_payload_shape">matching_<wbr>payload_<wbr>shape</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd>Matches the narrow supported <code>AVG(payload * payload)</code> or
<code>SUM(payload * payload)</code> shape and returns the join plus everything the
rewrite needs from it.</dd><dt><a class="fn" href="fn.partial_aggregate.html" title="fn query::optimizer::factorized_join_agg::partial_aggregate">partial_<wbr>aggregate</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.partial_aliases.html" title="fn query::optimizer::factorized_join_agg::partial_aliases">partial_<wbr>aliases</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd>The four partial-aggregate output names, made collision-free against every
field name the rewritten aggregates can still see.</dd><dt><a class="fn" href="fn.product_operands.html" title="fn query::optimizer::factorized_join_agg::product_operands">product_<wbr>operands</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd>The two operands of a payload aggregate’s argument, which must be a
multiplication of two columns of the joined inputs, in either order.</dd><dt><a class="fn" href="fn.resolve_expr_through_projection.html" title="fn query::optimizer::factorized_join_agg::resolve_expr_through_projection">resolve_<wbr>expr_<wbr>through_<wbr>projection</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.resolve_through_projection.html" title="fn query::optimizer::factorized_join_agg::resolve_through_projection">resolve_<wbr>through_<wbr>projection</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dt><a class="fn" href="fn.rewrite_payload.html" title="fn query::optimizer::factorized_join_agg::rewrite_payload">rewrite_<wbr>payload</a><span title="Restricted Visibility">&nbsp;🔒</span> </dt><dd>Rewrites the matched <code>AVG(value * weight)</code> or <code>SUM(value * weight)</code>
aggregate into a join of two partial aggregates whose projection
reconstructs the payload function from them.</dd></dl></section></div></main></body></html>