Conversation
This was referenced Oct 4, 2026
Pass 1 listed alternatives for a filtered single-measure aggregate (SQL FILTER, or the IS NOT NULL a COUNT(nullable) implies) but every non-pass-through choice failed to compose. The measure's filter now becomes SummaryAgg.filter, so exact accumulators and sketches (Hydra included) compose, build, and execute. Coverage stays whole-source. A FinalizeExactAccumulator or quantile SummaryEstimate over a filtered build is declared nullable, as the filtered aggregate it realizes is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zzylol
force-pushed
the
stack/509-y2-filtered-aggregates
branch
from
October 5, 2026 06:21
4c68af1 to
e1a4e6d
Compare
zzylol
force-pushed
the
stack/509-y2b-filtered-pass1
branch
from
October 5, 2026 06:21
cabe9d9 to
a90e186
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack: Wave 3 chain: #605 → #607 → #608 → #609 → #610
Rebased on main d4869a7 (DF 54).
Stack: … → #605 → #607 → this PR
Why
Part of #509 and #580 (J, filtered aggregates); Q47 (a). Pass 1 listed alternatives for a filtered single-measure aggregate, but
realizerejected every non-pass-through choice ("filtered or HAVING aggregate"). So these alternatives failed in Stage 1, and the query could only run as written, which #607 makes possible. This covers SQLFILTER (WHERE …)andCOUNT(y)over a nullabley, which is lowered as a count filtered byy IS NOT NULL.What
SELECT g, COUNT(*) FILTER (WHERE x > 0) AS c FROM events GROUP BY gat ε = 0.1, δ = 0.01:Countacc, CMS, CountSketch, UnivMon and HydraCms fail:unsupported local realization: filtered or HAVING aggregateSummaryAggcarriesfilter: x > 0. An alternative binds in the executor exactly when its unfiltered counterpart does. TheCountaccumulator and HydraCms execute to a 2, b 0, c 1, matching the exact plan.For a filtered
SUMand a filteredapprox_percentile_cont, the exactSumaccumulator, KLL and DDSketch execute to the exact answer. They read NULL for the group with no matching row.Selection: the Examples 1, 3a, 3b and 4a stage documents are byte-identical to #607's, and the committed Example 1 fixture is unchanged. Example 2 has no filtered measure (
planner_layering_example2asserts this), and its tests are unchanged. I did not tune costs.How
Pass 1 (
logical_candidates::realize): a single measure's filter becomesSummaryAgg.filter, which reads the same input rows. This applies to every family, Hydra, and tumbling panes, since each pane carries the filter. HAVING stays rejected. The SQL frontend lowers it to aFilterabove the aggregate anyway. A whole-expression (absorbing) target is never filtered.Coverage stays whole-source (Check declared summary coverage population against subtree filters #570: the declared population is trusted). A filtered state holds a subset of its source, so whole-source over-states its population. That is the conservative direction:
A
column = literalfilter could be declared as that population, but nothing reads populations from Pass 1 yet. I did not do this.Types:
FinalizeExactAccumulatorand a quantileSummaryEstimateover a filtered build are declared nullable, like the filtered aggregate each realizes. Without this, a filtered exact SUM read 0.0 for an empty group.Tests
These failed or did not exist on #607:
filtered_aggregates::pass1_offers_filtered_count_alternatives: the six alternatives, the filter on each, bind parity with the unfiltered plan, and execution matching the exact plan.filtered_aggregates::pass1_filtered_sum_and_quantile_alternatives_execute: SUM (exact acc) and percentile (KLL, DDSketch within 2%), with NULL for the empty group.stage_pipeline_selection::sql_filtered_aggregates_dp_equals_exhaustive: a filtered grouped count × a filtered percentile, 18 combinations. The DP equals exhaustive, and none is rejected while being built.filtered_aggregates::exact_filtered_sum_is_null_for_groups_without_matchesfrom #607 now selects the filteredSumaccumulator, and it still reads NULL.Not in this PR
Aggregatestays rejected. The frontends never emit it; SQL HAVING is a post-aggregateFilter.COUNT(*)does not bind (keyed summary weight must be a finalized value column), and filtered ingestion-time precompute is unsupported (executor: filtered aggregates and summary builds #607).Gates
cargo fmt --all --check,cargo clippy --workspace --all-targets --all-features -- -D warnings: pass.cargo test --workspace: 1,652 passed, 23 ignored (feat(planner): Pass 1 offers HydraCms for grouped approximate counts #605: 1,642; executor: filtered aggregates and summary builds #607: 1,649; +3).tools/dag-viewer): 29 ran, 6 skipped.Refs #509, #580, #605.
🤖 Generated with Claude Code