cockroachdb / cockroachdb/cockroach
sql/multiregion: ALTER SUPER REGION missing DROP SECONDARY REGION and DROP PRIMARY REGION syntax
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Is your feature request related to a problem?**
At the database level, `ALTER DATABASE ... DROP SECONDARY REGION` ([alter_database.go:2171-2279](https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/alter_database.go#L2171-L2279)) clears the secondary region by setting it to `""` on both the database descriptor and type descriptor, then regenerates zone configs. No equivalent exists for super regions:
- `ALTER DATABASE ... ALTER SUPER REGION ... SET PRIMARY REGION` — still an unimplemented stub
- `ALTER DATABASE ... ALTER SUPER REGION ... SET SECONDARY REGION` — still an unimplemented stub
- `ALTER DATABASE ... ALTER SUPER REGION ... DROP SECONDARY REGION` — does not exist at all
As a result, once a super region is created with:
```sql
ALTER DATABASE ... ADD SUPER REGION "sr1" VALUES ... PRIMARY REGION "x" SECONDARY REGION "y"
```
the only way to remove the secondary region is to drop the entire super region and re-add it without one. Additionally, `ALTER SUPER REGION "sr1" VALUES ...` unconditionally preserves the old primary/secondary settings, so even changing the region list does not help.
This is a real gap in the super region API surface.
**Describe the solution you'd like:**
1. Add `ALTER DATABASE ... ALTER SUPER REGION ... DROP SECONDARY REGION` — following the database-level pattern in [alter_database.go:2171-2279](https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/alter_database.go#L2171-L2279). Without it, there is no way to unset a secondary region on a super region short of drop-and-recreate.
2. Add `ALTER DATABASE ... ALTER SUPER REGION ... DROP PRIMARY REGION`, with a guard ensuring the primary cannot be dropped while a secondary region is defined (mirroring the ordering constraint at the database level).
**Describe alternatives you've considered:**
Dropping and re-adding the super region is the only current workaround, but it is disruptive and non-atomic.
**Additional context:**
The existing unimplemented stubs for `SET PRIMARY REGION` and `SET SECONDARY REGION` on super regions should also be addressed as part of or alongside this work.
Jira issue: CRDB-60969
Epic CRDB-45396
Contributor guide
Assessment
This issue has not been assessed yet.