Skip to content

Commit 6e7d450

Browse files
committed
sql/schemachanger: support partitions and RBR tables for alter PK
Previously, ALTER PRIMARY KEY in the declarative schema changer did not support partitioned / RBR tables, which would cause it to fallback. This meant that ALTER PRIMARY KEY would always use the legacy schema changer on multi-region environments. To address this, this patch adds partitioning and RBR support into the declarative ALTER PRIMARY KEY. This includes logic to generate subzone config for replacement indexes and generating zone configurations for new primary keys. Fixes: #146725 Release note: None
1 parent e76f45b commit 6e7d450

File tree

80 files changed

+11569
-2739
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+11569
-2739
lines changed

pkg/ccl/partitionccl/zone_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,10 +1022,12 @@ func TestPrimaryKeyChangeZoneConfigs(t *testing.T) {
10221022
// dropped copy of i2, new copy of i1, and new copy of i2.
10231023
// These have ID's 2, 3, 6 and 8 respectively.
10241024
expectedSpans := []roachpb.Key{
1025-
table.IndexSpan(codec, 2 /* indexID */).Key,
1026-
table.IndexSpan(codec, 3 /* indexID */).Key,
1027-
table.IndexSpan(codec, 6 /* indexID */).Key,
1028-
table.IndexSpan(codec, 8 /* indexID */).Key,
1025+
table.IndexSpan(codec, 2 /* indexID */).Key, // index: old_i1
1026+
table.IndexSpan(codec, 3 /* indexID */).Key, // index: old_i2
1027+
table.IndexSpan(codec, 4 /* indexID */).Key, // index: i1
1028+
table.IndexSpan(codec, 5 /* indexID */).Key, // index: i1_tmp
1029+
table.IndexSpan(codec, 6 /* indexID */).Key, // index: i2
1030+
table.IndexSpan(codec, 7 /* indexID */).Key, // index: i2_tmp
10291031
}
10301032
if len(zone.SubzoneSpans) != len(expectedSpans) {
10311033
t.Fatalf("expected subzones to have length %d", len(expectedSpans))

pkg/ccl/schemachangerccl/ccl_generated_test.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/schemachangerccl/sctestbackupccl/backup_multiregion_generated_test.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
setup
2+
CREATE DATABASE multiregion_db PRIMARY REGION "us-east1" REGIONS "us-east2", "us-east3" SURVIVE REGION FAILURE;
3+
CREATE TABLE multiregion_db.public.table_regional_by_row (
4+
k INT NOT NULL,
5+
V STRING
6+
) LOCALITY REGIONAL BY ROW;
7+
CREATE INDEX on multiregion_db.table_regional_by_row(v);
8+
----
9+
10+
stage-exec phase=PostCommitPhase stage=:
11+
USE multiregion_db;
12+
INSERT INTO multiregion_db.table_regional_by_row(k) VALUES($stageKey);
13+
INSERT INTO multiregion_db.table_regional_by_row(k) VALUES($stageKey + 1);
14+
----
15+
16+
stage-exec phase=PostCommitNonRevertiblePhase stage=:
17+
USE multiregion_db;
18+
INSERT INTO multiregion_db.table_regional_by_row(k) VALUES($stageKey);
19+
INSERT INTO multiregion_db.table_regional_by_row(k) VALUES($stageKey + 1);
20+
----
21+
22+
stage-exec phase=PostCommitPhase stage=:
23+
USE multiregion_db;
24+
SELECT crdb_internal.validate_multi_region_zone_configs()
25+
----
26+
27+
stage-exec phase=PostCommitNonRevertiblePhase stage=:
28+
USE multiregion_db;
29+
SELECT crdb_internal.validate_multi_region_zone_configs()
30+
----
31+
32+
test
33+
alter table multiregion_db.table_regional_by_row add column m int8 default unique_rowid(), alter primary key using columns(k) USING HASH;
34+
----

0 commit comments

Comments
 (0)