You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Zhen Chen (Jira)" <ji...@apache.org> on 2025/09/03 04:25:00 UTC
[jira] [Resolved] (CALCITE-4617) Wrong offset when SortJoinTransposeRule pushes a Sort with an offset
[ https://issues.apache.org/jira/browse/CALCITE-4617?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Zhen Chen resolved CALCITE-4617.
--------------------------------
Fix Version/s: 1.41.0
Assignee: Zhen Chen (was: Ruben Q L)
Resolution: Fixed
Fixed in https://github.com/apache/calcite/commit/41e1ab8b8c18b186730b30cd2cbebffe807d86f3
Thanks for the review [~mbudiu][~rubenql]
> Wrong offset when SortJoinTransposeRule pushes a Sort with an offset
> --------------------------------------------------------------------
>
> Key: CALCITE-4617
> URL: https://issues.apache.org/jira/browse/CALCITE-4617
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.26.0
> Reporter: Sylvain Crozon
> Assignee: Zhen Chen
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.41.0
>
> Time Spent: 2h
> Remaining Estimate: 0h
>
> The SortJoinTransposeRule will push a sort node past a join, and then duplicate the sort node on top of the join. When the sort node has an offset, we should only apply it once, otherwise we end up skipping twice as many rows as we should. The sort node added on top of the join should have a null offset.
>
> For example the testSortJoinTranspose6 test checks that for this initial plan
> {code}
> LogicalProject(DEPTNO=[$0], EMPNO=[$2])
> LogicalSort(offset=[2], fetch=[10])
> LogicalJoin(condition=[=($0, $9)], joinType=[right])
> LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {code}
> the SortJoinTransposeRule should convert to
> {code}
> LogicalProject(DEPTNO=[$0], EMPNO=[$2])
> LogicalSort(offset=[2], fetch=[10])
> LogicalJoin(condition=[=($0, $9)], joinType=[right])
> LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
> LogicalSort(offset=[2], fetch=[10])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {code}
> Which will result in applying the offset twice. Instead the LogicalSort on top of the join should just have a null offset
--
This message was sent by Atlassian Jira
(v8.20.10#820010)