Skip to content

feat(multi_update): optional __mo_cpkey_col consistency assertion to diagnose duplicate PK (#24975)#24994

Open
ck89119 wants to merge 2 commits into
matrixorigin:mainfrom
ck89119:issue-24975-main
Open

feat(multi_update): optional __mo_cpkey_col consistency assertion to diagnose duplicate PK (#24975)#24994
ck89119 wants to merge 2 commits into
matrixorigin:mainfrom
ck89119:issue-24975-main

Conversation

@ck89119

@ck89119 ck89119 commented Jun 15, 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:

related to issue #24975 (diagnostic only — this PR does not fix the root cause)

What this PR does / why we need it:

#24975 reports rows on a composite-PK table whose hidden __mo_cpkey_col
does not match their own primary-key columns (serial(pk) != __mo_cpkey_col),
which lets a duplicate primary key slip past dedup. The seed is rare
(~15 rows / 3.77M), runtime, and not reproducible by fault injection, so we
cannot locate it by static analysis or after-the-fact scans.

This PR adds an optional, default-off consistency check in the main-table
insert path (check_null_and_insert_main_table). For composite-PK tables it
recomputes serial(pk cols) for each row about to be written and compares it
to the __mo_cpkey_col value being inserted. On mismatch it reports the
recomputed vs stored key, so the corruption is caught at the moment a
misaligned row is written
(with the statement/stack context), turning an
unreproducible ghost into a concrete, locatable event.

Controlled by env MO_DEBUG_CPKEY_ASSERT:

  • unset / anything else (default): off — no per-row overhead
  • log: log an error on mismatch, keep running (safe for canary/long-run)
  • panic: log + panic on mismatch (dumps the stack to locate the producer)

Notes:

🤖 Generated with Claude Code

…diagnose duplicate PK (matrixorigin#24975)

Add an optional, default-off runtime check in the main-table insert path
(check_null_and_insert_main_table). For composite-PK tables it recomputes
serial(pk cols) per written row and compares against the __mo_cpkey_col
being inserted; on mismatch (a row whose stored composite key does not
match its own primary-key columns) it logs or panics, controlled by env
MO_DEBUG_CPKEY_ASSERT:

  - unset / anything else (default): off, no per-row overhead
  - "log":   log an error on mismatch, keep running
  - "panic": log + panic on mismatch (dumps stack to locate the cause)

This is a diagnostic to catch the genesis of the duplicate-primary-key
corruption reported in matrixorigin#24975 at the moment a misaligned row is written.
It does not change execution behavior when disabled and is not a fix for
the root cause.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ck89119 ck89119 requested a review from ouyuanning as a code owner June 15, 2026 13:59
@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 →

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

Labels

kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants