Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19534 +/- ##
=========================================
Coverage 67.72% 67.72%
Complexity 1450 1450
=========================================
Files 3490 3490
Lines 225032 225043 +11
Branches 35527 35530 +3
=========================================
+ Hits 152393 152406 +13
+ Misses 60612 60608 -4
- Partials 12027 12029 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Rows rejected by GROUP BY top-K trimming still allocate sort-key storage and wrappers. Reuse scratch across consecutive rejections while preserving ownership of admitted rows, comparator behavior and result ordering.
xiangfu0
force-pushed
the
xiangfu0/java-groupby-topk-allocation
branch
from
September 12, 2026 19:25
f4ee8ea to
e597d09
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
GROUP BY top-K trimming allocates sort-key arrays and intermediate wrappers for rejected candidates. Reuse that storage across consecutive rejections; create a wrapper with the current key/record when a candidate is admitted. Immediate admissions retain the existing path, including comparator, tie handling and output order. An admitted row's sort-key array is never subsequently overwritten.
Reproduction and benchmark
Select top K from a deterministic prepared map of numeric group results. Small/large K retain 20/5,000 of 8,192 groups; the large-N case retains 5,000 of 100,000. Best-first rejects every later candidate; worst-first admits every later candidate. Full-sort/no-trim retain all 8,192 with/without sorting, and unsorted top-K retains 5,000 without ordering the output. Timing includes construction of
TableResizer, ORDER BY extraction, heap maintenance and optional output sorting; it excludes input-map preparation, SQL parsing, scanning, aggregation, JNI and transport.Measured against upstream
5771d6acea60cd72738116835111cf7c49965373on an Apple M2 Max (12 cores, 32 GiB), macOS ARM64 and Temurin JDK 25. Three AB/BA/AB pairs, one fresh JMH fork per case/arm, one thread, 512 MiB heap, three 500 ms warmups and five 500 ms measurements, with GC profiling. Both arms use the same pinned runtime and measurement code; only theTableResizerclass family differs. Sorted classpath order and runtime hashes were checked. The workstation was shared, with no task builds or other task benchmarks during timing.Results
Times and allocations are medians of three arm means. Ratios are medians of paired baseline/candidate time ratios; ranges retain all three pairs. Values above 1 favor the candidate.
The small-K all-admitted case is about 3% slower with unchanged allocation; large-K random has a 0.995× median ratio. The no-trim control includes a 0.923× individual pair despite its 0.998× median. These non-wins remain part of the result. This is a controlled component comparison, not packaged deployment throughput or proof that every query benefits.
Validation
Recorded local validation: 81 tests passed—13 table-resizer, 9 indexed-table, 3 deterministic-indexed-table, 12 sorted-combine and 44 inter-segment GROUP BY tests. Regression coverage includes rejection runs, immediate admissions, exact identities/order, ties, both resize directions, nulls/NaN/signed zero and aggregate-state ownership. Every measurement fork validated complete result membership, uniqueness, ordering, record identity and input preservation against an independent oracle before timing.
Normal compilation/tests, Spotless, Checkstyle and license format/check passed. Independent correctness, testing and performance reviews found no actionable issues. Scoped lint reported no source warnings and four existing dependency-manifest path warnings. Full-reactor Xlint was not repeated after the same-base attempt failed in unchanged Zstandard code on a missing JetBrains annotation.