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

Ruben Q L commented on CALCITE-6474:
------------------------------------

Notice that there is a test that should cover this issue in 
{{RelMdMetadataTest}}:
{code}
  @Test void testRowCountAggregateConstantKeys() {
    final String sql = "select distinct deptno from emp where deptno=4";
    sql(sql).assertThatRowCount(is(1D), is(0D), is(1D));
  }
{code}

Unfortunately, since the aggregate's input is small, the "normal" rowCount 
computation returns 0.2, which is adjusted to 1, so the problem is undetected 
(test is successful "by chance").
However, the same test on a bigger input can reproduce the problem.


> Aggregate with constant key can get a RowCount greater than its MaxRowCount
> ---------------------------------------------------------------------------
>
>                 Key: CALCITE-6474
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6474
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.37.0
>            Reporter: Ruben Q L
>            Assignee: Ruben Q L
>            Priority: Major
>             Fix For: 1.38.0
>
>
> An Aggregate with constant key can get a RowCount greater than its 
> MaxRowCount.
> The root cause is that this logic in RelMdMaxRowCount
> {code}
> // Aggregate with constant GROUP BY always returns 1 row
> if (rel.getGroupType() == Aggregate.Group.SIMPLE) {
>   final RelOptPredicateList predicateList =
>     mq.getPulledUpPredicates(rel.getInput());
>   if (!RelOptPredicateList.isEmpty(predicateList)
>     && allGroupKeysAreConstant(rel, predicateList)) {
>     return 1D;
>   }
> }
> {code}
> is not applied in RelMdRowCount.
> Therefore we can get an Aggregate whose MaxRowCount is 1, but its RowCount is 
> X (> 1).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to