Repository navigation
Conversation
The attach index step now gives a table that is itself partitioned a valid partitioned index for each of the parent's plain indexes, by running the partitioned index build on it, so the ATTACH pairs them and builds nothing. A parent key constraint is taken only when the table already has it.
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.
The online attach's index step now gives a table that is itself partitioned the parent's indexes, built concurrently, so the attach of such a table builds no index.
Why
When pg-sprite attaches a partition online, it first gives the new table every index of the parent, built concurrently while writes go on, because the
ATTACHwould otherwise build them while it blocks the table. For a table that is itself partitioned, theATTACHlooks for a valid partitioned index on that table to pair with each parent index. If it finds none, it builds the index on every partition of the table, all underACCESS EXCLUSIVE. Until now the index step refused a partitioned table outright. This PR gives it those indexes ahead of time, one step closer to attaching a sub-partitioned table online. The attach flow still refuses one until the foreign key step follows.What
<index>_p<table oid>. The build creates the table's indexON ONLY, builds every leaf's index concurrently, attaches each level bottom up, and returns once the table's index is valid. A rerun resumes an index a stop left invalid.ATTACHpairs a valid one and passes over an invalid one, building the index across the whole tree. The pairing already skipped invalid indexes.PRIMARY KEYorUNIQUEconstraint is taken when the table already has the matching key. Otherwise it is refused withattach-partition-index-unsupportedbefore anything is built; the key build follows in the next PR.Before / after
Take
visits, indexed onidandlower(page), andvisits_2027, partitioned by region intovisits_2027_euandvisits_2027_us, which is split again by id. The index step runs onvisits_2027before the attach. Before, it refused the table; after, it builds both indexes across the tree without blocking writes, and theATTACHtakes them.