yujun777 opened a new pull request, #69851: URL: https://github.com/apache/doris/pull/69851
### What problem does this PR solve? `EXPLAIN REFRESH MATERIALIZED VIEW mv COMPLETE` for an IVM materialized view did not show the plan the refresh actually runs. The explain path installed `IvmRewriteContext.fullExplain`, which carried neither a reset partition scope nor a stream read mode, so `hasFullRefreshStreamScans()` was false and `IvmFullRefreshMTMV` never rewrote the base-table scans. The statement therefore printed the normalized MV query over ordinary base-table scans, while a real COMPLETE refresh reads every base table it does not partition by through an IVM table stream in RESET mode (the first batch of a whole-MV refresh). That rewrite reshapes the plan, so the explained plan and the executed plan differed in exactly the part EXPLAIN is used to debug. Problem Summary: - Root cause: `IvmRewriteContext.fullExplain` passed an empty reset partition map and an empty non-PCT read mode, so the full-refresh stream rewrite rule was gated off during EXPLAIN. - Fix: the explain context now carries `StreamReadMode.RESET`, the mode the first batch of a whole-MV COMPLETE refresh reads with (`MTMVTask#executePartitionBasedRefresh`). An explained complete refresh therefore plans the same stream scans the refresh reads. - `IvmFullRefreshMTMV` now keeps a base table's own scan when an EXPLAIN finds no usable IVM stream. Only a real COMPLETE refresh reconciles (creates) a missing stream before it plans; EXPLAIN must not create one, and the read it is planning for that table is the base table's own scan either way. Notes: - A refresh split into batches continues with SNAPSHOT for the later batches, which a single EXPLAIN statement cannot represent; the javadoc on `fullExplain` says so. - Base tables the MV is partitioned by (PCT) still keep their ordinary scans in EXPLAIN: their reset scope is the set of base partitions mapped from the refreshed MV partitions, which the explain path does not resolve. Unchanged by this PR. - No execution state is touched. EXPLAIN never builds an insert transaction, so no stream offset advances; the only added work at plan time is reading stream metadata. Trace issue: https://github.com/apache/doris/issues/65418 ### Release note None ### Check List (For Author) - Test - [ ] Regression test - [x] Unit Test — `IvmFullRefreshMTMVTest` (2 new cases: the explain context reads the base table with RESET; a missing stream keeps the plain scan), `ExplainRefreshMTMVCommandTest`, and `org.apache.doris.mtmv.ivm.*Test` plus `CreateMTMVCommandTest` (488 tests, all pass) - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - Behavior changed: - [ ] No. - [x] Yes. `EXPLAIN REFRESH MATERIALIZED VIEW mv COMPLETE` on an IVM MV now shows the stream-scan plan instead of plain base scans; nothing is executed and no stream offset moves. - Does this need documentation? - [x] No. - [ ] Yes. <!-- Add document PR link here. eg: https://github.com/apache/doris-website/pull/1214 --> -- 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]
