Skip to content

Commit

Permalink
updated filter
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Nov 11, 2024
1 parent 39f175d commit 176bb00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion posting/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (sh *StatsHolder) InsertRecord(pred string, key []byte, count uint64) {
val.InsertRecord(key, count)
}

func (sh *StatsHolder) ProcessPredicate(pred string, key []byte) uint64 {
func (sh *StatsHolder) ProcessEqPredicate(pred string, key []byte) uint64 {
sh.RLock()
val, ok := sh.predStats[pred]
sh.RUnlock()
Expand Down
14 changes: 11 additions & 3 deletions worker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1812,10 +1812,16 @@ func planForEqFilter(fc *functionContext, pred string, uidlist []uint64) {
return true
}

if uint64(len(uidlist)) < Config.TypeFilterUidLimit && checkUidEmpty(uidlist) {
fc.tokens = fc.tokens[:0]
fc.n = len(uidlist)
return
}

estimatedCount := uint64(0)
gotEstimate := false
for _, eqToken := range fc.tokens {
count := posting.GlobalStatsHolder.ProcessPredicate(pred, []byte(eqToken))
count := posting.GlobalStatsHolder.ProcessEqPredicate(pred, []byte(eqToken))
if count != math.MaxUint64 {
estimatedCount += count
gotEstimate = true
Expand All @@ -1828,12 +1834,14 @@ func planForEqFilter(fc *functionContext, pred string, uidlist []uint64) {
gotEstimate = false
}

// TODO make a different config
if gotEstimate && uint64(len(uidlist)) < estimatedCount/Config.TypeFilterUidLimit && checkUidEmpty(uidlist) {
fc.tokens = fc.tokens[:0]
fc.n = len(uidlist)
} else {
fc.n = len(fc.tokens)
return
}

fc.n = len(fc.tokens)
}

func parseSrcFn(ctx context.Context, q *pb.Query) (*functionContext, error) {
Expand Down

0 comments on commit 176bb00

Please sign in to comment.