Repository navigation
Conversation
The attach index step now gives a table that is itself partitioned the key constraint a parent PRIMARY KEY or UNIQUE constraint adopts at the attach, by running the partitioned key build on it, so the ATTACH builds no index.
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 1539478: 0 blocking, 3 non-blocking. Inspected the whole diff at head Relation to #713. This PR's base is exactly #713's head ( What the PR does, and whether it is right. For a parent PRIMARY KEY or UNIQUE constraint with nothing on a partitioned table to pair with, Why it holds:
Invariants: ST-7 extends (the table is proved before the build at L51 and again, in the same read as the key lookup, at L60); CO-9 upholds ( Non-blocking1. A refusal for a nested tree comes after earlier parent indexes have been built. Test case (not run here: no local Postgres or build)func TestEnsureAttachIndexesRefusesANestedTreeBeforeBuildingAnyIndex(t *testing.T) {
withAttachProofServer(t, func(t *testing.T, newFixture func(t *testing.T) attachProofFixture) {
f := newFixture(t)
f.exec(t, `
CREATE TABLE %[1]s.visits (
id bigint NOT NULL, day date NOT NULL, region text NOT NULL
) PARTITION BY RANGE (day);
CREATE INDEX visits_region_idx ON %[1]s.visits (region);
ALTER TABLE %[1]s.visits ADD CONSTRAINT visits_pkey PRIMARY KEY (id, day, region);
CREATE TABLE %[1]s.visits_2027 (
id bigint NOT NULL, day date NOT NULL, region text NOT NULL
) PARTITION BY LIST (region);
CREATE TABLE %[1]s.visits_2027_eu PARTITION OF %[1]s.visits_2027 FOR VALUES IN ('eu');
CREATE TABLE %[1]s.visits_2027_us PARTITION OF %[1]s.visits_2027
FOR VALUES IN ('us') PARTITION BY RANGE (id);
CREATE TABLE %[1]s.visits_2027_us_low PARTITION OF %[1]s.visits_2027_us
FOR VALUES FROM (0) TO (100)`)
_, err := ensureAttachIndexes(t.Context(), f.pool, f.parentOID(t, "visits"), f.standalonePartitioned(t, "visits_2027"), attachIndexBudget, nil, 0, nil)
require.ErrorIs(t, err, ErrPartitionedKeySubPartitioned)
for _, rel := range []string{"visits_2027", "visits_2027_eu", "visits_2027_us", "visits_2027_us_low"} {
assert.Empty(t, f.tableIndexes(t, rel), rel)
}
})
}Expected to fail on 2. The build resolves the table by name and does not hold the table's own lock; the proof is before and after, not around. 3. The tests pin PRIMARY KEY on a fresh two-leaf table, and little else of the new branch. Not covered: a parent UNIQUE constraint (the Test case for a parent UNIQUE constraint (not run here: no local Postgres or build)func TestEnsureAttachIndexesGivesAPartitionedTableTheUniqueKey(t *testing.T) {
withAttachProofServer(t, func(t *testing.T, newFixture func(t *testing.T) attachProofFixture) {
f := newFixture(t)
f.exec(t, strings.Replace(keyedVisits,
"CONSTRAINT visits_pkey PRIMARY KEY (id, day, region)",
"CONSTRAINT visits_uniq UNIQUE (id, day, region)", 1))
parent, table := f.parentOID(t, "visits"), f.standalonePartitioned(t, "visits_2027")
name := derivedPartitionIndexName("visits_uniq", table.oid)
results, err := ensureAttachIndexes(t.Context(), f.pool, parent, table, attachIndexBudget, nil, 0, nil)
require.NoError(t, err)
require.Len(t, results, 1)
assert.Equal(t, attachIndexKeyed, results[0].action)
assert.Equal(t, name, results[0].index)
f.attach(t, attachVisits2027)
assert.Equal(t, []tableKey{{name: name, adopted: true}}, f.tableKeys(t, "visits_2027"))
})
}Needs This review was generated by Claude Code (claude-sonnet-5-5). |
|
🤖 Review 2/2 (OSS adoption and integration ease) of 1539478: 0 blocking, 3 non-blocking. Same head, For adopters. The change removes a dead end: attaching a partitioned table under a parent with a primary key or unique constraint used to be refused unless the table already carried a matching key, and now the step builds it online and the ATTACH changes only the catalog. The PR description's before/after is accurate against the code and the new test (the three indexes in the tree are the ones the step built; the attach builds none). For a caller, a refusal now arrives as a typed, exported error ( Non-blocking1. The invariants registry still describes the step as it was. 2. The error text names a constraint the adopter never wrote. A nested tree under a parent 3. The table's key keeps an OID-derived name after the attach. As for the leaf path and the index step, the constraint is 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 across the two review comments above (3 correctness, 3 OSS adoption and integration).
This stamp was left by Claude Code (claude-sonnet-5-5).
|
🤖 Static review of I checked the shared key eligibility checks, the post-build lookup scoped to the candidate table’s OID, and the final pairing. The new integration test records all three index OIDs before The automated review result was unavailable. No local tests were run. |
The online attach's index step now gives a table that is itself partitioned the parent's primary key and unique constraints, built concurrently, so the attach adopts them and builds no index.
Why
A partitioned parent's primary key or unique constraint must also exist on every partition. When pg-sprite attaches a partitioned table online, the
ATTACHlooks for a matching key on that table to adopt. Without one, it builds the key's index on every partition of the table while it blocks them all. The previous PR gave such a table the parent's plain indexes ahead of time but refused the parent's keys. This PR builds the keys too, so only foreign keys stand between a sub-partitioned table and an online attach.What
<constraint>_p<table oid>. Each leaf's unique index is built concurrently and given the constraint, then the table's ownADD CONSTRAINTadopts them in one brief transaction that builds nothing. A rerun finds the key.DEFERRABLE, a plain unique btree index on its columns) move into one helper,attachKeySpec, that both paths share.ErrPartitionedKeySubPartitioneduntil that build takes nested trees.Before / after
Take
visitswithPRIMARY KEY (id, day, region), andvisits_2027, partitioned by region intovisits_2027_euandvisits_2027_us, with no key. The index step runs onvisits_2027before the attach. Before, it refused the parent's key; after, it builds the key without blocking writes, and theATTACHadopts it.