[fix](show) apply ORDER BY and LIMIT correctly to SHOW TABLETS (#65871) - #66116
Open
SudharsanK2308 wants to merge 5 commits into
Open
[fix](show) apply ORDER BY and LIMIT correctly to SHOW TABLETS (#65871)#66116SudharsanK2308 wants to merge 5 commits into
SudharsanK2308 wants to merge 5 commits into
Conversation
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary: RecordPickerUtils used a top-K heap before returning sorted records. Replace the heap selection with a stable full lexicographic sort before truncation so mixed-direction keys such as LocalDataSize DESC and TabletId ASC are applied in sequence. Negative no-limit values continue to sort the complete result.
### Release note
Fix multi-column ordering for SHOW TABLETS results.
### Check List (For Author)
- Test: Manual test
- Verified LocalDataSize DESC, TabletId ASC with equal-size groups and a limit
- Behavior changed: Yes, all ORDER BY keys are applied before limiting results
- Does this need documentation: No
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
### What problem does this PR solve? Issue Number: close apache#65871 Related PR: None Problem Summary: SHOW TABLETS represented both an absent LIMIT and LIMIT 0 as zero. The command consequently converted explicit LIMIT 0 to an unlimited request, returning all records. Preserve absent LIMIT as -1, pass it to RecordPickerUtils as Optional.empty(), retain explicit zero as Optional.of(0), and apply offset after the complete multi-column ordering. ### Release note SHOW TABLETS now honors LIMIT 0 and applies LIMIT/OFFSET after multi-column ordering. ### Check List (For Author) - Test: Manual test - Verified LIMIT 0 returns no records and unlimited LocalDataSize DESC, TabletId ASC ordering - Behavior changed: Yes, explicit LIMIT 0 no longer behaves as unlimited - Does this need documentation: No Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
SudharsanK2308
requested review from
924060929,
englefly,
morrySnow and
starocean999
as code owners
July 27, 2026 10:56
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Author
|
run buildall |
morrySnow
reviewed
Jul 28, 2026
| Optional<Integer> sizeLimit = Optional.empty(); | ||
| if (offset > 0 && limit > 0) { | ||
| sizeLimit = offset + limit; | ||
| sizeLimit = Optional.of((int) (offset + limit)); |
Contributor
There was a problem hiding this comment.
offset and limit should be long. check overflow by org.apache.doris.nereids.util.Utils#addOverflows
Author
There was a problem hiding this comment.
@morrySnow Since it is already typecast in the original version, I preserved the same. Also,
List<List<Comparable>> tabletInfos
's size always returns int.
SudharsanK2308
commented
Jul 28, 2026
| } | ||
| Collections.sort(tabletInfos, comparator); | ||
| if (sizeLimit > -1) { | ||
| tabletInfos = tabletInfos.subList((int) offset, |
Author
There was a problem hiding this comment.
Narrowing Type Casting in the existing version
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.
What problem does this PR solve?
Issue Number: close #65871
Related PR: #xxx
Problem Summary:
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)