github-actions[bot] commented on code in PR #65396: URL: https://github.com/apache/doris/pull/65396#discussion_r3567770409
########## 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"'), + "expected an OVERLAPPING multi-segment rowset in ${tbl}, tablet meta: check MemTable.need_flush debug point") + } + + // AGG-table variant: the same ordinal-space mismatch also hits the aggregate + // merge path (BlockReader::_init_agg_state used to build the reader_replace + // argument type from the full TabletColumn while the stored block uses the + // pruned type). It needs no debug point, no topn and no special session vars: + // two ordinary inserts (two rowsets) + a pruned read used to fail with + // "Aggregate function reader_replace argument 0 type check failed". + sql """ + CREATE TABLE ${aggTable} ( + k1 BIGINT, + c ARRAY<ARRAY<STRUCT<col1:INT, col2:TINYINT, col17:TEXT>>> REPLACE + ) AGGREGATE KEY(k1) + DISTRIBUTED BY HASH(k1) BUCKETS 1 + PROPERTIES('replication_num' = '1') + """ + sql """ + INSERT INTO ${aggTable} + SELECT number, array(array(named_struct( + 'col1', CAST(number AS INT), + 'col2', CAST(number % 127 AS TINYINT), + 'col17', concat('s', number)))) + FROM numbers('number' = '1000') + """ + sql """ + INSERT INTO ${aggTable} + SELECT number + 1000, array(array(named_struct( + 'col1', CAST(number + 1000 AS INT), + 'col2', CAST(number % 127 AS TINYINT), + 'col17', concat('s', number + 1000)))) + FROM numbers('number' = '1000') + """ + + def expectedTwoCols = (1..10).collect { [String.valueOf(it), "s" + it] } + def expectedOneCol = (1..10).collect { ["s" + it] } + def expectedIntCol = (1..10).collect { [String.valueOf(3000000 + it)] } + + def assertRows = { List<List<Object>> actual, List<List<String>> expected, String tag -> + assertEquals(expected.size(), actual.size(), "row count mismatch for ${tag}") + for (int i = 0; i < expected.size(); i++) { + for (int j = 0; j < expected[i].size(); j++) { + assertEquals(expected[i][j], String.valueOf(actual[i][j]), + "value mismatch for ${tag} at row ${i} col ${j}") + } + } + } + + // 1. Default session: on master this plans VMaterializeNode (TopN lazy + // materialization + rowid fetch); guards that path stays correct too. + assertRows(sql(""" + SELECT element_at(c[1][1], 1), element_at(c[1][1], 'col17') + FROM ${dictTable} WHERE k1 IS NOT NULL ORDER BY k1 LIMIT 10 + """), expectedTwoCols, "dict table, default session") + + // AGG merge path, pure default session (no topn involved at all). + assertRows(sql(""" + SELECT element_at(c[1][1], 1), element_at(c[1][1], 'col17') + FROM ${aggTable} WHERE k1 >= 1 AND k1 <= 10 ORDER BY k1 + """), expectedTwoCols, "agg table, default session") + // Rows from the second rowset must merge and read correctly too. + assertRows(sql(""" + SELECT element_at(c[1][1], 'col17') + FROM ${aggTable} WHERE k1 >= 1501 AND k1 <= 1510 ORDER BY k1 + """), (1501..1510).collect { ["s" + it] }, "agg table second rowset, default session") + + // 2. Force the inline topn scan path (no VMaterializeNode). This is the exact + // path that used to fail with + // "[E-3110] Method insert_many_dict_data is not supported for TINYINT". + sql "SET topn_lazy_materialization_threshold = -1" Review Comment: This still does not fully force the repaired inline TopN/`VMergeIterator` path. The test disables TopN lazy materialization, but the storage ordered-key read is gated separately by `enable_segment_limit_pushdown`: `OlapScanner` only sets `read_orderby_key`/`read_orderby_key_limit` when that flag participates in `can_push_down_segment_limit`, and the variable is fuzzy/randomized in regression runs. If it is false, this DUP_KEYS scan keeps `need_ordered_result=false`, so `BetaRowsetReader::is_merge_iterator()` will not select `VMergeIterator` even if the rowset is overlapping and multi-segment, and these value checks can pass through the normal scan path. Please pin this section with `SET enable_segment_limit_pushdown = true` (or a `SET_VAR` hint) before the inline TopN assertions so the regression always exercises the path this fix targets. -- 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]
