Skip to content

Commit

Permalink
DDL: check table-level check constraint when create table (#20202) (#…
Browse files Browse the repository at this point in the history
…20214)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
Signed-off-by: AilinKid <314806019@qq.com>
  • Loading branch information
ti-srebot authored Oct 3, 2020
1 parent 4d54559 commit 6efcee0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4604,6 +4604,19 @@ func (s *testDBSuite2) TestDDLWithInvalidTableInfo(c *C) {
c.Assert(err.Error(), Equals, "[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 94 near \"then (b / a) end));\" ")
}

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|1064|You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 63 near \");\"The CHECK clause is parsed but ignored by all storage engines. "))
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) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use " + s.schemaName)
Expand Down
6 changes: 4 additions & 2 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,8 +1215,10 @@ 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 {
continue
}
// build index info.
Expand Down

0 comments on commit 6efcee0

Please sign in to comment.