Repository navigation
Avoid PIT context exhaustion by pruning indices that cannot match - #5727
Conversation
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit b25d8b7.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
PR Reviewer Guide 🔍(Review updated until commit 2d90333)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 2d90333 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 1bbddad
Suggestions up to commit 8a8c4c4
Suggestions up to commit 146b86f
Suggestions up to commit bd28765
Suggestions up to commit d447702
|
b25d8b7 to
d447702
Compare
|
Persistent review updated to latest commit d447702 |
d447702 to
bd28765
Compare
|
Persistent review updated to latest commit bd28765 |
bd28765 to
146b86f
Compare
|
Persistent review updated to latest commit 146b86f |
146b86f to
8a8c4c4
Compare
|
Persistent review updated to latest commit 8a8c4c4 |
Prune a wildcard index expression down to the indices that can hold data in the query's @timestamp range, so a scan over many indices no longer exhausts the per-node open PIT context limit. Off by default behind plugins.query.pruning.enabled, and skipped for an alias, a data stream, a cross-cluster expression, or a match list that is empty, excludes nothing or exceeds an internal cap. Signed-off-by: Chen Dai <[email protected]>
8a8c4c4 to
1bbddad
Compare
|
Persistent review updated to latest commit 1bbddad |
Signed-off-by: Chen Dai <[email protected]>
|
Persistent review updated to latest commit 2d90333 |
|
Verifying CI fix in #5733. |
The schema-conflict half of Approach 1 that opensearch-project#5727 left open, implemented as Approach 3 of the design on opensearch-project#5698: a request-level time range, applied while the table is still being resolved. A wildcard index expression is expanded -- and the mapping of every index it matches merged -- before any predicate in the query text has been parsed, so nothing downstream of that resolution can narrow it. opensearch-project#5727 reads its range from the filter already sitting in the pushdown context, which is the broadest coverage available without an API change but runs too late for the merge. Declaring the range on the request puts it in hand before planning starts: start_time/end_time/time_field -> PPLQueryRequest.getTimeBounds -> AbstractPlan -> QueryService.buildFrameworkConfig (seeded once) -> OpenSearchSchema.registerTable -> OpenSearchStorageEngine.getTable(.., TimeBounds) -> IndexPruner -> OpenSearchIndex Following the design's shape: - Bounds are global, applied to every table the query resolves rather than attributed to one relation -- the scope Splunk's time range picker and ES|QL's request-level filter have. That is what lets them be a plain request parameter with no AST work, no visitor change and no ordering problem. - Narrowing happens as the table is built, via a new SupportsIndexPruning the storage engine implements, not by mutating a table afterwards: a table's row type is derived from the merge, so once one exists the cost is already paid. The interface keeps the probe in the module owning a client to probe with, and core free of OpenSearch types. - Bounds are carried as the strings the request sent and handed to _field_caps as-is, so OpenSearch's own date parser reads them and date math works. Re-interpreting them here risks a narrower window than the caller meant, which would drop an index that can match -- the divergence hazard the design flags for Approach 1. Two additions the design leaves implicit. time_field makes the field explicit rather than assuming @timestamp, because a Dashboards index pattern is routinely configured on another field and would otherwise never prune. And the probe's format list accepts a UTC wall clock alongside the OpenSearch defaults, since a client that also writes the bound into the query text produces the spelling PPL accepts there; without it such a bound fails to parse and pruning silently declines. A source whose time_field is not a date excludes itself, read off the same probe response, so a range that cannot prove an index disjoint prunes nothing. Unusable bounds are dropped rather than rejected: they only decide which indices are read, so failing a query over a parameter it does not need is the worse outcome. Gated by plugins.query.pruning.enabled, which opensearch-project#5759 turns on by default. Verified on a security-enabled cluster over eight monthly indices whose newest one renamed a field's shape from object to keyword. Without bounds the merge sees the object and charting by it fails; with them only the newest is resolved and the same query returns its rows. Row counts are identical either way, a range covering every index prunes none, and a range no index can match declines rather than pruning all. Signed-off-by: Kai Huang <[email protected]>
…hose indices Reviewing this against the Dashboards side turned up two things the separate reviews could not see. The guard added for the unmapped-field case was applied to both pruning paths, which regressed opensearch-project#5727's own yaml case "Prunes an index that does not map the timestamp". The two paths are not alike. When the range is read out of the query's own pushed-down filter, an index that does not map the field cannot satisfy that filter either, so its documents are already excluded from the answer and dropping the index is lossless -- which is exactly what that test asserts. When the range arrives as a request parameter the query text need not mention the field at all, so those documents are still wanted. The guard now applies only to the bounds path; the filter path is untouched, and the yaml suite passes again. And rather than declining outright when the field is unmapped somewhere, the bounds path now keeps those indices and prunes among the rest. _field_caps already names them in the unmapped bucket of an include_unmapped probe, so this costs nothing and turns a case that gave up into one that prunes correctly -- worth having because a Dashboards index pattern spanning a stray index without the time field would otherwise never prune at all. Declining is kept only where nothing better is possible: no index maps the field, it is mapped as a non-date somewhere, or the probe does not name the unmapped indices. Signed-off-by: Kai Huang <[email protected]>
…cannot match Reverts the retain-unmapped behaviour, and with it the mapping probe that existed to detect the case. Under a request-level time range a document with no time value is in no window, so the index holding it can be excluded on the same evidence as one whose values fall outside the range. That is what the pushed-down-filter path does -- opensearch-project#5727's own yaml case asserts it -- and what ES|QL's request filter and Splunk's picker do. Retaining such an index was the inconsistent special case, and it protected only a usage the manual already tells callers not to attempt: bounds sent without an equivalent predicate in the query text, where rows are dropped for in-range indices anyway. It also cost a warning. Keeping an index that maps none of the group fields gives the partial-result feature something to exclude, so a query that had no mapping conflict gained a "mapping conflict" banner naming a field that is merely absent, with a rerun prompt that would buy nothing. The probe goes with it. An unmapped time field now self-declines through the existing empty-candidate path -- every index reports as non-matching, so nothing is substituted -- which is one fewer blocking round trip per distinct source on the bounds path. The consequence is deliberate and now documented: pruning removes the index's schema along with its rows, so a query naming a field only that index maps fails with "Field [x] not found." rather than quietly returning nothing. The IT asserts the loud failure. Signed-off-by: Kai Huang <[email protected]>
Description
Prunes a wildcard index expression down to the indices that can match the query's
@timestamprange before the PIT is created, so a scan over many time-bucketed indices no longer opens a reader context per shard of every matching index and exhaustssearch.max_open_pit_context._field_capswithindex_filter— Option A of the approaches weighed on the issue — driven by the resolved filter already sitting in the pushdown context.One decision is left open for review: the candidate list is capped at 50 rather than tied to[removed]search.max_open_pit_context, so an expression matching more indices than the cap falls back to the wildcard and opens every context.Example
Three monthly indices, one shard each, one document each.
max_result_windowis 2 so thathead 5exceeds it and the query takes the PIT path, which is where pruning runs.No reader contexts opened yet:
Query a range only February can satisfy, with pruning at its default of
false:All three indices opened a reader context, including the two that cannot match:
{"indices": { "demo-2026-01": {"total": {"search": {"point_in_time_total": 1}}}, "demo-2026-02": {"total": {"search": {"point_in_time_total": 1}}}, "demo-2026-03": {"total": {"search": {"point_in_time_total": 1}}}}}Now recreate the indices to reset the counters, and enable pruning:
The same query returns the same row:
{"datarows": [["february"]], "total": 1, "size": 1}But only February was read — three reader contexts down to one:
{"indices": { "demo-2026-01": {"total": {"search": {"point_in_time_total": 0}}}, "demo-2026-02": {"total": {"search": {"point_in_time_total": 1}}}, "demo-2026-03": {"total": {"search": {"point_in_time_total": 0}}}}}Related Issues
Part of #5698
Check List
--signoffor-s.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.