Use LongHashSet for sparse ordinal sets in DocValuesRangeIterator#16297
Open
costin wants to merge 4 commits into
Open
Use LongHashSet for sparse ordinal sets in DocValuesRangeIterator#16297costin wants to merge 4 commits into
costin wants to merge 4 commits into
Conversation
Replace LongBitSet with LongHashSet in buildOrdinalSet() so memory scales with the number of matching terms rather than the total ordinal count of the segment. Defer the LongHashSet allocation until after the contiguity check so contiguous ordinal sets (which route to forOrdinalRange) never allocate a set at all. Collect ords into a temporary long[] during TermsEnum iteration, detect contiguity from the sorted ord stream, then build the LongHashSet only for non-contiguous sets. The internal OrdinalSet record now holds a LongPredicate for membership testing, decoupling it from the concrete set type. The public forOrdinalSet(SortedSetDocValues, ..., LongBitSet) overload is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace LongBitSet with LongHashSet in buildOrdinalSet() so memory scales with the number of matching terms rather than the total ordinal count of the segment.
This is an issue since DocValuesRangeIterator.buildOrdinalSet() builds a set of matching ordinals for MultiTermQuery rewrites which fires for prefix, wildcard, and regexp queries on doc-values-only fields.
The current implementation allocates, per query, a
LongBitSet(ordCount)whereordCountis the total number of unique values in the segment. This means a wildcard query matching 10 terms against a 10M-cardinality field allocates 1.2 MB per segment of mostly-zero bits.This PR replaces LongBitSet with LongHashSet, which allocates proportionally to matching terms (~32 bytes/entry). Contiguous ordinal sets skip the hash set allocation entirely, ords are collected into a temporary long[] and contiguity is detected from the sorted stream.
Memory per query instance per segment
LongBitSet)LongHashSet)