Skip to content

Commit

Permalink
ddl: refine error message for expression index (pingcap#20337)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanavril authored Oct 9, 2020
1 parent c561298 commit a8dea3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,8 @@ func (s *testIntegrationSuite7) TestCreateExpressionIndexError(c *C) {
tk.MustExec("drop table if exists t;")
tk.MustGetErrCode("create table t (j json, key k (((j,j))))", errno.ErrFunctionalIndexRowValueIsNotAllowed)
tk.MustExec("create table t (j json, key k ((j+1),(j+1)))")

tk.MustGetErrCode("create table t1 (col1 int, index ((concat(''))));", errno.ErrWrongKeyColumnFunctionalIndex)
}

func (s *testIntegrationSuite7) TestAddExpressionIndexOnPartition(c *C) {
Expand Down
2 changes: 2 additions & 0 deletions ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ var (
errOnlyOnRangeListPartition = terror.ClassDDL.New(mysql.ErrOnlyOnRangeListPartition, mysql.MySQLErrName[mysql.ErrOnlyOnRangeListPartition])
// errWrongKeyColumn is for table column cannot be indexed.
errWrongKeyColumn = terror.ClassDDL.New(mysql.ErrWrongKeyColumn, mysql.MySQLErrName[mysql.ErrWrongKeyColumn])
// errWrongKeyColumnFunctionalIndex is for expression cannot be indexed.
errWrongKeyColumnFunctionalIndex = terror.ClassDDL.New(mysql.ErrWrongKeyColumnFunctionalIndex, mysql.MySQLErrName[mysql.ErrWrongKeyColumnFunctionalIndex])
// errWrongFKOptionForGeneratedColumn is for wrong foreign key reference option on generated columns.
errWrongFKOptionForGeneratedColumn = terror.ClassDDL.New(mysql.ErrWrongFKOptionForGeneratedColumn, mysql.MySQLErrName[mysql.ErrWrongFKOptionForGeneratedColumn])
// ErrUnsupportedOnGeneratedColumn is for unsupported actions on generated columns.
Expand Down
3 changes: 3 additions & 0 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func checkIndexPrefixLength(columns []*model.ColumnInfo, idxColumns []*model.Ind

func checkIndexColumn(col *model.ColumnInfo, ic *ast.IndexPartSpecification) error {
if col.Flen == 0 && (types.IsTypeChar(col.FieldType.Tp) || types.IsTypeVarchar(col.FieldType.Tp)) {
if col.GeneratedExprString != "" {
return errors.Trace(errWrongKeyColumnFunctionalIndex.GenWithStackByArgs(col.GeneratedExprString))
}
return errors.Trace(errWrongKeyColumn.GenWithStackByArgs(ic.Column.Name))
}

Expand Down

0 comments on commit a8dea3a

Please sign in to comment.