NoahKusaba opened a new issue, #2952:
URL: https://github.com/apache/datafusion-ballista/issues/2952
**Describe the bug**
With the adaptive planner, some queries return their rows in an order that
breaks the query's `ORDER BY`. When the query also has a `LIMIT`, it can return
the wrong rows. The static planner returns the right rows in order.
**To Reproduce**
Standalone Ballista on `main` (446fa54c9) with
`ballista.planner.adaptive.enabled = true` and default settings otherwise.
```sql
WITH t1(a, b) AS (VALUES (1, 10), (2, 20), (3, 30), (4, 40), (5, 50)),
t2(x, y) AS (VALUES (1, 100), (2, 200), (3, 300), (6, 600), (7, 700))
SELECT t1.a, t1.b, t2.x
FROM t1 LEFT JOIN t2 ON t1.a = t2.x AND t1.b > t2.y
ORDER BY t1.b ASC LIMIT 3;
-- returned (order varies between runs): (2, 20, NULL), (1, 10, NULL), (3,
30, NULL)
-- expected: (1, 10, NULL), (2, 20, NULL), (3, 30, NULL)
WITH t1(x, y) AS (VALUES (1, 1), (3, 3)), t2(y, z) AS (VALUES (4, 4))
(SELECT x, y FROM t1 UNION BY NAME SELECT y, z FROM t2 ORDER BY 1)
EXCEPT SELECT NULL, 2, 2 AS two FROM t1
ORDER BY 1;
-- returned: (3, 3, NULL), (1, 1, NULL), (NULL, 4, 4)
-- expected: (1, 1, NULL), (3, 3, NULL), (NULL, 4, 4)
```
Both return the right order with `datafusion.execution.target_partitions =
1`.
**Expected behavior**
Rows in `ORDER BY` order, and the first N rows in that order for `ORDER BY …
LIMIT N`.
**Additional context**
Found by running DataFusion's sqllogictest files on Ballista (#2945).
Records that fail the same way on the adaptive planner only:
- `push_down_topk_through_join.slt` 139, 229, 258, 445, 902, 1006, 1076,
1108, 1236, 1310 (`LEFT JOIN … ORDER BY … LIMIT n`)
- `lateral_join.slt` 185, 195, 205, 215, 308, 403 (`ORDER BY t1.id` over a
`LATERAL` aggregate)
- `union_by_name.slt:243`, `push_down_filter_parquet.slt:1556`
- `join_disable_repartition_joins.slt:96`: `RIGHT SEMI JOIN … ORDER BY a2,
t2.b LIMIT 10` returns unsorted rows, and rows that aren't in the first 10.
--
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]