Repository navigation
Conversation
The attach foreign key step now gives a table that is itself partitioned a validated foreign key of each of the parent's, so the ATTACH adopts it and validates nothing: through the partitioned foreign key build before PostgreSQL 18, and the table's own NOT VALID foreign key from 18.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
🤖 Review 1/2 (correctness) of 7c8e368: 0 blocking, 5 non-blocking. Inspected the full diff at head 7c8e368 (stacked on #714, base The change is correct as far as I can trace it. Invariants (from BlockingNone. Non-blocking1. On PostgreSQL 14 to 17, a partitioned table that already carries a matching validated foreign key under another name is refused; on 18, and for a plain table, it is found. Test case (not run here: no clone or containers available to this review)func TestEnsureAttachForeignKeysTakesAPartitionedTablesOwnForeignKeyUnderAnotherName(t *testing.T) {
withAttachProofServer(t, func(t *testing.T, newFixture func(t *testing.T) attachProofFixture) {
f := newFixture(t)
f.exec(t, paymentsFKByRegion)
f.exec(t, `ALTER TABLE %[1]s.payments_2027
ADD CONSTRAINT my_account_fk FOREIGN KEY (account_id)
REFERENCES %[1]s.accounts (id) ON DELETE CASCADE`)
table := f.standalonePartitioned(t, "payments_2027")
results, err := ensureAttachForeignKeys(t.Context(), f.pool, f.parentOID(t, "payments"), table, attachProofTestBudget, nil, 0, nil)
require.NoError(t, err)
require.Len(t, results, 1)
assert.Equal(t, leafFKFound, results[0].action)
assert.Equal(t, "my_account_fk", results[0].constraint)
assert.Equal(t, []string{"my_account_fk"}, slices.Collect(maps.Keys(f.tableFKs(t, "payments_2027"))))
})
}Expected: passes on 18 (the leaf step finds it) and fails on 14 to 17 with 2. The partitioned-table tests do not pin several behaviors the PR text claims.
Test case (not run here: no clone or containers available to this review)func TestEnsureAttachForeignKeysResumesAPartitionedTableAfterAViolationIsFixed(t *testing.T) {
withAttachProofServer(t, func(t *testing.T, newFixture func(t *testing.T) attachProofFixture) {
f := newFixture(t)
f.exec(t, paymentsFKByRegion)
f.exec(t, `INSERT INTO %[1]s.payments_2027 VALUES (3, '2027-05-01', 'us', 99)`)
parent, table := f.parentOID(t, "payments"), f.standalonePartitioned(t, "payments_2027")
_, err := ensureAttachForeignKeys(t.Context(), f.pool, parent, table, attachProofTestBudget, nil, 0, nil)
require.ErrorIs(t, err, ErrPartitionedForeignKeyViolation)
usFKs := f.tableFKs(t, "payments_2027_us")
require.Len(t, usFKs, 1, "the leaf holding the bad row keeps the foreign key the step added")
for _, fk := range usFKs {
assert.False(t, fk.validated)
}
f.exec(t, `DELETE FROM %[1]s.payments_2027 WHERE id = 3`)
results, err := ensureAttachForeignKeys(t.Context(), f.pool, parent, table, attachProofTestBudget, nil, 0, nil)
require.NoError(t, err)
require.Len(t, results, 1)
for _, rel := range []string{"payments_2027", "payments_2027_eu", "payments_2027_us"} {
fks := f.tableFKs(t, rel)
require.Len(t, fks, 1, rel)
for _, fk := range fks {
assert.True(t, fk.validated, "%s's foreign key is validated after the rerun", rel)
}
}
})
}Expected to pass on 14 to 18 at this head; read from the code, not run. It would catch a resume that re-adds a foreign key or leaves a leaf 3. On PostgreSQL 18 the cost model differs from the one the comments describe. 4. The build still resolves the table by name, and the error text still names an OID-derived constraint (repeats of #714 notes). 5. Verified
This review was generated by Claude Code (claude-sonnet-5-5). |
|
🤖 Review 2/2 (OSS adoption and integration ease) of 7c8e368: 0 blocking, 1 non-blocking. Same head, 7c8e368, read through the eyes of someone adopting pg-sprite for the first time, and of a host that imports the executor (schemabot is one) and has to turn each outcome into something an operator can act on. The correctness review is the comment above. BlockingNone. Non-blocking1. The behavior now differs by server major, and nothing user-facing says so. Checked, no finding
This review was generated by Claude Code (claude-sonnet-5-5). |
aparajon
left a comment
There was a problem hiding this comment.
🤖 Approving with comments: 0 blocking, 6 non-blocking across the two review comments above.
This review was generated by Claude Code (claude-sonnet-5-5).
|
🤖 Static review of P2 · Preserve the referenced table OID before enabling partitioned attach. The pre-18 branch gets the resolved CI reports success on PostgreSQL 14–18. I did not run tests locally. The automated review result was unavailable. No local tests were run. |
The online attach's foreign key step now gives a table that is itself partitioned the parent's foreign keys, validated while writes go on, so the attach adopts them and validates nothing.
Why
A partitioned parent's foreign key must hold on every partition. When pg-sprite attaches a partitioned table online, the
ATTACHadopts a validated foreign key of the same definition on that table. Without one, it creates the foreign key on every partition of the table and checks every row against the referenced table while it blocks them all. Until now the foreign key step refused a partitioned table. This PR builds those foreign keys ahead of time, which is the last step the online attach needs before it can take a partitioned table.What
ADD FOREIGN KEY ... NOT VALIDon a partitioned table, the step runs the existing partitioned foreign key build on the table under the derived name<fk>_p<table oid>. Each leaf's foreign key is addedNOT VALIDand validated, then the table's ownADD FOREIGN KEYadopts them in one brief transaction that scans nothing.ADD ... NOT VALIDreaches every partition at every level, and itsVALIDATEvalidates each one.ATTACHthen adopts the table's foreign key and scans neither the table's leaves nor the referenced table.ErrPartitionedForeignKeySubPartitioneduntil that build takes nested trees.Before / after
Take
paymentswithFOREIGN KEY (account_id) REFERENCES accounts, andpayments_2027, partitioned by region intopayments_2027_euandpayments_2027_us, with no foreign key. The step runs onpayments_2027before the attach. Before, it refused the table; after, it validates the foreign key without blocking writes, and theATTACHadopts it.