morrySnow opened a new pull request, #67700: URL: https://github.com/apache/doris/pull/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. ## Tests `./run-fe-ut.sh --run org.apache.doris.nereids.rules.exploration.mv.MaterializedViewUtilsTest` - 37 tests run - 0 failures - 0 errors - FE reactor build succeeded -- 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]
