forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql/schemachanger: clean up SequenceOwner elements during restore
Previously, when restoring a backup taken in middle of a DROP COLUMN, where a column had a sequence owner assigned, it was possible for the backup to be unrestorable. This would happen because the sequence reference would have been dropped in the plan, but the seqeunce owner element was still within the state. To address this, this test updates the rewrite logic to clean up any SequenceOwner elements which have the referenced sequence already removed. Fixes: cockroachdb#130778 Release note (bug fix): Addressed a rare bug that could prevent backups taken during a DROP COLUMN where the column was sequence owner. The restore would fail with: "rewriting descriptor ids: missing rewrite for <id> in SequenceOwner..."
- Loading branch information
Showing
14 changed files
with
1,493 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...nger/testdata/end_to_end/drop_column_sequence_owner/drop_column_sequence_owner.definition
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
setup | ||
CREATE TABLE t (i INT PRIMARY KEY, j INT, k int); | ||
CREATE SEQUENCE sq1 OWNED BY t.j; | ||
COMMENT ON TABLE t IS 't has a comment'; | ||
COMMENT ON COLUMN t.j IS 'j has a comment'; | ||
INSERT INTO t VALUES(-1); | ||
INSERT INTO t VALUES(-2); | ||
INSERT INTO t VALUES(-3); | ||
---- | ||
|
||
stage-exec phase=PostCommitPhase stage=: | ||
INSERT INTO t VALUES($stageKey); | ||
INSERT INTO t VALUES($stageKey + 1); | ||
UPDATE t SET k=$stageKey; | ||
UPDATE t SET k=i; | ||
DELETE FROM t WHERE i=-1; | ||
DELETE FROM t WHERE i=$stageKey; | ||
INSERT INTO t VALUES($stageKey); | ||
INSERT INTO t VALUES(-1); | ||
---- | ||
|
||
# Each insert will be injected twice per stage, plus 3 injected | ||
# at the start. | ||
stage-query phase=PostCommitPhase stage=: | ||
SELECT count(*)=($successfulStageCount*2)+3 FROM t; | ||
---- | ||
true | ||
|
||
stage-exec phase=PostCommitNonRevertiblePhase stage=: | ||
INSERT INTO t VALUES($stageKey); | ||
INSERT INTO t VALUES($stageKey + 1); | ||
UPDATE t SET k=$stageKey; | ||
UPDATE t SET k=i; | ||
DELETE FROM t WHERE i=-1; | ||
DELETE FROM t WHERE i=$stageKey; | ||
INSERT INTO t VALUES($stageKey); | ||
INSERT INTO t VALUES(-1); | ||
---- | ||
|
||
# Each insert will be injected twice per stage, plus 3 injected | ||
# at the start. | ||
stage-query phase=PostCommitNonRevertiblePhase stage=: | ||
SELECT count(*)=($successfulStageCount*2)+3 FROM t; | ||
---- | ||
true | ||
|
||
test | ||
ALTER TABLE t DROP COLUMN j | ||
---- |
Oops, something went wrong.