Skip to content

Commit

Permalink
ddl: forbidden changing decimal to int (#19645)
Browse files Browse the repository at this point in the history
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
  • Loading branch information
wjhuang2016 authored Sep 1, 2020
1 parent 9047a9c commit e62e1fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,9 @@ func (s *testColumnSuite) TestModifyColumn(c *C) {
{"decimal(2,1)", "decimal(3,2)", errUnsupportedModifyColumn.GenWithStackByArgs("can't change decimal column precision")},
{"decimal(2,1)", "decimal(2,2)", errUnsupportedModifyColumn.GenWithStackByArgs("can't change decimal column precision")},
{"decimal(2,1)", "decimal(2,1)", nil},
{"decimal(2,1)", "int", errUnsupportedModifyColumn.GenWithStackByArgs("type int(11) not match origin decimal(2,1)")},
{"decimal", "int", errUnsupportedModifyColumn.GenWithStackByArgs("type int(11) not match origin decimal(11,0)")},
{"decimal(2,1)", "bigint", errUnsupportedModifyColumn.GenWithStackByArgs("type bigint(20) not match origin decimal(2,1)")},
}
for _, tt := range tests {
ftA := s.colDefStrToFieldType(c, tt.origin)
Expand Down
3 changes: 3 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3237,6 +3237,9 @@ func CheckModifyTypeCompatible(origin *types.FieldType, to *types.FieldType) (al
}
}
case mysql.TypeNewDecimal:
if origin.Tp != to.Tp {
return "", errUnsupportedModifyColumn.GenWithStackByArgs(unsupportedMsg)
}
// The root cause is modifying decimal precision needs to rewrite binary representation of that decimal.
if to.Flen != origin.Flen || to.Decimal != origin.Decimal {
return "", errUnsupportedModifyColumn.GenWithStackByArgs("can't change decimal column precision")
Expand Down

0 comments on commit e62e1fe

Please sign in to comment.