[
https://issues.apache.org/jira/browse/CALCITE-7011?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17953805#comment-17953805
]
Yu Xu commented on CALCITE-7011:
--------------------------------
[~asolimando] According to my test, rule FILTER_REDUCE_EXPRESSIONS can achieve
the goal. The effect before and after optimization is:
{code:java}
<Resource name="planBefore">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[OR(=($7, 1), =($7, 1), =($7, 2))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
<Resource name="planAfter">
<![CDATA[
LogicalProject(DEPTNO=[$7])
LogicalFilter(condition=[SEARCH($7, Sarg[1, 2])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
{code}
So there is no need to add additional rules at present. Thank you for your
guidance and I would close the jira ticket.
> Filter conditions should be distinct avoid duplicate condition
> --------------------------------------------------------------
>
> Key: CALCITE-7011
> URL: https://issues.apache.org/jira/browse/CALCITE-7011
> Project: Calcite
> Issue Type: New Feature
> Components: core
> Affects Versions: 1.39.0
> Reporter: Yu Xu
> Assignee: Yu Xu
> Priority: Major
> Labels: pull-request-available
>
> sql:
> {code:java}
> select deptno from emp where deptno=1 or deptno in (1,2) {code}
> currently would convert to a plan:
> {code:java}
> LogicalProject(DEPTNO=[$7])
> LogicalFilter(condition=[OR(=($7, 1), =($7, 1), =($7, 2))])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
> we can find that ($7, 1) is duplicate(in this case in would transform to
> multiple OR), we should distinct the conditions as:
> {code:java}
> LogicalProject(DEPTNO=[$7])
> LogicalFilter(condition=[SEARCH($7, Sarg[1, 2])])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
> maybe we can add a new rule to resolve the issue.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)