Repository navigation
[feat](seq mapping) uniq table supports multi-stream merging through sequence mapping - #54936
Conversation
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
049b532 to
cfe00a4
Compare
|
run buildall |
cfe00a4 to
a264265
Compare
|
run buildall |
Cloud UT Coverage ReportIncrement line coverage Increment coverage report
|
TPC-H: Total hot run time: 34750 ms |
TPC-DS: Total hot run time: 185399 ms |
ClickBench: Total hot run time: 32.47 s |
a264265 to
637b19e
Compare
637b19e to
9b45113
Compare
|
run buildall |
Cloud UT Coverage ReportIncrement line coverage Increment coverage report
|
TPC-H: Total hot run time: 34821 ms |
TPC-DS: Total hot run time: 189967 ms |
ClickBench: Total hot run time: 29.65 s |
5df34d4 to
1882828
Compare
|
run buildall |
1 similar comment
|
run buildall |
Cloud UT Coverage ReportIncrement line coverage Increment coverage report
|
|
run feut |
|
run beut |
22a3449 to
76dda6b
Compare
|
run buildall |
Cloud UT Coverage ReportIncrement line coverage Increment coverage report
|
FE UT Coverage ReportIncrement line coverage |
TPC-H: Total hot run time: 36621 ms |
TPC-DS: Total hot run time: 180351 ms |
ClickBench: Total hot run time: 27.34 s |
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
|
run vault_p0 |
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
## Versions - [ x ] dev - [ ] 3.0 - [ ] 2.1 - [ ] 2.0 ## Languages - [ x ] Chinese - [ x ] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built apache/doris#54936 Co-authored-by: zhangshixin.1024 <zhangshixin.1024@bytedance.com>
|
@dataroaring @bobhan1 @gavinchou Do we have a plan to apply this feature to mow table? |
### What problem does this PR solve? Issue Number: N/A Related PR: apache#35432, apache#54936 Problem Summary: One load that flushes several memtables writes a rowset whose segments overlap on keys, so the same key can sit in two segments of one rowset. Reading such a rowset merges its segments in BetaRowsetReader (VMergeIterator) before VCollectIterator merges the rowsets, and three bugs on that path return wrong rows for merge-on-read tables, in queries and in horizontal compaction. 1. The older row of a key wins (merge-on-read UNIQUE_KEYS, REPLACE columns of AGG_KEYS). The segment merge orders the rows of one key and one sequence value by the data_id of their iterators, so that the segment flushed later supplies the newer row. Since apache#35432 the merge reads LazyInitSegmentIterators, which did not override data_id() and all answered 0, so the tie fell to the heap order and a read could keep the row of the older segment. Vertical compaction orders by iterator position and kept the newer row, so the result of a query also changed after compaction. LazyInitSegmentIterator now answers the id of its segment, the same value SegmentIterator::data_id() reports. 2. A key group cut by a Block boundary is returned twice (AGG_KEYS, and sequence-map tables). The VCollectIterator::Level0Iterator of the lowest-version rowset reads it Block by Block together with the same-key bits of its segment merge, and took the bit of the next row before refresh_current_row() had moved to the next Block, so the first row of every Block lost its bit and BlockReader started a new key group there. The bit is now taken after the refresh. 3. A sequence-map table loses column groups (apache#54936). Such a table needs every row of a key, because BlockReader takes each column group from the row with that group's largest sequence value; VCollectIterator therefore does not skip same-key rows of it, but TabletReader still asked the segment merge to keep only the newest row of a key (is_unique). A column group whose largest sequence value was in another segment lost its values. The segment merge now keeps every row of a sequence-map table. Reproduction (regression test test_overlapping_segments_merge): with the MemTable.need_flush debug point and batch_size = 20, load numbers 0..39 as k = number % 20 into an AGG_KEYS table, a merge-on-read UNIQUE_KEYS table and a sequence-map table, so that keys 0..19 sit in both of two overlapping segments and the second segment holds the newer rows; then read with batch_size = 3. - Before: the AGG_KEYS table returned 7 of the 20 keys twice and its REPLACE column took the older value, the UNIQUE_KEYS table returned the older value of every key, and the sequence-map table returned the older row's v2 group for every key. After a full compaction the AGG_KEYS and UNIQUE_KEYS tables (vertical compaction) were right, while the sequence-map table (horizontal compaction) kept the wrong values. - After: every key comes back once with the newer values, and every column group of the sequence-map table with its largest-sequence values, before and after the full compaction. ### Release note Fix wrong query results and compaction output of merge-on-read UNIQUE KEY tables (including tables with sequence mapping) and AGGREGATE KEY tables when one load wrote the same key into several segments of one rowset. ### Check List (For Author) - Test: Regression test / Unit Test - New BE UT block_reader_overlapping_segments_test.cpp: all 4 tests fail before the fix and pass after it. Also ran BlockReader*, VCollect*, *Changelog*, VerticalBlockReaderTest*, VerticalCompactionTest*, VerticalMergeIteratorTest*, OrderedDataCompactionTest*, SegCompactionTest*, TestRowIdConversion*, BetaRowsetTest*, *SchemaChange*, CumulativeCompaction*, EstimateCollectedEnough* and CollectedEnough*: 254 tests pass. be/test/exprs/function/function_string_test.cpp was left out of the local UT build because it does not compile on master (FunctionContext::FRAGMENT_LOCAL, from apache#69223). - New regression test fault_injection_p0/test_overlapping_segments_merge: run on a build without the fix it returned the wrong rows above; with the fix it passes. - Behavior changed: Yes. Reads of such rowsets return the newer row of a key, fold every key group once, and keep every column group of a sequence-map table. Rowsets that an older version already compacted keep what they were written with. - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
### What problem does this PR solve? Issue Number: N/A Related PR: apache#35432, apache#54936 Problem Summary: One load that flushes several memtables writes a rowset whose segments overlap on keys, so the same key can sit in two segments of one rowset. Reading such a rowset merges its segments in BetaRowsetReader (VMergeIterator) before VCollectIterator merges the rowsets, and three bugs on that path return wrong rows for merge-on-read tables, in queries and in horizontal compaction. 1. The older row of a key wins (merge-on-read UNIQUE_KEYS, REPLACE columns of AGG_KEYS). The segment merge orders the rows of one key and one sequence value by the data_id of their iterators, so that the segment flushed later supplies the newer row. Since apache#35432 the merge reads LazyInitSegmentIterators, which did not override data_id() and all answered 0, so the tie fell to the heap order and a read could keep the row of the older segment. Vertical compaction orders by iterator position and kept the newer row, so the result of a query also changed after compaction. LazyInitSegmentIterator now answers the id of its segment, the same value SegmentIterator::data_id() reports. 2. A key group cut by a Block boundary is returned twice (AGG_KEYS, and sequence-map tables). The VCollectIterator::Level0Iterator of the lowest-version rowset reads it Block by Block together with the same-key bits of its segment merge, and took the bit of the next row before refresh_current_row() had moved to the next Block, so the first row of every Block lost its bit and BlockReader started a new key group there. The bit is now taken after the refresh. 3. A sequence-map table loses column groups (apache#54936). Such a table needs every row of a key, because BlockReader takes each column group from the row with that group's largest sequence value; VCollectIterator therefore does not skip same-key rows of it, but TabletReader still asked the segment merge to keep only the newest row of a key (is_unique). A column group whose largest sequence value was in another segment lost its values. The segment merge now keeps every row of a sequence-map table. Reproduction (regression test test_overlapping_segments_merge): with the MemTable.need_flush debug point and batch_size = 20, load numbers 0..39 as k = number % 20 into an AGG_KEYS table, a merge-on-read UNIQUE_KEYS table and a sequence-map table, so that keys 0..19 sit in both of two overlapping segments and the second segment holds the newer rows; then read with batch_size = 3. - Before: the AGG_KEYS table returned 7 of the 20 keys twice and its REPLACE column took the older value, the UNIQUE_KEYS table returned the older value of every key, and the sequence-map table returned the older row's v2 group for every key. After a full compaction the AGG_KEYS and UNIQUE_KEYS tables (vertical compaction) were right, while the sequence-map table (horizontal compaction) kept the wrong values. - After: every key comes back once with the newer values, and every column group of the sequence-map table with its largest-sequence values, before and after the full compaction. ### Release note Fix wrong query results and compaction output of merge-on-read UNIQUE KEY tables (including tables with sequence mapping) and AGGREGATE KEY tables when one load wrote the same key into several segments of one rowset. ### Check List (For Author) - Test: Regression test / Unit Test - New BE UT block_reader_overlapping_segments_test.cpp: all 4 tests fail before the fix and pass after it. Also ran BlockReader*, VCollect*, *Changelog*, VerticalBlockReaderTest*, VerticalCompactionTest*, VerticalMergeIteratorTest*, OrderedDataCompactionTest*, SegCompactionTest*, TestRowIdConversion*, BetaRowsetTest*, *SchemaChange*, CumulativeCompaction*, EstimateCollectedEnough* and CollectedEnough*: 254 tests pass. be/test/exprs/function/function_string_test.cpp was left out of the local UT build because it does not compile on master (FunctionContext::FRAGMENT_LOCAL, from apache#69223). - New regression test fault_injection_p0/test_overlapping_segments_merge: run on a build without the fix it returned the wrong rows above; with the fix it passes. - Behavior changed: Yes. Reads of such rowsets return the newer row of a key, fold every key group once, and keep every column group of a sequence-map table. Rowsets that an older version already compacted keep what they were written with. - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…release notes (#4678) `sequence_mapping` (apache/doris#54936) was merged only into `master` and is not included in `branch-4.1` or `branch-4.2`. Remove the `4.x` `multi-stream-update-for-unique-model` pages, sidebar entry, inbound links in `update-overview`, and the `4.1.0` release note entry across locales while keeping the `dev` documentation intact. ## Versions - [ ] dev - [x] 4.x - [ ] 3.x - [ ] 2.1 or older (not covered by version/language sync gate) ## Languages - [x] Chinese - [x] English ## Docs Checklist - [x] Checked by AI - [ ] Test Cases Built (documentation removal; no new SQL examples) - [x] Updated required version and language counterparts, or explained why not - [x] If only one language changed, confirmed whether source/translation counterparts need sync ## Versions - [ ] dev - [ ] 4.x - [ ] 3.x - [ ] 2.1 or older (not covered by version/language sync gate) ## Languages - [ ] Chinese - [ ] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built - [ ] Updated required version and language counterparts, or explained why not - [ ] If only one language changed, confirmed whether source/translation counterparts need sync
…69797) ### What problem does this PR solve? When one load flushes several memtables, its rowset has segments that overlap on keys, and the rowset reader merges them. Four bugs on that merge returned wrong rows; horizontal compaction reads through the same merge, so bugs 1 to 3 also wrote wrong rows into the compacted rowset. ```sql -- curl -X POST http://<be_host>:<be_webserver_port>/api/debug_point/add/MemTable.need_flush SET parallel_pipeline_task_num = 1; SET batch_size = 8192; CREATE TABLE mor_unique (k INT, v INT) UNIQUE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1 PROPERTIES ("replication_num" = "1", "disable_auto_compaction" = "true", "enable_unique_key_merge_on_write" = "false"); CREATE TABLE agg_sum (k INT, s BIGINT SUM) AGGREGATE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1 PROPERTIES ("replication_num" = "1", "disable_auto_compaction" = "true"); CREATE TABLE seq_map (k INT, v1 INT, s1 BIGINT, v2 INT, s2 BIGINT) UNIQUE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1 PROPERTIES ("replication_num" = "1", "disable_auto_compaction" = "true", "enable_unique_key_merge_on_write" = "false", "light_schema_change" = "true", "sequence_mapping.s1" = "v1", "sequence_mapping.s2" = "v2"); CREATE TABLE mow_topn (k1 INT, k2 INT, v INT) UNIQUE KEY(k1, k2) DISTRIBUTED BY HASH(k1) BUCKETS 1 PROPERTIES ("replication_num" = "1", "disable_auto_compaction" = "true", "enable_unique_key_merge_on_write" = "true"); -- older write: v = k; newer write: v = 100 + k INSERT INTO mor_unique SELECT number % 4, number % 4 + if(number < 8192, 0, 100) FROM numbers("number" = "16384"); -- each write folds into s = 2048 per key, so every key sums to 4096 INSERT INTO agg_sum SELECT number % 4, 1 FROM numbers("number" = "16384"); -- older write: v1 = v2 = k, s1 = 2, s2 = 1; newer write: v1 = v2 = 100 + k, s1 = 1, s2 = 2 INSERT INTO seq_map SELECT number % 4, number % 4 + if(number < 8192, 0, 100), if(number < 8192, 2, 1), number % 4 + if(number < 8192, 0, 100), if(number < 8192, 1, 2) FROM numbers("number" = "16384"); -- older write: k2 = k1; newer write: k2 = k1 + 8192, so every k1 is in two keys INSERT INTO mow_topn SELECT number % 8192, number, number FROM numbers("number" = "16384"); ``` Results before the fix are from master `31a036fbcda`, after it from this PR. **1. A merge-on-read UNIQUE KEY table returns the older value (REPLACE columns of AGGREGATE KEY too):** the segment merge picks the newer row by `data_id()`, which `LazyInitSegmentIterator` (used for merges since #46570) answered with 0. ```sql SELECT k, v FROM mor_unique ORDER BY k; -- before: (0, 0) (1, 1) (2, 2) (3, 3) -- after: (0, 100) (1, 101) (2, 102) (3, 103) ``` **2. An AGGREGATE KEY table returns a key twice when a Block boundary cuts its rows (sequence-mapping tables too):** `Level0Iterator` took the same-key flag before loading the next Block, so the first row of every Block lost it. ```sql -- the segment merge yields k = 0 0 1 1 2 2 3 3; Blocks of 3 rows cut key 1 SELECT /*+ SET_VAR(batch_size = 3) */ k, s FROM agg_sum ORDER BY k; -- before: (0, 4096) (1, 2048) (1, 2048) (2, 4096) (3, 4096) -- after: (0, 4096) (1, 4096) (2, 4096) (3, 4096) ``` **3. A sequence-mapping table loses a column group:** the segment merge kept one row per key, while each column group must come from the row with the largest value of its own sequence column (#54936 handled only the merge across rowsets). ```sql -- v1 must come from the older write (s1 = 2), v2 from the newer one (s2 = 2) SELECT k, v1, s1, v2, s2 FROM seq_map ORDER BY k; -- before: (0, 0, 2, 0, 1) (1, 1, 2, 1, 1) (2, 2, 2, 2, 1) (3, 3, 2, 3, 1) -- after: (0, 0, 2, 100, 2) (1, 1, 2, 101, 2) (2, 2, 2, 102, 2) (3, 3, 2, 103, 2) ``` **4. `ORDER BY <key prefix> LIMIT n` on a merge-on-write UNIQUE KEY table misses rows:** the storage TopN merges segments by the ORDER BY columns, on which different keys compare equal, but still dropped "same key" rows as older versions (#15663). ```sql SELECT * FROM (SELECT k1, k2 FROM mow_topn ORDER BY k1 LIMIT 4) t ORDER BY k1, k2; -- before: (0, 0) (1, 1) (2, 2) (3, 3) -- after: (0, 0) (0, 8192) (1, 1) (1, 8193) ``` Fixes: (1) `LazyInitSegmentIterator::data_id()` answers its segment id; (2) `Level0Iterator::next()` takes the same-key flag after `refresh_current_row()`; (3) `TabletReader` keeps every row of a key for a sequence-mapping table, and `BlockReader` merges the column groups; (4) `BetaRowsetReader` drops older rows only when it merges by the whole key (a merge-on-write table's delete bitmap already filters them). Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
In some business scenarios, business operations need to update different columns in the same wide table through two or more data streams. For example, one data stream will write in real time to update some fields of this table; another data stream will perform imports on demand to update other columns of this table. During the update process, both data stream jobs need to ensure the order of replacement; and during queries, data from all columns should be queryable.
documentation: apache/doris-website#2954