You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 957c8d6
Browse filesBrowse the repository at this point in the historyBrowse files
fix: keep DISTINCT on mixed aggregate nodes, and correct three mis-tagged functions
Review of the previous commit turned up two problems.
`EliminateAggregateDistinct` stripped a no-op `DISTINCT` from one aggregate
without regard for the others on the same node, which changed which plans
`SingleDistinctToGroupBy` rewrites. That rule keys off how many distinct
aggregates a node has and whether they share an argument, so removing one can
push a node either way: `sum(DISTINCT cast(x)), max(DISTINCT x)` newly
qualified once the max lost its flag, gaining an inner group by it never had,
and where a rewrite happened regardless a shared inner group key turned into a
separate accumulator at that finer grain. Gate the rule on every `DISTINCT` in
the node being `Ignored`. This is conservative - `min(DISTINCT x),
count(DISTINCT y)` now keeps the min flag though no rewrite is possible either
way - but it cannot regress a plan. `group_by.slt` returns to its original
expectations.
`stddev`, `stddev_pop`, `var_samp`, `var_pop` and `approx_median` were tagged
`Unsupported` on the grounds that their accumulators return `not_impl_err!`.
That path is only reached when `SingleDistinctToGroupBy` cannot fire. All five
take a single argument, so the rewrite deduplicates the input for them and
`f(DISTINCT x)` returns the right answer today, as `aggregate.slt:749` already
asserts for `approx_median`. Leave them at the default `Honored` with a comment,
since enforcing `Unsupported` later would have broken those queries. Verified
the remaining `Unsupported` tags: `approx_percentile_cont`, `nth_value` and
`covar_samp` take more than one argument, so no rewrite fires and they silently
return the non-distinct answer, while `approx_percentile_cont_with_weight`
errors.
Also widen the `Honored` and `Unsupported` doc comments, which described only
the accumulator and promised a planning-time rejection that does not exist yet.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015YwFpxheiiUNMadTNyeHiu
# Mixed: only the duplicate-insensitive aggregate loses its DISTINCT
539
+
# Mixed: a node that still needs one DISTINCT keeps all of them, so this rule
540
+
# cannot change which plans SingleDistinctToGroupBy rewrites
540
541
query III
541
542
SELECT g, min(DISTINCT v), sum(DISTINCT v) FROM distinct_simplify_t GROUP BY g ORDER BY g;
542
543
----
@@ -547,12 +548,12 @@ query TT
547
548
EXPLAIN SELECT g, min(DISTINCT v), sum(DISTINCT v) FROM distinct_simplify_t GROUP BY g;
548
549
----
549
550
logical_plan
550
-
01)Aggregate: groupBy=[[distinct_simplify_t.g]], aggr=[[min(distinct_simplify_t.v) AS min(DISTINCT distinct_simplify_t.v), sum(DISTINCT CAST(distinct_simplify_t.v AS Int64))]]
551
+
01)Aggregate: groupBy=[[distinct_simplify_t.g]], aggr=[[min(DISTINCT distinct_simplify_t.v), sum(DISTINCT CAST(distinct_simplify_t.v AS Int64))]]
0 commit comments