From 13acfc00902356f737ee967eec73660872809aa6 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Thu, 15 May 2025 16:33:19 +0800 Subject: [PATCH 1/2] Fix invalid expression index Signed-off-by: JaySon-Huang --- pkg/ddl/index.go | 2 +- tests/integrationtest/r/ddl/db_integration.result | 2 ++ tests/integrationtest/t/ddl/db_integration.test | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) 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..3dfe9713a0ca4 100644 --- a/tests/integrationtest/t/ddl/db_integration.test +++ b/tests/integrationtest/t/ddl/db_integration.test @@ -1052,6 +1052,7 @@ 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('')))); +create table t1 (col1 int, index ((null))); -- error 3756 CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED); From 3dea9d1d56bb9731f7c8133fb63d245dea55e7a5 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Thu, 15 May 2025 17:38:58 +0800 Subject: [PATCH 2/2] fix Signed-off-by: JaySon-Huang --- tests/integrationtest/t/ddl/db_integration.test | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integrationtest/t/ddl/db_integration.test b/tests/integrationtest/t/ddl/db_integration.test index 3dfe9713a0ca4..a2d61e739fd4f 100644 --- a/tests/integrationtest/t/ddl/db_integration.test +++ b/tests/integrationtest/t/ddl/db_integration.test @@ -1052,6 +1052,7 @@ 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);