Skip to content

Commit

Permalink
refactor index validation and prevent indexes over json columns (#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Apr 30, 2024
1 parent 3d60d20 commit b241685
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 298 deletions.
5 changes: 5 additions & 0 deletions enginetest/enginetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5559,9 +5559,14 @@ func findRole(toUser string, roles []*mysql_db.RoleEdge) *mysql_db.RoleEdge {
func TestBlobs(t *testing.T, h Harness) {
h.Setup(setup.MydbData, setup.BlobData, setup.MytableData)

// By default, strict_mysql_compatibility is disabled, but these tests require it to be enabled.
err := sql.SystemVariables.SetGlobal("strict_mysql_compatibility", int8(1))
require.NoError(t, err)
for _, tt := range queries.BlobErrors {
runQueryErrorTest(t, h, tt)
}
err = sql.SystemVariables.SetGlobal("strict_mysql_compatibility", int8(0))
require.NoError(t, err)

e := mustNewEngine(t, h)
defer e.Close()
Expand Down
4 changes: 2 additions & 2 deletions enginetest/queries/fulltext_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ var FulltextTests = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "CREATE TABLE test (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v1, v1));",
ExpectedErr: sql.ErrFullTextDuplicateColumn,
ExpectedErr: sql.ErrDuplicateColumn,
},
},
},
Expand All @@ -1100,7 +1100,7 @@ var FulltextTests = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "CREATE TABLE test (v1 VARCHAR(200), v2 VARCHAR(200), FULLTEXT idx (v3));",
ExpectedErr: sql.ErrUnknownIndexColumn,
ExpectedErr: sql.ErrKeyColumnDoesNotExist,
},
},
},
Expand Down
45 changes: 45 additions & 0 deletions enginetest/queries/index_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4192,4 +4192,49 @@ var IndexQueries = []ScriptTest{
},
},
},
{
Name: "secondary index errors",
SetUpScript: []string{
"create table json_tbl (pk int primary key, i int, j json);",
"create table idx_tbl (pk int primary key, j int, index(j));",
},
Assertions: []ScriptTestAssertion{
{
Query: "create index idx on json_tbl(j)",
ExpectedErr: sql.ErrJSONIndex,
},
{
Query: "create index idx on json_tbl(i, j)",
ExpectedErr: sql.ErrJSONIndex,
},
{
Query: "create index idx on json_tbl(j, i)",
ExpectedErr: sql.ErrJSONIndex,
},
{
Query: "alter table idx_tbl modify column j json;",
ExpectedErr: sql.ErrJSONIndex,
},
{
Query: "create table t1 (i int primary key, j json, index(j));",
ExpectedErr: sql.ErrJSONIndex,
},
{
Query: "create table t2 (i int, j json, index(i, j));",
ExpectedErr: sql.ErrJSONIndex,
},
{
Query: "create table t3 (i int, j json, index(j, i));",
ExpectedErr: sql.ErrJSONIndex,
},
{
// Ensure the above statements did not create tables without indexes
Query: "show tables;",
Expected: []sql.Row{
{"json_tbl"},
{"idx_tbl"},
},
},
},
},
}
2 changes: 1 addition & 1 deletion enginetest/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -10412,7 +10412,7 @@ var ErrorQueries = []QueryErrorTest{
},
{
Query: `CREATE TABLE test (pk int, primary key(pk, noexist))`,
ExpectedErr: sql.ErrUnknownIndexColumn,
ExpectedErr: sql.ErrKeyColumnDoesNotExist,
},
{
Query: `CREATE TABLE test (pk int auto_increment, pk2 int auto_increment, primary key (pk))`,
Expand Down
Loading

0 comments on commit b241685

Please sign in to comment.