diff --git a/pkg/ddl/index.go b/pkg/ddl/index.go index e232e24621ea8..4a068d8156045 100644 --- a/pkg/ddl/index.go +++ b/pkg/ddl/index.go @@ -217,7 +217,7 @@ func indexColumnsLen(cols []*model.ColumnInfo, idxCols []*model.IndexColumn, col // checkIndexColumn will be run for all non-columnar indexes. func checkIndexColumn(col *model.ColumnInfo, indexColumnLen int, suppressTooLongKeyErr bool) error { - if col.GetFlen() == 0 && (types.IsTypeChar(col.FieldType.GetType()) || types.IsTypeVarchar(col.FieldType.GetType())) { + if col.FieldType.GetType() == mysql.TypeNull || (col.GetFlen() == 0 && (types.IsTypeChar(col.FieldType.GetType()) || types.IsTypeVarchar(col.FieldType.GetType()))) { if col.Hidden { return errors.Trace(dbterror.ErrWrongKeyColumnFunctionalIndex.GenWithStackByArgs(col.GeneratedExprString)) } diff --git a/tests/integrationtest/r/ddl/db_integration.result b/tests/integrationtest/r/ddl/db_integration.result index 18c25997e3590..0f876949e1f6c 100644 --- a/tests/integrationtest/r/ddl/db_integration.result +++ b/tests/integrationtest/r/ddl/db_integration.result @@ -1239,6 +1239,8 @@ Error 3800 (HY000): Expression of expression index 'k' cannot refer to a row val create table t (j json, key k ((j+1),(j+1))); create table t1 (col1 int, index ((concat('')))); Error 3761 (HY000): The used storage engine cannot index the expression 'concat(_utf8mb4'')' +create table t1 (col1 int, index ((null))); +Error 3761 (HY000): The used storage engine cannot index the expression 'null' CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED); Error 3756 (HY000): The primary key cannot be an expression index drop table if exists t; diff --git a/tests/integrationtest/t/ddl/db_integration.test b/tests/integrationtest/t/ddl/db_integration.test index 0857c6ddec31b..a2d61e739fd4f 100644 --- a/tests/integrationtest/t/ddl/db_integration.test +++ b/tests/integrationtest/t/ddl/db_integration.test @@ -1052,6 +1052,8 @@ create table t (j json, key k (((j,j)))); create table t (j json, key k ((j+1),(j+1))); -- error 3761 create table t1 (col1 int, index ((concat('')))); +-- error 3761 +create table t1 (col1 int, index ((null))); -- error 3756 CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);