github-actions[bot] commented on code in PR #62222:
URL: https://github.com/apache/doris/pull/62222#discussion_r3050771344
##########
be/src/exec/scan/olap_scanner.cpp:
##########
@@ -531,6 +531,14 @@ Status OlapScanner::_init_tablet_reader_params(
}
}
+ // Propagate shared scan limit to storage layer for dynamic I/O
reduction.
+ // Both topn and general-limit paths benefit from this: the segment
+ // iterator can tighten its per-batch row budget based on how many rows
+ // the whole query still needs, avoiding unnecessary I/O.
+ if (olap_scan_local_state->_storage_no_merge()) {
+ _tablet_reader_params.shared_scan_limit =
_local_state->shared_scan_limit_ptr();
Review Comment:
Applying `shared_scan_limit` to the `read_orderby_key_limit` path breaks the
correctness contract of parallel top-N scanning. In this branch, each scanner
is supposed to produce its own local top-N candidate set
(`_limit_per_scanner`), and only the upper operator merges those candidates
into the final global top-N.
After this change, `BetaRowsetReader` passes the global remaining-row budget
down into `SegmentIterator::read_limit`, so one scanner can exhaust the shared
counter and cause other scanners to stop before they have produced their own
local top-N rows. That can return the wrong result under parallel scan.
Concrete case: with parallel scan enabled, imagine tablet A contains keys
`100..199` and tablet B contains keys `1..99`, and the query is `SELECT ...
ORDER BY k LIMIT 10`. If scanner A runs first and returns 10 rows, the shared
counter reaches 0. Scanner B can then stop without returning its local top-10
rows (`1..10`), so the final merge never sees the real best rows.
This shared budget is safe as an I/O hint for plain unordered `LIMIT`, but
it is not safe for the `ORDER BY key LIMIT` / per-scanner top-N path. The new
regression tests do not cover this because the ORDER BY cases use a
single-bucket table only.
--
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]