sql: ALTER COLUMN TYPE does not check partial index definitions#131590
sql: ALTER COLUMN TYPE does not check partial index definitions#131590craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
|
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
12e2476 to
1ac07e7
Compare
1ac07e7 to
464bddd
Compare
spilchen
left a comment
There was a problem hiding this comment.
You were on the right track. I just had a couple of suggestions for modifications.
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @Dedej-Bergin)
-- commits line 11 at r1:
Let's include the epic in the commit message: CRDB-25314
pkg/sql/catalog/schemaexpr/expr.go line 518 at r1 (raw file):
) error { for _, index := range tableDesc.AllIndexes() { if index.IsPartial() {
Should we verify that the column is included in the partial index?
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1218 at r1 (raw file):
DROP TABLE t_int; subtest end
I usually aim to include a single subtest end at the bottom of the test. Since you've already added one, you can probably remove this line.
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1223 at r1 (raw file):
statement ok set enable_experimental_alter_column_type_general='true';
I don't think we need this statement. We already call this higher up in the testcase.
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1224 at r1 (raw file):
statement ok set enable_experimental_alter_column_type_general='true'; set use_declarative_schema_changer = off;
I think we call this test for the local-legacy-schema-changer config. So, I don't think we need this.
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1233 at r1 (raw file):
statement error pq: cannot alter type of column "b" because it is referenced by partial index "idx" alter table a alter column b set data type timestamp using a::timestamp;
We should expand this test and verify that we can alter the type of other columns not included in the partial index.
464bddd to
499a23e
Compare
Dedej-Bergin
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @spilchen)
Previously, spilchen wrote…
Let's include the epic in the commit message: CRDB-25314
Thanks, just updated it.
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1218 at r1 (raw file):
Previously, spilchen wrote…
I usually aim to include a single
subtest endat the bottom of the test. Since you've already added one, you can probably remove this line.
Thanks, I just removed it.
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1223 at r1 (raw file):
Previously, spilchen wrote…
I don't think we need this statement. We already call this higher up in the testcase.
Okay great, I just removed it, thanks!
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1224 at r1 (raw file):
Previously, spilchen wrote…
I think we call this test for the
local-legacy-schema-changerconfig. So, I don't think we need this.
Right, I just added onlyif config local-legacy-schema-changer just now and removed this line, thanks!
spilchen
left a comment
There was a problem hiding this comment.
Reviewed all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @Dedej-Bergin)
Previously, Dedej-Bergin (Bergin Dedej) wrote…
Thanks, just updated it.
Apologies, I meant to say that you should include this in the commit message. I thought there was a git hook in place to ensure the commit message follows the correct format.
Epic: CRDB-25314
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1224 at r1 (raw file):
Previously, Dedej-Bergin (Bergin Dedej) wrote…
Right, I just added onlyif config local-legacy-schema-changer just now and removed this line, thanks!
We should be seeing the same error when the commands are run through the DSC. Are you observing a different outcome?
|
Previously, spilchen wrote…
Yes a bit different, for the new code changes I just added, with these repro steps: I was thinking to make it work like this: For DSC on the second one it seems to error out with unimplemented... not sure if that's the error message we want: |
499a23e to
1bc6f42
Compare
Dedej-Bergin
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @spilchen)
Previously, spilchen wrote…
Apologies, I meant to say that you should include this in the commit message. I thought there was a git hook in place to ensure the commit message follows the correct format.
Epic: CRDB-25314
Just added this, for some reason I thought this happens automatically.
pkg/sql/catalog/schemaexpr/expr.go line 518 at r1 (raw file):
Previously, spilchen wrote…
Should we verify that the column is included in the partial index?
Yes just added this code, thanks @spilchen!
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1233 at r1 (raw file):
Previously, spilchen wrote…
We should expand this test and verify that we can alter the type of other columns not included in the partial index.
Just added the expanded test, thanks!
spilchen
left a comment
There was a problem hiding this comment.
Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @Dedej-Bergin)
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1224 at r1 (raw file):
Previously, Dedej-Bergin (Bergin Dedej) wrote…
Yes a bit different, for the new code changes I just added, with these repro steps:
create table roach\_village ( roach\_id int primary key, first\_name text, last\_name text, legs int ); create index idx on roach\_village(last\_name) where first\_name = 'papa roach'; alter table roach\_village alter column first\_name set data type timestamp using first\_name::timestamp; alter table roach\_village alter column last\_name set data type timestamp using last\_name::timestamp;I was thinking to make it work like this:
For DSC on the second one it seems to error out with unimplemented... not sure if that's the error message we want:
The unimplemented error is expected for now—that’s what #127014 will address. In the meantime, can you try using a simpler type conversion instead of a complex one? A simple conversion is one that doesn’t require a backfill. This is supported in the DSC now and should let us run the test in both modes. For example, converting from TEXT to CHAR(20) would qualify as a simple conversion.
Dedej-Bergin
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @spilchen)
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1224 at r1 (raw file):
Previously, spilchen wrote…
The unimplemented error is expected for now—that’s what #127014 will address. In the meantime, can you try using a simpler type conversion instead of a complex one? A simple conversion is one that doesn’t require a backfill. This is supported in the DSC now and should let us run the test in both modes. For example, converting from
TEXTtoCHAR(20)would qualify as a simple conversion.
So it seems that DSC doesn't block when the column is part of the predicate.
|
Previously, Dedej-Bergin (Bergin Dedej) wrote…
Actually we seem to error out on the predicate, but on the column that has the index we seem to not error out on DSC. |
spilchen
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @Dedej-Bergin)
pkg/sql/logictest/testdata/logic_test/alter_column_type line 1224 at r1 (raw file):
Previously, Dedej-Bergin (Bergin Dedej) wrote…
Actually we seem to error out on the predicate, but on the column that has the index we seem to not error out on DSC.
Is this something we should change in the DSC?
Thanks for running these tests. The DSC behavior is correct: it should fail only when modifying the partial expression and succeed when modifying a key column. Key columns can be changed because we’ll rewrite the index if a backfill is needed, or, if no backfill is required, the on-disk encoding of the column in the index remains unchanged (e.g., BIGINT to SMALLINT).
Could you remove the key column check in the legacy code? Sorry for not mentioning this earlier!
Previously we would allow ALTER COLUMN TYPE to succeed on a column even when we have a partial index on it. This would cause issues down the line for example at insert and is inconsistent with postgres. This fix now checks for partial index and errors out like postgres when your run the ALTER COLUMN TYPE command on a column with a partial index. Fixes: cockroachdb#72456 Epic: CRDB-25314 Release note (bug fix): ALTER COLUMN TYPE now errors out when we have a partial index dependent on the column being altered.
1bc6f42 to
5047d8b
Compare
|
Previously, spilchen wrote…
No worries, just made the changes. The test-case results are now coming back the same for both DSC and legacy, thanks! |
spilchen
left a comment
There was a problem hiding this comment.
Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @Dedej-Bergin)
|
bors r+ |




Previously we would allow ALTER COLUMN TYPE to succeed on a column even when we have a partial index on it. This would cause issues down the line for example at insert and is inconsistent with postgres. This fix now checks for partial index and errors out like postgres when your run the ALTER COLUMN TYPE command on a column with a partial index.
Fixes: #72456
Epic: CRDB-25314
Release note (bug fix): ALTER COLUMN TYPE now errors out when we have a partial index dependent on the column being altered.