Skip to content

fix: avoid crash by setting default index constraint type#508

Merged
staticlibs merged 1 commit into
duckdb:mainfrom
hello-world-bfree:fix/postgres-indexes-constraint-type-assertion
Jul 9, 2026
Merged

fix: avoid crash by setting default index constraint type#508
staticlibs merged 1 commit into
duckdb:mainfrom
hello-world-bfree:fix/postgres-indexes-constraint-type-assertion

Conversation

@hello-world-bfree

@hello-world-bfree hello-world-bfree commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Resolves #507

Problem

duckdb_indexes() scanning an attached Postgres catalog can crash with an internal assertion:

INTERNAL Error: Assertion triggered in file "duckdb/src/parser/parsed_data/create_index_info.cpp" on line 65: constraint_type == IndexConstraintType::UNIQUE || constraint_type == IndexConstraintType::NONE

PostgresIndexSet::LoadEntries constructs a CreateIndexInfo for every Postgres index then lazily loads into the catalog. But it doesn't assign constraint_type. Since the field has no default it ends up being whatever garbage memory that happens to be sitting at the address at the time, which then flows straight into the catalog entry. Anything that later calls ToSQL()/ToString() on it asserts if the value isn't UNIQUE or NONE. That then causes a crash in some scenario

Fix

Explicitly initializing constraint_type to NONE right where the entry is built, the same place every other field on info is already set

CreateIndexInfo info;
info.constraint_type = IndexConstraintType::NONE;
info.SetQualifiedName(...);

@staticlibs staticlibs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@staticlibs staticlibs merged commit 3dc5744 into duckdb:main Jul 9, 2026
7 checks passed
staticlibs pushed a commit that referenced this pull request Jul 9, 2026
This is a backport of the PR #508 to `v1.5-variegata` stable branch.

Resolves #507

`duckdb_indexes()` scanning an attached Postgres catalog can crash with
an internal assertion:

```text
INTERNAL Error: Assertion triggered in file "duckdb/src/parser/parsed_data/create_index_info.cpp" on line 65: constraint_type == IndexConstraintType::UNIQUE || constraint_type == IndexConstraintType::NONE
```

`PostgresIndexSet::LoadEntries` constructs a `CreateIndexInfo` for
every Postgres index then lazily loads into the catalog. But it
doesn't assign `constraint_type`. Since the field has no default it
ends up being whatever garbage memory that happens to be sitting at the
address at the time, which then flows straight into the catalog entry.
Anything that later calls `ToSQL()`/`ToString()` on it asserts if the
value isn't `UNIQUE` or `NONE`. That then causes a crash in some
scenario

Explicitly initializing `constraint_type` to `NONE` right where the
entry is built, the same place every other field on `info` is already
set

```cpp
CreateIndexInfo info;
info.constraint_type = IndexConstraintType::NONE;
info.SetQualifiedName(...);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Catalog index entry bug

2 participants