-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](storage) align pruned complex column types with sub-column iterators on merge/agg read paths #65396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
csun5285
wants to merge
1
commit into
apache:master
Choose a base branch
from
csun5285:fix-topn-pruned-struct-merge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[fix](storage) align pruned complex column types with sub-column iterators on merge/agg read paths #65396
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
...ession-test/suites/fault_injection_p0/test_topn_pruned_struct_overlapping_segments.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
|
|
||
| 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, inline topn path") | ||
|
|
||
| // Single pruned child: the misalignment shifts col17 data onto col1 (INT), | ||
| // which used to fail with "... is not supported for INT". | ||
| assertRows(sql(""" | ||
| SELECT element_at(c[1][1], 'col17') | ||
| FROM ${dictTable} WHERE k1 IS NOT NULL ORDER BY k1 LIMIT 10 | ||
| """), expectedOneCol, "dict table single child, inline topn path") | ||
|
|
||
| // Same-typed children: the shifted decode does not error out, so the pairing | ||
| // loop used to run past the pruned iterator vector and SIGSEGV the BE; a | ||
| // partial regression could also return col1's values (1000001..) here. | ||
| assertRows(sql(""" | ||
| SELECT element_at(c[1][1], 'col3') | ||
| FROM ${intTable} WHERE k1 IS NOT NULL ORDER BY k1 LIMIT 10 | ||
| """), expectedIntCol, "int table last child, inline topn path") | ||
|
|
||
| sql "DROP TABLE IF EXISTS ${dictTable}" | ||
| sql "DROP TABLE IF EXISTS ${intTable}" | ||
| sql "DROP TABLE IF EXISTS ${aggTable}" | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.