Skip to content

branch-4.1: [fix](mv) Prevent snapshot reads from using current MVs #67700 - #67729

Merged
yiguolei merged 1 commit into
branch-4.1from
auto-pick-67700-branch-4.1
Sep 9, 2026
Merged

branch-4.1: [fix](mv) Prevent snapshot reads from using current MVs #67700#67729
yiguolei merged 1 commit into
branch-4.1from
auto-pick-67700-branch-4.1

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Cherry-picked from #67700

## Problem

An external-table query that explicitly reads an older snapshot can
still enter materialized view rewrite. The candidate materialized view
represents the table state at its refresh snapshot, so using a current
materialized view for a historical query can silently return data from
the wrong point in time.

## Root cause

`LogicalFileScan` stores standard `FOR TIME AS OF` and `FOR VERSION AS
OF` clauses in `tableSnapshot`. The materialized-view eligibility
checker rejected scans with table samples or scan parameters, but did
not inspect `tableSnapshot`. As a result, the historical scan was
treated like an ordinary latest-snapshot scan.

## How to reproduce

1. Create an Iceberg table and insert an initial row, then record that
snapshot ID.
2. Insert newer data and refresh a materialized view over the table at
the current snapshot.
3. Enable materialized-view rewrite and query the Iceberg table with
`FOR VERSION AS OF <old_snapshot_id>` (the same issue applies to `FOR
TIME AS OF`).
4. Before this change, the historical query can be considered eligible
for rewrite by the current-snapshot materialized view, producing current
rather than historical results.

The same condition can be reproduced directly in the optimizer by
building a `LogicalFileScan` with a non-empty `tableSnapshot`: the
table-query-operator checker previously returned false.

## Fix

Treat a non-empty `LogicalFileScan.tableSnapshot` as a table-level query
operator, alongside table samples and scan parameters. This
conservatively prevents materialized-view rewrite until the optimizer
can prove that the query snapshot and materialized-view refresh snapshot
are semantically equivalent.

Add a unit test that constructs a file scan with a version snapshot and
verifies that the checker rejects it from ordinary rewrite eligibility.
@github-actions
github-actions Bot requested a review from yiguolei as a code owner September 9, 2026 09:43
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 0.00% (0/73) 🎉
Increment coverage report
Complete coverage report

@yiguolei
yiguolei merged commit eb203f8 into branch-4.1 Sep 9, 2026
40 of 42 checks passed
@github-actions

Copy link
Copy Markdown
Contributor Author

PR approved by anyone and no changes requested.

@github-actions

Copy link
Copy Markdown
Contributor Author

PR approved by at least one committer and no changes requested.

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Sep 10, 2026
yiguolei pushed a commit that referenced this pull request Sep 10, 2026
…67700 (#67729)

Cherry-picked from #67700

Co-authored-by: morrySnow <zhangwenxin@selectdb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants