Skip to content

test: Add regression test for limit / sort - #26161

Draft
alamb wants to merge 1 commit into
apache:mainfrom
alamb:alamb/limit_sort_test
Draft

alamb wants to merge 1 commit into
apache:mainfrom
alamb:alamb/limit_sort_test

Conversation

@alamb

@alamb alamb commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

@jayzhan211 suggests

This PR also fixes a wrong-result bug on main: with multiple partitions, an OFFSET-only subquery over ORDER BY b followed by ORDER BY b, a returns 1, 21, 4, 24, … on main, because the [b, a] sort is pushed under SortPreservingMergeExec: [b]. Please add a result check so this doesn't regress:

statement ok
set datafusion.execution.target_partitions = 4;

statement ok
CREATE TABLE src (a INT, b INT) AS VALUES (1, 3), (2, 1), (3, 2), (4, 3), (5, 1), (6, 2), (7, 3), (8, 1);

statement ok
CREATE TABLE t AS SELECT a, b FROM src UNION ALL SELECT a + 10, b FROM src
  UNION ALL SELECT a + 20, b FROM src UNION ALL SELECT a + 30, b FROM src;

query II
SELECT * FROM (SELECT a, b FROM t ORDER BY b OFFSET 20) ORDER BY b, a;
----
1 3
4 3
7 3
11 3
14 3
17 3
21 3
24 3
27 3
31 3
34 3
37 3

What changes are included in this PR?

Add this test

What is the testing strategy for this PR?

Are there any user-facing changes?

Only tests

SELECT * FROM (SELECT a, b FROM t ORDER BY b OFFSET 20) ORDER BY b, a;
----
1 3
4 3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note this test fails on main

@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant