Skip to content

Commit c5a3d18

Browse files
committed
scplan: tighten rule for transient check constraints
This rule was only needed for the ALTER COLUMN TYPE op, so the rule is updated to only apply in that case. Release note: None
1 parent dd3d68a commit c5a3d18

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,25 @@ func init() {
3939
"transient-check-constraint", "column-type",
4040
func(from, to NodeVars) rel.Clauses {
4141
colID := rel.Var("columnID")
42+
tableID := rel.Var("table-id")
43+
oldColumnType := MkNodeVars("old-column-type")
4244
return rel.Clauses{
4345
from.Type((*scpb.CheckConstraint)(nil)),
4446
to.Type((*scpb.ColumnType)(nil)),
45-
JoinOnDescID(from, to, "table-id"),
47+
JoinOnDescID(from, to, tableID),
4648
to.El.AttrEqVar(screl.ColumnID, colID),
4749
from.ReferencedColumnIDsContains(colID),
4850
from.TargetStatus(scpb.TransientAbsent),
4951
to.TargetStatus(scpb.ToPublic),
5052
from.CurrentStatus(scpb.Status_TRANSIENT_VALIDATED),
5153
to.CurrentStatus(scpb.Status_PUBLIC),
54+
// Only apply this rule if there's an old column type being dropped,
55+
// which indicates this is an ALTER COLUMN TYPE operation.
56+
oldColumnType.Type((*scpb.ColumnType)(nil)),
57+
oldColumnType.El.AttrEqVar(screl.DescID, tableID),
58+
oldColumnType.El.AttrEqVar(screl.ColumnID, colID),
59+
oldColumnType.TargetStatus(scpb.ToAbsent),
60+
oldColumnType.JoinTargetNode(),
5261
}
5362
},
5463
)

0 commit comments

Comments
 (0)