Copilot commented on code in PR #61003:
URL: https://github.com/apache/doris/pull/61003#discussion_r2878069592
##########
be/src/vec/exec/scan/olap_scanner.cpp:
##########
@@ -164,6 +164,11 @@ Status OlapScanner::prepare() {
// value (e.g. select a from t where a .. and b ... limit 1),
// it will be very slow when reading data in segment iterator
_tablet_reader->set_batch_size(_state->batch_size());
+ if (_state->adjust_tablet_reader_batch_size_by_limit()) {
+ _tablet_reader->set_batch_size(
+ _limit == -1 ? _state->batch_size()
+ :
std::min(static_cast<int64_t>(_state->batch_size()), _limit));
Review Comment:
When this flag is enabled, `_limit` can be 0 (e.g. LIMIT 0), which makes the
computed value for `set_batch_size()` become 0. A 0 batch size is propagated
into storage readers as `block_row_max` and is also compared against in
`BlockReader` loops, which can lead to incorrect behavior (e.g. never producing
rows or control-flow issues). Please clamp the computed batch size to at least
1 (and cast explicitly to `int`, since `set_batch_size` takes `int`).
```suggestion
int64_t desired_batch_size =
_limit == -1 ? static_cast<int64_t>(_state->batch_size())
:
std::min(static_cast<int64_t>(_state->batch_size()), _limit);
if (desired_batch_size < 1) {
desired_batch_size = 1;
}
_tablet_reader->set_batch_size(static_cast<int>(desired_batch_size));
```
--
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]