mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-21 19:39:04 -05:00
Fix point lookup bug w/ prefix matching secondary (#5670)
* Fix point lookup bug w/ prefix matching secondary * docstring
This commit is contained in:
committed by
GitHub
parent
310c3d75a0
commit
b86b2b2011
@@ -260,6 +260,7 @@ func NewLookupBuilder(
|
||||
base.sec = durable.ProllyMapFromIndex(s.Secondary)
|
||||
base.secKd, base.secVd = base.sec.Descriptors()
|
||||
base.ns = base.sec.NodeStore()
|
||||
base.prefDesc = base.secKd.PrefixDesc(len(di.columns))
|
||||
}
|
||||
|
||||
switch {
|
||||
@@ -330,6 +331,7 @@ type baseLookupBuilder struct {
|
||||
|
||||
sec prolly.Map
|
||||
secKd, secVd val.TupleDesc
|
||||
prefDesc val.TupleDesc
|
||||
ns tree.NodeStore
|
||||
}
|
||||
|
||||
@@ -346,7 +348,7 @@ func (lb *baseLookupBuilder) NewRowIter(ctx *sql.Context, part sql.Partition) (s
|
||||
// every subsequent point lookup. Note that equality joins can have a mix of
|
||||
// point lookups on concrete values, and range lookups for null matches.
|
||||
func (lb *baseLookupBuilder) newPointLookup(ctx *sql.Context, rang prolly.Range) (iter prolly.MapIter, err error) {
|
||||
err = lb.sec.Get(ctx, rang.Tup, func(key val.Tuple, value val.Tuple) (err error) {
|
||||
err = lb.sec.GetPrefix(ctx, rang.Tup, lb.prefDesc, func(key val.Tuple, value val.Tuple) (err error) {
|
||||
if key != nil && rang.Matches(key) {
|
||||
iter = prolly.NewPointLookup(key, value)
|
||||
} else {
|
||||
|
||||
@@ -237,6 +237,26 @@ func (t StaticMap[K, V, O]) Get(ctx context.Context, query K, cb KeyValueFn[K, V
|
||||
return cb(key, value)
|
||||
}
|
||||
|
||||
func (t StaticMap[K, V, O]) GetPrefix(ctx context.Context, query K, prefixOrder O, cb KeyValueFn[K, V]) (err error) {
|
||||
cur, err := newLeafCursorAtKey(ctx, t.NodeStore, t.Root, query, t.Order)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var key K
|
||||
var value V
|
||||
|
||||
if cur.Valid() {
|
||||
key = K(cur.CurrentKey())
|
||||
if prefixOrder.Compare(query, key) == 0 {
|
||||
value = V(cur.currentValue())
|
||||
} else {
|
||||
key = nil
|
||||
}
|
||||
}
|
||||
return cb(key, value)
|
||||
}
|
||||
|
||||
func (t StaticMap[K, V, O]) Has(ctx context.Context, query K) (ok bool, err error) {
|
||||
cur, err := newLeafCursorAtKey(ctx, t.NodeStore, t.Root, query, t.Order)
|
||||
if err != nil {
|
||||
|
||||
@@ -246,6 +246,12 @@ func (m Map) Get(ctx context.Context, key val.Tuple, cb tree.KeyValueFn[val.Tupl
|
||||
return m.tuples.Get(ctx, key, cb)
|
||||
}
|
||||
|
||||
// GetPrefix returns the first key-value pair that matches the prefix key
|
||||
// or nil to the callback.
|
||||
func (m Map) GetPrefix(ctx context.Context, key val.Tuple, prefDesc val.TupleDesc, cb tree.KeyValueFn[val.Tuple, val.Tuple]) (err error) {
|
||||
return m.tuples.GetPrefix(ctx, key, prefDesc, cb)
|
||||
}
|
||||
|
||||
// Has returns true is |key| is present in the Map.
|
||||
func (m Map) Has(ctx context.Context, key val.Tuple) (ok bool, err error) {
|
||||
return m.tuples.Has(ctx, key)
|
||||
|
||||
Reference in New Issue
Block a user