← Back to Pull requests

[fix](ivm) Fall back to complete refresh on negative aggregate counts #70804

Closed
unknown closed this pull request without merging on Nov 23, 2026 04:30 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 08:34 UTC
Author

Background

An incremental aggregate materialized view applies signed changes from its base tables to the counts it already stores. Runtime guards reject a merge that would make a count negative. A refresh request that allows fallback can rebuild the view when the stored state cannot be used to apply the change.

What problem does this PR solve?

Issue Number: None
Related PR: #62606 (introduced the aggregate guards), #69772 (uses the same recovery path for expired stream offsets)
PR Type: Bugfix

Problem Summary:

An incremental refresh that calculates a negative count fails even when the request allows fallback. This can be reproduced by moving facts to an already populated group through an excluded dimension, then deleting more facts than the view has recorded for that group. The refresh now rebuilds the view and its stream baselines when the request allows fallback.

Details

  • Frequency: Reproduced with SQL when the delete delta for a group exceeds the count stored by the view. Production frequency is unknown.

  • Root cause: The aggregate assertions returned ordinary query errors that IVM's execution failure classifier did not recognize. The incremental attempt propagated the error and the refresh task never reached the fallback path.

  • Why existing tests missed it: IvmIncrRefreshManagerTest covers other recognized executor errors. test_ivm_minmax_runtime_fallback reaches the fallback path through a MIN/MAX boundary guard and does not make an aggregate count negative.

  • Fix: Tag the shared non-negative count assertion and classify it as NEGATIVE_AGGREGATE_COUNT. Use the existing direct-to-COMPLETE route to recompute view state and reset the stream baselines together.

  • Other paths and branches: The shared guard covers the group count, hidden non-null counts, and COUNT(expr) in both deployment modes. The Apache Doris 3.1, 4.0, 4.1, and 4.2 release branches checked do not contain this classifier.

  • Behavior change: INCREMENTAL FALLBACK and AUTO try COMPLETE after this guard trips. Strict INCREMENTAL reports NEGATIVE_AGGREGATE_COUNT and includes the assertion detail.
  • Testing

  • Reproduced negative group count with an unset fallback reason on a local cluster running the unfixed FE. A second refresh with INCREMENTAL FALLBACK failed on the same assertion.
  • ./build.sh --fe completed with zero FE Core Checkstyle violations.

  • test_ivm_negative_aggregate_count_fallback passed on the local shared-nothing cluster. Strict incremental failed with the classified reason and preserved the rows. Both fallback-enabled modes finished as COMPLETE, followed by a successful incremental refresh.
  • All 129 suites under mtmv_p0/ivm passed on the local shared-nothing cluster.

  • All 548 selected FE IVM and materialized view unit tests passed.
  • Release note

    Incremental aggregate materialized view refreshes that allow fallback now attempt a complete refresh if applying a change would make a count negative.

    Check List (For Author)

  • Behavior changed: Yes (see Details)

  • Does this need documentation: No

  • Pre-submission status: Ready
  • Diff: 393 lines (+294 / -99) across 4 files Reviewer: morrySnow Review duration: 4076m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 393 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%
    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.358
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #70804"
    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: 43.1% (MEDIUM) · Higher = larger blast radius
    43.1%
    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: 17% · Safe to merge
    17%
    Repository