pingcap / pingcap/tidb

Window function returns incorrect result

Open
#58,879 0 comments 0 reactions 0 assignees View on GitHub
impact/wrong-result may-affects-5.4 may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```sql
use test;
drop table if exists test.t3;
create table test.t3 (p int, o int, v varchar(100) not null);
insert into test.t3 values (3, 10, "j7jhgvuev"), (3, 20, "pmgo99f3"), (3, 40, ""), (3, 41, "TGh54h54htever");
select p, o, v, min(v) over w as "min", max(v) over w as "max" from t3 window w as (partition by p order by o rows between 2 preceding and 1 following);
```

### 2. What did you expect to see? (Required)

```
+------+------+----------------+-----------+----------------+
| p | o | v | min | max |
+------+------+----------------+-----------+----------------+
| 3 | 10 | j7jhgvuev | j7jhgvuev | pmgo99f3 |
| 3 | 20 | pmgo99f3 | | pmgo99f3 |
| 3 | 40 | | | TGh54h54htever |
| 3 | 41 | TGh54h54htever | | TGh54h54htever |
+------+------+----------------+-----------+----------------+
```

### 3. What did you see instead (Required)

```
+------+------+----------------+-----------+----------+
| p | o | v | min | max |
+------+------+----------------+-----------+----------+
| 3 | 10 | j7jhgvuev | j7jhgvuev | pmgo99f3 |
| 3 | 20 | pmgo99f3 | | pmgo99f3 |
| 3 | 40 | | | pmgo99f3 |
| 3 | 41 | TGh54h54htever | | pmgo99f3 |
+------+------+----------------+-----------+----------+
```

### 4. What is your TiDB version? (Required)

nightly(c44672e0c51c4e50391ffc43902c980eef4c64cb)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.