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

Move index costing into join planning phase #2191

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion enginetest/engine_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ func TestShowCharset(t *testing.T) {
}

func TestTableFunctions(t *testing.T) {
// TODO different error messages
harness := enginetest.NewDefaultMemoryHarness()
harness.Setup(setup.MydbData)

Expand Down
2 changes: 1 addition & 1 deletion enginetest/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
}
TestQueryWithContext(t, ctx, e, harness, assertion.Query, expected, assertion.ExpectedColumns, assertion.Bindings)
}
if assertion.ExpectedIndexes != nil {
if assertion.ExpectedIndexes != nil && !IsServerEngine(e) {
evalIndexTest(t, harness, e, assertion.Query, assertion.ExpectedIndexes, assertion.Skip)
}
if assertion.JoinTypes != nil {
Expand Down
24 changes: 12 additions & 12 deletions enginetest/join_planning_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,12 @@ var JoinPlanningTests = []struct {
},
{
q: "select * from xy where x not in (select u from uv where u not in (select a from ab where a not in (select r from rs where r = 1))) order by 1;",
types: []plan.JoinType{plan.JoinTypeLeftOuterHashExcludeNulls, plan.JoinTypeLeftOuterHashExcludeNulls, plan.JoinTypeLeftOuterMerge},
types: []plan.JoinType{plan.JoinTypeLeftOuterHashExcludeNulls, plan.JoinTypeLeftOuterHashExcludeNulls, plan.JoinTypeLeftOuterLookup},
exp: []sql.Row{{0, 2}, {2, 1}, {3, 3}},
},
{
q: "select * from xy where x != (select r from rs where r = 1) order by 1;",
types: []plan.JoinType{plan.JoinTypeLeftOuterMerge},
types: []plan.JoinType{plan.JoinTypeLeftOuterLookup},
exp: []sql.Row{{0, 2}, {2, 1}, {3, 3}},
},
{
Expand All @@ -380,7 +380,7 @@ select * from uv where u > (
order by 1 limit 1
)
order by 1;`,
types: []plan.JoinType{plan.JoinTypeSemi, plan.JoinTypeCrossHash, plan.JoinTypeLeftOuterMerge},
types: []plan.JoinType{plan.JoinTypeSemi, plan.JoinTypeCrossHash, plan.JoinTypeLeftOuterLookup},
exp: []sql.Row{{1, 1}, {2, 2}, {3, 2}},
},
{
Expand All @@ -392,7 +392,7 @@ order by 1;`,
{
// order by will be discarded
q: "select * from xy where x != (select r from rs where r = 1 order by 1) order by 1;",
types: []plan.JoinType{plan.JoinTypeLeftOuterMerge},
types: []plan.JoinType{plan.JoinTypeLeftOuterLookup},
exp: []sql.Row{{0, 2}, {2, 1}, {3, 3}},
},
{
Expand All @@ -409,7 +409,7 @@ order by 1;`,
{
// semi join will be right-side, be passed non-nil parent row
q: "select x,a from ab, (select * from xy where x = (select r from rs where r = 1) order by 1) sq order by 1,2",
types: []plan.JoinType{plan.JoinTypeCrossHash, plan.JoinTypeLookup},
types: []plan.JoinType{plan.JoinTypeCrossHash, plan.JoinTypeSemiLookup},
exp: []sql.Row{{1, 0}, {1, 1}, {1, 2}, {1, 3}},
},
//{
Expand Down Expand Up @@ -445,7 +445,7 @@ order by 1;`,
},
{
q: "select * from xy where x in (select u from uv join ab on u = a and a = 2) order by 1;",
types: []plan.JoinType{plan.JoinTypeHash, plan.JoinTypeMerge},
types: []plan.JoinType{plan.JoinTypeLookup, plan.JoinTypeLookup},
exp: []sql.Row{{2, 1}},
},
{
Expand Down Expand Up @@ -509,7 +509,7 @@ HAVING count(v) >= 1)`,
},
{
q: "select * from xy where y-1 = (select u from uv where v = 2 order by 1 limit 1);",
types: []plan.JoinType{plan.JoinTypeSemiLookup},
types: []plan.JoinType{plan.JoinTypeSemi},
exp: []sql.Row{{3, 3}},
},
{
Expand Down Expand Up @@ -537,15 +537,15 @@ HAVING count(v) >= 1)`,
EXISTS (SELECT * FROM xy Alias1 WHERE Alias1.x = (xy.x + 1))
AND EXISTS (SELECT * FROM uv Alias2 WHERE Alias2.u = (xy.x + 2)));`,
// These should both be JoinTypeSemiLookup, but for https://github.com/dolthub/go-mysql-server/issues/1893
types: []plan.JoinType{plan.JoinTypeSemiLookup, plan.JoinTypeMerge},
types: []plan.JoinType{plan.JoinTypeSemiLookup, plan.JoinTypeSemiLookup},
exp: []sql.Row{{0, 2}, {1, 0}},
},
{
q: `SELECT * FROM xy WHERE (
EXISTS (SELECT * FROM xy Alias1 WHERE Alias1.x = (xy.x + 1))
AND EXISTS (SELECT * FROM uv Alias1 WHERE Alias1.u = (xy.x + 2)));`,
// These should both be JoinTypeSemiLookup, but for https://github.com/dolthub/go-mysql-server/issues/1893
types: []plan.JoinType{plan.JoinTypeSemiLookup, plan.JoinTypeMerge},
types: []plan.JoinType{plan.JoinTypeSemiLookup, plan.JoinTypeSemiLookup},
exp: []sql.Row{{0, 2}, {1, 0}},
},
{
Expand Down Expand Up @@ -579,7 +579,7 @@ WHERE EXISTS (
select x from xy where
not exists (select a from ab where a = x and a = 1) and
not exists (select a from ab where a = x and a = 2)`,
types: []plan.JoinType{plan.JoinTypeLeftOuterLookup, plan.JoinTypeLeftOuterMerge},
types: []plan.JoinType{plan.JoinTypeLeftOuterLookup, plan.JoinTypeLeftOuterLookup},
exp: []sql.Row{{0}, {3}},
},
{
Expand Down Expand Up @@ -615,7 +615,7 @@ FROM xy
},
{
q: `select * from xy where exists (select * from uv join ab on u = a)`,
types: []plan.JoinType{plan.JoinTypeCrossHash, plan.JoinTypeMerge},
types: []plan.JoinType{plan.JoinTypeCrossHash, plan.JoinTypeLookup},
exp: []sql.Row{{0, 2}, {1, 0}, {2, 1}, {3, 3}},
},
},
Expand Down Expand Up @@ -754,7 +754,7 @@ where u in (select * from rec);`,
tests: []JoinPlanTest{
{
q: "select * from xy where x in (select u from uv join ab on u = a and a = 2) order by 1;",
types: []plan.JoinType{plan.JoinTypeHash, plan.JoinTypeMerge},
types: []plan.JoinType{plan.JoinTypeHash, plan.JoinTypeLookup},
exp: []sql.Row{{2, 1}},
},
{
Expand Down
Loading