Add query planner Phase 2: logical planning and cost estimation #19244
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.
Following up on Phase 1 (PR #19060), this adds the cost estimation
infrastructure needed for query optimization (RFC #18906).
What this does:
Builds a tree of QueryPlanNode objects from QueryBuilder
Estimates query costs by summing Lucene scorer costs across all segments
Tracks CPU/memory/IO costs alongside document counts
Preserves field names and query metadata (lost when converting to Lucene)
The main insight is using Lucene's existing scorer.cost() aggregated
properly across index leaves, then adding our own heuristics for
things Lucene doesn't track.
Notable implementation details:
BooleanPlanNode caps must_not penalties so costs don't explode
Percentage minimumShouldMatch now works (e.g. "50%")
Feature flagged: -Dopensearch.experimental.feature.query_planner.enabled
No user-visible changes yet - this is just the foundation for Phase 3
where we'll actually optimize queries based on these costs.
Signed-off-by: Atri Sharma [email protected]
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.