← Back to Pull requests

[fix](ivm) Initialize layout signatures on the first refresh #70785

Closed
unknown closed this pull request without merging on Nov 21, 2026 15:04 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 04:02 UTC
Author

Background

Unique-key IVM materialized views use a normalized plan signature to protect the row identity and aggregate state layout across refreshes. Incremental refresh checks the stored signature before it builds delta writes.

What problem does this PR solve?

Issue Number: None
Related PR: #62606 (introduced IVM layout signatures), #69890 (publishes the signature after a complete refresh)
PR Type: Bugfix

Problem Summary:

A newly created deferred IVM can fail its first incremental refresh because CREATE signed its SELECT plan and REFRESH signs an INSERT plan. This PR establishes the baseline from the first successful write and uses the analyzed table sink's column names and types in the signature.

SELECT u.channel, COUNT(*) AS row_count, SUM(u.amount) AS total_amount
FROM (
    SELECT channel, amount FROM sales      -- channel is VARCHAR(16)
    UNION ALL
    SELECT 'refund' AS channel, -amount FROM refunds
) u
GROUP BY u.channel

Details

  • Change map: 271 production lines cover signature input, refresh publication, and DRY RUN. 354 test lines update FE assertions and exercise the grouped UNION ALL, with 23 generated golden lines.

  • Frequency: Reproducible before the first COMPLETE when binding the refresh adds a write Project, including the grouped UNION ALL above.

  • Root cause: The union combines the VARCHAR(16) column and the VARCHAR(6) literal and produces STRING. CREATE applies its physical-schema rule for the first visible column and stores it as VARCHAR(65533), the maximum payload length with a two-byte storage prefix. That schema rule runs before IVM chooses the hidden row ID as the key. REFRESH binds an INSERT against the resulting schema. With automatic truncation enabled, BindSink inserts substring(channel, 1, 65533) in a Project above the grouped query, so signing the CREATE and REFRESH plans gives different results. NULL to TINYINT and ARRAY element length coercion can also add write-side projections.

  • Why existing tests missed it: The existing fallback test injects a mismatch after a COMPLETE has already established a table-sink signature. It does not exercise the first write of a deferred MV with a write-side type conversion.

  • Fix: Generate signatures from a normalized OLAP table sink and retain the Project topology, including passthrough Projects. Record the ordered bound target column names and types. A first successful incremental or partition write establishes the baseline. Whole-MV COMPLETE checks its batch signatures and can replace the baseline on success. CREATE and DRY RUN use a result sink and skip the signature. EXPLAIN REFRESH plans the table-sink path and leaves the stored signature untouched. The unique-key normalizer owns root validation and signature comparison. The update log records the matching normalized tree, canonical signature, and SHA-256. The task result handler consumes these diagnostics before the task enters history.

  • Other paths and branches: This applies to the MOW IVM model. Table-sink partition IDs and DML options vary by execution path and are outside the signature. The signature format version remains 1 because IVM has not been released. Comparing a subsequent partition-only rebuild against the stored signature is a follow-up.

  • Behavior change: A deferred IVM can run its first refresh with write-side type coercion and does not require a prior COMPLETE. DRY RUN can preview delta rows even when the execution plan would fail signature validation.
  • Testing

  • Built the FE with ./build.sh --fe, passed Checkstyle, and passed 100 focused FE tests on the final change with run-fe-ut.sh --run.

  • Ran the grouped UNION ALL regression, DRY RUN, append-only chaining, and signature mismatch fallback suites on the final build. Regenerated the ordered DRY RUN golden tag and reran the grouped UNION ALL suite.

  • Ran the original grouped SQL, a partitioned MV, and the NULL and ARRAY coercion cases against a local cluster. The initial write and COMPLETE produced the same signature in each case. The original MV returned the defining SELECT's rows after incremental and full refresh.
  • Verified that EXPLAIN REFRESH INCREMENTAL and EXPLAIN REFRESH COMPLETE create no task and do not publish a signature, before and after an actual COMPLETE.
  • Release note

    Fixed a false IVM layout signature mismatch during the first refresh of a newly created MOW materialized view with write-side type conversions.

    Check List (For Author)

  • Behavior changed: Yes (see Details)

  • Does this need documentation: No

  • Pre-submission status: Ready
  • Diff: 576 lines (+432 / -144) across 7 files Reviewer: morrySnow Review duration: 2102m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 576 lines diff across 7 files
    0.50
    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%
    56%
    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.380
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #70785"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 49.8% (MEDIUM) · Higher = larger blast radius
    49.8%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 21.6% · Safe to merge
    21.6%
    Repository