Commit 4ed46b5
Merge cockroachdb#154608
154608: scbuild: implement RENAME CONSTRAINT in declarative schema changer r=rafiss a=rafiss
This patch implements full support for RENAME CONSTRAINT in the
declarative schema changer. The implementation handles two types of
constraints:
1. Index-backed constraints (PRIMARY KEY, UNIQUE with index): These
rename by dropping the old IndexName element and adding a new one
with the updated name.
2. Non-index constraints (CHECK, FK, UNIQUE without index): These
rename by dropping the old ConstraintWithoutIndexName element and
adding a new one with the updated name.
The implementation includes proper validation:
- Checks for constraint existence
- Validates the constraint is not being added/dropped concurrently
- Prevents name conflicts with existing constraints and indexes
- Ensures views don't depend on index-backed constraints being renamed
New dependency rules ensure the old name element reaches ABSENT before
the new name element becomes PUBLIC, preventing conflicts and ensuring
correct rollback behavior.
### scplan: add dependency rules for cross-constraint name conflicts during rename
This commit enhances the RENAME CONSTRAINT implementation by adding
dependency rules to handle name conflicts that occur when multiple
constraints are renamed in the same schema change operation.
Previously, the dependency rules only handled simple single-constraint
renames (A → B). However, when multiple constraints are renamed such
that names are swapped or reused (e.g., C1: "old" → "new" while C2:
"new" → "other"), the original rules could allow conflicting names to
exist simultaneously during execution.
This adds two new Precedence rules:
1. For index-backed constraints: Ensures old IndexName elements reach
ABSENT before new IndexName elements with the same name become PUBLIC.
Includes special handling to exclude secondary index swaps during
ALTER PRIMARY KEY operations.
2. For cross-type conflicts: Handles name conflicts between any
combination of ConstraintWithoutIndexName and IndexName elements,
preventing CHECK constraints from conflicting with UNIQUE constraint
names, for example.
---
fixes cockroachdb#148341
Release note: None
Co-authored-by: Rafi Shamim <[email protected]>File tree
98 files changed
+1146
-158
lines changed- pkg
- ccl/schemachangerccl
- sctestbackupccl
- testdata/end_to_end
- add_column_multiple_regional_by_row
- alter_table_alter_primary_key_rbr
- sql/schemachanger
- scbuild
- internal/scbuildstmt
- testdata
- scplan
- internal/rules/current
- testdata
- testdata
- testdata/end_to_end
- alter_table_add_primary_key_drop_rowid_with_secondary_idx
- alter_table_add_primary_key_drop_rowid
- alter_table_alter_column_type_general_expr
- alter_table_alter_column_type_general
- alter_table_alter_primary_key_drop_rowid_with_idx
- alter_table_alter_primary_key_drop_rowid
- alter_table_multiple_commands
- alter_table_rename_constraint
- alter_table_validate_constraint
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
98 files changed
+1146
-158
lines changedLines 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: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
| 83 | + | |
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
| 83 | + | |
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
| 87 | + | |
89 | 88 | | |
90 | 89 | | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
119 | | - | |
| 118 | + | |
120 | 119 | | |
121 | 120 | | |
122 | 121 | | |
| |||
128 | 127 | | |
129 | 128 | | |
130 | 129 | | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
118 | 117 | | |
119 | 118 | | |
120 | 119 | | |
121 | | - | |
| 120 | + | |
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
| |||
128 | 127 | | |
129 | 128 | | |
130 | 129 | | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
0 commit comments