From 94b90273eb0e1245b9e3d68f4f68d2a1faf3c4ea Mon Sep 17 00:00:00 2001 From: Kolbe Kegel Date: Mon, 18 Mar 2019 11:12:38 -0700 Subject: [PATCH 1/7] Ignore FULLTEXT KEYs in CREATE TABLE statements. --- ddl/ddl.go | 3 +++ ddl/ddl_api.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/ddl/ddl.go b/ddl/ddl.go index 422a953d1cb2..26604ba6f325 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -215,6 +215,8 @@ var ( ErrAlterOperationNotSupported = terror.ClassDDL.New(codeNotSupportedAlterOperation, mysql.MySQLErrName[mysql.ErrAlterOperationNotSupportedReason]) // ErrWrongObject returns for wrong object. ErrWrongObject = terror.ClassDDL.New(codeErrWrongObject, mysql.MySQLErrName[mysql.ErrWrongObject]) + // ErrTableCantHandleFt returns FULLTEXT keys are not supported by table type + ErrTableCantHandleFt = terror.ClassDDL.New(codeErrTableCantHandleFt, mysql.MySQLErrName[mysql.ErrTableCantHandleFt]) ) // DDL is responsible for updating schema in data store and maintaining in-memory InfoSchema cache. @@ -695,6 +697,7 @@ const ( codePrimaryCantHaveNull = terror.ErrCode(mysql.ErrPrimaryCantHaveNull) codeWrongExprInPartitionFunc = terror.ErrCode(mysql.ErrWrongExprInPartitionFunc) codeWarnDataTruncated = terror.ErrCode(mysql.WarnDataTruncated) + codeErrTableCantHandleFt = terror.ErrCode(mysql.ErrTableCantHandleFt) codeCoalesceOnlyOnHashPartition = terror.ErrCode(mysql.ErrCoalesceOnlyOnHashPartition) codeUnknownPartition = terror.ErrCode(mysql.ErrUnknownPartition) codeErrGeneratedColumnRefAutoInc = terror.ErrCode(mysql.ErrGeneratedColumnRefAutoInc) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 1fd6d59db8bf..e70e691f30e6 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -947,6 +947,11 @@ func buildTableInfo(ctx sessionctx.Context, d *ddl, tableName model.CIStr, cols } } } + if constr.Tp == ast.ConstraintFulltext { + sc := ctx.GetSessionVars().StmtCtx + sc.AppendWarning(ErrTableCantHandleFt) + continue + } // build index info. idxInfo, err := buildIndexInfo(tbInfo, model.NewCIStr(constr.Name), constr.Keys, model.StatePublic) if err != nil { From 8ae3d6360e4d29c48a2bb422a940fcd3fe1bf855 Mon Sep 17 00:00:00 2001 From: Kolbe Kegel Date: Mon, 18 Mar 2019 14:55:39 -0700 Subject: [PATCH 2/7] Fixed TestSlowQueryZapLogger to work with negative UTC offset timezones --- util/logutil/log_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/logutil/log_test.go b/util/logutil/log_test.go index 5b012715bd8e..624a5d8eede6 100644 --- a/util/logutil/log_test.go +++ b/util/logutil/log_test.go @@ -33,7 +33,7 @@ const ( logPattern = `\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d\.\d\d\d ([\w_%!$@.,+~-]+|\\.)+:\d+: \[(fatal|error|warning|info|debug)\] .*?\n` // zapLogPatern is used to match the zap log format, such as the following log: // [2019/02/13 15:56:05.385 +08:00] [INFO] [log_test.go:167] ["info message"] ["str key"=val] ["int key"=123] - zapLogPattern = `\[\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d.\d\d\d\ \+\d\d:\d\d\] \[(FATAL|ERROR|WARN|INFO|DEBUG)\] \[([\w_%!$@.,+~-]+|\\.)+:\d+\] \[.*\] (\[.*=.*\]).*\n` + zapLogPattern = `\[\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d.\d\d\d\ (\+|-)\d\d:\d\d\] \[(FATAL|ERROR|WARN|INFO|DEBUG)\] \[([\w_%!$@.,+~-]+|\\.)+:\d+\] \[.*\] (\[.*=.*\]).*\n` ) func Test(t *testing.T) { From a85aad1084cab352a3d85a1c84b5f5e39128788c Mon Sep 17 00:00:00 2001 From: Kolbe Kegel Date: Tue, 19 Mar 2019 09:37:05 -0700 Subject: [PATCH 3/7] Issue ErrTableCantHandleFt warning for ALTER TABLE ADD FULLTEXT KEY --- ddl/ddl_api.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index e70e691f30e6..dbbe90c20689 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -431,7 +431,7 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o _, dependColNames := findDependedColumnNames(colDef) col.Dependences = dependColNames case ast.ColumnOptionFulltext: - // TODO: Support this type. + ctx.GetSessionVars().StmtCtx.AppendWarning(ErrTableCantHandleFt) } } } @@ -1582,6 +1582,8 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A err = d.CreateForeignKey(ctx, ident, model.NewCIStr(constr.Name), spec.Constraint.Keys, spec.Constraint.Refer) case ast.ConstraintPrimaryKey: err = ErrUnsupportedModifyPrimaryKey.GenWithStackByArgs("add") + case ast.ConstraintFulltext: + ctx.GetSessionVars().StmtCtx.AppendWarning(ErrTableCantHandleFt) default: // Nothing to do now. } From 7ec0176717469560918bd95d34f8545742aa5990 Mon Sep 17 00:00:00 2001 From: Kolbe Kegel Date: Tue, 19 Mar 2019 22:10:48 -0700 Subject: [PATCH 4/7] Add test case for ignoring FULLTEXT KEY in CREATE and ALTER TABLE --- ddl/db_integration_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 6f69f2d9bc82..3365648238d6 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1282,3 +1282,12 @@ func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { s.assertAlterErrorExec(c, "alter table t default charset = utf8mb4, ALGORITHM=INPLACE") s.tk.MustExec("alter table t default charset = utf8mb4, ALGORITHM=INSTANT") } + +func (s *testIntegrationSuite) TestFulltextIndexIgnore(c *C) { + s.tk = testkit.NewTestKit(c, s.store) + s.tk.MustExec("use test") + s.tk.MustExec("drop table if exists t_ft") + defer s.tk.MustExec("drop table if exists t_ft") + s.assertWarningExec(c, "create table t_ft (a text, fulltext key (a))", ddl.ErrTableCantHandleFt) + s.assertWarningExec(c, "alter table t_ft add fulltext key (a)", ddl.ErrTableCantHandleFt) +} From 3b8d0eff390b2dd4f402b957e56897a80ad769a0 Mon Sep 17 00:00:00 2001 From: Kolbe Kegel Date: Wed, 20 Mar 2019 09:39:52 -0700 Subject: [PATCH 5/7] Added test to make sure no indexes exist after attempting to create a FULLTEXT index. --- ddl/db_integration_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 3365648238d6..99de137fca75 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1290,4 +1290,11 @@ func (s *testIntegrationSuite) TestFulltextIndexIgnore(c *C) { defer s.tk.MustExec("drop table if exists t_ft") s.assertWarningExec(c, "create table t_ft (a text, fulltext key (a))", ddl.ErrTableCantHandleFt) s.assertWarningExec(c, "alter table t_ft add fulltext key (a)", ddl.ErrTableCantHandleFt) + + //t := s.testGetTable(c, "t_anonymous_index") + //c.Assert(t.Indices(), HasLen, 0) + r := s.tk.MustQuery("show index from t_ft") + c.Assert(r.Rows(), HasLen, 0) + r = s.tk.MustQuery("select * from information_schema.statistics where table_schema='test' and table_name='t_ft'") + c.Assert(r.Rows(), HasLen, 0) } From bade342fcf4d6d7074795a8834605ae38f6a3410 Mon Sep 17 00:00:00 2001 From: Kolbe Kegel Date: Wed, 20 Mar 2019 10:07:14 -0700 Subject: [PATCH 6/7] Improved comments for TestFulltextIndexIgnore --- ddl/db_integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 99de137fca75..984a02eac19c 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1288,11 +1288,11 @@ func (s *testIntegrationSuite) TestFulltextIndexIgnore(c *C) { s.tk.MustExec("use test") s.tk.MustExec("drop table if exists t_ft") defer s.tk.MustExec("drop table if exists t_ft") + // Make sure that creating and altering to add a fulltext key gives the correct warning s.assertWarningExec(c, "create table t_ft (a text, fulltext key (a))", ddl.ErrTableCantHandleFt) s.assertWarningExec(c, "alter table t_ft add fulltext key (a)", ddl.ErrTableCantHandleFt) - //t := s.testGetTable(c, "t_anonymous_index") - //c.Assert(t.Indices(), HasLen, 0) + // Make sure table t_ft still has no indexes even after it was created and altered r := s.tk.MustQuery("show index from t_ft") c.Assert(r.Rows(), HasLen, 0) r = s.tk.MustQuery("select * from information_schema.statistics where table_schema='test' and table_name='t_ft'") From 0f654e4eb0ae906c3febbe606045c4bcd7febb6b Mon Sep 17 00:00:00 2001 From: Kolbe Kegel Date: Wed, 3 Apr 2019 10:35:04 -0700 Subject: [PATCH 7/7] Added codeErrTableCantHandleFt to ddlMySQLErrCodes --- ddl/ddl.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ddl/ddl.go b/ddl/ddl.go index c46c8bf7203e..d30aa3d30db4 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -767,6 +767,7 @@ func init() { codePrimaryCantHaveNull: mysql.ErrPrimaryCantHaveNull, codeWrongExprInPartitionFunc: mysql.ErrWrongExprInPartitionFunc, codeWarnDataTruncated: mysql.WarnDataTruncated, + codeErrTableCantHandleFt: mysql.ErrTableCantHandleFt, codeCoalesceOnlyOnHashPartition: mysql.ErrCoalesceOnlyOnHashPartition, codeUnknownPartition: mysql.ErrUnknownPartition, codeNotSupportedAlterOperation: mysql.ErrAlterOperationNotSupportedReason,