github-actions[bot] commented on code in PR #62222:
URL: https://github.com/apache/doris/pull/62222#discussion_r3123887895


##########
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 new test reaches into `SegmentIterator` private members/methods 
(`_opts`, `_column_predicate_index_exec_status`, `_can_opt_limit_reads()`) 
without any access shim. Unlike the existing white-box test 
`segment_iterator_apply_index_expr_test.cpp`, this file does not use `#define 
private public`, and there is no `friend` declaration on `SegmentIterator`, so 
`doris_be_test` will fail to compile once this file is picked up by 
`be/test/CMakeLists.txt`.



##########
be/src/exec/scan/scanner_context.cpp:
##########
@@ -742,11 +716,6 @@ std::shared_ptr<ScanTask> 
ScannerContext::_pull_next_scan_task(
     }
 
     if (!_pending_tasks.empty()) {
-        // If shared limit quota is exhausted, do not submit new scanners from 
pending queue.

Review Comment:
   Removing the exhausted-limit check here regresses the startup fast-path for 
`LIMIT 0` / already-satisfied LIMIT queries. `Scanner::get_block()` now returns 
EOF quickly, but only after `prepare()` / `open()` have already run, so pending 
scanners can still be pulled and initialized even though the shared limit is 
already `0`.



##########
regression-test/suites/query_p0/limit/test_unified_limit_pushdown.groovy:
##########
@@ -0,0 +1,217 @@
+// 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.
+
+// Test unified limit pushdown to SegmentIterator.
+// This exercises the code path where _can_opt_limit_reads() returns true
+// because all column predicates are evaluated by inverted index, allowing
+// the segment iterator to tighten nrows_read_limit using topn_limit and
+// shared_scan_limit.
+
+suite("test_unified_limit_pushdown") {
+
+    // ---- DUP_KEYS table with inverted indexes ----
+    // Inverted indexes on all queried columns allow _can_opt_limit_reads()
+    // to return true, enabling the SegmentIterator limit optimization.
+    sql "DROP TABLE IF EXISTS dup_inv_limit"
+    sql """
+        CREATE TABLE dup_inv_limit (
+            k1 INT NOT NULL,
+            k2 INT NOT NULL,
+            v1 VARCHAR(100) NULL,
+            INDEX idx_k1 (k1) USING INVERTED,
+            INDEX idx_k2 (k2) USING INVERTED,
+            INDEX idx_v1 (v1) USING INVERTED
+        )
+        DUPLICATE KEY(k1, k2)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES ("replication_num" = "1");
+    """
+
+    // Insert 200 rows for sufficient data volume
+    StringBuilder sb = new StringBuilder()
+    sb.append("INSERT INTO dup_inv_limit VALUES ")
+    for (int i = 1; i <= 200; i++) {
+        if (i > 1) sb.append(",")
+        sb.append("(${i}, ${1000 - i}, 'val_${i}')")
+    }
+    sql sb.toString()
+
+    // Basic LIMIT — general_read_limit path with inverted index optimization.
+    def count1 = sql """
+        SELECT COUNT(*) FROM (
+            SELECT k1, k2 FROM dup_inv_limit LIMIT 10
+        ) t
+    """
+    assert count1[0][0] == 10 : "DUP inverted: basic LIMIT 10, got 
${count1[0][0]}"

Review Comment:
   These new regression cases only assert `COUNT(*)`, which is too weak for a 
LIMIT/ORDER BY optimization change. They would still pass if the optimized path 
silently stopped firing or returned the wrong subset/order with the same 
cardinality. Please add at least one ordered-result assertion that validates 
the actual rows, not just the count.



-- 
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]

Reply via email to