Dolt ignores secondary `ORDER BY` keys for `RANGE CURRENT ROW` peer groups.
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 120
Description
## What happened
For a `RANGE` frame with multiple `ORDER BY` expressions, Dolt forms peer groups
using only the first order key. MySQL uses the full order key list.
## Environment
Dolt main at commit `a995f245c032bc412aed308194d81ee12bc74f6b0a1fae5fd40e0d` (`dolt version 2.2.3`).
## How to reproduce
In a fresh Dolt repository, run:
```sql
CREATE TABLE t(id INT PRIMARY KEY, k INT, v INT);
INSERT INTO t VALUES
(1,1,10),
(2,1,20),
(3,2,5);
SELECT id,
SUM(v) OVER (
ORDER BY k, id
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS s,
COUNT(*) OVER (
ORDER BY k, id
RANGE BETWEEN CURRENT ROW AND CURRENT ROW
) AS c
FROM t
ORDER BY id;
```
## Expected result
MySQL 8.4.9 returns:
```text
id s c
1 10 1
2 30 1
3 35 1
```
## Actual result
Dolt treats rows `id=1` and `id=2` as peers because they share `k=1`, even
though the secondary `id` order key differs:
```text
id,s,c
1,30,2
2,30,2
3,35,1
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Run the SQL reproduction in a fresh Dolt repository and compare its window-function output with MySQL 8.4.9. No source file or test is named; trace the RANGE CURRENT ROW peer-group handling for multiple ORDER BY expressions, then add coverage showing that the full key list determines peers and the results match the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, mysql, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100