github-actions[bot] commented on code in PR #62222:
URL: https://github.com/apache/doris/pull/62222#discussion_r3057136669
##########
be/src/exec/scan/olap_scanner.cpp:
##########
@@ -531,6 +533,27 @@ Status OlapScanner::_init_tablet_reader_params(
}
}
+ // Propagate shared scan limit to storage layer for dynamic I/O
reduction.
+ // Only for the general (non-topn) limit path: the segment iterator can
+ // tighten its per-batch row budget based on how many rows the whole
+ // query still needs, avoiding unnecessary I/O.
+ //
+ // NOT propagated for the topn (ORDER BY key LIMIT) path because each
+ // scanner must independently produce its full local top-N candidates
+ // for the merge step — a global budget would let one scanner starve
+ // others and produce wrong results.
+ if (_tablet_reader_params.read_orderby_key_limit > 0) {
+ // TopN path: each scanner must independently produce full local
+ // top-N candidates, so disable the cross-scanner shared limit
+ // (which was set by Scanner::init() as the default).
Review Comment:
`read_orderby_key_limit > 0` only identifies the storage-level no-merge
top-N optimization. It does **not** cover the rest of the `sort_info` top-N
path, because `Scanner::init()` has already cached `_shared_scan_limit` for
every scanner by default. For merge-required `ORDER BY key LIMIT` queries, that
means one scanner can consume the shared budget first and stop its peers before
they emit their own local candidates, which can make the final merge miss
smaller keys from later scanners. Example: two scanners participate in a
key-ordered top-N merge, scanner A returns `N` rows first, `_shared_scan_limit`
reaches 0, scanner B never contributes even though it contains smaller keys.
The shared limit needs to be disabled for the entire top-N path, not only when
`read_orderby_key_limit` is set.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]