Repository navigation
Optimize PostgreSQL visibility migrations to reduce table rewrites - #12933
Open
BackendArchitectX wants to merge 2 commits into
Open
BackendArchitectX wants to merge 2 commits into
BackendArchitectX wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
What changed?
Optimized PostgreSQL visibility schema migrations v1.7 and v1.8 to reduce redundant rewrites of the
executions_visibilitytable.ALTER TABLEstatement.ALTER TABLEstatement for upgrades from historical v1.7 schemas.IF NOT EXISTSto support retries when columns have already been created.Result: A v1.6 → v1.8 upgrade now requires one table rewrite instead of four.
Closes #12923.
Why?
Adding a
GENERATED ALWAYS AS (...) STOREDcolumn requires PostgreSQL to rewrite the underlying table.Previously, separate
ALTER TABLEstatements caused repeated full-table rewrites, extending theACCESS EXCLUSIVElock and potentially disrupting workflow visibility queries during upgrades.Combining the column additions eliminates redundant rewrites without changing the intended schema or index definitions.
This follows the optimization pattern previously applied to later PostgreSQL visibility migrations.
How did you test it?
PostgreSQL migration compatibility
Rewrite-count regression
Rewrite counts were verified through local PostgreSQL database experiments. The benchmarks are single-run measurements, not statistically controlled performance comparisons.
Go regression tests
GOMAXPROCS=2 go test -p 2 ./schema ./tools/common/schema -count=1Both packages passed before and after rebasing onto upstream
main.Potential risks
ACCESS EXCLUSIVElock. Large production tables may require an upgrade maintenance window.IF NOT EXISTSchecks column existence but does not validate the type or expression of a pre-existing column. Broader drift detection is outside this change.