feat(insert): align ON DUPLICATE KEY UPDATE with MySQL, drop legacy operator#24973
Open
ck89119 wants to merge 3 commits into
Open
feat(insert): align ON DUPLICATE KEY UPDATE with MySQL, drop legacy operator#24973ck89119 wants to merge 3 commits into
ck89119 wants to merge 3 commits into
Conversation
…perator Replace the legacy Node_ON_DUPLICATE_KEY operator with the modern DEDUP JOIN + MULTI_UPDATE path for INSERT ... ON DUPLICATE KEY UPDATE, and make real-PK tables align with MySQL: any unique-key conflict (PRIMARY or a secondary UNIQUE key) updates the first conflicting row, in PRIMARY > unique-key definition order, instead of raising a duplicate-entry error. - real-PK ODKU resolves a single UPDATE target up front via target_pk = coalesce(pk-existence-probe, uk1_pri, uk2_pri, ...), treating PRIMARY as the 0th index, and keys the main dedup-update join on target_pk. The per-unique-key FAIL dedup is kept as in-batch duplicate protection (two brand-new rows sharing a new unique-key value still error). - fake-PK tables (first unique key as anchor) and FK-table ODKU are handled on the modern path; FK parent existence is enforced via generated DetectSqls. - Tables carrying irregular (vector / fulltext) indexes use the modern path; the irregular index is stripped by getValidIndexes and maintained asynchronously. - Remove the now-dead Node_ON_DUPLICATE_KEY enum, the OnDuplicateKeyCtx and pipeline.OnDuplicateKey messages, and the OnDuplicateKey vm opcode. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
…table
Dropping the legacy ON DUPLICATE KEY operator broke ivfflat/hnsw/cagra/fulltext
index creation. Index maintenance upserts a version counter into the index
metadata table via INSERT ... ON DUPLICATE KEY UPDATE. That metadata table is a
plain real-PK key/value table, but it carries an algo-specific TableType
("metadata"/"hnsw_meta"/...) and a secondary-index name, so:
- the modern insert guard rejected it as "insert into vector/text index table",
and the ODKU could no longer fall back to the (now removed) legacy operator;
- canSkipDedup skipped the dedup-update join the ODKU needs to fetch the old row.
Fix on the modern path: allow an ODKU-update through the index-table guard, and
do not skip dedup when onDupAction is UPDATE. Plain index-maintenance inserts
(no ODKU) keep their existing behavior. The metadata table is a normal real-PK
table the modern dedup + multi-update path handles correctly.
Adds a plan unit test (ODKU into a metadata-typed index table builds a
MULTI_UPDATE) and a BVT covering ivfflat index creation plus user ODKU on the
indexed table.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24939
What this PR does / why we need it:
Replace the legacy
Node_ON_DUPLICATE_KEYoperator with the modernDEDUP JOIN+MULTI_UPDATEpath forINSERT ... ON DUPLICATE KEY UPDATE,and make real-PK tables align with MySQL.
Behavior change (real-PK, MySQL alignment)
Previously, on a table with a real primary key, only a primary-key conflict
triggered the update; any unique-key conflict raised a duplicate-entry error.
Now any unique-key conflict (PRIMARY or a secondary UNIQUE key) updates the
first conflicting row, in
PRIMARY > unique-key definition order— matchingMySQL.
Implementation: real-PK ODKU resolves a single UPDATE target up front via
target_pk = coalesce(pk-existence-probe, uk1_pri, uk2_pri, ...)(treatingPRIMARY as the 0th index) and keys the main dedup-update join on
target_pk.The conflicting row is updated in place (its primary key and non-
SETcolumnsare preserved). The per-unique-key
FAILdedup is kept as in-batch duplicateprotection: two brand-new rows that share a new unique-key value in the same
statement still error deterministically (documented gap vs MySQL's in-batch
sequential semantics).
Modern path coverage
on the modern path; FK parent existence is enforced via generated
DetectSqls.the irregular index is stripped by
getValidIndexesand maintainedasynchronously.
Cleanup
Remove the now-dead
Node_ON_DUPLICATE_KEYenum, theOnDuplicateKeyCtxandpipeline.OnDuplicateKeymessages, and theOnDuplicateKeyvm opcode(reserved in proto).
Tests
insert_duplicate,on_duplicate_key_edge(rewritten),on_duplicate_key_modern(real-PK multi-UK + in-batch protection +irregular-index cases); the whole
dml/insertsuite passes on themulti-CN cluster.
🤖 Generated with Claude Code