jayzhan211 commented on code in PR #25053:
URL: https://github.com/apache/datafusion/pull/25053#discussion_r4650093334
##########
datafusion/sqllogictest/test_files/joins.slt:
##########
@@ -6300,3 +6300,86 @@ reset datafusion.optimizer.repartition_file_scans;
statement ok
set datafusion.execution.target_partitions = 4;
+
+# Duplicate probe keys restart the build-side ordering for each matching row.
+statement ok
+set datafusion.execution.target_partitions = 2;
+
+statement ok
+set datafusion.optimizer.prefer_hash_join = false;
+
+statement ok
+CREATE TABLE duplicate_join_left AS VALUES (1, 10), (1, 20), (2, 30);
+
+statement ok
+CREATE TABLE duplicate_join_right AS VALUES (1, 100), (1, 200), (2, 300);
+
+# Sorting the build side alone must not satisfy the output ordering.
+query II
+SELECT l.column1, r.column2
+FROM duplicate_join_left l JOIN duplicate_join_right r ON l.column1 = r.column1
+ORDER BY l.column1, r.column2;
+----
+1 100
+1 100
+1 200
+1 200
+2 300
+
+query II
+SELECT l.column1, r.column2
+FROM duplicate_join_left l JOIN duplicate_join_right r ON l.column1 = r.column1
+ORDER BY l.column1, r.column2 LIMIT 2;
Review Comment:
Agree with @sunchao: the `LIMIT 2` query on the in-memory tables still
passes without the fix, because a TopK stays above the join. An inner hash join
over the ordered `duplicate_ordering` source does catch it: without the fix it
returns `1 10, 1 20`, and with it `1 10, 1 10`. I ran `joins.slt` with this
change on both versions:
```diff
@@ ORDER BY l.column1, r.column2;
1 200
2 300
-query II
-SELECT l.column1, r.column2
-FROM duplicate_join_left l JOIN duplicate_join_right r ON l.column1 =
r.column1
-ORDER BY l.column1, r.column2 LIMIT 2;
-----
-1 100
-1 100
-
query IIII rowsort
@@ ORDER BY r.column1, l.column1, l.column2;
1 1 20
2 NULL NULL
+# Inner join: the build-side ordering must not satisfy ORDER BY ... LIMIT.
+query II
+SELECT r.column1, l.column2
+FROM duplicate_ordering l
+JOIN duplicate_ordering r ON l.column1 = r.column1
+ORDER BY r.column1, l.column2
+LIMIT 2;
+----
+1 10
+1 10
+
statement ok
set datafusion.execution.target_partitions = 4;
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]