Skip to content

first_value and last_value window functions cause 'Internal error' if all values are NULL and IGNORE NULLS is set #20136

Description

@alexk-sr

What happens?

If all values in a partition in the window function are NULL and ORDER BY and IGNORE NULLS is set an error is thrown.

Attempted to access index X within vector of size X

This problem is probably related to #17002

To Reproduce

CREATE TABLE bug_report (order_col int,value_col float,partition_col int);
INSERT INTO bug_report VALUES (2,NULL,10);
INSERT INTO bug_report VALUES (1,NULL,10);

SELECT first_value(value_col ORDER BY order_col IGNORE NULLS) over (PARTITION BY partition_col) FROM bug_report ;
INTERNAL Error:
Attempted to access index 0 within vector of size 0

Stack Trace:

duckdb() [0xa2a636]
duckdb() [0xa2a6f4]
duckdb() [0xa2f551]
duckdb() [0x81663c]
duckdb() [0x19154d6]
duckdb() [0x18f309e]
duckdb() [0x18fdd9f]
duckdb() [0x1906c38]
duckdb() [0x16b2250]
duckdb() [0x16b53d9]
duckdb() [0x16b552b]
duckdb() [0xd144ed]
duckdb() [0xd1cee7]
duckdb() [0xd1d219]
duckdb() [0xd15a61]
duckdb() [0xd1e61e]
/lib/x86_64-linux-gnu/libstdc++.so.6(+0xe1224) [0x7fe0796e1224]
/lib/x86_64-linux-gnu/libc.so.6(+0x92b7b) [0x7fe07946fb7b]
/lib/x86_64-linux-gnu/libc.so.6(+0x1107b8) [0x7fe0794ed7b8]

This error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.
For more information, see https://duckdb.org/docs/stable/dev/internal_errors

OS:

Debian 6.12.41-1 (2025-08-12) x86_64 GNU/Linux

DuckDB Version:

1.4.3

DuckDB Client:

CLI

Hardware:

No response

Full Name:

Alex Kment

Affiliation:

SpiderRock

Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

  • Yes, I have

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant data sets for reproducing the issue?

Yes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions