Fix the regression of terms agg optimization - #20623
Conversation
Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR introduces a configurable maximum cardinality threshold for terms aggregation precomputation. A new cluster setting controls when terms aggregations should avoid expensive precomputation for high-cardinality fields, integrating the threshold check into aggregation factories and segment processing logic. Changes
Sequence Diagram(s)sequenceDiagram
participant ClusterConfig as Cluster Configuration
participant SearchCtx as SearchContext
participant AggFactory as TermsAggregatorFactory
participant Aggregator as Aggregator Execution
ClusterConfig->>SearchCtx: Initialize with TERMS_AGGREGATION_MAX_PRECOMPUTE_CARDINALITY setting
SearchCtx->>SearchCtx: termsAggregationMaxPrecomputeCardinality() evaluates and caches threshold
AggFactory->>SearchCtx: Query threshold for match-all with high cardinality
SearchCtx-->>AggFactory: Return max precompute cardinality (30000)
AggFactory->>AggFactory: Check if maxCardinality <= threshold
alt Cardinality within threshold
AggFactory->>Aggregator: Proceed with optimized streaming disabled
else Cardinality exceeds threshold
AggFactory->>Aggregator: Use streaming for high-cardinality field
end
Aggregator->>Aggregator: tryCollectFromTermFrequencies checks segment cardinality
Aggregator->>Aggregator: Skip precomputation if cardinality exceeds threshold
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20623 +/- ##
============================================
- Coverage 73.30% 73.23% -0.07%
+ Complexity 71965 71934 -31
============================================
Files 5781 5781
Lines 329200 329210 +10
Branches 47491 47492 +1
============================================
- Hits 241314 241091 -223
- Misses 68491 68760 +269
+ Partials 19395 19359 -36 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
|
❌ Gradle check result for 830fefe: null Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
❌ Gradle check result for 830fefe: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
❌ Gradle check result for 830fefe: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
8c244c0
into
opensearch-project:main
* Fix the regression of terms agg optimization Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * Change log Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * add code coverage Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> --------- Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> (cherry picked from commit 8c244c0) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
* Fix the regression of terms agg optimization Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * Change log Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * add code coverage Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> --------- Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
* Fix the regression of terms agg optimization Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * Change log Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * add code coverage Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> --------- Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
* Fix the regression of terms agg optimization Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * Change log Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> * add code coverage Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com> --------- Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
Description
We discovered on clickbench that when terms aggregation is applied on very high cardinality field, the performance actually regressed.
The optimization in terms aggregation uses terms dictionary but also reads the actual BytesRef/value. So for very high cardinality field, this value reading becomes a problem.
This PR introduces a cluster setting to guard the max cardinality supported for terms aggregation. The default value is set to 30,000 for now because we know this optimization worked well for big5 terms aggregation on a field with 26,xxx cardinality.
The fallback logic of streaming aggregation is also updated accordingly
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
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.