cockroachdb / cockroachdb/cockroach
sql: schema_locked is unset at the same time as other descriptor updates
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
The RFC for the schema_locked feature (https://github.com/ajwerner/cockroach/blob/ajwerner/low-latency-rfc-take-3/docs/RFCS/20230328_low_latency_changefeeds.md) says:
> The act of locking a descriptor is to publish a new version of the descriptor which is identical to the current (unlocked) version, but with the locked bit set. The act of unlocking a descriptor is to publish a new version of the descriptor which is identical to the current (locked) version, but with the locked bit cleared.
However, it seems like the schema changer can publish a new version of the descriptor that both removes the bit and starts mutations.
**Example**
SQL:
```
CREATE TABLE hasfams (id int primary key, a string, b string, c string, FAMILY id_a (id, a), FAMILY b_and_c (b, c));
ALTER TABLE hasfams DROP COLUMN a;
```
Descriptor changes:
```
{
"ID": 106,
- "Version": 1,
+ "Version": 2,
- "ModificationTime": "1752123348.584960555,0",
+ "ModificationTime": "1752123348.699179128,1",
"ParentID": 104,
"ParentSchemaID": 105,
"State": "PUBLIC",
- "SchemaLocked": true,
"NextColumnID": 5,
"Columns": [
{
"ID": 1,
"TypeID": 20,
"Null": false
- },
- {
- "ID": 2,
- "TypeID": 25,
- "Null": true
},
{
"ID": 3,
"TypeID": 25,
"Null": true
},
{
"ID": 4,
"TypeID": 25,
"Null": true
}
],
"NextFamilyID": 2,
"Families": [
{
"ID": 0,
"Columns": [
1,
2
]
},
{
"ID": 1,
"Columns": [
3,
4
]
}
],
+ "Mutations": [
+ {
+ "MutationID": 1,
+ "Direction": "ADD",
+ "State": "BACKFILLING",
+ "Index": {
+ "ID": 2,
+ "Unique": true,
+ "KeyColumns": [
+ {
+ "ID": 1,
+ "Dir": "ASC"
+ }
+ ],
+ "StoreColumns": [
+ 3,
+ 4
+ ],
+ "State": "ADD",
+ "MutationID": 1
+ }
+ },
+ {
+ "MutationID": 1,
+ "Direction": "ADD",
+ "State": "DELETE_ONLY",
+ "Index": {
+ "ID": 3,
+ "Unique": true,
+ "KeyColumns": [
+ {
+ "ID": 1,
+ "Dir": "ASC"
+ }
+ ],
+ "StoreColumns": [
+ 3,
+ 4
+ ],
+ "State": "ADD",
+ "MutationID": 1
+ }
+ },
+ {
+ "MutationID": 1,
+ "Direction": "DROP",
+ "State": "WRITE_ONLY",
+ "Column": {
+ "ID": 2,
+ "TypeID": 25,
+ "Null": true,
+ "State": "DROP",
+ "MutationID": 1
+ }
+ }
+ ],
"PrimaryIndex": 1,
- "NextIndexID": 2,
+ "NextIndexID": 4,
"Indexes": [
{
"ID": 1,
"Unique": true,
"KeyColumns": [
{
"ID": 1,
"Dir": "ASC"
}
],
"StoreColumns": [
2,
3,
4
]
}
]
}
```
(Note: I made the following change to get the SchemaLocked bit to show up.)
```
diff --git a/pkg/sql/catalog/tabledesc/safe_format.go b/pkg/sql/catalog/tabledesc/safe_format.go
index 0d5ecbefef8..0e26df6ccf3 100644
--- a/pkg/sql/catalog/tabledesc/safe_format.go
+++ b/pkg/sql/catalog/tabledesc/safe_format.go
@@ -42,6 +42,9 @@ func formatSafeTableProperties(w *redact.StringBuilder, desc catalog.TableDescri
if desc.IsVirtualTable() {
w.Printf(", Virtual: true")
}
+ if desc.IsSchemaLocked() {
+ w.Printf(", SchemaLocked: true")
+ }
formatSafeTableColumns(w, desc)
formatSafeTableColumnFamilies(w, desc)
formatSafeTableMutationJobs(w, desc)
```
Jira issue: CRDB-52464
Epic CRDB-104
Contributor guide
Assessment
This issue has not been assessed yet.