From 8f8333e01bb1345790fe54d2f2889397d4acf0b2 Mon Sep 17 00:00:00 2001 From: Steve Yen Date: Tue, 19 Dec 2017 17:44:25 -0800 Subject: [PATCH] scorch optimize zap Count() This proposed approach avoids building a temporary AndNot() bitmap, following the same kind of optimization used by mem segments. --- index/scorch/segment/zap/posting.go | 9 +++++++-- index/scorch/snapshot_segment.go | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/index/scorch/segment/zap/posting.go b/index/scorch/segment/zap/posting.go index 1ef85eef..1b7a0a58 100644 --- a/index/scorch/segment/zap/posting.go +++ b/index/scorch/segment/zap/posting.go @@ -85,10 +85,15 @@ func (p *PostingsList) Iterator() segment.PostingsIterator { // Count returns the number of items on this postings list func (p *PostingsList) Count() uint64 { if p.postings != nil { + n := p.postings.GetCardinality() if p.except != nil { - return roaring.AndNot(p.postings, p.except).GetCardinality() + e := p.except.GetCardinality() + if e > n { + e = n + } + return n - e } - return p.postings.GetCardinality() + return n } return 0 } diff --git a/index/scorch/snapshot_segment.go b/index/scorch/snapshot_segment.go index c543af82..f2bcfb06 100644 --- a/index/scorch/snapshot_segment.go +++ b/index/scorch/snapshot_segment.go @@ -32,6 +32,7 @@ type SegmentDictionarySnapshot struct { } func (s *SegmentDictionarySnapshot) PostingsList(term string, except *roaring.Bitmap) (segment.PostingsList, error) { + // TODO: if except is non-nil, perhaps need to OR it with s.s.deleted? return s.d.PostingsList(term, s.s.deleted) }