Skip to content

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

Open
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-67700-branch-4.1
Open

branch-4.1: [fix](mv) Prevent snapshot reads from using current MVs #67700#67729
github-actions[bot] wants to merge 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants