dolthub / dolthub/dolt

Temporal `RANGE INTERVAL` endpoints use incompatible types

Open
#11,463 0 comments 0 reactions 0 assignees View on GitHub
bug correctness customer issue good repro
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 5h
Merged PRs (30d)
108

Description

## What happened

Temporal `RANGE INTERVAL` endpoints use incompatible types.

## Environment

Dolt main commit `91b1a7043126313a349503269230b874afdf8ded` (`dolt version 2.2.3`).

## How to reproduce

```sql
CREATE TABLE ttimeunit(id INT PRIMARY KEY, d TIME, v INT);
INSERT INTO ttimeunit VALUES
(1, '00:00:00', 10),
(2, '00:00:30', 20),
(3, '00:01:00', 30),
(4, '01:00:00', 40);

SELECT id,
COUNT(*) OVER (
ORDER BY d
RANGE BETWEEN INTERVAL 30 SECOND PRECEDING AND CURRENT ROW
) AS c30,
COUNT(*) OVER (
ORDER BY d
RANGE BETWEEN INTERVAL 1 MINUTE PRECEDING AND CURRENT ROW
) AS c60,
COUNT(*) OVER (
ORDER BY d
RANGE BETWEEN INTERVAL 1 HOUR PRECEDING AND CURRENT ROW
) AS c3600
FROM ttimeunit
ORDER BY id;
```

## Expected result

```text
+----+-----+-----+-------+
| id | c30 | c60 | c3600 |
+----+-----+-----+-------+
| 1 | 1 | 1 | 1 |
| 2 | 2 | 2 | 2 |
| 3 | 2 | 3 | 3 |
| 4 | 1 | 1 | 4 |
+----+-----+-----+-------+
```

For example, the 30-second frame at `00:01:00` contains the rows at `00:00:30` and `00:01:00`; the one-hour frame at `01:00:00` contains all four rows. This follows MySQL's documented temporal `RANGE` frame semantics.

## Actual result

Dolt returns an empty frame for every bounded temporal interval:

```text
+----+-----+-----+-------+
| id | c30 | c60 | c3600 |
+----+-----+-----+-------+
| 1 | 0 | 0 | 0 |
| 2 | 0 | 0 | 0 |
| 3 | 0 | 0 | 0 |
| 4 | 0 | 0 | 0 |
+----+-----+-----+-------+
```

Scalar inspection shows that Dolt evaluates `d - INTERVAL 30 SECOND` as a `DATETIME`, while the window order values remain `TIME`.

A `DATE` order key with a sub-day interval shows the same endpoint-type defect:

```sql
CREATE TABLE tdate(id INT PRIMARY KEY, k DATE, v INT NOT NULL);
INSERT INTO tdate VALUES
(1, '2024-01-01', 10), (2, '2024-01-02', 20),
(3, '2024-01-03', 30), (4, '2024-01-05', 50);

SELECT id,
SUM(v) OVER (
ORDER BY k
RANGE BETWEEN INTERVAL 1 HOUR PRECEDING AND CURRENT ROW
) AS wf
FROM tdate ORDER BY id;
```

MySQL's interval arithmetic excludes the prior date because the lower bound for `2024-01-02` is `2024-01-01 23:00:00`; the expected values are `10, 20, 30, 50`. Dolt returns `10, 30, 50, 50`, treating the sub-day bound as if it were truncated to the `DATE` value during comparison.

Contributor guide

No contributing guide indexed for this repository

Research direction

Run the supplied SQL reproducer first, then trace the window RANGE frame endpoint comparison and temporal interval arithmetic for TIME and DATE order keys. Done means bounded frames match the documented expected outputs, including the sub-day DATE case, without changing unrelated frame behavior.

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
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.