Skip to content

Restore CLUSTER ON statements after their referenced indexes#907

Merged
kvch merged 5 commits into
mainfrom
fix/restore-cluster-after-indexes
Jun 29, 2026
Merged

Restore CLUSTER ON statements after their referenced indexes#907
kvch merged 5 commits into
mainfrom
fix/restore-cluster-after-indexes

Conversation

@kvch

@kvch kvch commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Problem

ALTER TABLE ... CLUSTER ON <index> references an index. During snapshot restore it could be emitted before the index was created, causing the restore to fail.

Fix

Route ALTER TABLE ... CLUSTER ON ... statements into the indices/constraints restore phase so the referenced index always exists first.

Testing

  • Unit: TestSnapshotGenerator_parseDumpMovesClusterOnToConstraints (asserts CLUSTER ON is ordered after CREATE INDEX)
  • Integration: Test_SnapshotToPostgres_ClusteredIndex
  • go test ./pkg/snapshot/generator/postgres/schema/pgdumprestore/...

Cherry-picked from @danddanddand (fix/restore-cluster-after-indexes).

@kvch kvch marked this pull request as ready for review June 23, 2026 18:06
@kvch kvch requested a review from tsg June 23, 2026 18:06
@kvch kvch changed the title Restore CLUSTER ON statements after their referenced indexes Restore CLUSTER ON statements after their referenced indexes Jun 24, 2026
@kvch

kvch commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

…fter-indexes

# Conflicts:
#	pkg/snapshot/generator/postgres/schema/pgdumprestore/snapshot_pg_dump_restore_generator.go
#	pkg/snapshot/generator/postgres/schema/pgdumprestore/snapshot_pg_dump_restore_generator_test.go
#	pkg/stream/integration/snapshot_pg_integration_test.go

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflicts in 9b20584. Both sides of each conflict were retained:

  • isClusterOnAlterTable (PR) and isLegacyPLPGSQLHandlerFunctionStart (main) in the generator
  • Both new unit tests and both new integration tests

Copilot finished work on behalf of kvch June 29, 2026 11:33
@kvch

kvch commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

…fter-indexes

# Conflicts:
#	pkg/snapshot/generator/postgres/schema/pgdumprestore/snapshot_pg_dump_restore_generator_test.go
#	pkg/stream/integration/snapshot_pg_integration_test.go

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved in 6f15fd9. The new conflicts came from origin/main adding TestSnapshotGenerator_parseDumpMovesMaterializedViewIndexesToViews and Test_SnapshotToPostgres_MaterializedViewRefresh at the same locations. Both the PR's tests and main's new tests are now preserved.

Copilot finished work on behalf of kvch June 29, 2026 14:37
@github-actions

Copy link
Copy Markdown

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgstream/pkg/snapshot/generator/postgres/schema/pgdumprestore 89.22% (+0.04%) 👍
github.com/xataio/pgstream/pkg/stream/integration 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgstream/pkg/snapshot/generator/postgres/schema/pgdumprestore/snapshot_pg_dump_restore_generator.go 84.65% (+0.11%) 404 (+3) 342 (+3) 62 👍

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

  • github.com/xataio/pgstream/pkg/snapshot/generator/postgres/schema/pgdumprestore/snapshot_pg_dump_restore_generator_test.go
  • github.com/xataio/pgstream/pkg/stream/integration/snapshot_pg_integration_test.go

@kvch kvch merged commit 1b090aa into main Jun 29, 2026
8 checks passed
@kvch kvch deleted the fix/restore-cluster-after-indexes branch June 29, 2026 14:50
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>
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.

4 participants