[
https://issues.apache.org/jira/browse/CALCITE-6836?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17927175#comment-17927175
]
Steven Phillips commented on CALCITE-6836:
------------------------------------------
I think it's good to have this rule available, although I am curious when it
would be useful. The EXISTS query doesn't seem any more optimal to me, in fact
a little less optimal, because now it's correlated and will need to be
decorrelated.
> Add Rule to convert INTERSECT to EXISTS
> ---------------------------------------
>
> Key: CALCITE-6836
> URL: https://issues.apache.org/jira/browse/CALCITE-6836
> Project: Calcite
> Issue Type: Bug
> Reporter: xiong duan
> Priority: Major
>
> The INTERSECT SQL:
> {code:java}
> SELECT a.CustID FROM tbl1 AS a
> INTERSECT
> SELECT b.CustID FROM tbl2 AS b {code}
> The converted Exists SQL:
> {code:java}
> SELECT DISTINCT a.CustID FROM tbl1 AS a
> WHERE EXISTS (SELECT b.CustID FROM tbl2 b WHERE (a.CustID=b.CustID)) {code}
> This optimized method is also described in the paper(The eighth rule in
> Chapter Three) [Extensible/rule based query rewrite optimization in
> Starburst|https://15799.courses.cs.cmu.edu/spring2025/papers/03-starburst/pirahesh-sigmodrec1992.pdf].
--
This message was sent by Atlassian Jira
(v8.20.10#820010)