-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
scplan: Fix deprules for dropping computed columns #120794
Conversation
Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
98bd1ce
to
28d9cb7
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.
Reviewed 4 of 23 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rimadeodhar)
pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column
line 1353 at r1 (raw file):
StatementPhase stage 1 of 1 with 42 MutationType ops transitions: [[Column:{DescID: 107, ColumnID: 3}, ABSENT], PUBLIC] -> WRITE_ONLY
Just thinking about this if we have a transaction what makes v2 invisible in this scenario? I think we are waiting this post commit non-revertible phase in this scenario?
i.e
BEGIN
ALTER TABLE defaultdb.foo DROP COLUMN v2 CASCADE;
SELECT * FROM defaultdb.foo;
...
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 (waiting on @fqazi)
pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column
line 1353 at r1 (raw file):
Previously, fqazi (Faizan Qazi) wrote…
Just thinking about this if we have a transaction what makes v2 invisible in this scenario? I think we are waiting this post commit non-revertible phase in this scenario?
i.e BEGIN ALTER TABLE defaultdb.foo DROP COLUMN v2 CASCADE; SELECT * FROM defaultdb.foo; ...
Yeah, good point. I think for transactions we would need to introduce an additional stage where the columns being dropped move to inaccessible in the statement phase. I'll file a tracking issue for it. We would still need the changes contained within this PR as without them we will continue to get errors once the column moves to WRITE_ONLY.
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 (waiting on @fqazi)
pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column
line 1353 at r1 (raw file):
Previously, rimadeodhar (Rima Deodhar) wrote…
Yeah, good point. I think for transactions we would need to introduce an additional stage where the columns being dropped move to inaccessible in the statement phase. I'll file a tracking issue for it. We would still need the changes contained within this PR as without them we will continue to get errors once the column moves to WRITE_ONLY.
Created #120863
Looks like you'll need to do
(I was literally just trying to figure out why I get this diff on 23.1 but not 23.2 or master, so congratulations on the fix! 😆) |
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.
Great work, just a couple of comments to improve performance on the rule evaluation side
Reviewed 19 of 23 files at r1, 18 of 19 files at r2, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rimadeodhar)
pkg/sql/schemachanger/scplan/internal/rules/helpers.go
line 307 at r2 (raw file):
return rel.Clauses{ indexColumn.Type((*scpb.IndexColumn)(nil)), indexColumn.AttrEqVar(screl.DescID, rel.Blank),
This should be tableID?
pkg/sql/schemachanger/scplan/internal/rules/current/dep_drop_column.go
line 151 at r2 (raw file):
} for _, refColumns := range colType.ComputeExpr.ReferencedColumnIDs { if refColumns == column.ColumnID {
We can use: ReferencedColumnIDsContains and do it before the filter
4c7e879
to
967eb34
Compare
3579df8
to
edb8aa5
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 (waiting on @fqazi)
pkg/sql/schemachanger/scplan/internal/rules/helpers.go
line 307 at r2 (raw file):
Previously, fqazi (Faizan Qazi) wrote…
This should be tableID?
Done.
pkg/sql/schemachanger/scplan/internal/rules/current/dep_drop_column.go
line 151 at r2 (raw file):
Previously, fqazi (Faizan Qazi) wrote…
We can use: ReferencedColumnIDsContains and do it before the filter
The referencedColumnIDs field is contained within the expression field in the ColumnType element, so I can't use this helper. Any other recommendations?
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.
All of this looks good. I do have one comment below, not sure if we want to add some other safety or something else as a follow on, since it seems like a potential pitfall if users aren't careful.
Reviewed 34 of 85 files at r3, 79 of 79 files at r4.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rimadeodhar)
pkg/sql/schemachanger/scplan/internal/rules/current/dep_drop_column.go
line 151 at r2 (raw file):
Previously, rimadeodhar (Rima Deodhar) wrote…
The referencedColumnIDs field is contained within the expression field in the ColumnType element, so I can't use this helper. Any other recommendations?
Ugh, no other options here then. Though its not too terrible since its limited to the columns on the table.
pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.definition
line 9 at r4 (raw file):
# for j stage-exec phase=PostCommitPhase stage=: INSERT INTO t (i) VALUES($stageKey);
I think logically and correctness wise all of this makes sense, since we need to be able to rollback consistently. I think the only worry I have is someone accidentally doing a DROP COLUMN and not realizing that inserts will be blocked until the table is backfilled.
Not sure if we want a safety net of some sort 🤔 . Not sure what your thoughts are on that scenario.
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 (waiting on @fqazi)
pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.definition
line 9 at r4 (raw file):
Previously, fqazi (Faizan Qazi) wrote…
I think logically and correctness wise all of this makes sense, since we need to be able to rollback consistently. I think the only worry I have is someone accidentally doing a DROP COLUMN and not realizing that inserts will be blocked until the table is backfilled.
Not sure if we want a safety net of some sort 🤔 . Not sure what your thoughts are on that scenario.
Do you mean a scenario where someone drops a column accidentally, cancels the job and then the table is inaccessible for inserts until backfill part of the rollback is completed?
This PR fixes the new schema changer deprules for dropping virtual computed columns which are also used for hash and expression indexes. Currently, the optimizer allows for virtual, computed columns to be evaluated even when under mutation. However, this causes concurrent DML issues when the schemachanger job is running as the column that the virtual computed column depends on moves into WRITE_ONLY stage prior to the computed column being dropped. As a result, the optimizer is unable to access the column for evaluating the compute expression. This PR updates the dep rules to ensure the virtual, computed column is dropped before the dependent column moves to WRITE_ONLY ensuring that the compute expression can be enforced correctly for concurrent DML during all stages of the schema change. Epic: none Fixes: cockroachdb#111608 Fixes: cockroachdb#111619 Release note: None
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 (waiting on @rimadeodhar)
pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.definition
line 9 at r4 (raw file):
Previously, rimadeodhar (Rima Deodhar) wrote…
Do you mean a scenario where someone drops a column accidentally, cancels the job and then the table is inaccessible for inserts until backfill part of the rollback is completed?
Wait, I misread the plan this is a non-issue. Plus the rollback won't have any backfill only validation, which should be quick so it should be a small blip
edb8aa5
to
47aa2d5
Compare
TFTR! bors r+ |
This PR fixes the new schema changer deprules for
dropping virtual computed columns which are also
used for hash and expression indexes.
Currently, the optimizer allows for virtual, computed
columns to be evaluated even when under mutation.
However, this causes concurrent DML issues when the
schemachanger job is running as the column that the
virtual computed column depends on moves into WRITE_ONLY
stage prior to the computed column being dropped.
As a result, the optimizer is unable to access the column
for evaluating the compute expression.
This PR updates the dep rules to ensure the virtual,
computed column is dropped before the dependent column
moves to WRITE_ONLY ensuring that the compute expression
can be enforced correctly for concurrent DML during all
stages of the schema change.
Epic: none
Fixes: #111608
Fixes: #111619
Release note: None
Note for reviewers: This PR is stacked on top of #120792.