Skip to content

Commit

Permalink
ddl: Ignore FULLTEXT KEYs in CREATE/ALTER TABLE statements (#9821)
Browse files Browse the repository at this point in the history
  • Loading branch information
kolbe authored and zz-jason committed Apr 11, 2019
1 parent 5b469e0 commit ee99570
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
}
Expand Down

0 comments on commit ee99570

Please sign in to comment.