Skip to content

Commit 543ddd0

Browse files
committed
Unwrap values when inserting them into a key cache.
1 parent a17f203 commit 543ddd0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

sql/plan/subquery.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func (s *Subquery) HashMultiple(ctx *sql.Context, row sql.Row) (sql.KeyValueCach
407407
defer s.cacheMu.Unlock()
408408
if !s.resultsCached || s.hashCache == nil {
409409
hashCache, disposeFn := ctx.Memory.NewHistoryCache()
410-
err = putAllRows(hashCache, result)
410+
err = putAllRows(ctx, hashCache, result)
411411
if err != nil {
412412
return nil, err
413413
}
@@ -417,7 +417,7 @@ func (s *Subquery) HashMultiple(ctx *sql.Context, row sql.Row) (sql.KeyValueCach
417417
}
418418

419419
cache := sql.NewMapCache()
420-
return cache, putAllRows(cache, result)
420+
return cache, putAllRows(ctx, cache, result)
421421
}
422422

423423
// HasResultRow returns whether the subquery has a result set > 0.
@@ -464,8 +464,19 @@ func (s *Subquery) HasResultRow(ctx *sql.Context, row sql.Row) (bool, error) {
464464
return true, nil
465465
}
466466

467-
func putAllRows(cache sql.KeyValueCache, vals []interface{}) error {
467+
// normalizeValue returns a canonical version of a value for use in a sql.KeyValueCache.
468+
// Two values that compare equal should have the same canonical version.
469+
// TODO: Fix https://github.com/dolthub/dolt/issues/9049 by making this function collation-aware
470+
func normalizeForKeyValueCache(ctx *sql.Context, val interface{}) (interface{}, error) {
471+
return sql.UnwrapAny(ctx, val)
472+
}
473+
474+
func putAllRows(ctx *sql.Context, cache sql.KeyValueCache, vals []interface{}) error {
468475
for _, val := range vals {
476+
val, err := normalizeForKeyValueCache(ctx, val)
477+
if err != nil {
478+
return err
479+
}
469480
rowKey, err := sql.HashOf(sql.NewRow(val))
470481
if err != nil {
471482
return err

0 commit comments

Comments
 (0)