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, planner, types: add M>=D checking for decimal column definition with default value #21845

Merged
merged 8 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2665,3 +2665,11 @@ func (s *testIntegrationSuite7) TestDuplicateErrorMessage(c *C) {
}
}
}

func (s *testIntegrationSuite3) TestIssue21835(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
_, err := tk.Exec("create table t( col decimal(1,2) not null default 0);")
c.Assert(err.Error(), Equals, "[types:1427]For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 'col').")
}
7 changes: 7 additions & 0 deletions planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@ func checkColumn(colDef *ast.ColumnDef) error {
if tp.Flen > mysql.MaxFloatingTypeWidth {
return types.ErrTooBigDisplayWidth.GenWithStackByArgs(colDef.Name.Name.O, mysql.MaxFloatingTypeWidth)
}
if tp.Flen < tp.Decimal {
return types.ErrMBiggerThanD.GenWithStackByArgs(colDef.Name.Name.O)
}
}
case mysql.TypeSet:
if len(tp.Elems) > mysql.MaxTypeSetMembers {
Expand All @@ -953,6 +956,10 @@ func checkColumn(colDef *ast.ColumnDef) error {
if tp.Flen > mysql.MaxDecimalWidth {
return types.ErrTooBigPrecision.GenWithStackByArgs(tp.Flen, colDef.Name.Name.O, mysql.MaxDecimalWidth)
}

if tp.Flen < tp.Decimal {
return types.ErrMBiggerThanD.GenWithStackByArgs(colDef.Name.Name.O)
}
case mysql.TypeBit:
if tp.Flen <= 0 {
return types.ErrInvalidFieldSize.GenWithStackByArgs(colDef.Name.Name.O)
Expand Down