Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: forbidden changing decimal to int (#19645) #19681

Merged
merged 6 commits into from Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions ddl/column_test.go
Expand Up @@ -922,6 +922,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
Expand Up @@ -2469,6 +2469,9 @@ func modifiable(origin *types.FieldType, to *types.FieldType) error {
}
}
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