Skip to content

Commit

Permalink
sql: disallow REGIONAL BY ROW transitions if indexes being dropped are
Browse files Browse the repository at this point in the history
incompatible

Release note (bug fix): Previously, if a DROP INDEX failed during a
REGIONAL BY ROW transition, the index may be re-inserted back into the
REGIONAL BY ROW table but would be invalid if it was sharded or
partitioned. This is now rectified.
  • Loading branch information
otan committed Apr 21, 2021
1 parent cc94126 commit 3ed3826
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ CREATE TABLE hash_sharded_idx_table (
pk INT PRIMARY KEY USING HASH WITH BUCKET_COUNT = 8
)

statement error cannot convert a table to REGIONAL BY ROW if table table contains hash sharded indexes
statement error cannot convert hash_sharded_idx_table to REGIONAL BY ROW as the table contains hash sharded indexes
ALTER TABLE hash_sharded_idx_table SET LOCALITY REGIONAL BY ROW

statement ok
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/alter_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ func checkCanConvertTableToMultiRegion(
tableDesc.GetName(),
)
}
for _, idx := range tableDesc.NonDropIndexes() {
for _, idx := range tableDesc.AllIndexes() {
if idx.GetPartitioning().NumColumns > 0 {
return errors.WithDetailf(
pgerror.Newf(
Expand Down
8 changes: 6 additions & 2 deletions pkg/sql/alter_table_locality.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,13 @@ func (n *alterTableSetLocalityNode) alterTableLocalityToRegionalByRow(
return interleaveOnRegionalByRowError()
}

for _, idx := range n.tableDesc.NonDropIndexes() {
for _, idx := range n.tableDesc.AllIndexes() {
if idx.IsSharded() {
return pgerror.New(pgcode.FeatureNotSupported, "cannot convert a table to REGIONAL BY ROW if table table contains hash sharded indexes")
return pgerror.Newf(
pgcode.FeatureNotSupported,
"cannot convert %s to REGIONAL BY ROW as the table contains hash sharded indexes",
tree.Name(n.tableDesc.GetName()),
)
}
}

Expand Down

0 comments on commit 3ed3826

Please sign in to comment.