Skip to content

fix: clear the target chunk when the copy goes through the hypertable - #207

Open
alejandrodnm wants to merge 1 commit into
adn/delete-compressed-chunk-rows-before-copyfrom
adn/delete-from-chunk-not-hypertable
Open

fix: clear the target chunk when the copy goes through the hypertable#207
alejandrodnm wants to merge 1 commit into
adn/delete-compressed-chunk-rows-before-copyfrom
adn/delete-from-chunk-not-hypertable

Conversation

@alejandrodnm

Copy link
Copy Markdown
Contributor

When the source chunk is partial and the target chunk isn't, copy_chunk writes the uncompressed rows through the hypertable instead of into the chunk, because setting a chunk's status to partial needs a permission tsdbadmin doesn't have. The delete meant to clear the range followed the copy to the hypertable, and DELETE FROM ONLY <hypertable> clears nothing: a hypertable keeps every row in its chunks, so its own heap is always empty. On that path the copy adds to whatever the chunk already held.

It stays invisible while the branch is only reached on a first copy, where the chunk is empty anyway. Writing the rows through the hypertable makes the chunk partial, so a second copy takes the other branch and deletes normally. But anything that folds those rows back into compressed form, which is what a compression policy does, clears the partial status and puts a second copy back on this branch with data already in place, and the target ends up with twice the rows.

The delete and the cagg invalidation trigger now act on the chunk, the relation that ends up holding the rows, while the copy still goes wherever the caller needs it. That also restores the assumption #206 relies on: from TimescaleDB 2.23 the delete that clears a chunk's uncompressed rows removes its compressed batches too, which only holds if that delete reaches the chunk in the first place.

Stacked on #206, review that one first.

https://claude.ai/code/session_01DMDRhYXfUK4WpAD6zUfeaW

Point the delete and the cagg invalidation trigger at the chunk that ends
up holding the rows, rather than at wherever the copy happens to be
written. Add a regression test covering a partial source chunk copied
twice with the target recompressed in between.

Claude-Session: https://claude.ai/code/session_01DMDRhYXfUK4WpAD6zUfeaW
@alejandrodnm
alejandrodnm requested a review from a team as a code owner August 27, 2026 08:56
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.

1 participant