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

hashlookups can hash byte slices #1408

Merged
merged 2 commits into from
Nov 16, 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
33 changes: 33 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2674,6 +2674,39 @@ var ScriptTests = []ScriptTest{
},
},
},
{
Name: "hash lookup for joins works with binary",
SetUpScript: []string{
"create table uv (u int primary key, v int);",
"create table xy (x int primary key, y int);",
"insert into uv values (0,0), (1,1), (2,2);",
"insert into xy values (0,0), (1,1), (2,2);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select uv.u from uv join xy on binary xy.x = binary uv.u;",
Expected: []sql.Row{
{0},
{1},
{2},
},
},
{
Query: "explain select uv.u from uv join xy on binary xy.x = binary uv.u;",
Expected: []sql.Row{
{"Project"},
{" ├─ columns: [uv.u]"},
{" └─ HashJoin(BINARY(xy.x) = BINARY(uv.u))"},
{" ├─ Table(uv)"},
{" │ └─ columns: [u]"},
{" └─ HashLookup(child: (BINARY(xy.x)), lookup: (BINARY(uv.u)))"},
{" └─ CachedResults"},
{" └─ Table(xy)"},
{" └─ columns: [x]"},
},
},
},
},
}

var SpatialScriptTests = []ScriptTest{
Expand Down
4 changes: 4 additions & 0 deletions sql/plan/hash_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func (n *HashLookup) getHashKey(ctx *sql.Context, e sql.Expression, row sql.Row)
return sql.HashOf(s)
}
}
// byte slices are not hashable
if k, ok := key.([]byte); ok {
key = string(k)
}
return key, nil
}

Expand Down