Skip to content

Commit

Permalink
Merge #118780
Browse files Browse the repository at this point in the history
118780: sql: Allow dropping enum value when referenced by UDF r=rafiss a=rimadeodhar

This PR extends the current validation code executed
while dropping an enum value to also check for the value
being referenced in a UDF. Additionally, we re-enable
testing for `alterTypeDropValue` within the random
schema change workload.

Prior to dropping an enum value, we confirm that the value
is unused in tables, constraints, indices etc. However,
when we added support for UDFs, we did not extend the
scope of this to also check for an enum value being
referenced in a UDF. This introduced a bug where we were
unable to drop an unused enum value if some other value
from within the enum was  being referenced by a UDF.
For example, if an enum 'e' contained values {'1', '2', '3'},
with the value '1' being referenced in a UDF, we were
unable to drop the values '2' and '3' as well.
This PR fixes this bug by expanding the usage check for
enum values to also include UDFs. With this fix, we can drop
an enum value as long as the value itself is unreferenced.

The **first commit** address this bug and and  refactors some of
the common code into its own methods to avoid code duplication. 
It extends the existing test suite to test for multiple scenarios 
when an enum value is dropped. 

The **second commit** re-enables testing for `alterTypeDropValue`
within the random schema workload. This was disabled
due to the bug which is being addressed in the first commit.

Epic: none

Fixes: #115612, #114844

Release note (bug fix): Fix an existing bug where we are
unable to drop an unused value from an enum if the enum is being
referenced in a UDF. With this bug fix, we can drop a value
from an enum as long as the value is not being referenced
by a UDF. Note, the enum can still be referenced by a UDF.
We only allow a value to be dropped if the value is not being
referenced by any other data element including UDFs.

Co-authored-by: rimadeodhar <[email protected]>
  • Loading branch information
craig[bot] and rimadeodhar committed Mar 5, 2024
2 parents f39413a + 20ca2b5 commit ba61280
Show file tree
Hide file tree
Showing 4 changed files with 551 additions and 233 deletions.
1 change: 1 addition & 0 deletions pkg/sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ go_test(
deps = [
"//pkg/base",
"//pkg/build/bazel",
"//pkg/ccl",
"//pkg/ccl/changefeedccl/schemafeed/schematestutils",
"//pkg/cloud/impl:cloudimpl",
"//pkg/clusterversion",
Expand Down
Loading

0 comments on commit ba61280

Please sign in to comment.