github-actions[bot] commented on code in PR #62334:
URL: https://github.com/apache/doris/pull/62334#discussion_r3087213965
##########
be/src/storage/iterator/vcollect_iterator.cpp:
##########
@@ -247,8 +257,43 @@ Status VCollectIterator::next(Block* block) {
return _topn_next(block);
}
+ // Fast path: if general limit already reached, return EOF immediately
+ if (_limit_mode == LimitMode::GENERAL &&
+ _rows_returned >= static_cast<int64_t>(_local_read_limit)) {
+ return Status::Error<END_OF_FILE>("");
+ }
+
if (LIKELY(_inner_iter)) {
- return _inner_iter->next(block);
+ auto st = _inner_iter->next(block);
+ if (UNLIKELY(!st.ok())) {
+ return st;
+ }
+
+ // Apply filter_block_conjuncts that were moved from
Scanner::_conjuncts.
+ // This must happen BEFORE limit counting so that _rows_returned
+ // reflects post-filter rows (same pattern as _topn_next).
+ // filter_block_conjuncts is only populated when the general-limit or
+ // topn branches move conjuncts into the storage layer (topn takes
+ // the _topn_next path and never reaches here).
+ if (!_reader->_reader_context.filter_block_conjuncts.empty()) {
+ RETURN_IF_ERROR(VExprContext::filter_block(
+ _reader->_reader_context.filter_block_conjuncts, block,
block->columns()));
+ }
+
+ // Enforce general read limit: truncate block if needed
+ if (_limit_mode == LimitMode::GENERAL) {
+ _rows_returned += block->rows();
+ if (_rows_returned > static_cast<int64_t>(_local_read_limit)) {
+ // Truncate block to return exactly the remaining rows needed
+ int64_t excess = _rows_returned -
static_cast<int64_t>(_local_read_limit);
+ int64_t keep = block->rows() - excess;
+ DCHECK_GT(keep, 0);
Review Comment:
When this GENERAL-limit path truncates the block, the row-location side
channel is left at the pre-truncation size. `Level0Iterator` / `Level1Iterator`
already cached `_block_row_locations` for the full block, and both
`BlockReader::_direct_next_block()` and
`VerticalBlockReader::_direct_next_block()` DCHECK that
`current_block_row_locations().size() == block->rows()`. So any
`general_read_limit` + `record_rowids` call path can hit a block/rowid mismatch
here. Please trim the stored row locations together with the block, or disable
this path when `record_rowids` is enabled.
##########
be/test/storage/segment/segment_iterator_limit_opt_test.cpp:
##########
@@ -0,0 +1,111 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "gtest/gtest.h"
+#include "storage/olap_common.h"
+#include "storage/predicate/block_column_predicate.h"
+#include "storage/predicate/null_predicate.h"
+#include "storage/segment/segment_iterator.h"
+#include "storage/tablet/tablet_schema.h"
+
+namespace doris::segment_v2 {
+
+class SegmentIteratorLimitOptTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ TabletSchemaPB schema_pb;
+ schema_pb.set_keys_type(KeysType::DUP_KEYS);
+ auto* col = schema_pb.add_column();
+ col->set_unique_id(0);
+ col->set_name("k1");
+ col->set_type("INT");
+ col->set_is_key(true);
+ col->set_is_nullable(true);
+
+ _tablet_schema = std::make_shared<TabletSchema>();
+ _tablet_schema->init_from_pb(schema_pb);
+ _read_schema = std::make_shared<Schema>(_tablet_schema);
+ }
+
+ // Build a SegmentIterator with minimal opts for _can_opt_limit_reads()
testing.
+ // The segment pointer is null — only _opts and internal maps are accessed.
+ std::unique_ptr<SegmentIterator> make_iter() {
+ auto iter = std::make_unique<SegmentIterator>(nullptr, _read_schema);
+ iter->_opts.tablet_schema = _tablet_schema;
Review Comment:
This test reaches into `SegmentIterator` internals (`_opts`,
`_can_opt_limit_reads()`, `_column_predicate_index_exec_status`), but
`segment_iterator.h` still declares all of those as private and this file does
not add any test-only access (`FRIEND_TEST` or `#define private public`). As
written, `doris_be_test` should fail to compile. Please expose the internals
for this test the same way the other BE tests do, or rewrite the test to stay
on the public API.
--
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]