Describe the bug
Sliding aggregate window functions can return incorrect results when a bounded RANGE frame transitions from non-empty to empty and then back to non-empty.
The empty frame returns the correct default value, but the accumulator retains values from the previous frame. These stale values are included in subsequent results.
To Reproduce
SELECT k,
SUM(v) OVER w,
COUNT(v) OVER w,
MIN(v) OVER w,
MAX(v) OVER w
FROM (VALUES
(0, 100),
(10, 90),
(30, 10),
(40, 20)
) AS t(k, v)
WINDOW w AS (
ORDER BY k
RANGE BETWEEN 10 PRECEDING AND 5 PRECEDING
);
Current result:
0 NULL 0 NULL NULL
10 100 1 100 100
30 NULL 0 NULL NULL
40 110 2 10 100
Expected behavior
0 NULL 0 NULL NULL
10 100 1 100 100
30 NULL 0 NULL NULL
40 10 1 10 10
Additional context
No response
Describe the bug
Sliding aggregate window functions can return incorrect results when a bounded
RANGEframe transitions from non-empty to empty and then back to non-empty.The empty frame returns the correct default value, but the accumulator retains values from the previous frame. These stale values are included in subsequent results.
To Reproduce
Current result:
Expected behavior
Additional context
No response