Skip to content

Enable plugins.query.pruning.enabled by default - #5759

Merged
dai-chen merged 1 commit into
opensearch-project:mainfrom
dai-chen:enable-index-pruning-by-default
Sep 12, 2026
Merged

dai-chen merged 1 commit into
opensearch-project:mainfrom
dai-chen:enable-index-pruning-by-default

Conversation

@dai-chen

Copy link
Copy Markdown
Collaborator

Description

Index pruning shipped in PR #5727 turned off behind plugins.query.pruning.enabled. As the required resolve index and fields cap permissions added to ppl_full_access role 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

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

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.

@dai-chen dai-chen self-assigned this Sep 10, 2026
@dai-chen dai-chen added enhancement New feature or request PPL Piped processing language labels Sep 10, 2026
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit 59b832c)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Latest suggestions up to 59b832c

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Use boolean-specific assertion methods

Use assertTrue and assertFalse instead of assertEquals with boolean literals for
better readability and more idiomatic JUnit assertions. This makes the test intent
clearer and provides better failure messages.

opensearch/src/test/java/org/opensearch/sql/opensearch/setting/OpenSearchSettingsTest.java [134-137]

-assertEquals(true, settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
+assertTrue(settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
 
 settings.new Updater(Settings.Key.QUERY_PRUNING_ENABLED).accept(false);
-assertEquals(false, settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
+assertFalse(settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
Suggestion importance[1-10]: 5

__

Why: Using assertTrue and assertFalse instead of assertEquals with boolean literals is a valid improvement for code readability and provides more idiomatic JUnit assertions. However, this is a minor style improvement that doesn't affect functionality or correctness.

Low

Previous suggestions

Suggestions up to commit 38a4b67
CategorySuggestion                                                                                                                                    Impact
General
Use boolean-specific assertion methods

Use assertTrue() instead of assertEquals(true, ...) for better readability and more
descriptive assertion failures. Similarly, use assertFalse() for the boolean false
check below.

opensearch/src/test/java/org/opensearch/sql/opensearch/setting/OpenSearchSettingsTest.java [134]

-assertEquals(true, settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
+assertTrue(settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
Suggestion importance[1-10]: 4

__

Why: While using assertTrue() instead of assertEquals(true, ...) is a valid improvement for test readability and more descriptive failure messages, this is a minor code style enhancement that doesn't affect functionality or correctness.

Low
Suggestions up to commit d2ba155
CategorySuggestion                                                                                                                                    Impact
General
Use boolean-specific assertions

Use assertTrue and assertFalse instead of assertEquals with boolean literals for
better readability and more descriptive test failures. This follows JUnit best
practices for boolean assertions.

opensearch/src/test/java/org/opensearch/sql/opensearch/setting/OpenSearchSettingsTest.java [134-137]

-assertEquals(true, settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
+assertTrue(settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
 
 settings.new Updater(Settings.Key.QUERY_PRUNING_ENABLED).accept(false);
-assertEquals(false, settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
+assertFalse(settings.getSettingValue(Settings.Key.QUERY_PRUNING_ENABLED));
Suggestion importance[1-10]: 5

__

Why: Using assertTrue and assertFalse instead of assertEquals with boolean literals is a valid improvement that enhances test readability and provides clearer failure messages. However, this is a minor style improvement that doesn't affect functionality or correctness.

Low

@dai-chen
dai-chen force-pushed the enable-index-pruning-by-default branch from d2ba155 to 38a4b67 Compare September 11, 2026 16:34
@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 38a4b67

@dai-chen
dai-chen force-pushed the enable-index-pruning-by-default branch from 38a4b67 to 04e5334 Compare September 11, 2026 16:53
@github-actions

Copy link
Copy Markdown
Contributor

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]>
@dai-chen
dai-chen force-pushed the enable-index-pruning-by-default branch from 04e5334 to 59b832c Compare September 11, 2026 16:59
@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 59b832c

@dai-chen
dai-chen merged commit 43b1af3 into opensearch-project:main Sep 12, 2026
60 of 61 checks passed
ahkcs added a commit to ahkcs/OpenSearch-Dashboards that referenced this pull request Sep 14, 2026
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]>
ahkcs added a commit to ahkcs/sql that referenced this pull request Sep 14, 2026
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]>
ahkcs added a commit to ahkcs/sql that referenced this pull request Sep 14, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PPL Piped processing language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants