Skip to content

Commit dd3d68a

Browse files
committed
scplan: relax constraint for cleaning up non-index-backed constraints
This rule was matching all non-index-backed constraints, but it only needs to apply to UNIQUE WITHOUT INDEX constraints. Release note: None
1 parent 77a89ad commit dd3d68a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pkg/sql/schemachanger/scplan/internal/rules/current/dep_drop_constraint.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,23 @@ func init() {
9696
)
9797
}
9898

99-
// These rules ensure that a non-indexed backed constraint with a column
100-
// name in its expression is cleaned up before the column is dropped.
99+
// These rules ensure that a unique without index constraint with a column
100+
// name in its expression is cleaned up before the column name is dropped.
101+
// This is needed because unique without index constraints can have predicates
102+
// that reference columns by name.
101103
func init() {
102104
registerDepRuleForDrop(
103-
"non-indexed backed constraint should be cleaned up "+
104-
"before column name references",
105+
"unique without index constraint should be cleaned up before column name references",
105106
scgraph.Precedence,
106107
"constraint", "referenced-column-name",
107108
scpb.Status_ABSENT, scpb.Status_ABSENT,
108109
func(from, to NodeVars) rel.Clauses {
109110
fromColumnID := rel.Var("fromColumnID")
110111
return rel.Clauses{
111-
from.TypeFilter(rulesVersionKey, isNonIndexBackedConstraint, isWithExpression),
112+
from.Type(
113+
(*scpb.UniqueWithoutIndexConstraint)(nil),
114+
(*scpb.UniqueWithoutIndexConstraintUnvalidated)(nil),
115+
),
112116
from.ReferencedColumnIDsContains(fromColumnID),
113117
to.Type((*scpb.ColumnName)(nil)),
114118
to.El.AttrEqVar(screl.ColumnID, fromColumnID),

0 commit comments

Comments
 (0)