@@ -729,7 +729,7 @@ explain select * from testSubQueryLimit as t1 join (select * from testSubQueryLi
729729----
730730logical_plan
73173101)Limit: skip=0, fetch=10
732- 02)--Cross Join:
732+ 02)--Cross Join:
73373303)----SubqueryAlias: t1
73473404)------Limit: skip=0, fetch=10
73573505)--------TableScan: testsubquerylimit projection=[a, b], fetch=10
@@ -754,7 +754,7 @@ explain select * from testSubQueryLimit as t1 join (select * from testSubQueryLi
754754----
755755logical_plan
75675601)Limit: skip=0, fetch=2
757- 02)--Cross Join:
757+ 02)--Cross Join:
75875803)----SubqueryAlias: t1
75975904)------Limit: skip=0, fetch=2
76076005)--------TableScan: testsubquerylimit projection=[a, b], fetch=2
@@ -867,7 +867,7 @@ limit 1000;
867867
868868# Config reset
869869
870- # The SLT runner sets `target_partitions` to 4 instead of using the default, so
870+ # The SLT runner sets `target_partitions` to 4 instead of using the default, so
871871# reset it explicitly.
872872statement ok
873873set datafusion.execution.target_partitions = 4;
@@ -927,3 +927,46 @@ DROP TABLE t;
927927# Tear down src_table table:
928928statement ok
929929DROP TABLE src_table;
930+
931+ # LIMIT must work when SELECT projects columns in different order than table schema
932+
933+ statement ok
934+ CREATE TABLE t21176 (col_a TEXT, col_b DOUBLE, col_c TEXT) AS VALUES
935+ ('a-0', 0, 'c-0'), ('a-1', 1, 'c-1'), ('a-2', 2, 'c-2'), ('a-3', 3, 'c-3'),
936+ ('a-4', 4, 'c-4'), ('a-5', 5, 'c-5'), ('a-6', 6, 'c-6'), ('a-7', 7, 'c-7'),
937+ ('a-8', 8, 'c-8'), ('a-9', 9, 'c-9'), ('a-10', 10, 'c-10'), ('a-11', 11, 'c-11'),
938+ ('a-12', 12, 'c-12'), ('a-13', 13, 'c-13'), ('a-14', 14, 'c-14'), ('a-15', 15, 'c-15'),
939+ ('a-16', 16, 'c-16'), ('a-17', 17, 'c-17'), ('a-18', 18, 'c-18'), ('a-19', 19, 'c-19');
940+
941+ # Schema-order SELECT with LIMIT should return 5 rows
942+ query RT rowsort
943+ SELECT col_b, col_c FROM t21176 LIMIT 5;
944+ ----
945+ 0 c-0
946+ 1 c-1
947+ 2 c-2
948+ 3 c-3
949+ 4 c-4
950+
951+ # Reverse-order SELECT with LIMIT should also return 5 rows (not 20)
952+ query TR rowsort
953+ SELECT col_c, col_b FROM t21176 LIMIT 5;
954+ ----
955+ c-0 0
956+ c-1 1
957+ c-2 2
958+ c-3 3
959+ c-4 4
960+
961+ # Single column reverse SELECT with LIMIT
962+ query T rowsort
963+ SELECT col_c FROM t21176 LIMIT 5;
964+ ----
965+ c-0
966+ c-1
967+ c-2
968+ c-3
969+ c-4
970+
971+ statement ok
972+ DROP TABLE t21176;
0 commit comments