LIMIT directly over VALUES returns every row
Describe the bug
A LIMIT directly over VALUES is ignored: the query returns every row. This happens with both the static and the adaptive planner.
To Reproduce
Standalone Ballista on main (446fa54c9), default settings:
SELECT a FROM (VALUES (0), (1), (2), (3), (4), (5)) AS v(a) LIMIT 2;
-- returns 6 rows
These return the right number of rows:
SELECT count(*) FROM (SELECT a FROM (VALUES (0), (1), (2), (3), (4), (5)) AS v(a) LIMIT 2); -- 2
SELECT a FROM parquet_table LIMIT 2; -- 2 rows
Expected behavior
2 rows.
Additional context
Found by running DataFusion's sqllogictest files on Ballista (#2945): 42 records in 14 files, for example limit.slt:1161 (SELECT col_b, col_c FROM t21176 LIMIT 5 returns 20 rows). A guess I haven't confirmed: the limit is pushed into the memory scan as its fetch, and the fetch is lost before the scan runs on an executor. datafusion-proto's MemoryScanExecNode has a fetch field, so the loss may be on Ballista's side, for example where a scan is restricted to a task's partitions.
take