Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: check the limitation when creating multi-valued index #39818

Merged
merged 5 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ func buildIndexColumns(ctx sessionctx.Context, columns []*model.ColumnInfo, inde
if err := checkIndexColumn(ctx, col, ip.Length); err != nil {
return nil, false, err
}
mvIndex = mvIndex || col.FieldType.IsArray()
if col.FieldType.IsArray() {
if mvIndex {
return nil, false, dbterror.ErrNotSupportedYet.GenWithStack("'more than one multi-valued key part per index'")
}
mvIndex = true
hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
}
indexColLen := ip.Length
indexColumnLength, err := getIndexColumnLength(col, ip.Length)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,11 @@ error = '''
Incorrect usage of %s and %s
'''

["ddl:1235"]
error = '''
This version of TiDB doesn't yet support '%s'
'''

["ddl:1246"]
error = '''
Converting column '%s' from %s to %s
Expand Down
2 changes: 1 addition & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ func ColumnInfos2ColumnsAndNames(ctx sessionctx.Context, dbName, tblName model.C
if err != nil {
return nil, nil, errors.Trace(err)
}
e, err := RewriteAstExpr(ctx, expr, mockSchema, names, false)
e, err := RewriteAstExpr(ctx, expr, mockSchema, names, true)
if err != nil {
return nil, nil, errors.Trace(err)
}
Expand Down
11 changes: 11 additions & 0 deletions expression/multi_valued_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ func TestMultiValuedIndexDDL(t *testing.T) {
tk.MustGetErrCode("create table t(j json, gc json as (cast(j->'$[*]' as unsigned array)));", errno.ErrNotSupportedYet)
tk.MustGetErrCode("create view v as select cast('[1,2,3]' as unsigned array);", errno.ErrNotSupportedYet)
tk.MustExec("create table t(a json, index idx((cast(a as signed array))));")

tk.MustExec("drop table t")
tk.MustGetErrCode("create table t(a json, b int, index idx(b, (cast(a as signed array)), (cast(a as signed array))));", errno.ErrNotSupportedYet)
tk.MustExec("create table t(a json, b int);")
tk.MustGetErrCode("create index idx on t (b, (cast(a as signed array)), (cast(a as signed array)))", errno.ErrNotSupportedYet)
tk.MustGetErrCode("alter table t add index idx(b, (cast(a as signed array)), (cast(a as signed array)))", errno.ErrNotSupportedYet)
tk.MustExec("create index idx1 on t (b, (cast(a as signed array)))")
tk.MustExec("alter table t add index idx2(b, (cast(a as signed array)))")

tk.MustExec("drop table t")
tk.MustExec("create table t(a json, b int, index idx3(b, (cast(a as signed array))));")
}
3 changes: 3 additions & 0 deletions util/dbterror/ddl_terror.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,7 @@ var (
ErrTempTableNotAllowedWithTTL = ClassDDL.NewStd(mysql.ErrTempTableNotAllowedWithTTL)
// ErrUnsupportedTTLReferencedByFK returns when the TTL config is set for a table referenced by foreign key
ErrUnsupportedTTLReferencedByFK = ClassDDL.NewStd(mysql.ErrUnsupportedTTLReferencedByFK)

// ErrNotSupportedYet returns when tidb does not support this feature.
ErrNotSupportedYet = ClassDDL.NewStd(mysql.ErrNotSupportedYet)
)