morningman opened a new issue, #70277: URL: https://github.com/apache/doris/issues/70277
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Version master @ 72e91896bbdd8760f8bd4e488e5672406b40ce52 (2026-11-03). The code paths below are unchanged on master as of 2026-11-05. ### What's Wrong? For a Unique Key Merge-on-Write base table, `<stream>@snapshot()` rebuilds the image at the consumption offset for partitions that changed after the offset. The rebuild combines two parts ([NormalizeOlapTableStreamScan.java#L318-L345](https://github.com/apache/doris/blob/72e91896bbdd8760f8bd4e488e5672406b40ce52/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NormalizeOlapTableStreamScan.java#L318-L345)): 1. **Base table part:** rows whose commit TSO is not newer than the partition offset. 2. **Changelog part:** a `MIN_DELTA` changelog scan from the offset, filtered to `DELETE` and `UPDATE_BEFORE` rows, which adds back the before image of rows changed after the offset ([#L160-L166](https://github.com/apache/doris/blob/72e91896bbdd8760f8bd4e488e5672406b40ce52/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NormalizeOlapTableStreamScan.java#L160-L166), [#L222-L229](https://github.com/apache/doris/blob/72e91896bbdd8760f8bd4e488e5672406b40ce52/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/NormalizeOlapTableStreamScan.java#L222-L229)). `MIN_DELTA` drops a key's change group entirely when the first before image equals the last after image (the no-op elimination added in #66849). In the `UPDATE_BEFORE_AFTER` case, `_min_delta_values_equal()` returns true and nothing is emitted for the key ([block_reader.cpp#L318-L323](https://github.com/apache/doris/blob/72e91896bbdd8760f8bd4e488e5672406b40ce52/be/src/storage/iterator/block_reader.cpp#L318-L323), [#L133-L167](https://github.com/apache/doris/blob/72e91896bbdd8760f8bd4e488e5672406b40ce52/be/src/storage/iterator/block_reader.cpp#L133-L167)). So when a key is rewritten with identical values after the offset (an upsert of the same row, or a DELETE followed by an INSERT of the same values): - the base table part filters the row out, because its commit TSO is now newer than the offset; - the changelog part emits nothing for the key, because `MIN_DELTA` treats the change as a no-op. The key is then missing from `@snapshot()`, although it existed at the offset and still exists. IVM may be affected as well. The join delta handler reads the other side's pre-refresh image through the same snapshot path (`IvmJoinDeltaHandler` → `IvmDeltaRewriteHelper.preSnapshot()` → `withSnapshot(...)`; [IvmJoinDeltaHandler.java#L123-L149](https://github.com/apache/doris/blob/72e91896bbdd8760f8bd4e488e5672406b40ce52/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmJoinDeltaHandler.java#L123-L149), [IvmDeltaRewriteHelper.java#L425-L448](https://github.com/apache/doris/blob/72e91896bbdd8760f8bd4e488e5672406b40ce52/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmDeltaRewriteHelper.java#L425-L448)), so a join MV refresh could miss matches for such keys. ### What You Expected? `@snapshot()` returns every row that was visible at the consumption offset. The no-op elimination is correct for consumers of net changes, but the snapshot rebuild needs the `UPDATE_BEFORE` of such a group, or must read the changelog without the elimination. ### How to Reproduce? ```sql -- fe.conf: enable_feature_changelog = true, enable_table_stream = true CREATE TABLE t (k INT, v VARCHAR(10)) UNIQUE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1 PROPERTIES ( "replication_num" = "1", "enable_unique_key_merge_on_write" = "true", "changelog.enable" = "true", "changelog.need_historical_value" = "true" ); INSERT INTO t VALUES (1, 'a'), (2, 'b'); CREATE STREAM s ON TABLE t PROPERTIES ("type" = "min_delta", "show_initial_rows" = "false"); -- identical rewrite after the offset INSERT INTO t VALUES (1, 'a'); SELECT * FROM s@snapshot() ORDER BY k; -- expected: (1, 'a'), (2, 'b') -- suspected: (2, 'b') only ``` `DELETE FROM t WHERE k = 1; INSERT INTO t VALUES (1, 'a');` between the stream creation and the snapshot read should hit the same path. ### Anything Else? Found by code reading while documenting the changelog and Table Stream features; the reproduction above has not been run yet. Regression cases for identical rewrites and for delete-then-reinsert of the same values, under both `@snapshot()` and a join IVM refresh, would cover this. ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
