yujun777 opened a new pull request, #71241:
URL: https://github.com/apache/doris/pull/71241

   ### Background
   
   Incremental View Maintenance (IVM) materialized views store a persisted 
layout signature (`IvmPlanSignature`) so that after an upgrade, an incremental 
refresh can detect when the physical unique-key or column layout produced by 
the normalized IVM plan no longer matches existing MV data and safely fall back 
to a complete refresh. Previously, `IvmPlanSignatureGenerator` serialized the 
entire normalized logical plan tree below `LogicalOlapTableSink`, and users 
could only inspect the persisted SHA-256 digest rather than the underlying 
canonical signature text.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: None
   PR Type: Enhancement
   
   Problem Summary:
   Serializing the full normalized logical plan makes the IVM layout signature 
overly sensitive to harmless planner refactors (adding/merging 
`LogicalProject`, `Filter`, `SubQueryAlias`, join reordering below `Aggregate`, 
or alias renames), causing unnecessary full refreshes after upgrades. This PR 
replaces full-plan serialization with a layout-focused canonical signature that 
pins the target sink schema and traces every Merge-on-Write `UNIQUE KEY` column 
back to its base scan columns, and adds an FE-only scalar function 
`ivm_plan_signature('[catalog.][db.]mv')` so users and tests can inspect the 
live canonical signature text directly. Existing IVM MVs that were created with 
the previous signature format will fall back to a one-time complete refresh on 
their next refresh and persist the new signature.
   
   ### Details
   
   - **Change map:** ~1,334 lines production code, ~1,014 lines tests (unit 
tests + regression suite and golden `.out`).
     - `IvmPlanSignatureGenerator.java` / `IvmPlanSignature.java` (~1,034 
lines): scoped demand-driven lineage tracing for all target `UNIQUE KEY` 
columns, sink schema + extra-output pinning, live-probed `ROW_ID_HASH_DEF`, 
structural CSE (`SHARED`), and explicit expression serialization.
     - `IvmPlanSignatureEvaluator.java` / `IvmPlanSignatureFunc.java` / 
`BuiltinScalarFunctions.java` / `ScalarFunctionVisitor.java` / 
`FoldConstantRuleOnFE.java` (~300 lines): FE-only constant-folded 
`ivm_plan_signature('[catalog.][db.]mv')` scalar function.
     - `IvmPlanSignatureGeneratorTest.java` / `IvmPlanSignatureFuncTest.java` / 
`IvmNormalizeUniqKeysMTMVTest.java` / 
`test_ivm_plan_signature_function.{groovy,out}` (~1,014 lines): unit and 
regression test coverage.
   - **Before and after:**
     - Before: `IvmPlanSignatureGenerator` serialized the whole logical plan 
tree, so intermediate projections, filters, subquery aliases, join order 
changes under `Aggregate`, and alias renames changed the signature. Only the 
SHA-256 hash was stored, with no SQL way to inspect the raw canonical signature 
text.
     - After: The signature encodes only what determines physical MV layout 
compatibility: `TABLE_SINK` ordered column names/types, `EXTRA_OUTPUTS` (if 
sink output exceeds target slots), live-probed `ROW_ID_HASH_DEF` (when 
`RowIdHash` is used, probed with both numeric and string placeholders), 
`SHARED` structural CSE definitions (when a non-leaf expression is referenced 
at least twice), and `UNIQUE_KEYS` lineage for every target-table key column 
(`__DORIS_IVM_ROW_ID_COL__`, visible keys, and `ivm_use_full_keys` hidden 
keys). `ivm_plan_signature('[catalog.][db.]mv')` computes and returns the live 
canonical signature string on FE without running a refresh, mutating metadata, 
or consuming stream offsets (returning `NULL` for append-only duplicate-key IVM 
MVs, and requiring `SHOW` privilege).
   - **Configs and defaults:** None.
   - **Impact on existing users:** Existing unique-key IVM MVs will experience 
a one-time `PLAN_SIGNATURE_MISMATCH` fallback to complete refresh upon upgrade, 
after which the new stable signature is persisted. No user configuration 
changes are required.
   
   ### Testing
   
   - FE unit tests (local):
     - `IvmPlanSignatureGeneratorTest` (17 tests): stability across 
intermediate `Project`/`Filter`/`SubQueryAlias`, join reordering below 
`Aggregate`, nested `UNION ALL` under `Aggregate`, lambda parameter 
alpha-renaming, partition-id changes; sensitivity to join type/order, `UNION 
ALL` branch order, `ivm_use_full_keys`, sink truncation/casts, `LogicalRepeat` 
grouping sets, `TABLE_SINK`/`EXTRA_OUTPUTS`, `Cast` vs `TryCast`; scalability 
on 30-table join and 25-level doubling DAG via structural CSE; self-referencing 
`ExprId` cycle safety.
     - `IvmPlanSignatureFuncTest` (6 tests): 1/2/3-part qualified name parsing 
with optional backticks, malformed name and non-internal catalog rejection, 
non-constant argument rejection, `NULL` propagation, FE constant folding to 
canonical text or `NULL`.
     - `IvmNormalizeUniqKeysMTMVTest` (64 tests): all existing IVM unique-key 
normalization tests pass.
   - FE checkstyle (local): `mvn -f fe/pom.xml -pl fe-core -am validate 
-DskipTests` passed with 0 violations.
   - Regression tests (local 1FE+1BE):
     - `mtmv_p0/ivm`: `test_ivm_plan_signature_function` (golden `.out` 
verifies live canonical signature strings for single-table, multi-table 
inner/left join, `UNION ALL`, aggregate, `ivm_use_full_keys`, append-only 
duplicate-key MV, qualified/backtick names, and error cases), 
`test_ivm_plan_signature_fallback`, `test_ivm_partition_signature_fallback`, 
`test_ivm_sink_truncation_signature` — 4/4 suites passed.
   
   ### Release note
   
   Stabilized IVM layout signature generation to depend only on target sink 
schema and unique-key column lineage, and added the 
`ivm_plan_signature('[catalog.][db.]mv')` scalar function to inspect the live 
canonical layout signature text of an IVM materialized view.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Ready
   


-- 
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]

Reply via email to