From df761ba015717f96ad22be28e03b853a68da183a Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Thu, 3 Sep 2020 21:38:08 +0800 Subject: [PATCH] ddl: forbidden changing decimal to int (#19645) (#19682) --- ddl/column_test.go | 3 +++ ddl/ddl_api.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/ddl/column_test.go b/ddl/column_test.go index d16a1dbd24873..af373407c0f82 100644 --- a/ddl/column_test.go +++ b/ddl/column_test.go @@ -948,6 +948,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) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 0ce48000220c8..034a8e9ef6b3c 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2750,6 +2750,9 @@ func checkModifyTypes(origin *types.FieldType, to *types.FieldType, needRewriteC } } 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")