xiedeyantu commented on code in PR #4515:
URL: https://github.com/apache/calcite/pull/4515#discussion_r2313544232


##########
core/src/test/resources/sql/planner.iq:
##########
@@ -351,4 +351,179 @@ FROM "scott"."EMP";
 
 !ok
 
+# [CALCITE-4617] Wrong offset when SortJoinTransposeRule pushes a Sort with an 
offset
+select d.deptno, empno from "scott"."DEPT" d
+right join "scott"."EMP" e using (deptno) limit 10 offset 2;
++--------+-------+
+| DEPTNO | EMPNO |
++--------+-------+
+|     10 |  7934 |
+|     20 |  7369 |
+|     20 |  7566 |
+|     20 |  7788 |
+|     20 |  7876 |
+|     20 |  7902 |
+|     30 |  7499 |
+|     30 |  7521 |
+|     30 |  7654 |
+|     30 |  7698 |
++--------+-------+
+(10 rows)
+
+!ok
+EnumerableCalc(expr#0..2=[{inputs}], proj#0..1=[{exprs}])
+  EnumerableLimit(offset=[2], fetch=[10])
+    EnumerableHashJoin(condition=[=($0, $2)], joinType=[right])
+      EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
+        EnumerableTableScan(table=[[scott, DEPT]])
+      EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], DEPTNO=[$t7])

Review Comment:
   If I change the limit to 3, we can get a plan like this:
   ```
   select d.deptno, empno from "scott"."DEPT" d
   right join "scott"."EMP" e using (deptno) limit 3 offset 1;
   +--------+-------+
   | DEPTNO | EMPNO |
   +--------+-------+
   |     20 |  7566 |
   |     30 |  7499 |
   |     30 |  7521 |
   +--------+-------+
   (3 rows)
   
   !ok
   EnumerableCalc(expr#0..2=[{inputs}], proj#0..1=[{exprs}])
     EnumerableLimit(offset=[1], fetch=[3])
       EnumerableHashJoin(condition=[=($0, $2)], joinType=[right])
         EnumerableCalc(expr#0..2=[{inputs}], DEPTNO=[$t0])
           EnumerableTableScan(table=[[scott, DEPT]])
         EnumerableCalc(expr#0..7=[{inputs}], EMPNO=[$t0], DEPTNO=[$t7])
           EnumerableLimit(fetch=[4])
             EnumerableTableScan(table=[[scott, EMP]])
   !plan
   ```
   I think this is affected by the volcano cost choice.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to