New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: squash add and drop mutations in same transaction #32066
base: master
Are you sure you want to change the base?
Conversation
b26e340
to
240b219
Compare
pkg/sql/schema_changer_test.go
Outdated
// ADD and DROP column squashed and works. | ||
{`add-drop-column`, `ALTER TABLE t.kv ADD COLUMN i INT`, `ALTER TABLE t.kv DROP COLUMN i`, ``}, | ||
// CREATE and DROP index squashed and works. | ||
{`add-drop-index`, `CREATE INDEX foobar ON t.kv (v)`, `DROP INDEX t.kv@foobar`, ``}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these can be modeled in the logic tests. See the tests in logictest file schema_change_in_txn
You can also add the ADD, DROP, ADD cases there
and the ADD, DROP, RENAME (to the name used by the ADD) case
pkg/sql/table.go
Outdated
// squashNewMutations rewrites the mutations list, removing | ||
// mutations where schema elements are added and dropped in | ||
// the same transaction, and marking the mutation jobs as | ||
// succeeded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should only care about DROP mutations in the DELETE_AND_WRITE_ONLY state that were not present in the ClusterVersion.
240b219
to
d30b4a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/sql/table.go, line 782 at r1 (raw file):
Previously, vivekmenezes wrote…
I believe this should only care about DROP mutations in the DELETE_AND_WRITE_ONLY state that were not present in the ClusterVersion.
All DROP mutations not present in the cluster version should be in the DELETE_AND_WRITE_ONLY state, I don't think we need to do any checks on state here.
pkg/sql/schema_changer_test.go, line 2411 at r1 (raw file):
Previously, vivekmenezes wrote…
I think these can be modeled in the logic tests. See the tests in logictest file schema_change_in_txn
You can also add the ADD, DROP, ADD cases there
and the ADD, DROP, RENAME (to the name used by the ADD) case
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together! It could be nice to get the PR out that ensures that a transaction
uses only a single mutation id before we merge this one. Your call.
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/sql/table.go, line 783 at r2 (raw file):
// the same transaction, and marking the mutation jobs as // succeeded. func (p *planner) squashNewMutations(
perhaps rename this to maybeSquashNewMutations
pkg/sql/table.go, line 793 at r2 (raw file):
addDroppedColumns := make(map[sqlbase.ColumnID]bool) addDroppedIndexes := make(map[sqlbase.IndexID]bool) for _, m := range desc.Mutations[origLen:] {
Can you add a comment here discussing what this code is doing?
pkg/sql/table.go, line 819 at r2 (raw file):
var squashedIDs []sqlbase.MutationID for _, m := range desc.Mutations[origLen:] {
Can you add a column here as to what this code is doing.
pkg/sql/table.go, line 841 at r2 (raw file):
var prev sqlbase.MutationID for _, id := range squashedIDs {
you should need to only squash a single mutation ID corresponding to the mutation ID of the transaction being processed.
How about adding a TODO to fix the issue of using a mutation ID for each transaction. Even better if you can fix that issue and then merge this PR after that one.
pkg/sql/logictest/testdata/logic_test/schema_change_in_txn, line 539 at r2 (raw file):
statement ok COMMIT
Can you add a SHOW JOBS check to ensure the jobs are cleaned up properly
Schema elements in an adding state can be dropped if the drop happens in the same transaction as the one which initiated the add because the rest of the cluster is not aware that the element ever existed. This change uses the cluster version of the mutable table descriptor to squash these new mutations. Related to cockroachdb#16020. Release note: None
d30b4a8
to
873c7ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/sql/table.go, line 783 at r2 (raw file):
Previously, vivekmenezes wrote…
perhaps rename this to maybeSquashNewMutations
Done.
pkg/sql/table.go, line 793 at r2 (raw file):
Previously, vivekmenezes wrote…
Can you add a comment here discussing what this code is doing?
Done.
pkg/sql/table.go, line 819 at r2 (raw file):
Previously, vivekmenezes wrote…
Can you add a column here as to what this code is doing.
Done.
pkg/sql/table.go, line 841 at r2 (raw file):
Previously, vivekmenezes wrote…
you should need to only squash a single mutation ID corresponding to the mutation ID of the transaction being processed.
How about adding a TODO to fix the issue of using a mutation ID for each transaction. Even better if you can fix that issue and then merge this PR after that one.
Rebased after merging that PR, PTAL.
pkg/sql/logictest/testdata/logic_test/schema_change_in_txn, line 539 at r2 (raw file):
Previously, vivekmenezes wrote…
Can you add a SHOW JOBS check to ensure the jobs are cleaned up properly
Done.
Erik Trinh seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Schema elements in an adding state can be dropped if the drop happens in
the same transaction as the one which initiated the add because
the rest of the cluster is not aware that the element ever existed. This
change uses the cluster version of the mutable table descriptor to
squash these new mutations.
Related to #16020.
Release note: None