What happened
Dolt returns all four rows for a legal SELECT DISTINCT whose projection is a ROW_NUMBER() window, even though the session sql_select_limit is 2. Unsure whether this is ignored or just unsupported?
Environment
Dolt main (commit c3b5ce3c67f8677ca08a0a58d8c03cdc95bff8b7). MySQL version 8.0.43.
How to reproduce
Run the corresponding SQL in a fresh Dolt repository.
CREATE TABLE t(id INT PRIMARY KEY, g INT NOT NULL);
INSERT INTO t VALUES (1, 0), (2, 0), (3, 1), (4, 1);
SET @@sql_select_limit = 2;
SELECT DISTINCT ROW_NUMBER() OVER (ORDER BY id) AS rn
FROM t
ORDER BY rn;
Expected Result
MySQL defines sql_select_limit as the maximum number of rows returned by a SELECT; an explicit LIMIT takes precedence. Window evaluation occurs before ORDER BY, LIMIT, and SELECT DISTINCT, so the four row numbers are formed, the result is distinct, and the first two ordered rows are returned. See the
MySQL sql_select_limit documentation and MySQL window execution order.
The independent SQLite 3 oracle, run with an equivalent explicit LIMIT 2, returns:
What happened
Dolt returns all four rows for a legal
SELECT DISTINCTwhose projection is aROW_NUMBER()window, even though the sessionsql_select_limitis2. Unsure whether this is ignored or just unsupported?Environment
Dolt main (commit
c3b5ce3c67f8677ca08a0a58d8c03cdc95bff8b7). MySQL version 8.0.43.How to reproduce
Run the corresponding SQL in a fresh Dolt repository.
Expected Result
MySQL defines
sql_select_limitas the maximum number of rows returned by aSELECT; an explicitLIMITtakes precedence. Window evaluation occurs beforeORDER BY,LIMIT, andSELECT DISTINCT, so the four row numbers are formed, the result is distinct, and the first two ordered rows are returned. See theMySQL
sql_select_limitdocumentation and MySQL window execution order.The independent SQLite 3 oracle, run with an equivalent explicit
LIMIT 2, returns: