From ee99570183dcb26a12e5edd8990a4d9a6ae9167f Mon Sep 17 00:00:00 2001 From: Kolbe Kegel Date: Wed, 10 Apr 2019 19:05:20 -0700 Subject: [PATCH] ddl: Ignore FULLTEXT KEYs in CREATE/ALTER TABLE statements (#9821) --- ddl/db_integration_test.go | 16 ++++++++++++++++ ddl/ddl.go | 4 ++++ ddl/ddl_api.go | 9 ++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index e9098d0c5b932..8ab7b9fbdca20 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1397,6 +1397,22 @@ func (s *testIntegrationSuite) TestAlterAlgorithm(c *C) { 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") + // 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) + + // 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'") + c.Assert(r.Rows(), HasLen, 0) +} + func (s *testIntegrationSuite) TestTreatOldVersionUTF8AsUTF8MB4(c *C) { s.tk = testkit.NewTestKit(c, s.store) s.tk.MustExec("use test") diff --git a/ddl/ddl.go b/ddl/ddl.go index cd8528a8a3144..5729a75584860 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -228,6 +228,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]) // ErrFieldNotFoundPart returns an error when 'partition by columns' are not found in table columns. ErrFieldNotFoundPart = terror.ClassDDL.New(codeFieldNotFoundPart, mysql.MySQLErrName[mysql.ErrFieldNotFoundPart]) // ErrPartitionColumnList returns "Inconsistency in usage of column lists for partitioning". @@ -716,6 +718,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) codeErrGeneratedColumnFunctionIsNotAllowed = terror.ErrCode(mysql.ErrGeneratedColumnFunctionIsNotAllowed) @@ -776,6 +779,7 @@ func init() { codePrimaryCantHaveNull: mysql.ErrPrimaryCantHaveNull, codeWrongExprInPartitionFunc: mysql.ErrWrongExprInPartitionFunc, codeWarnDataTruncated: mysql.WarnDataTruncated, + codeErrTableCantHandleFt: mysql.ErrTableCantHandleFt, codeCoalesceOnlyOnHashPartition: mysql.ErrCoalesceOnlyOnHashPartition, codeUnknownPartition: mysql.ErrUnknownPartition, codeNotSupportedAlterOperation: mysql.ErrAlterOperationNotSupportedReason, diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index c7c79bf614136..d01242d69fb55 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -441,7 +441,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) } } } @@ -968,6 +968,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 { @@ -1710,6 +1715,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. }