← Back to Pull requests

[opt](ivm) Reduce snapshot checks for outer join NULL repair #70561

Closed
unknown closed this pull request without merging on Nov 19, 2026 06:44 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 08:29 UTC
Author

Background

During incremental refresh, a change to B in A LEFT JOIN B can change a joined row and can also retract or insert the NULL-extended A row. The same repair is needed in the opposite direction for RIGHT and FULL joins. FULL joins additionally preserve unmatched rows from the delta itself.

What problem does this PR solve?

Issue Number: None
Related PR: #70630 (sign-aware sequence for repair rows)
PR Type: Performance

Outer join refresh builds separate pre- and post-snapshot existence checks for NULL repair. If a retained A row has at most one matching B row in either snapshot, its repair sign is exactly the negative change in its match count. This PR computes that change from the signed delta and also shares key-based repair events between LEFT, RIGHT and FULL equijoins.

Details

Each row describes one contribution from the changing input B. A is the opposite-side snapshot. The LEFT/RIGHT column covers changes from the null-producing side. When the preserved input changes, that contribution uses the original directional outer join directly. For FULL, apply the column once for each changing input.

| ON condition and B uniqueness | LEFT/RIGHT, B changes | FULL, B changes | B pre/post snapshots for repair |
| --- | --- | --- | --- |
| Pure deterministic ordinary equalities. All B equality keys support value-preserving grouping, and B's direct equality slots cover a unique key of the original relation. | A INNER JOIN events. Events are B detail plus signed key repairs. | A RIGHT OUTER JOIN B_delta for detail, including unmatched B rows, plus A INNER JOIN signed_key_repairs. | Neither |
| Pure deterministic ordinary equalities. All B equality keys support value-preserving grouping, and B's uniqueness is unproven, for example with a partial composite key or an expression key. | A INNER JOIN events. Events are B detail plus pre/post key ANTI JOIN repairs. | A RIGHT OUTER JOIN B_delta for detail plus A INNER JOIN to the union of the pre/post key repairs. | Both |
| Deterministic equality plus a residual predicate. B's direct equality slots cover a unique key, A is repeatable, and A's ON inputs support value-preserving grouping. | A INNER JOIN B_delta for detail plus signed repair grouped by A's ON inputs. | A RIGHT OUTER JOIN B_delta for detail plus the same repair grouped by A's ON inputs. | Neither |
| All remaining cases. Examples include a FLOAT or DOUBLE B equality key, an unproven B key with a residual predicate, and a retained-side producer or input type that cannot be used for tuple repair. | A INNER JOIN B_delta for detail plus the two pre/post SEMI JOIN / ANTI JOIN repairs. | A RIGHT OUTER JOIN B_delta for detail plus the same two pre/post repairs. | Both |

Both pure-equality event paths group B keys before probing A. GROUP BY can merge +0.0 and -0.0 while a hash join distinguishes them. An update between signed zeros can cancel distinct repair events or make the grouped event probe the wrong rows. Keys that do not support value-preserving grouping use the original per-row SEMI/ANTI snapshot repair and still refresh incrementally.

Pure equijoin, LEFT/RIGHT, unique B with eligible equality keys. The key aggregate replaces two repair inputs below the same probe. Ordinary same-key payload updates still flow through detail.

 INNER JOIN (complete join key)
 |-- A_post snapshot
 `-- UNION ALL
     |-- delta_B detail events
-    |-- PROJECT (NULL payload, factor = -1)
-    |   `-- LEFT ANTI JOIN
-    |       |-- FILTER (has_positive)
-    |       |   `-- AGGREGATE (key, MAX positive/negative flags)
-    |       |       `-- delta_B
-    |       `-- B_pre snapshot
-    `-- PROJECT (NULL payload, factor = +1)
-        `-- LEFT ANTI JOIN
-            |-- FILTER (has_negative)
-            |   `-- AGGREGATE (key, MAX positive/negative flags)
-            |       `-- delta_B
-            `-- B_post snapshot
+    `-- PROJECT (NULL payload, factor = -net_count)
+        `-- FILTER (net_count <> 0)
+            `-- AGGREGATE (key, SUM(dml_factor) AS net_count)
+                `-- FILTER (join keys IS NOT NULL)
+                    `-- delta_B

Pure equijoin, FULL, B delta with eligible equality keys. The detail branch emits even a B row with no A match. Only repair events probe A by key.

 UNION ALL
 |-- A_snapshot RIGHT OUTER JOIN B_delta
-|-- (A_snapshot SEMI JOIN B_inserts) ANTI JOIN B_pre
-`-- (A_snapshot SEMI JOIN B_deletes) ANTI JOIN B_post
+`-- A_snapshot INNER JOIN repair_events ON key
+    unique B:    FILTER net <> 0 -> AGG BY key, SUM(B_delta.factor)
+    unproven B:  UNION ALL
+                 |-- affected insert keys ANTI JOIN B_pre
+                 `-- affected delete keys ANTI JOIN B_post

Additional ON predicate, unique B. For example, given A.k = B.k AND A.threshold < B.amount, a same-key update can change the match for only some A rows. Evaluate the entire predicate before counting. Retained rows with the same values for every A slot in ON have identical matches. For n such rows, the signed sum is n times the match change, so its sign determines one unit repair per original row. Look up the retained bag with NULL-safe comparisons on the complete tuple. This also works for nullable, colliding or independently generated row IDs. The tuple path accepts booleans, integral and decimal values, character strings, dates/timestamps, IPs and UUIDs. Other input types use snapshot repair. The same fallback applies when a retained subtree produces nondeterministic values, including an otherwise deterministic-looking ON slot backed by a UUID alias.

 UNION ALL
 |-- detail (INNER for LEFT/RIGHT null-side delta; directional OUTER for FULL)
-|-- (A_snapshot SEMI JOIN B_inserts ON full predicate) ANTI JOIN B_pre
-`-- (A_snapshot SEMI JOIN B_deletes ON full predicate) ANTI JOIN B_post
+`-- PROJECT A payload, NULL B payload, factor = -sign(net)
+    `-- A_snapshot INNER JOIN changed_tuples ON each A predicate input <=> its group key
+        `-- FILTER net <> 0
+            `-- AGG BY A.k, A.threshold, SUM(B_delta.factor) AS net
+                `-- A_snapshot INNER JOIN B_delta ON full predicate

Results and cost. For a unique B that qualifies for signed repair, both repair snapshot reads disappear. In FULL equijoins with eligible equality keys, the opposite-side snapshot occurs twice instead of three times. The residual path evaluates the match join for repair as well as detail and looks up the retained rows for each changed tuple. These are logical plan differences. Runtime will depend on the changed rows, selectivity and snapshot sizes. No elapsed-time benchmark was run.

Testing

  • Join-handler unit tests check both FULL delta directions, unique and nonunique keys, residual evaluation below the predicate-tuple aggregate, signed unit factors for duplicate retained tuples, type eligibility, absence of repair ANTI joins, and scan identities. The shared repair sign is covered for BIGINT and LARGEINT sequences.

  • The unique-key regression compares signed bag multiplicities with full recomputation at eight refresh stages. It includes same-key updates across different thresholds, duplicate retained keys, NULL keys, nullable row identities, NULL residual inputs, duplicate predicate tuples, unmatched detail, and simultaneous changes on both sides. EXPLAIN checks verify all three residual join orientations select signed repair.

  • Added four signed-zero join cases covering LEFT, RIGHT, and FULL, FLOAT and DOUBLE, and both proven and unproven B uniqueness. Three update batches test both sign changes, insertion, last-match deletion, and changes on both inputs. All 12 result comparisons with fresh queries matched, and EXPLAIN verified the expected SEMI/ANTI repair branches. The baseline returned differing rows in both grouped equality paths.

  • The targeted regression passed in Cloud mode with the updated FE. All 128 IVM suites passed in a local non-Cloud run.

  • 193 FE unit tests passed across IvmJoinDeltaHandlerTest (34), IvmDeltaRewriterTest (23), CreateMTMVCommandTest (99), and DataTypeTest (37). The FE build and Checkstyle passed.
  • Reproduced and rechecked three residual repair cases in local SQL: a nullable retained row-id (the stale NULL row disappears), forced full-key row-id collisions (an unrelated row survives), and an aggregate over an excluded DUP table with generated row-ids (the count stays at 2).
  • Verified the opted-in volatile alias case with a real residual join on LENGTH(A.tag) where the retained project computes UUID() AS tag. The snapshot repair removes the old NULL rows.
  • Release note

    Incremental outer join refresh can use fewer snapshot reads when repairing NULL-extended rows.

    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: 8534m
    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 #70561"
    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