Skip to content

fix(plan): dedup update from source matches#24932

Open
ck89119 wants to merge 4 commits into
matrixorigin:4.0-devfrom
ck89119:issue-23137
Open

fix(plan): dedup update from source matches#24932
ck89119 wants to merge 4 commits into
matrixorigin:4.0-devfrom
ck89119:issue-23137

Conversation

@ck89119

@ck89119 ck89119 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #23137

What this PR does / why we need it:

This PR fixes the PostgreSQL-style UPDATE ... SET ... FROM ... WHERE ... path when duplicate source rows match the same target row on tables without FK constraints.

The new UPDATE path previously fed duplicate joined rows directly into the update pipeline, which could materialize duplicate primary-key rows for one target row. This change adds a planner-side dedup step for UPDATE ... FROM: group by the target row's original columns and use any_value() for updated columns, matching the existing fallback path behavior.

Test coverage includes:

  • A planner unit test that asserts the new UPDATE path produces AGG + any_value dedup.
  • A BVT case without FK constraints that verifies duplicate source matches still leave each target primary key with exactly one row.

Tested with:

  • git diff --check
  • go test ./pkg/sql/plan -run TestUpdatePgStyleFromDedupsDuplicateSourceMatchesOnNewPath -count=1
  • go test ./pkg/sql/plan -count=1
  • mo-tester update_pg_style_from.sql (108/108 passed)
  • make
  • make static-check (0 issues)

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/XXL Denotes a PR that changes 2000+ lines labels Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants