Skip to content

[spark] Extend disjoint INSERT optimization in Data Evolution MERGE - #11565

Open
JustinBinber wants to merge 1 commit into
apache:masterfrom
JustinBinber:codex/generalize-de-merge-insert-antijoin
Open

JustinBinber wants to merge 1 commit into
apache:masterfrom
JustinBinber:codex/generalize-de-merge-insert-antijoin

Conversation

@JustinBinber

Copy link
Copy Markdown
Contributor

Purpose

Fixes #11564.

This extends #11526, which used predicate disjointness for the native delete-marker alternative discussed in #11174. For each conditional INSERT action, prove that its analyzed source attribute equals a different non-null literal from a required ON conjunct. If every INSERT action passes, filter the source with the OR of these conditions and let MergeRows retain first-applicable action semantics.

The INSERT proof is independent of matched UPDATE, matched DELETE and the separate NOT MATCHED BY SOURCE work. Shared join reuse remains the first choice when present. Overlapping or unproven conditions use the existing anti-join. The target split relation is evaluated on demand, which also avoids eager target-side pruning in the insert-only case. The existing single-snapshot commit publishes all prepared changes.

Tests

  • The baseline still used an INSERT LeftAnti for marked UPDATE with multiple disjoint INSERT actions and for insert-only MERGE. Each now skips it.
  • Tests cover shared join reuse, persisted sources, NULL operation markers, same-key INSERT rows, overlapping clauses and action ordering, NOT MATCHED BY SOURCE DELETE, RowIDs, one-snapshot publication and the existing append failure regression.
  • Spark 3.5.9: 14 focused tests passed. Spark 4.0.5: 9 focused tests passed. Scoped Spotless checks passed.

Local benchmark

Spark 3.5.9, WSL Linux local[2] and AQE. A 128-column, 100,000-row target in 512 files received 5,000 flagged one-column UPDATEs and 1,250 flagged INSERTs. Each arm used the same SQL and integration classpath, with the native MERGE command as the only code difference. We rotated the order across three pairs, using a fresh JVM and target clone for each run.

Variant Runs (s) Median full SQL (s) Target Parquet bytes returned (MB) Spark task CPU (s)
Baseline 22.99, 21.41, 18.52 21.41 138.96 12.06
Optimized 18.16, 19.80, 16.78 18.16 98.92 10.50

The optimized plan removed INSERT LeftAnti in all three runs. All six runs passed full-row and RowID validation and published one snapshot. Shuffle write was 25.49 MB in each run. These are single-host results for the marked workload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Extend disjoint INSERT optimization across Data Evolution MERGE actions

1 participant