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: check table-level check constraint when create table #20202

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5091,7 +5091,7 @@ func (s *testDBSuite4) TestColumnCheck(c *C) {
tk.MustExec("create table column_check (pk int primary key, a int check (a > 1))")
defer tk.MustExec("drop table if exists column_check")
c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(1))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|8231|Column check is not supported"))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|8231|CONSTRAINT CHECK is not supported"))
}

func (s *testDBSuite5) TestAlterCheck(c *C) {
Expand Down Expand Up @@ -5127,6 +5127,19 @@ func (s *testDBSuite7) TestAddConstraintCheck(c *C) {
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|8231|ADD CONSTRAINT CHECK is not supported"))
}

func (s *testDBSuite7) TestCreateTableIngoreCheckConstraint(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use " + s.schemaName)
tk.MustExec("drop table if exists table_constraint_check")
tk.MustExec("CREATE TABLE admin_user (enable bool, CHECK (enable IN (0, 1)));")
c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(1))
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|8231|CONSTRAINT CHECK is not supported"))
tk.MustQuery("show create table admin_user").Check(testutil.RowsWithSep("|", ""+
"admin_user CREATE TABLE `admin_user` (\n"+
" `enable` tinyint(1) DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}

func (s *testDBSuite6) TestAlterOrderBy(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use " + s.schemaName)
Expand Down
11 changes: 7 additions & 4 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,9 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o
col.FieldType.Collate = v.StrValue
}
case ast.ColumnOptionFulltext:
ctx.GetSessionVars().StmtCtx.AppendWarning(ErrTableCantHandleFt)
ctx.GetSessionVars().StmtCtx.AppendWarning(ErrTableCantHandleFt.GenWithStackByArgs())
case ast.ColumnOptionCheck:
ctx.GetSessionVars().StmtCtx.AppendWarning(ErrUnsupportedConstraintCheck.GenWithStackByArgs("Column check"))
ctx.GetSessionVars().StmtCtx.AppendWarning(ErrUnsupportedConstraintCheck.GenWithStackByArgs("CONSTRAINT CHECK"))
}
}
}
Expand Down Expand Up @@ -1361,8 +1361,11 @@ func buildTableInfo(
}

if constr.Tp == ast.ConstraintFulltext {
sc := ctx.GetSessionVars().StmtCtx
sc.AppendWarning(ErrTableCantHandleFt)
ctx.GetSessionVars().StmtCtx.AppendWarning(ErrTableCantHandleFt.GenWithStackByArgs())
continue
}
if constr.Tp == ast.ConstraintCheck {
ctx.GetSessionVars().StmtCtx.AppendWarning(ErrUnsupportedConstraintCheck.GenWithStackByArgs("CONSTRAINT CHECK"))
continue
}
// build index info.
Expand Down