Repository navigation
Avoid caching multiple times in doc-partitioning - #142913
Merged
Merged
Conversation
Collaborator
|
Hi @dnhatn, I've created a changelog YAML for you. |
dnhatn
marked this pull request as ready for review
February 24, 2026 00:49
Collaborator
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
nik9000
reviewed
Feb 24, 2026
nik9000
left a comment
Contributor
There was a problem hiding this comment.
Lovely! I scanned it tonight but haven't finished. Will look tomorrow.
| public long cost() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| }; |
| ); | ||
| return new WeightAndCache(searcher.createWeight(query, scoreMode, 1), queryCache::blockedOnCaching); | ||
| } else { | ||
| return new WeightAndCache(ctx.searcher().createWeight(query, scoreMode, 1), unused -> null); |
Contributor
There was a problem hiding this comment.
nit, could you use LuceneSlice.NEVER_BLOCKED here
parkertimmins
self-requested a review
February 24, 2026 16:22
parkertimmins
approved these changes
Feb 24, 2026
parkertimmins
left a comment
Contributor
There was a problem hiding this comment.
Looks good! Though I can't say I understand it in it's entirety. Definitely worth getting some more eyes.
nik9000
approved these changes
Feb 24, 2026
Member
Author
|
Thanks friends! |
dnhatn
added a commit
that referenced
this pull request
Feb 26, 2026
I have been looking into replacing the head-stealing slice queue with a bisection work-splitting queue; however, the improvement is small, which does not justify the complexity added with the new queue. With slices of 250K documents, the locality and page cache thrashing or even postings iterating is not too expensive; hence I've decided not to move forward with that change. I believe the caching fix in #142913 addresses the remaining concern there. This change enables doc-partitioning for all queries except for queries that are expensive to build the scorer. Specifically, we disable doc-partitioning for MultiTermQuery and PointRangeQuery. That means many queries from Kibana with time-range queries will still run with segment partitioning. I will look into how to enable doc-partitioning for such queries later.
PeteGillinElastic
pushed a commit
to PeteGillinElastic/elasticsearch
that referenced
this pull request
Feb 27, 2026
I have been looking into replacing the head-stealing slice queue with a bisection work-splitting queue; however, the improvement is small, which does not justify the complexity added with the new queue. With slices of 250K documents, the locality and page cache thrashing or even postings iterating is not too expensive; hence I've decided not to move forward with that change. I believe the caching fix in elastic#142913 addresses the remaining concern there. This change enables doc-partitioning for all queries except for queries that are expensive to build the scorer. Specifically, we disable doc-partitioning for MultiTermQuery and PointRangeQuery. That means many queries from Kibana with time-range queries will still run with segment partitioning. I will look into how to enable doc-partitioning for such queries later.
dnhatn
added a commit
that referenced
this pull request
Mar 9, 2026
A bulk scorer of a Weight can be non-null before caching but become null after caching. This happens when the query matches no docs (but not rewritten to MatchNoDocsQuery), and RoaringDocIdSet is used for caching. RoaringDocIdSet returns null for no matches, and CachingWeight returns null for scorerSupplier in this case. In ES|QL, we assume that once a Weight returns a non-null ScorerSupplier, it will never return null on subsequent calls, but this is not true after caching. This happened before once but became more frequent with #142913.
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.
I have been looking into enabling doc-partitioning by default for ES|QL. There are two major overheads:
This PR addresses the first issue by introducing a query cache wrapper for doc-partitioning. Only one thread will populate the cache for a specific leaf; other threads will be blocked and yield execution until the cache is populated, then use the cached iterators to execute the query.
I tested this PR with:
The key difference is run 4, where caching is triggered. Doc partitioning on main took twice as long as segment partitioning due to redundant cache population. With this change, doc partitioning should be better than the default segment partitioning in most cases.
However, we will still need to address the second issue before enabling doc-partitioning for all queries.