Repository navigation
Conversation
The proof and constraint steps of the online attach now act on a table that is itself partitioned: each CHECK reaches every partition below it, and SET NOT NULL skips every partition's scan. The flow still refuses a partitioned table to attach until its index and foreign key steps follow.
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 0686a0f: 0 blocking, 4 non-blocking. Inspected the whole change at The change lets the proof step and the NOT NULL helper run on a table that is itself partitioned. Three production edits carry it. The proof's Invariants ( Non-blocking
Test case: a leaf with another column order (not run here)// The leaf's id is attnum 2 while the table's is attnum 1; the NOT VALID
// not-null constraint on the leaf must still be found, by name.
func TestEnsureAttachConstraintsRefusesANotValidNotNullOnALeafOfAnotherColumnOrder(t *testing.T) {
withAttachProofServer(t, func(t *testing.T, newFixture func(t *testing.T) attachProofFixture) {
f := newFixture(t)
if major := f.serverMajor(t); major < 18 {
t.Skipf("a NOT VALID not-null constraint needs PostgreSQL 18, have %d", major)
}
f.exec(t, `
CREATE TABLE %[1]s.payments (
id bigint NOT NULL,
paid date NOT NULL,
amount integer
) PARTITION BY RANGE (paid);
CREATE TABLE %[1]s.payments_2027 (
id bigint,
paid date,
amount integer
) PARTITION BY LIST (amount);
CREATE TABLE %[1]s.payments_2027_leaf (
paid date,
id bigint,
amount integer
);
ALTER TABLE %[1]s.payments_2027 ATTACH PARTITION %[1]s.payments_2027_leaf FOR VALUES IN (1);
ALTER TABLE %[1]s.payments_2027_leaf
ADD CONSTRAINT payments_2027_leaf_id_not_null NOT NULL id NOT VALID`)
_, err := ensureAttachConstraints(t.Context(), f.pool, f.tableOID(t, "payments"), f.attachTable(t, "payments_2027"),
attachProofTestBudget, 0, nil, nil)
require.ErrorIs(t, err, errAttachNotNullNotValid)
})
}Not run here (it needs a PostgreSQL 18 container). It should pass at the head, and fail against
Verified
This review was generated by Claude Code (claude-sonnet-5-5). |
|
🤖 Review 2/2 (OSS adoption and integration) of 0686a0f: 0 blocking, 2 non-blocking. Read the change from two seats: a contributor who works on the online attach and relies on Non-blocking
What reads well for adopters
This review was generated by Claude Code (claude-sonnet-5-5). |
aparajon
left a comment
There was a problem hiding this comment.
🤖 Stamping with comments: 0 blocking, 6 non-blocking (see the review comments above).
This stamp was left by Claude Code (claude-sonnet-5-5).
|
🤖 Reviewed There is a potential race in This was a static review. I ran no tests. |
The online attach's proof and constraint steps now work on a table that is itself partitioned, the first step toward attaching a sub-partitioned table online.
Why
pg-sprite runs
ATTACH PARTITIONonline: before the brief attach, it gives the new table a validatedCHECKthat proves its rows fit the bound, plus the parent'sCHECKs andNOT NULLs, so the attach itself scans nothing. Today every one of those steps accepts only a plain table, so a table that is itself partitioned (for example a year table split by region) cannot be attached online at all. This PR lets the first two steps work on such a table. The attach flow still refuses one until the index and foreign key steps follow in later PRs.What
ADD CONSTRAINT ... NOT VALIDandVALIDATErecurse to every partition. The wait for long-lived lock holders now covers every partition below the table, because theADDandDROPlock each of them.NOT NULLhelper works the same way on a partitioned table.SET NOT NULLrecurses, and each partition skips its scan on its copy of the validated helper.NOT VALIDnot-null constraint on any partition below the table is refused, as one on the table already was, becauseSET NOT NULLon the table leaves itNOT VALID.errAttachProofNotPlainTablebecomeserrAttachProofTableKind. It now refuses only relations that are neither plain nor partitioned tables (a view, a foreign table) and keeps the same outcome code.Before / after
Take
payments_2027, partitioned bycurrencyintopayments_2027_usdand aDEFAULTpartition that is itself split by half year, attached underpayments. Before, the proof step refused the table outright. After, the steps give the whole tree what the attach needs, and the attach proves the bound from the validatedCHECKinstead of scanning any leaf. The flow's own refusal of a partitioned table to attach is unchanged in this PR.A
DEFAULTpartition of the parent that is itself partitioned works the same way at the step level: its exclusion proof reaches its leaves, and the attach skips their scan.