You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2022/03/29 17:08:00 UTC

[jira] [Commented] (CALCITE-5069) Method of minus's getRowCount has not consider 'except all'

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

Julian Hyde commented on CALCITE-5069:
--------------------------------------

Can you give an example to justify your new formula?

Suppose that
{code:java}
SELECT deptno FROM dept EXCEPT SELECT deptno FROM emp
{code}
returns 2 rows (two departments have no employees in them). Then
{code}
SELECT deptno FROM dept EXCEPT ALL SELECT deptno FROM emp
{code}
will never return fewer than 2 rows, might return a few more (if there are duplicates in the {{dept}} table) but 2 is a reasonably safe estimate.

> Method of minus's getRowCount has not consider 'except all'
> -----------------------------------------------------------
>
>                 Key: CALCITE-5069
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5069
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Xurenhe
>            Assignee: Xurenhe
>            Priority: Major
>
> Current code of *RelMdRowCount* has not consider 'except all', it should be double.
> It's similar to [CALCITE-3287|https://issues.apache.org/jira/browse/CALCITE-3287] and [CALCITE-3988|https://issues.apache.org/jira/browse/CALCITE-3988]
> CODE: *RelMdRowCount#getRowCount(Minus, RelMetadataQuery)*
>  
> {code:java}
> // now
> public @Nullable Double getRowCount(Minus rel, RelMetadataQuery mq) {
>   Double rowCount = null;
>   for (RelNode input : rel.getInputs()) {
>     Double partialRowCount = mq.getRowCount(input);
>     if (rowCount == null
>         || partialRowCount != null && partialRowCount < rowCount) {
>       rowCount = partialRowCount;
>     }
>   }
>   return rowCount;
> }
> // right 
> public @Nullable Double getRowCount(Minus rel, RelMetadataQuery mq) {
>   Double rowCount = null;
>   for (RelNode input : rel.getInputs()) {
>     Double partialRowCount = mq.getRowCount(input);
>     if (rowCount == null
>         || partialRowCount != null && partialRowCount < rowCount) {
>       rowCount = partialRowCount;
>     }
>   }
>   if (rowCount == null || !rel.all) {
>     return rowCount;
>   } else {
>     return rowCount * 2;
>   }
> }{code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)