Skip to content

Commit 849fb50

Browse files
committed
Add regression test for when one index is strictly better than another for a lookup.
1 parent caed79c commit 849fb50

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

enginetest/queries/index_queries.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,6 +4065,78 @@ var IndexPrefixQueries = []ScriptTest{
40654065
},
40664066
},
40674067
},
4068+
{
4069+
Name: "multiple nullable index prefixes",
4070+
SetUpScript: []string{
4071+
"create table test(pk int primary key, shared1 int, shared2 int, a3 int, a4 int, b3 int, b4 int, unique key a_idx(shared1, shared2, a3, a4), unique key b_idx(shared1, shared2, b3, b4))",
4072+
},
4073+
Assertions: []ScriptTestAssertion{
4074+
{
4075+
Query: "select * from test where shared1 = 1 and shared2 = 2 and a3 = 3;",
4076+
Expected: []sql.Row{},
4077+
ExpectedIndexes: []string{"a_idx"},
4078+
},
4079+
{
4080+
Query: "select * from test where shared1 = 1 and shared2 = 2 and b3 = 3;",
4081+
Expected: []sql.Row{},
4082+
ExpectedIndexes: []string{"b_idx"},
4083+
},
4084+
},
4085+
},
4086+
{
4087+
Name: "multiple non-unique index prefixes",
4088+
SetUpScript: []string{
4089+
"create table test(pk int primary key, shared1 int not null, shared2 int not null, a3 int not null, a4 int not null, b3 int not null, b4 int not null, key a_idx(shared1, shared2, a3, a4), key b_idx(shared1, shared2, b3, b4))",
4090+
},
4091+
Assertions: []ScriptTestAssertion{
4092+
{
4093+
Query: "select * from test where shared1 = 1 and shared2 = 2 and a3 = 3;",
4094+
Expected: []sql.Row{},
4095+
ExpectedIndexes: []string{"a_idx"},
4096+
},
4097+
{
4098+
Query: "select * from test where shared1 = 1 and shared2 = 2 and b3 = 3;",
4099+
Expected: []sql.Row{},
4100+
ExpectedIndexes: []string{"b_idx"},
4101+
},
4102+
},
4103+
},
4104+
{
4105+
Name: "multiple non-unique nullable index prefixes",
4106+
SetUpScript: []string{
4107+
"create table test(pk int primary key, shared1 int, shared2 int, a3 int, a4 int, b3 int, b4 int, key a_idx(shared1, shared2, a3, a4), key b_idx(shared1, shared2, b3, b4))",
4108+
},
4109+
Assertions: []ScriptTestAssertion{
4110+
{
4111+
Query: "select * from test where shared1 = 1 and shared2 = 2 and a3 = 3;",
4112+
Expected: []sql.Row{},
4113+
ExpectedIndexes: []string{"a_idx"},
4114+
},
4115+
{
4116+
Query: "select * from test where shared1 = 1 and shared2 = 2 and b3 = 3;",
4117+
Expected: []sql.Row{},
4118+
ExpectedIndexes: []string{"b_idx"},
4119+
},
4120+
},
4121+
},
4122+
{
4123+
Name: "unique and non-unique nullable index prefixes",
4124+
SetUpScript: []string{
4125+
"create table test(pk int primary key, shared1 int, shared2 int, a3 int, a4 int, b3 int, b4 int, unique key a_idx(shared1, shared2, a3, a4), key b_idx(shared1, shared2, b3, b4))",
4126+
},
4127+
Assertions: []ScriptTestAssertion{
4128+
{
4129+
Query: "select * from test where shared1 = 1 and shared2 = 2 and a3 = 3;",
4130+
Expected: []sql.Row{},
4131+
ExpectedIndexes: []string{"a_idx"},
4132+
},
4133+
{
4134+
Query: "select * from test where shared1 = 1 and shared2 = 2 and b3 = 3;",
4135+
Expected: []sql.Row{},
4136+
ExpectedIndexes: []string{"b_idx"},
4137+
},
4138+
},
4139+
},
40684140
}
40694141

40704142
var IndexQueries = []ScriptTest{

0 commit comments

Comments
 (0)