msirek opened a new issue, #8048: URL: https://github.com/apache/arrow-datafusion/issues/8048
### Describe the bug While testing #8038, I ran into some incorrect results cases in LIMIT queries. ### To Reproduce ```sql ❯ CREATE TABLE IF NOT EXISTS t1 (a INT) AS VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); 0 rows in set. Query took 0.009 seconds. ❯ EXPLAIN SELECT COUNT(*) FROM (SELECT a FROM t1 WHERE a > 3 LIMIT 3 OFFSET 6); +---------------+---------------------------------------------------------------+ | plan_type | plan | +---------------+---------------------------------------------------------------+ | logical_plan | Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1)) AS COUNT(*)]] | | | Limit: skip=6, fetch=3 | | | Filter: t1.a > Int32(3) | | | TableScan: t1 projection=[a] | | physical_plan | ProjectionExec: expr=[9 as COUNT(*)] | | | EmptyExec: produce_one_row=true | | | | +---------------+---------------------------------------------------------------+ 2 rows in set. Query took 0.015 seconds. -- The correct answer is 1. ❯ SELECT COUNT(*) FROM (SELECT a FROM t1 WHERE a > 3 LIMIT 3 OFFSET 6); +----------+ | COUNT(*) | +----------+ | 9 | +----------+ ❯ CREATE EXTERNAL TABLE sales(customer_id VARCHAR, revenue BIGINT) STORED AS CSV location '/home/ms/git/arrow-datafusion/datafusion/core/tests/data/customer.csv'; 0 rows in set. Query took 0.002 seconds. -- The correct answer is 1. ❯ SELECT COUNT(*) FROM (SELECT customer_id FROM sales LIMIT 10000000000); +-------------+ | COUNT(*) | +-------------+ | 10000000000 | +-------------+ 1 row in set. Query took 0.009 seconds. ❯ explain SELECT COUNT(*) FROM (SELECT customer_id FROM sales LIMIT 10000000000); +---------------+---------------------------------------------------------------+ | plan_type | plan | +---------------+---------------------------------------------------------------+ | logical_plan | Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1)) AS COUNT(*)]] | | | Limit: skip=0, fetch=10000000000 | | | TableScan: sales projection=[], fetch=10000000000 | | physical_plan | ProjectionExec: expr=[10000000000 as COUNT(*)] | | | EmptyExec: produce_one_row=true | | | | +---------------+---------------------------------------------------------------+ 2 rows in set. Query took 0.015 seconds. ``` ### Expected behavior Correct results from query execution ### Additional context _No response_ -- 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]
