Repository navigation
Description
Why do you want to refactor this code?
INSERT ... ON DUPLICATE KEY UPDATE (ODKU) currently has two execution paths, mirroring the situation REPLACE INTO had before #23946 / #24044:
- Modern path (default):
bindInsert→appendDedupAndMultiUpdateNodesForBindInsert, built onDEDUP JOIN+MULTI_UPDATE. - Legacy path (fallback):
build.gocatchesErrUnsupportedDMLand falls back tobuildInsert→buildInsertOnDuplicateUpdatePlans, producing aNode_ON_DUPLICATE_KEYnode executed by the colexeconduplicatekeyoperator.
Maintaining two paths duplicates semantics, complicates correctness/perf work, and keeps the legacy onduplicatekey operator alive. We should eliminate the legacy ODKU path and unify everything onto the operator-based path, the same way REPLACE was unified.
The legacy path is still reached today for three scenarios the modern path rejects with ErrUnsupportedDML:
| Scenario | Trigger | Modern | Legacy |
|---|---|---|---|
| No explicit PK + has unique key (fake PK + UK) | bind_insert.go update on duplicate without primary key |
✗ | ✓ |
| Vector / irregular index table | bind_insert.go insert into vector/text index table / have vector index table |
✗ | ✓ |
| Foreign-key table (or referenced) | dml_context.go foreign key constraint in ResolveTables |
✗ | ✓ |
Two other fallback cases — updating a PK column and updating a UK column — are rejected by both paths, so removing the legacy path causes no functional loss for them (only error-message unification).
Describe the solution you'd like
Unify all ODKU scenarios onto the modern DEDUP JOIN + MULTI_UPDATE path, then delete the legacy Node_ON_DUPLICATE_KEY path. Reuse the techniques already proven in #24044:
- Fake PK + UK: introduce an
isFakePKbranch inappendDedupAndMultiUpdateNodesForBindInsert. With a unique key, dedup/conflict-detect on the first unique key instead of the PK; with no unique key, degrade to a plain INSERT. - Vector / irregular index tables: drop the hard rejections and reuse
getValidIndexesto skip irregular indexes (maintained asynchronously by cron), as REPLACE does. - FK tables: lift the
ResolveTablesrejection. Unlike REPLACE (which deletes the parent row and needs RESTRICT pre-checks), ODKU does not delete rows — its FK semantics are closer to INSERT + partial UPDATE, so the FK validation must be designed specifically (only when FK/referenced columns are actually updated). This is the largest unknown and may be split into a sub-task.
Then remove the legacy code:
- Drop the ODKU fallback branch in
build.go. - Remove the
Node_ON_DUPLICATE_KEYconstruction branch andbuildInsertOnDuplicateUpdatePlansinbuild_insert.go. - Remove the colexec
onduplicatekeyoperator and its compile/remote-run/explain references. - Mark
Node_ON_DUPLICATE_KEY/OnDuplicateKeyCtxasreservedin the proto. - Keep
ondup_update_binder.go(still used by the modern path).
Add BVT/UT coverage for fake PK + UK, vector index tables, FK tables, NULL on unique key, multi-column UK, and composite PK under ODKU.
Describe alternatives you've considered
- Keep both paths: rejected — it is the status quo and the source of the maintenance burden.
- Delete the legacy path without filling the gaps: rejected — it would regress fake-PK-with-UK, vector-index, and FK tables from working to erroring.
Additional information
- Reference: [Feature Request]: REPLACE INTO Optimization - Unify Legacy/Modern Paths and Improve Performance #23946 (REPLACE unify-paths feature) and feat: eliminate legacy REPLACE path, unify to operator-based execution #24044 (REPLACE legacy-path removal implementation), whose
bind_replace.goisFakePKhandling is the direct blueprint here. - Note: ODKU is part-column UPDATE, not full-row replace, so REPLACE's "NULL old columns" trick cannot be copied; the existing
updateExprsbinding,OnUpdatecolumns, and generated-column recompute logic must be preserved. - Note: perf(onduplicatekey): replace O(N²) linear scan with O(1) hash map #24069 optimized the legacy
onduplicatekeyoperator recently, so confirm the operator is only reachable via fallback before deletion.
Activity
fix(frontend): restore legacy insert path for tables with irregular i…
ck89119 commentedon Jun 18, 2026
Scope: this issue/PR also absorbs #25000 — REPLACE does not maintain vector/fulltext indexes
Folding the scope of #25000 into this work, since the same modern-DML index-maintenance rework is the right place to fix it.
Problem (from #25000):
REPLACEinto a table carrying an irregular index (ivfflat vector / fulltext) succeeds but does not maintain the index synchronously, so a row inserted — or whose vector/text is changed — viaREPLACEis not reflected in a subsequent index-backed ANN/KNN or fulltext search. Root cause is #24044, which removed the legacy REPLACE fallback and madebind_replacestrip the irregular index (validIndexes, _ := getValidIndexes(tableDef)) instead of maintaining it.Repro (from #25000):
Fix (this PR #24973): REPLACE now maintains IVF/fulltext indexes on the modern path — it deletes the conflicting old row's entries and inserts the new row's entries, keyed by the matched old row's PK (which can differ from the new PK when the conflict is on a non-PK unique key). Added BVT
replace_statement/replace_irregular_indexcovering PK conflict, unique-key conflict (old PK != new PK) and no-conflict insert, for both fulltext and IVF.The standalone fix PR #25016 is closed in favor of this one.
feat(insert): align ON DUPLICATE KEY UPDATE with MySQL, drop legacy o…