Skip to content

Fix PostgreSQL covering index columns - #67

Merged
pwelter34 merged 1 commit into
loresoft:mainfrom
DavidBoone:pg-index-include-columns
Sep 5, 2026
Merged

Fix PostgreSQL covering index columns#67
pwelter34 merged 1 commit into
loresoft:mainfrom
DavidBoone:pg-index-include-columns

Conversation

@DavidBoone

Copy link
Copy Markdown
Contributor

Reading a table with an INCLUDE index threw InvalidCastException: "Cannot read a non-nullable collection of elements because the returned array contains nulls". unnest(indkey, indoption) pads the shorter array with nulls, and indoption covers only key columns, so every included column produced a null sort option.

Each array now unnests indkey alone and subscripts indoption by ordinal position, and a new included_columns array feeds AddIncludedColumn so covering indexes keep their non-key columns.

The fixture had no INCLUDE index, so nothing exercised the mismatch. IX_Task_Covering keys on ("StatusId", "PriorityId" DESC) and includes ("Title", "Created"); the descending second key pins the indoption subscripting as well as the included column split, so an off-by-one in either direction fails a test rather than silently moving the sort order onto the wrong column. Reverting the reader with the fixture in place reproduces the original failure across every IndexTests case.

Reading a table with an INCLUDE index threw InvalidCastException:
"Cannot read a non-nullable collection of elements because the returned
array contains nulls". unnest(indkey, indoption) pads the shorter array
with nulls, and indoption covers only key columns, so every included
column produced a null sort option.

Each array now unnests indkey alone and subscripts indoption by ordinal
position, and a new included_columns array feeds AddIncludedColumn so
covering indexes keep their non-key columns.

The fixture had no INCLUDE index, so nothing exercised the mismatch.
IX_Task_Covering keys on ("StatusId", "PriorityId" DESC) and includes
("Title", "Created"); the descending second key pins the indoption
subscripting as well as the included column split, so an off-by-one in
either direction fails a test rather than silently moving the sort order
onto the wrong column. Reverting the reader with the fixture in place
reproduces the original failure across every IndexTests case.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@pwelter34
pwelter34 merged commit a62e273 into loresoft:main Sep 5, 2026
3 checks passed
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.

2 participants