Skip to content

Sliding window min() returns stale value when all non-NULL values leave the frame #23872

Description

@neilconway

Describe the bug

SlidingMinAccumulator reports a stale minimum when every non-NULL value has been retracted from the window but the frame is still non-empty (i.e., the frame contains only NULLs). Sliding max is correct.

To Reproduce

SELECT id, x,
       MIN(x) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS min_x
FROM (VALUES (1, 3), (2, NULL), (3, NULL)) t(id, x)
ORDER BY id;

==>

+----+------+-------+
| id | x    | min_x |
+----+------+-------+
| 1  | 3    | 3     |
| 2  | NULL | 3     |
| 3  | NULL | 3     |
+----+------+-------+

Expected behavior

Postgres and DuckDB both return the expected results:

+----+------+-------+
| id | x    | min_x |
+----+------+-------+
| 1  | 3    | 3     |
| 2  | NULL | 3     |
| 3  | NULL | NULL  |
+----+------+-------+

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions