Skip to content

Commit

Permalink
release-24.2: schemachanger: add PartitionName to IndexZoneConfig attr
Browse files Browse the repository at this point in the history
This patch adds a `PartitionName` attribute to the `IndexZoneConfig`
element to uniquely identify partitions from one another. Prior to this,
hitting a certain DROP path on a table with more than 1 partition on an
index would panic with an undropped backref error due to our inability
to distinguish these partitions from eachother.

Our code to drop these partition elements would always refer to the
top-most partition element in the descsCache's `elementIndexMap`
-- as the key to identify partition1 from partition2 was the same. So,
partition1 would be marked `toAbsent` "twice"; while partition2 got
ignored </3.

Another thing to note is that this bug is not just met for partitioned
tables of the nature mentioned above -- as the `builderState`'s descriptor
cache would need to be unchanged between each partition's drop.

Epic: none
Fixes: #131862

Release note (bug fix): Addressed a bug with DROP CASCADE that would
occasionally panic with an undropped backref message on partitioned
tables.
  • Loading branch information
annrpom committed Nov 7, 2024
1 parent 8dfd45d commit e1a5934
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
24 changes: 24 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/multi_region_zone_configs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,3 +1864,27 @@ SELECT crdb_internal.reset_multi_region_zone_configs_for_table($tbl11_id)

query error user testuser must be owner of test or have CREATE privilege on database test
SELECT crdb_internal.validate_multi_region_zone_configs()

subtest drop_all_backrefs

user root

statement ok
CREATE DATABASE db1 PRIMARY REGION "ca-central-1" REGIONS "ap-southeast-2", "us-east-1" SURVIVE REGION FAILURE

statement ok
CREATE TABLE db1.t1_with_index_zone(x INT, j INT REFERENCES db1.t1_with_index_zone(x), PRIMARY KEY(x)) LOCALITY REGIONAL BY ROW

statement ok
ALTER PARTITION "ap-southeast-2" OF INDEX db1.t1_with_index_zone@t1_with_index_zone_pkey CONFIGURE ZONE USING gc.ttlseconds = 32000;

statement ok
ALTER PARTITION "ca-central-1" OF INDEX db1.t1_with_index_zone@t1_with_index_zone_pkey CONFIGURE ZONE USING gc.ttlseconds = 34000;

statement ok
ALTER PARTITION "us-east-1" OF INDEX db1.t1_with_index_zone@t1_with_index_zone_pkey CONFIGURE ZONE USING gc.ttlseconds = 38000;

statement ok
DROP TABLE db1.t1_with_index_zone CASCADE;

subtest end
4 changes: 4 additions & 0 deletions pkg/sql/schemachanger/screl/attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ const (
// Expr corresponds to the string representation of a SQL expression for an element.
Expr

// PartitionName corresponds to the name of a partition.
PartitionName

// AttrMax is the largest possible Attr value.
// Note: add any new enum values before TargetStatus, leave these at the end.
AttrMax = iota - 1
Expand Down Expand Up @@ -385,6 +388,7 @@ var elementSchemaOptions = []rel.SchemaOption{
rel.EntityMapping(t((*scpb.IndexZoneConfig)(nil)),
rel.EntityAttr(DescID, "TableID"),
rel.EntityAttr(IndexID, "IndexID"),
rel.EntityAttr(PartitionName, "PartitionName"),
),
rel.EntityMapping(t((*scpb.DatabaseData)(nil)),
rel.EntityAttr(DescID, "DatabaseID"),
Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/schemachanger/screl/attr_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e1a5934

Please sign in to comment.