Skip to content

Fix crash when merging chunks with different column layouts - #10667

Merged
svenklemm merged 1 commit into
mainfrom
sven/merge_chunk_layout
Sep 28, 2026
Merged

svenklemm merged 1 commit into
mainfrom
sven/merge_chunk_layout

Conversation

@svenklemm

@svenklemm svenklemm commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Chunks created before and after a column was dropped have different
physical column layouts. Merging such chunks copied rows by column
position, which crashed or corrupted data. Rows are now converted by
column name when the layouts differ.

Fixes #10665

Disable-check: loader-change

@github-actions

Copy link
Copy Markdown

@pnthao, @kpan2034: please review this pull request.

Powered by pull-review

@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.62745% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tsl/src/chunk_merge.c 68.62% 12 Missing and 4 partials ⚠️

πŸ“’ Thoughts on this report? Let us know!

@svenklemm
svenklemm force-pushed the sven/merge_chunk_layout branch 2 times, most recently from fc65466 to 9c5c643 Compare September 25, 2026 13:26
Comment thread tsl/src/chunk_merge.c Outdated
Comment on lines +678 to +679
/* Exclusive lock so that hint bits get set, which the rewrite needs */
LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);

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.

I don't understand this, can you explain more? Looks like heapam_relation_copy_for_cluster uses only BUFFER_LOCK_SHARE. The hint bits are only an optimization for reading, why is it important here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is copied from pg source, older versions used BUFFER_LOCK_SHARE but pg19 uses BUFFER_LOCK_EXCLUSIVE

https://github.com/postgres/postgres/blob/45da2c1d75663d7a692f967b77df42a84fdd6b4d/src/backend/access/heap/heapam_handler.c#L767-L782

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

made this conditional per pg19

Comment thread tsl/src/chunk_merge.c
NULL,
false,
cutoffs->OldestXmin,
if (map != NULL)

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.

If it's easy to make your new function apply an "empty map", consider running it always, and not running table_relation_copy_for_cluster at all. The mismatched layout is relatively rare, so this function won't be called often in the current approach, and might have rare bugs. If we call it always, it will be better covered.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is supposed to be fastpath so not a fan of removing it

@svenklemm
svenklemm force-pushed the sven/merge_chunk_layout branch 2 times, most recently from b7fa558 to 57fcbdb Compare September 26, 2026 07:25
Chunks created before and after a column was dropped have different
physical column layouts. Merging such chunks copied rows by column
position, which crashed or corrupted data. Rows are now converted by
column name when the layouts differ.

Fixes #10665
@svenklemm
svenklemm force-pushed the sven/merge_chunk_layout branch from 57fcbdb to ab9e5f1 Compare September 28, 2026 07:47
@svenklemm svenklemm added this to the v2.30.2 milestone Sep 28, 2026
@svenklemm svenklemm added the force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" label Sep 28, 2026
@svenklemm
svenklemm merged commit 3b8b95e into main Sep 28, 2026
71 of 72 checks passed
@svenklemm
svenklemm deleted the sven/merge_chunk_layout branch September 28, 2026 08:18
@timescale-automation timescale-automation added the released-2.30.2 Released in 2.30.2 label Sep 29, 2026
@timescale-automation timescale-automation added the released-2.31.0 Released in 2.31.0 label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported-2.30.x force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" released-2.30.2 Released in 2.30.2 released-2.31.0 Released in 2.31.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: merge_chunks segfaults when merging chunks created before and after DROP COLUMN

4 participants