Skip to content

quick exit on filter query matching no docs when rewriting knn query #14418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 31, 2025

Conversation

bugmakerrrrrr
Copy link
Contributor

Description

@jpountz
Copy link
Contributor

jpountz commented Mar 28, 2025

Can you help me understand what work this change helps save?

@bugmakerrrrrr
Copy link
Contributor Author

Can you help me understand what work this change helps save?

Thanks for your reply. I think if the filter query matches no docs, the knn query must also match no docs. Before this small change, we always executed search tasks for each leaf reader even if the filter query is MatchNoDocsQuery.

TimeLimitingKnnCollectorManager knnCollectorManager =
new TimeLimitingKnnCollectorManager(
getKnnCollectorManager(k, indexSearcher), indexSearcher.getTimeout());
TaskExecutor taskExecutor = indexSearcher.getTaskExecutor();
List<LeafReaderContext> leafReaderContexts = reader.leaves();
List<Callable<TopDocs>> tasks = new ArrayList<>(leafReaderContexts.size());
for (LeafReaderContext context : leafReaderContexts) {
tasks.add(() -> searchLeaf(context, filterWeight, knnCollectorManager));
}
TopDocs[] perLeafResults = taskExecutor.invokeAll(tasks).toArray(TopDocs[]::new);

@jpountz
Copy link
Contributor

jpountz commented Mar 30, 2025

Thank you, that makes sense. So in the case when the filter rewrites to MatchNoDocsQuery, IndexSearcher#search would now return immediately, while it may currently need to wait for tasks to be submitted (if the queue is not empty).

Can you add a CHANGES entry?

@bugmakerrrrrr
Copy link
Contributor Author

So in the case when the filter rewrites to MatchNoDocsQuery, IndexSearcher#search would now return immediately, while it may currently need to wait for tasks to be submitted (if the queue is not empty).

Yes, you are right.

Can you add a CHANGES entry?

Added.

@jpountz jpountz merged commit 71e5dc6 into apache:main Mar 31, 2025
7 checks passed
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.

2 participants