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

refactor index validation and prevent indexes over json columns #2469

Merged
merged 13 commits into from
Apr 30, 2024
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