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


##########
regression-test/suites/fault_injection_p0/test_topn_pruned_struct_overlapping_segments.groovy:
##########
@@ -0,0 +1,195 @@
+// 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.
+
+// Regression case for the pruned-struct read misalignment on the inline topn 
scan path.
+//
+// Root cause: when a topn ordered read (order by key limit N) hits a rowset 
with
+// multiple OVERLAPPING segments, BetaRowsetReader picks VMergeIterator, whose
+// VMergeIteratorContext::init() eagerly loads the first block of every 
segment.
+// That block is created from the storage Schema (FULL struct type, all 
children),
+// while the struct sub-column iterators have been filtered down to the pruned
+// subset by set_access_paths()/remove_pruned_sub_iterators(). The pairing 
loop in
+// StructFileColumnIterator::next_batch() indexes _sub_column_iterators[i] by 
the
+// dst tuple position, so the two ordinal spaces disagree:
+//   - text/dict child data decoded into a TINYINT child column
+//       -> [E-3110] insert_many_dict_data is not supported for TINYINT
+//   - same-typed children shift silently, and the loop runs past the pruned
+//     iterator vector -> out-of-bounds -> BE SIGSEGV
+//
+// The FE TopN lazy materialization (VMaterializeNode) usually shields this 
path
+// on master; setting topn_lazy_materialization_threshold=-1 (or any state 
where
+// the rule bails, e.g. light_schema_change=false tables) exposes it.
+//
+// Layout construction: MemTable.need_flush debug point forces one segment per
+// inserted block (batch_size=500, 2000 rows -> 4 segments, below the
+// segcompaction_batch_size=10 threshold so segcompaction never merges them), 
and
+// the NULL k1 rows in every block make every segment's key lower bound NULL, 
so
+// the segments overlap and the rowset is marked OVERLAPPING.
+suite("test_topn_pruned_struct_overlapping_segments", "nonConcurrent") {
+    def dictTable = "test_topn_pruned_struct_ovlp_dict"
+    def intTable = "test_topn_pruned_struct_ovlp_int"
+    def aggTable = "test_topn_pruned_struct_ovlp_agg"
+
+    sql "DROP TABLE IF EXISTS ${dictTable}"
+    sql "DROP TABLE IF EXISTS ${intTable}"
+    sql "DROP TABLE IF EXISTS ${aggTable}"
+    sql """
+        CREATE TABLE ${dictTable} (
+            k1 BIGINT,
+            c ARRAY<ARRAY<STRUCT<col1:INT, col2:TINYINT, col17:TEXT>>>
+        ) DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES('replication_num' = '1')
+    """
+    sql """
+        CREATE TABLE ${intTable} (
+            k1 BIGINT,
+            c ARRAY<ARRAY<STRUCT<col1:INT, col2:INT, col3:INT>>>
+        ) DUPLICATE KEY(k1)
+        DISTRIBUTED BY HASH(k1) BUCKETS 1
+        PROPERTIES('replication_num' = '1')
+    """
+
+    try {
+        GetDebugPoint().enableDebugPointForAllBEs("MemTable.need_flush")
+        // 4 blocks of 500 rows -> 4 segments per tablet; k1 NULL every 20 
rows so
+        // every segment starts at NULL -> overlapping key ranges -> 
OVERLAPPING rowset.
+        sql "SET batch_size = 500"
+        sql """
+            INSERT INTO ${dictTable}
+            SELECT if(number % 20 = 0, NULL, number),
+                   array(array(named_struct(
+                       'col1', CAST(number AS INT),
+                       'col2', CAST(number % 127 AS TINYINT),
+                       'col17', concat('s', number))))
+            FROM numbers('number' = '2000')
+        """
+        sql """
+            INSERT INTO ${intTable}
+            SELECT if(number % 20 = 0, NULL, number),
+                   array(array(named_struct(
+                       'col1', CAST(number + 1000000 AS INT),
+                       'col2', CAST(number + 2000000 AS INT),
+                       'col3', CAST(number + 3000000 AS INT))))
+            FROM numbers('number' = '2000')
+        """
+    } finally {
+        GetDebugPoint().disableDebugPointForAllBEs("MemTable.need_flush")
+    }
+
+    // Self-check the storage layout: the test is void unless the rowset 
really is
+    // a multi-segment OVERLAPPING one (that is what selects VMergeIterator).
+    for (def tbl : [dictTable, intTable]) {
+        def tablets = sql_return_maparray("SHOW TABLETS FROM ${tbl}")
+        def (code, out, err) = curl("GET", tablets[0].MetaUrl)
+        assertEquals(0, code)
+        assertTrue(out.contains('"segments_overlap_pb": "OVERLAPPING"'),

Review Comment:
   This check still does not prove the test is exercising the merge-reader 
path. `BetaRowsetReader::is_merge_iterator()` requires more than the overlap 
flag: it also needs `_get_segment_num() > 1`, and 
`RowsetMeta::is_segments_overlapping()` makes the same segment-count 
distinction. Please parse the tablet meta and assert the visible rowset has 
`num_segments > 1` as well as the overlap flag before running these TopN 
checks; otherwise this regression can keep passing even if the forced flush 
stops producing the multi-segment rowset that selects `VMergeIterator`.



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