diff --git a/pkg/planner/core/preprocess.go b/pkg/planner/core/preprocess.go index 19b6f811cfe6d..e68b3df13b67d 100644 --- a/pkg/planner/core/preprocess.go +++ b/pkg/planner/core/preprocess.go @@ -1415,21 +1415,22 @@ func checkColumn(colDef *ast.ColumnDef) error { } } case mysql.TypeNewDecimal: - if tp.GetDecimal() > mysql.MaxDecimalScale { - return types.ErrTooBigScale.GenWithStackByArgs(tp.GetDecimal(), colDef.Name.Name.O, mysql.MaxDecimalScale) + tpFlen := tp.GetFlen() + tpDecimal := tp.GetDecimal() + if tpDecimal > mysql.MaxDecimalScale { + return types.ErrTooBigScale.GenWithStackByArgs(tpDecimal, colDef.Name.Name.O, mysql.MaxDecimalScale) } - - if tp.GetFlen() > mysql.MaxDecimalWidth { - return types.ErrTooBigPrecision.GenWithStackByArgs(tp.GetFlen(), colDef.Name.Name.O, mysql.MaxDecimalWidth) + if tpFlen > mysql.MaxDecimalWidth { + return types.ErrTooBigPrecision.GenWithStackByArgs(tpFlen, colDef.Name.Name.O, mysql.MaxDecimalWidth) } - - if tp.GetFlen() < tp.GetDecimal() { + if tpFlen < tpDecimal { return types.ErrMBiggerThanD.GenWithStackByArgs(colDef.Name.Name.O) } // If decimal and flen all equals 0, just set flen to default value. - if tp.GetDecimal() == 0 && tp.GetFlen() == 0 { + if tpFlen == 0 && (tpDecimal == 0 || tpDecimal == types.UnspecifiedLength) { defaultFlen, _ := mysql.GetDefaultFieldLengthAndDecimal(mysql.TypeNewDecimal) tp.SetFlen(defaultFlen) + tp.SetDecimal(0) } case mysql.TypeBit: if tp.GetFlen() <= 0 { diff --git a/tests/integrationtest/r/ddl/column.result b/tests/integrationtest/r/ddl/column.result index 36af62a4acf00..7d285b5ec4881 100644 --- a/tests/integrationtest/r/ddl/column.result +++ b/tests/integrationtest/r/ddl/column.result @@ -57,3 +57,11 @@ t2 CREATE TABLE `t2` ( PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, UNIQUE KEY `authorIdx` (`authorId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +drop table if exists t; +create table t(a decimal(0,0), b decimal(0)); +show create table t; +Table Create Table +t CREATE TABLE `t` ( + `a` decimal(10,0) DEFAULT NULL, + `b` decimal(10,0) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin diff --git a/tests/integrationtest/t/ddl/column.test b/tests/integrationtest/t/ddl/column.test index 6962eb6351fd2..0376192a6ada0 100644 --- a/tests/integrationtest/t/ddl/column.test +++ b/tests/integrationtest/t/ddl/column.test @@ -18,3 +18,7 @@ show create table t1; CREATE TABLE `t2`( `id` INTEGER PRIMARY KEY, `authorId` int(11) AUTO_INCREMENT, UNIQUE KEY `authorIdx` (`authorId`)); show create table t2; +# TestIssue53779 +drop table if exists t; +create table t(a decimal(0,0), b decimal(0)); +show create table t;