Skip to content

Commit

Permalink
MB-50911 Make hash table for IN-list working properly
Browse files Browse the repository at this point in the history
Change-Id: Id00e32f476ee5ce98bb17300bc1f9d3fa32e7470
Reviewed-on: https://review.couchbase.org/c/query/+/170522
Reviewed-by: Sitaram Vemulapalli <sitaram.vemulapalli@couchbase.com>
Tested-by: Bingjie Miao <bingjie.miao@couchbase.com>
  • Loading branch information
miaobingjie committed Feb 11, 2022
1 parent a520fc2 commit 39d97bd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions expression/coll_in.go
Expand Up @@ -76,19 +76,19 @@ func (this *In) Evaluate(item value.Value, context Context) (value.Value, error)

if inlistHash != nil {
inlistHash.hashLock.Lock()
if inlistHash.ChkHash() {
if !inlistHash.HashChecked() {
inlistHash.SetHashChecked()
if inlistHash.IsHashEnabled() && len(sa) >= _INLIST_HASH_THRESHOLD {
if this.Second().Static() != nil {
buildHT = true
} else if sq, ok := this.Second().(Subquery); ok && !sq.IsCorrelated() {
buildHT = true
}
if buildHT {
hashTab = util.NewHashTable(util.HASH_TABLE_FOR_INLIST)
inlistHash.hashTab = hashTab
}
}
}
if buildHT {
hashTab = util.NewHashTable(util.HASH_TABLE_FOR_INLIST)
inlistHash.hashTab = hashTab
// lock is not released until hash table is built
} else {
hashTab = inlistHash.hashTab
Expand All @@ -103,6 +103,7 @@ func (this *In) Evaluate(item value.Value, context Context) (value.Value, error)
if buildHT {
err := hashTab.Put(v, true, value.MarshalValue, value.EqualValue, 0)
if err != nil {
inlistHash.hashLock.Unlock()
return nil, errors.NewHashTablePutError(err)
}
} else {
Expand Down Expand Up @@ -227,7 +228,7 @@ func NewInlistHash() *InlistHash {
return &InlistHash{}
}

func (this *InlistHash) ChkHash() bool {
func (this *InlistHash) HashChecked() bool {
return (this.hashFlags & INEXPR_HASHTAB_CHECKED) != 0
}

Expand Down

0 comments on commit 39d97bd

Please sign in to comment.