[ 
https://issues.apache.org/jira/browse/CALCITE-7978?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated CALCITE-7978:
------------------------------------
    Labels: pull-request-available  (was: )

> RelMdColumnUniqueness can incorrectly infer that an Aggregate preserves the 
> uniqueness of input column combinations
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-7978
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7978
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>         Environment: 
>            Reporter: zzwqqq
>            Assignee: zzwqqq
>            Priority: Major
>              Labels: pull-request-available
>
> RelMdColumnUniqueness treats (MIN(price), MAX(qty)) as unique because the 
> input pairs (price, qty) are unique, but the two aggregates can take their 
> values from different rows in a group. RelMdUniqueKeys makes the same 
> inference for a declared input key.
> {code:sql}
> SELECT DISTINCT MIN(price) AS min_price, MAX(qty) AS max_qty
> FROM (VALUES ('A', 1, 2), ('B', 1, 1), ('B', 2, 2)) AS sales(shop, price, qty)
> GROUP BY shop;
> {code}
> Actual result
> {code:sql}
> +-----------+---------+
> | MIN_PRICE | MAX_QTY |
> +-----------+---------+
> |         1 |       2 |
> |         1 |       2 |
> +-----------+---------+
> (2 rows)
> {code}
> Expected result
> {code:sql}
> +-----------+---------+
> | MIN_PRICE | MAX_QTY |
> +-----------+---------+
> |         1 |       2 |
> +-----------+---------+
> (1 row)
> {code}
> Consider an input key whose columns are returned directly or by unfiltered 
> aggregates in RelMdColumnUniqueness#PASSTHROUGH_AGGREGATIONS. For a simple 
> GROUP BY, I think either condition is sufficient to preserve the key.
>  * At most one input key column is outside the group set.
>  * The grouping columns are known to be unique in the input.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to