Skip to content

Fix MERGE into replicated tables - #2272

Open
roseduan wants to merge 1 commit into
apache:mainfrom
roseduan:fix_merge_on_replicated_tables
Open

roseduan wants to merge 1 commit into
apache:mainfrom
roseduan:fix_merge_on_replicated_tables

Conversation

@roseduan

@roseduan roseduan commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

MERGE into a DISTRIBUTED REPLICATED table did not broadcast the source relation, so each segment merged only the source rows stored locally. The replicas diverged and the reported row count was wrong.

Treat MERGE like UPDATE/DELETE when flagging a replicated result relation (upd_del_replicated_table), so the join broadcasts the source to all segments.

Also reject volatile functions in MERGE actions on replicated tables. The existing check only looked at the subplan targetlist, but MERGE action expressions are kept in mergeActionLists, so e.g. "UPDATE SET v = random()" was accepted and the replicas diverged.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


@my-ship-it my-ship-it left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
It is an existing bug, which is introduced by PG 16 merge.

@roseduan
roseduan requested a balanced review from Copilot November 9, 2026 08:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@leborchuk leborchuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, clear bug, just should be fixed

MERGE into a DISTRIBUTED REPLICATED table did not broadcast the source
relation, so each segment merged only the source rows stored locally.
The replicas diverged and the reported row count was wrong.

Treat MERGE like UPDATE/DELETE when flagging a replicated result
relation (upd_del_replicated_table), so the join broadcasts the source
to all segments.

Also reject volatile functions in MERGE actions on replicated tables.
The existing check only looked at the subplan targetlist, but MERGE
action expressions are kept in mergeActionLists, so e.g.
"UPDATE SET v = random()" was accepted and the replicas diverged.
@tuhaihe
tuhaihe force-pushed the fix_merge_on_replicated_tables branch from 4041a81 to 295ab8d Compare November 10, 2026 04:14
@tuhaihe
tuhaihe enabled auto-merge (rebase) November 10, 2026 04:14
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.

4 participants