Repository navigation
Enable plugins.query.pruning.enabled by default - #5759
Conversation
PR Reviewer Guide 🔍(Review updated until commit 59b832c)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 59b832c Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 38a4b67
Suggestions up to commit d2ba155
|
d2ba155 to
38a4b67
Compare
|
Persistent review updated to latest commit 38a4b67 |
38a4b67 to
04e5334
Compare
|
Persistent review updated to latest commit 04e5334 |
The permissions its probes need were added to ppl_full_access in opensearch-project/security#6471. Signed-off-by: Chen Dai <[email protected]>
04e5334 to
59b832c
Compare
|
Persistent review updated to latest commit 59b832c |
opensearch-project/sql#5759 enables plugins.query.pruning.enabled by default, so 'has no effect unless the cluster also sets it' stops being true and reads as though the switch does nothing. Say what each side controls instead: the cluster decides whether to act on the bounds, this decides whether to send them, and either opting out is enough. Signed-off-by: Kai Huang <[email protected]>
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]>
Correctness An index that does not map the time field was pruned away with its rows. A range on an unmapped field is *disjoint* for that index, not unknown, so _field_caps omits it exactly as it omits an index whose values fall outside the window -- the two are indistinguishable in the response, and the previous type check saw only the date entry the mapping indices reported and let pruning proceed. Verified against a cluster: a wildcard over one index mapping `ts` and one not returns only the former from the probe. The gate now runs on its own unfiltered probe with include_unmapped, which is the only way to see the indices a filtered probe has already hidden, and declines when the field is unmapped anywhere, not a date anywhere, or mapped by nothing. Costs one metadata probe, paid before the filtered one so a declining query stops early. New IT keeps a row that lives only in an index without the field. The gate also ran before the candidate count, so a window matching no index reported "[ts] is not a date field" -- field-caps returns an empty field map along with an empty index list -- and the "0 of N indices matched" line could never fire. Reordered. analyze dropped the bounds on both phases, so `"analyze": true` merged every matched index's mapping and reported a plan over an expression the execution would not have used. Threaded, as explain already was. Broken surface removed The URL-parameter loop could not work: BaseRestHandler rejects parameters absent from responseParams(), so start_time in a query string was a 400, and a real GET carries no jsonContent for the loop to write into. Dropped rather than half-supported. Tests createRoleWithIndexAccess granted neither indices:admin/resolve/index nor indices:data/read/field_caps*, so under security both probes were denied, pruning declined silently, and TimeBoundsPruningSecurityIT's positive case could not pass. Granted, matching what ppl_full_access carries since 3.9. Both ITs pinned the pruning setting to false on teardown; since opensearch-project#5759 made it default true, that left every later class in the cluster running with pruning off. They clear the override instead. Registered CalciteTimeBoundsPruningIT in CalciteNoPushdownIT, which the repo requires and which matters here: request-level pruning is meant to be independent of pushdown. Accuracy Documented that these bounds are not free of effect. Pruning drops whole indices, so a query whose text already constrains the same field to the same window returns the same rows -- the intended use -- while one that does not returns fewer. The previous claim that a request is "answered identically" was false, and this PR's own subsearch IT asserts a row count changing. Corrected the claim that a bound is read by the index's own date parser: the probe's format list replaces the field's, so a field with some other custom format is not pruned on. Said so, and noted that declining costs the optimization and never a row. Stopped promising the unified query path reads these; it builds its own schema and ignores them. The "Request-level time bounds" heading was a section sibling, sweeping the setting's own disable/result-set examples under it. Demoted to prose. Renamed the leftover "hint" and "time_range" vocabulary in tests to the shipped start_time/end_time/TimeBounds, reused OpenSearchConstants.IMPLICIT_FIELD_TIMESTAMP instead of a second copy, and made a one-sided window warn rather than vanish. Signed-off-by: Kai Huang <[email protected]>
Description
Index pruning shipped in PR #5727 turned off behind
plugins.query.pruning.enabled. As the required resolve index and fields cap permissions added toppl_full_accessrole in opensearch-project/security#6471, this PR enables it by default. The setting remains dynamic, so a cluster hit by one of the documented limitations can turn pruning off at runtime, as the user manual shows.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.