← Back to Pull requests

[fix](mtmv) Check MV partition coverage when union compensation is disabled #71138

Closed
unknown closed this pull request without merging on Nov 30, 2026 23:12 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 03:06 UTC
Author

Background

An asynchronous materialized view (MV) tracks freshness by partition. The optimizer can use fresh MV partitions and, when UNION ALL compensation is enabled, read missing partitions from the base table.

What problem does this PR solve?

Issue Number: None
Related PR: #49514 (introduced the partition-check gate)
PR Type: Bugfix

Problem Summary:

With enable_materialized_view_union_rewrite=false, the optimizer could rewrite a query to scan a stale partition of a partially fresh MV. The rewrite now checks partition coverage before using the MV. A query covered by fresh partitions can still use the MV, and a query that needs data from a stale partition falls back to the base table when compensation is disabled.

In the regression fixture, the MV contains 1 and 10. The base table receives an additional 11 in its second partition after the MV refresh.

SELECT SUM(k) FROM partition_freshness_base;

| Before the fix | With the fix |
|---|---|
| 11 from the MV | 22 from the base table |

Details

  • Frequency: Reproducible when UNION compensation is disabled and the optimizer selects a partially fresh MV for a query spanning a stale partition.

  • Root cause: AbstractMaterializedViewRule used the UNION switch to gate invalid-partition calculation. With the switch off, it could admit an MV scan with incomplete coverage.

  • Why existing tests missed it: PartitionCompensatorTest and PartitionCompensatorBatchTest cover partition calculation. The grace_period and partition_curd_union_rewrite suites cover freshness and compensation with the switch enabled.

  • Fix: Calculate partition coverage for eligible MV candidates and check the switch when the query needs base-table partitions. The same calculation can remove unused or stale MV partitions when the query is fully covered by the fresh ones.

  • Other paths and branches: The shared rule serves both pre-rewrite and CBO. The same gate is present in branch-3.1, branch-4.0, branch-4.1, and branch-4.2 by source inspection.

  • Behavior change: EXPLAIN can report that a candidate was rejected because it requires compensation and UNION compensation is disabled.
  • Testing

  • partition_freshness_without_union failed the base-table plan assertion on the unmodified master baseline and passed with the fix. With UNION compensation disabled, the fresh-only query scanned one MV partition and returned 1. The stale-only and full-table queries scanned the base table and returned 21 and 22.

  • Seven suites passed locally across the MV availability and union_rewrite directories in shared-nothing mode. The Hive-dependent suite was excluded.
  • Release note

    With UNION compensation disabled, queries that need a stale asynchronous MV partition now read current data from the base table. Queries covered by fresh MV partitions remain eligible for MV rewrite.

    Check List (For Author)

  • Behavior changed: Yes (see Details)

  • Does this need documentation: No

  • Pre-submission status: Ready
  • Diff: 381 lines (+285 / -96) across 4 files Reviewer: morrySnow Review duration: 1206m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 381 lines diff across 4 files
    0.43
    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.356
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #71138"
    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: 43.0% (MEDIUM) · Higher = larger blast radius
    43.0%
    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: 18.6% · Safe to merge
    18.6%
    Repository