Unexpected reindex when altering column types for partitioned tables - #411
Open
pg-hub-mirror[bot] wants to merge 3 commits into
Open
pg-hub-mirror[bot] wants to merge 3 commits into
pg-hub-mirror[bot] wants to merge 3 commits into
Conversation
…fe' alter column types on partitioned tables
…or partitioned tables During ALTER TABLE ALTER COLUMN TYPE for a partitioned table with an index, the old deletion behavior: 1. Processes the parent table in ATRewriteCatalogs before processing any of its child tables 2. Runs ATPostAlterTypeCleanup for the table, which drops the partitioned index at the end. That drop cascades to the child indexes. 3. Processes the child tables in ATRewriteCatalogs. However, the child indexes were already dropped, so we never remember them in RememberAllDependentForRebuilding. 4. When indexes are eventually recreated, they always need to be reindexed. This change batches the deletions in ATRewriteCatalogs so that they happen at the end of a processing step and not in each call to ATPostAlterTypeCleanup (which happens for each processed table). This ensures that child indexes are tracked when ATExecAlterColumnType calls RememberAllDependentForRebuilding for each child table. After the change, child indexes are now recreated twice: once when the parent index is created, and once by themselves. We need for the child indexes to be created first. That way, they use the remembered information to decide whether a reindex is needed. When the parent index is created, it will automatically use existing child indexes. To enforce this behavior, we add a new AT_PASS_OLD_PARTITIONED_INDEX that recreates the parent indexes.
… TABLE ALTER COLUMN TYPE for partitioned tables This is a follow-up to the same fix for non-constraint indexes. Just as in there, the parent constraint is dropped first, and cascades to the child constraints, so that the associated indexes cannot be recreated properly. We remove the condition that preented child constraints from being re-added. However, this causes the constraints to be added twice (once when the parent is recreated, and once when the constraints themselves are recreated). We need to make sure that this happens in the right order, so we first create the child constraints (reusing the index if possible), and then the parent constraint, which should automatically reuse all child constraints and indexes.
Author
|
Earlier design discussion: Discussion #317 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
pgsql-hackersCA+C_kKUgzQaq=ngDy0cJDBW1XVTPgB5yGqF5cjP7Dk=VTA=sRw@mail.gmail.comPatch files:
Hey Alberto,