Skip to content

[spark] Skip redundant INSERT anti-join in Data Evolution MERGE - #11526

Open
JustinBinber wants to merge 2 commits into
apache:masterfrom
JustinBinber:codex/native-de-merge-skip-insert-antijoin
Open

JustinBinber wants to merge 2 commits into
apache:masterfrom
JustinBinber:codex/native-de-merge-skip-insert-antijoin

Conversation

@JustinBinber

Copy link
Copy Markdown
Contributor

Purpose

Fixes #11525.

The wide-table replacement work in #11174 compared an atomic delete-and-append procedure with a native MERGE using delete markers. Both publish deletions and inserted rows together in one Paimon snapshot. This PR improves the existing SQL path.

For delete-only MERGE with one INSERT action, the command checks whether a required ON conjunct and the INSERT predicate compare the same resolved source attribute to distinct non-NULL literals. For example, rows satisfying s.op = 'I' cannot satisfy an ON predicate that requires s.op = 'D'. The INSERT path filters that source directly and keeps the existing assignment and write preparation. Unsupported and overlapping predicates retain the current plan. The matched DELETE path, conflict validation, and single snapshot publication use existing logic.

Tests

  • The regression reproduced the INSERT LeftAnti on the baseline. The candidate removes it, preserves duplicate incoming rows and the unaffected RowIDs, and publishes one snapshot.
  • An overlapping INSERT condition still filters out matched source rows. An injected append preparation failure leaves the original snapshot and rows visible.
  • Eight focused tests passed on Spark 3.5.9, including the existing join reuse suite. The three new cases also passed on the separate Spark 4.0.5 implementation. Scoped Spotless checks passed.

Local benchmark

Spark 3.5.9 with AQE, Java 8, WSL Linux local[2], 128 columns and 100,000 target rows in 512 files. The fixed input replaces 5,000 rows and appends 1,250 new rows. Three runs per arm in rotating order used fresh target clones and fresh JVMs. The two native arms ran identical SQL on the same integration classpath with only the MERGE command changed. The procedure from #11174 is a reference.

Execution Three runs (s) Median full SQL (s) Target Parquet bytes returned (MB) Spark task CPU (s)
Native delete-marker MERGE 19.87, 19.77, 19.61 19.77 120.10 10.58
Native MERGE with this change 18.24, 18.85, 18.45 18.45 80.06 9.30
Atomic CALL replace_by_keys 15.14, 14.60, 15.89 15.14 40.02 6.55

The native fast path removed the INSERT anti join in all three runs. It lowered median full SQL time by 6.7%, target FileIO bytes returned by 33.3%, and Spark task CPU by 12.1% on this single-host workload. All nine runs passed full-row and RowID checks, published one snapshot, and wrote 148.14 MB in three new data files.

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] Skip the redundant INSERT anti-join in Data Evolution MERGE

1 participant