opgen: make Column transitioning to public non-revertible#88489
Conversation
ded1737 to
9c2b5fe
Compare
|
I didn't fully understand the fix in the previous iteration and came up with a dep rule that didn't actually solve the problem. That dep rule delays the primary index swap and column turning public to happen in the same stage as the new unique secondary index turning public. This is not right because we would never be able to backfill the new unique secondary index to begin with, because that new column is not present in the (old) primary index. The reason we had such a requirement is definitely not obvious: it's related to an assumption that the optimizer holds deeply in the code and it's not easy to change any time soon. See this slack discussion for more details with an example included there. The alternative @ajwerner suggested is to mark the transition of the column element into public non-revertible. What this entails is that we would respect the requirement by swapping the primary index first while keeping the column in |
|
Whatever it takes. Regardless of this particular issue, I believe that making the column public a non-revertible op makes sense anyway. Go for it! |
|
The only failed test in CI is marked by TeamCity as "flaky", so I think it's RFAL! |
postamar
left a comment
There was a problem hiding this comment.
Nicely done. LGTM conditional on cosmetic changes.
| // The new primary index should reach VALIDATED, a ready state to be used as | ||
| // source to backfill the new secondary index, before the secondary index becomes existent. | ||
| registerDepRule( | ||
| "primary index with new columns should exist before secondary indexes", |
There was a problem hiding this comment.
This is an oversight on my part when I moved these rule definitions about, I think, but I just noticed that "new columns" should not be mentioned at all in this rule name. This rule can come into play regardless of columns. Instead, it might be worth mentioning why this rule is required for ADD COLUMN UNIQUE in the commentary above.
| statusesToPublicOrTransient(from, scpb.Status_VALIDATED, to, scpb.Status_DELETE_ONLY), | ||
| } | ||
| }) | ||
| } |
There was a problem hiding this comment.
These rules should remain where they were in the dep_add_index.go file.
ajwerner
left a comment
There was a problem hiding this comment.
Is there something that enforces that the primary index moves to public before any indexes involving a new column moves to DELETE_ONLY? It seems like maybe we're under-constrained and getting lucky.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @postamar and @Xiang-Gu)
Xiang-Gu
left a comment
There was a problem hiding this comment.
@ajwerner Marius had these two rules:
cockroach/pkg/sql/schemachanger/scplan/internal/rules/dep_add_index.go
Lines 118 to 159 in 6993039
that made sure if we are adding both primary index and a secondary index, and the source index of the secondary index is the primary index, as in the case for ADD COLUMN UNIQUE, then we make sure we the primary index transitioned to PUBLIC before the secondary index transitioned to BACKFILL_ONLY.
Does this answer your questions?
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @postamar)
pkg/sql/schemachanger/scplan/internal/rules/dep_add_column.go line 118 at r2 (raw file):
Previously, postamar (Marius Posta) wrote…
This is an oversight on my part when I moved these rule definitions about, I think, but I just noticed that "new columns" should not be mentioned at all in this rule name. This rule can come into play regardless of columns. Instead, it might be worth mentioning why this rule is required for ADD COLUMN UNIQUE in the commentary above.
I guess I am a bit confused about their original comments here
cockroach/pkg/sql/schemachanger/scplan/internal/rules/dep_add_index.go
Lines 118 to 121 in 6993039
Are they stale? Do you want me to keep the updated comments but just move those two rules back to dep_add_index.go?
pkg/sql/schemachanger/scplan/internal/rules/dep_add_column.go line 154 at r2 (raw file):
Previously, postamar (Marius Posta) wrote…
These rules should remain where they were in the
dep_add_index.gofile.
ack above.
ajwerner
left a comment
There was a problem hiding this comment.
I don't think it does, no. Didn't you delete that rule in this PR and change it to be about the primary index moving into validated prior to the temp index moving into DELETE_ONLY?
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @postamar)
Xiang-Gu
left a comment
There was a problem hiding this comment.
Ahh, right. I realized that and since we are not adding any dep rules anymore, I reverted the changes on the existing rules. But I haven't pushed the code yet.
With this existing rule, do you think we have constrained it properly?
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @postamar)
9c2b5fe to
0317cfc
Compare
Xiang-Gu
left a comment
There was a problem hiding this comment.
Just pushed the reverts; now this PR is truly a one-line changer revertible(false); under opgen_column.go
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @postamar)
ajwerner
left a comment
There was a problem hiding this comment.
Yeah, this looks right to me from the tests we have. Can you add an end-to-end test with a default value and a unique constraint?
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @postamar)
This PR delays the transitioning of the Column element into PUBLIC to the PostCommitNonRevertible phase. This helps with stmt like `ALTER TABLE t ADD COLUMN j INT DEFAULT 30 UNIQUE` where we will first do the pirmary index swap, then backfill the new unique secondary index, and finally turn the column and the new unique secondary index into public at the same stage. Previously, the column would incorrectly turn into public before the new unique secondary index even begins backfilling, as detailed in cockroachdb#82953. Release note: None
0317cfc to
32b766a
Compare
There was a problem hiding this comment.
@ajwerner
I added an end-to-end test for ADD COLUMN DEFAULT UNIQUE and generated the expected output.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @postamar)
pkg/sql/schemachanger/scplan/internal/rules/dep_add_column.go line 118 at r2 (raw file):
Previously, Xiang-Gu (Xiang Gu) wrote…
I guess I am a bit confused about their original comments here
cockroach/pkg/sql/schemachanger/scplan/internal/rules/dep_add_index.go
Lines 118 to 121 in 6993039
Are they stale? Do you want me to keep the updated comments but just move those two rules back to
dep_add_index.go?
I reverted this change -- it turns out we don't and shouldn't need to modify the existing rules; they are needed to constrain the graph such that the new unique secondary index (as well its temp index) didn't move out of ABSENT until the new primary index is PUBLIC.
ajwerner
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @postamar)
|
TFTR! bors r+ |
|
Build succeeded: |
|
blathers backport 22.2 22.2.0 |
|
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. error creating merge commit from 32b766a to blathers/backport-release-22.2-88489: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 22.2 failed. See errors above. error creating merge commit from 32b766a to blathers/backport-release-22.2.0-88489: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 22.2.0 failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Delayed the transitioning of the Column element into PUBLIC to
the PostCommitNonRevertible phase. This helps with stmt like
ALTER TABLE t ADD COLUMN j INT DEFAULT 30 UNIQUEwhere we willfirst do the pirmary index swap, then backfill the new unique secondary
index, and finally turn the column and the new unique secondary index
into public at the same stage. Previously, the column would incorrectly
turn into public before the new unique secondary index even begins
backfilling.
Fixes #82953
Release note: None