You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mihai Budiu (Jira)" <ji...@apache.org> on 2025/12/01 17:41:00 UTC
[jira] [Resolved] (CALCITE-6403) Rule AGGREGATE_EXPAND_DISTINCT_AGGREGATES is unsound
[ https://issues.apache.org/jira/browse/CALCITE-6403?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mihai Budiu resolved CALCITE-6403.
----------------------------------
Fix Version/s: 1.42.0
Resolution: Resolved
> Rule AGGREGATE_EXPAND_DISTINCT_AGGREGATES is unsound
> ----------------------------------------------------
>
> Key: CALCITE-6403
> URL: https://issues.apache.org/jira/browse/CALCITE-6403
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.37.0
> Reporter: Mihai Budiu
> Priority: Minor
> Fix For: 1.42.0
>
>
> Here is a simple SQL program that operates on a collection with no input rows:
> {code:sql}
> SELECT COUNT(*), COUNT(DISTINCT COL1) FROM T WHERE false
> {code}
> The rewrite rule expands this into:
> {code}
> LogicalProject(EXPR$0=[CAST($0):BIGINT NOT NULL], EXPR$1=[$1]), id = 39
> LogicalAggregate(group=[{}], EXPR$0=[MIN($1) FILTER $3], EXPR$1=[COUNT($0) FILTER $2]), id = 37
> LogicalProject(COL1=[$0], EXPR$0=[$1], $g_0=[=($2, 0)], $g_1=[=($2, 1)]), id = 35
> LogicalAggregate(group=[{0}], groups=[[{0}, {}]], EXPR$0=[COUNT()], $g=[GROUPING($0)]), id = 30
> LogicalValues(tuples=[[]]), id = 22
> {code}
> Notice that there is an inner group-by aggregate that produces an empty set, and an outer aggregation that uses MIN. MIN for an empty collection is NULL, whereas the original query should have produced 0.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)