You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Silun Dong (Jira)" <ji...@apache.org> on 2025/07/24 06:24:00 UTC
[jira] [Comment Edited] (CALCITE-7104) Remove duplicate sort keys
[ https://issues.apache.org/jira/browse/CALCITE-7104?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18009468#comment-18009468 ]
Silun Dong edited comment on CALCITE-7104 at 7/24/25 6:23 AM:
--------------------------------------------------------------
I prefer the recursive check approach. If I understand correctly, as you said, the Project with duplicate columns may not be a child of Sort, but a descendant. Directly matching Sort-Project does not fundamentally solve this problem.
Another point, you mentioned,
{code:java}
select d1 from (select deptno as d1, deptno + 1 as d2 from dept) as tmp order by d1, d2{code}
This case can be simplified to order by d1 only. In other words, the requirement for removing duplicate sort keys can be relaxed from "two keys are essentially the same" to "two keys are generated from the same column idempotent operation".
was (Author: JIRAUSER308615):
I prefer the recursive check approach. If I understand correctly, as you said, the Project with duplicate columns may not be a child of Sort, but a descendant. Directly matching Sort-Project does not fundamentally solve this problem.
Another point, you mentioned,
{code:java}
select d1 from (select deptno as d1, deptno + 1 as d2 from dept) as tmp order by d1, d2{code}
This case can be simplified to order by d1 only. In other words, the requirement for removing duplicate sort keys can be relaxed from "two keys are essentially the same" to "two keys are generated from the same column idempotent operation".
> Remove duplicate sort keys
> --------------------------
>
> Key: CALCITE-7104
> URL: https://issues.apache.org/jira/browse/CALCITE-7104
> Project: Calcite
> Issue Type: Improvement
> Reporter: weihua zhang
> Priority: Major
> Labels: pull-request-available
>
> {code:sql}
> select d1 from (select deptno as d1, deptno as d2 from dept ) as tmp order by d1, d2;
> {code}
> {noformat}
> LogicalProject(D1=[$0]), id = 2284
> LogicalSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[ASC]), id = 2283
> LogicalProject(D1=[$0], D2=[$0]), id = 2282
> LogicalTableScan(table=[[default, dept]]), id = 2278
> {noformat}
> LogicalSort can change to:
> {noformat}
> LogicalProject(D1=[$0]), id = 2284
> LogicalSort(sort0=[$0], dir0=[ASC]), id = 2283
> LogicalProject(D1=[$0], D2=[$0]), id = 2282
> LogicalTableScan(table=[[default, dept]]), id = 2278
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)