Skip to content

Conversation

@GovindBalaji-S-Glean
Copy link

Description

Fixes #14986.

A TermInSetQuery with rewriteMethod = MultiTermQuery.CONSTANT_SCORE_BLENDED_REWRITE creates a RewritingWeight. Getting a scorer from this RewritingWeight for a segment could involve rewriting to a BooleanQuery of multiple TermQuery with only the terms present in that particular segment.

These segment-specific BooleanQuery rewrites all thrash the UsageTrackingQueryCachingPolicy ring buffer, which is shared across all segments of the index. The expectation is that we mark a query only once per shard in this ring buffer - ref

In this change: When initializing AbstractMultiTermQueryConstantScoreWrapper.RewritingWeight, we copy the supplied indexSearcher but with setQueryCache(null) and pass it along for the segment-specific rewrites. The subsequent rewrites into BooleanQuery of TermQuery don't go through the query cache (The idea is that these should be cached as the parent TermInSet query itself)

Fixes apache#14986.

A `TermInSetQuery` with `rewriteMethod = MultiTermQuery.CONSTANT_SCORE_BLENDED_REWRITE` creates a `RewritingWeight`. Getting a scorer from this `RewritingWeight` for a segment could involve rewriting to a `BooleanQuery` of multiple `TermQuery` with only the terms present in that particular segment.

These segment-specific `BooleanQuery` rewrites all thrash the `UsageTrackingQueryCachingPolicy` ring buffer, which is shared across all segments of the index. The expectation is that we mark a query only once per shard in this ring buffer - [ref](https://github.com/apache/lucene/blob/a3fa283cfd6aefbcc5a4983e065da0ce7d3209fe/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java#L686-L688)

In this change: When initializing `AbstractMultiTermQueryConstantScoreWrapper.RewritingWeight`, we copy the supplied indexSearcher but with `setQueryCache(null)` and pass it along for the segment-specific rewrites.
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the [email protected] list. Thank you for your contribution!

@github-actions github-actions bot added the Stale label Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index level caching policy is thrashed by segment-specific query rewrites

1 participant