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

xiong duan commented on CALCITE-5117:
-------------------------------------

Fixed in 
[3db4dd1|https://github.com/apache/calcite/commit/3db4dd1ebf04abaf74d29464ae311a598ae929f7].
 Thanks for the review [~Chunwei Lei] .

> Optimize the EXISTS sub-query by Metadata RowCount
> --------------------------------------------------
>
>                 Key: CALCITE-5117
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5117
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.30.0
>            Reporter: xiong duan
>            Assignee: xiong duan
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.31.0
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> As same as the UNIQUE sub-query, before we convert the sub-query to RelNode. 
> we use the Metadata to optimize it.
> EXISTS sub-query, If the sub-query is guaranteed to produce at least one row, 
> just return TRUE. If the sub-query is guaranteed to produce no row, just 
> return FALSE.
> For example:
> {code:java}
> select *
> from dept as d
> where EXISTS (select count(*) from emp e where d.deptno = e.deptno){code}
> We can optimize it to:
> {code:java}
> EnumerableTableScan(table=[[scott, DEPT]]){code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to