Use ONLY for CTID snapshot queries to exclude inherited child rows#909
Merged
Conversation
kvch
marked this pull request as ready for review
June 23, 2026 18:10
tsg
approved these changes
Jun 26, 2026
kvch
enabled auto-merge (squash)
June 29, 2026 14:37
Merging this branch will not change overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
This was referenced Jun 30, 2026
kvch
added a commit
that referenced
this pull request
Jul 6, 2026
…) (#966) Backports the following snapshot/restore fixes from `main` to the `v1.1.x` release branch. | PR | Commit | Fix | |----|--------|-----| | #906 | 2cf967b | Skip legacy public PL/pgSQL handler functions on snapshot restore | | #908 | 5f1d6e3 | Refresh materialized views after data restore | | #909 | bce8ea8 | Use `ONLY` for CTID snapshot queries to exclude inherited child rows | | #907 | 1b090aa | Restore `CLUSTER ON` statements after their referenced indexes | | #910 | 6b3bb8a | Type `int4range`/`int8range` values before insert/COPY | --------- Co-authored-by: dand <daniel.dent@borderconnect.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The CTID page-range data snapshot uses
SELECT * FROM <table> WHERE ctid BETWEEN ...andSELECT MAX(ctid) FROM <table>. For a legacy-inheritance parent table (CREATE TABLE ... INHERITS), these implicitly span the parent plus all child heaps, so CTIDs aren't unique to the parent's storage: page ranges overlap and child rows get copied through the parent (and again when the child is snapshotted on its own).Fix
Add
ONLYto the page-range and max-CTID queries so each snapshot is confined to the selected table's own heap, matching pgstream's per-table snapshot model.Note: this is a no-op for plain tables and leaf partitions, and does not affect declaratively partitioned parents (
relkind='p'), which are already excluded from this path by therelkind='r'filter ingetTableInfo.Testing
TestSnapshotQueriesDoNotIncludeInheritedRowsTest_SnapshotToPostgres_SelectedParentTableDoesNotCopyInheritedRowsgo test ./pkg/snapshot/generator/postgres/data/...Cherry-picked from @danddanddand (
fix/snapshot-only-table-pages).