[ 
https://issues.apache.org/jira/browse/CALCITE-695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14510176#comment-14510176
 ] 

Julian Hyde edited comment on CALCITE-695 at 4/24/15 12:55 AM:
---------------------------------------------------------------

I'd say it's a bug, because we are generating a more complex, and perhaps less 
efficient, expression than we need.

It could be fixed (a) by recognizing the pattern at sql-to-rel time, of (b) 
using a planner rule. For (b) it is not safe to rely on estimated row count, 
but you could rely on RelMetadataQuery.areColumnsUnique or 
RelMetadataQuery.getUniqueKeys for an empty list of columns.


was (Author: julianhyde):
I'd say it's a bug, because we are generating a more complex, and perhaps less 
efficient, expression than we need.

It could be fixed (a) by recognizing the pattern at sql-to-rel time, of (b) 
using a planner rule. For (b) it is not safe to rely on estimated row count, 
but you could rely on RelMdDistinctRowCount or RelMdUniqueKeys.

> SqlSingleValueAggFunction is created when it may not be needed
> --------------------------------------------------------------
>
>                 Key: CALCITE-695
>                 URL: https://issues.apache.org/jira/browse/CALCITE-695
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.3.0-incubating
>            Reporter: Aman Sinha
>            Assignee: Julian Hyde
>
> In the following query, the subquery is producing a scalar value but the 
> logical plan still creates a SqlSingleValueAggFunction.   
> {code}
> select r_regionkey from region
>    where r_regionkey > (select min(n_regionkey) * 2 from nation);
> {code}
> If the aggregate is just min(n_regionkey) instead of the expression 
> min(n_regionkey) * 2 then  no SqlSingleValueAggFunction is created.  Ideally, 
> both should behave the same.  
> This is not necessarily a bug but it does create a burden on the underlying 
> execution engine to support this function even in cases where it may not be 
> needed. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to