Skip to content

Commit 555b81c

Browse files
authored
ddl: Fix invalid expression index (#61135)
close #61133
1 parent a206b0b commit 555b81c

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

pkg/ddl/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func indexColumnsLen(cols []*model.ColumnInfo, idxCols []*model.IndexColumn, col
217217

218218
// checkIndexColumn will be run for all non-columnar indexes.
219219
func checkIndexColumn(col *model.ColumnInfo, indexColumnLen int, suppressTooLongKeyErr bool) error {
220-
if col.GetFlen() == 0 && (types.IsTypeChar(col.FieldType.GetType()) || types.IsTypeVarchar(col.FieldType.GetType())) {
220+
if col.FieldType.GetType() == mysql.TypeNull || (col.GetFlen() == 0 && (types.IsTypeChar(col.FieldType.GetType()) || types.IsTypeVarchar(col.FieldType.GetType()))) {
221221
if col.Hidden {
222222
return errors.Trace(dbterror.ErrWrongKeyColumnFunctionalIndex.GenWithStackByArgs(col.GeneratedExprString))
223223
}

tests/integrationtest/r/ddl/db_integration.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,8 @@ Error 3800 (HY000): Expression of expression index 'k' cannot refer to a row val
12391239
create table t (j json, key k ((j+1),(j+1)));
12401240
create table t1 (col1 int, index ((concat(''))));
12411241
Error 3761 (HY000): The used storage engine cannot index the expression 'concat(_utf8mb4'')'
1242+
create table t1 (col1 int, index ((null)));
1243+
Error 3761 (HY000): The used storage engine cannot index the expression 'null'
12421244
CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);
12431245
Error 3756 (HY000): The primary key cannot be an expression index
12441246
drop table if exists t;

tests/integrationtest/t/ddl/db_integration.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,8 @@ create table t (j json, key k (((j,j))));
10521052
create table t (j json, key k ((j+1),(j+1)));
10531053
-- error 3761
10541054
create table t1 (col1 int, index ((concat(''))));
1055+
-- error 3761
1056+
create table t1 (col1 int, index ((null)));
10551057
-- error 3756
10561058
CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);
10571059

0 commit comments

Comments
 (0)