← Back to Pull requests

[improvement](ivm) Stabilize IVM layout signature via unique-key lineage and add ivm_plan_signature() #71241

Closed
unknown closed this pull request without merging on Dec 03, 2026 13:03 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 14:44 UTC
Author

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
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: morrySnow Review duration: 2779m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #71241"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository