Skip to content

Dolt drops sql_select_limit #11549

Description

@Yibo-Dong

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:

rn
1
2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcorrectnessWe don't return the same result as MySQLcustomer issueenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions