Repository navigation
feat(insert): align ON DUPLICATE KEY UPDATE with MySQL, drop legacy operator - #24973
Conversation
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? |
# Conflicts: # pkg/sql/plan/build_dml_util_test.go
XuPeng-SH
left a comment
There was a problem hiding this comment.
I found two substantive correctness issues in the current head.\n\n1. pkg/sql/plan/bind_insert.go:869-880 still resolves real-PK ODKU conflicts against the raw incoming column for every single-column unique index. That is wrong for prefix unique indexes like UNIQUE KEY u(col(4)): the hidden index table stores the truncated/materialized prefix key, so a conflict such as existing abcdxxxx vs incoming abcdyyyy will not resolve to the existing row here. The later unique-index dedup is prefix-aware, so the statement will still fail with duplicate-entry instead of doing the required UPDATE. The same file already materializes prefix-aware single-column unique keys at :1140-1163 for locking; target-PK resolution needs to use that materialized __mo_index_idx_col value as well, not the raw source column.\n\n2. pkg/sql/plan/bind_insert.go:227-235 routes every non-regular index into the new “irregular” maintenance path, which includes MASTER indexes. But the delete side in buildIrregularIndexDeleteMaintenance (:531-553) only handles FULLTEXT and IVF, while the insert side explicitly has a MASTER branch (:473-476). That means ON DUPLICATE KEY UPDATE / REPLACE can insert fresh MASTER-index entries for the new row image without ever deleting the stale old ones, leaving wrong search state behind. Please either add MASTER delete maintenance here or keep MASTER indexes out of getIrregularIndexes until the delete path is implemented.\n\nI would also add a targeted ODKU regression case for a single-column unique prefix index once the first bug is fixed.
…micity CI Review (XuPeng-SH): - Prefix unique-index ODKU: buildOnDupTargetPkResolution now resolves single-part unique conflicts with the prefix-aware key (makeIndexPartExpr), matching what the hidden index table stores, so e.g. UNIQUE KEY u(col(4)) correctly upserts 'abcdxxxx' vs 'abcdyyyy' instead of failing with duplicate-entry. Adds a targeted regression case. - MASTER/HNSW indexes: removed from getIrregularIndexes / the irregular insert maintenance (their delete side is unimplemented, so ODKU/REPLACE would leave stale entries). Such tables now defer plain INSERT/LOAD to the legacy planner, and reject ODKU/REPLACE with a clear unsupported error instead of corrupting. CI: - atomicity.result: the PR had regenerated the external-table SELECTs to 0 rows (its env could not resolve the resource CSV); restore the 4 CSV rows the file reads, matching CI, while keeping the modern ODKU error messages. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The duplicate-entry error reports the user column name under the pessimistic dedup-join (DedupColName) but the hidden index column __mo_index_idx_col under the optimistic index-table fuzzy filter (PkName), so no single key name passes both LAUNCH modes. Match the stable "Duplicate entry '<val>' for key" prefix with -- @regex instead of the key name, in fk_base and insert_duplicate. Co-Authored-By: Claude Opus 4.8 <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked the latest head. The earlier two blockers I raised are addressed, but I still see one remaining correctness issue in the new MASTER/HNSW gate, plus a few concrete follow-up suggestions.
Blocking issue
pkg/sql/plan/bind_insert.go:75-84 and pkg/sql/plan/bind_replace.go:47-50 now reject any table carrying a legacy-only irregular index (MASTER/HNSW) before the planner determines whether the statement can ever hit an existing row. That is too early.
For fake-PK tables with no usable primary/unique key, this PR already treats:
INSERT ... ON DUPLICATE KEY UPDATEas a plain INSERT / legacy-degenerate case (bind_insert.go:1040-1049)REPLACEas INSERT-like when there is no unique index (bind_replace.go:99-103)
In those cases there is no conflict-driven delete/update work at all, so there is no stale-entry problem to avoid. But the new early hasLegacyOnlyIrregularIndex() gate makes such statements fail up front anyway on tables with MASTER/HNSW indexes. A table like create table t(a int, b varchar(100), master index(b)); insert into t values (1,'x') on duplicate key update b='y'; should still be able to behave like INSERT here, not be rejected before key analysis.
Concrete implementation suggestions
-
Move the MASTER/HNSW rejection later, after key analysis.
- For ODKU, only reject once you know the statement can actually take the UPDATE path (real PK or a usable unique key exists).
- Keep the existing
isFakePK && firstUniqueIdxPos < 0fallback reachable for MASTER/HNSW tables.
-
Do the same for REPLACE.
- First compute whether any unique/PK conflict path exists.
- If not, keep the current
REPLACE behaves like INSERTpath reachable even on MASTER/HNSW tables.
-
Add targeted SQL/BVT coverage for the user-visible behavior.
I would add all of these while you are here:- ODKU on a MASTER/HNSW table without PK/UK -> behaves like INSERT
- REPLACE on a MASTER/HNSW table without PK/UK -> behaves like INSERT
- ODKU on a MASTER/HNSW table with a real conflict key -> explicit unsupported error
- REPLACE on a MASTER/HNSW table with a real conflict key -> explicit unsupported error
Non-blocking but worthwhile remaining coverage suggestions
LOAD DATA+ IVF/fulltext sync maintenance still deserves one end-to-end proof- FK ODKU update-branch should still get an invalid-parent unhappy-path case
Once the early gate is narrowed to the true conflict-driving cases, I am happy to re-check.
… modern MASTER indexes now have full synchronous modern maintenance (insert + delete), so INSERT / ON DUPLICATE KEY UPDATE / REPLACE maintain them on the modern dedup+MULTI_UPDATE path instead of being rejected or deferred to legacy: - isModernMaintainedIrregularAlgo / getIrregularIndexes now include MASTER. - Insert side reuses buildPreInsertMasterIndex from the modern source step. - Delete side: new buildIrregularMasterDeleteByPk joins on the master index table's independent __mo_index_pri_col (origin pk) == old/final pk — the same clean pk-join fulltext uses on doc_id, so no re-tokenization is needed. - Removed hasLegacyOnlyIrregularIndex / isFakePKWithoutUniqueKey and all the MASTER gates in bindInsert/bindReplace/bindLoad, the master/hnsw unsupported messages, legacyIrregularIndexCause/Msg, and the build.go fallback branch. HNSW/CAGRA/IVF-PQ are cron-maintained (idxcron, off the base-table CDC), so they ride the modern path with no inline sub-plan — they are no longer flagged as legacy-only. Also fixes a pre-existing bug in the REPLACE irregular-index delete on the merged-scan path (tables with no unique secondary key): the captured old-PK placeholder was not reliably materialized into the irregular-delete sink, so stale fulltext/IVF/master entries were left behind. Merged-scan only runs when there is no unique key, so every conflict is a PK conflict (old PK == new PK); key the irregular delete on the immutable new PK at its natural position. Tests: TestGetIrregularIndexes now keeps MASTER; dropped TestHasLegacyOnlyIrregularIndex. BVT: secondary_index_master gains INSERT/ODKU/ REPLACE coverage verifying the master index via prefix queries; replace_irregular_index gains a no-unique-key merged-scan REPLACE regression; new vector_hnsw_modern_dml exercises ODKU/REPLACE on an HNSW table. Co-Authored-By: Claude Opus 4.8 <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked this PR from a first-principles / unhappy-path angle. The overall direction is understandable, but I found two blocker regressions and one important scope mismatch.
-
INSERT IGNOREon FK child tables loses IGNORE semanticsbind_insert.goencodesINSERT IGNOREas the nil-sentinel shape (len(OnDuplicateUpdate)==1 && OnDuplicateUpdate[0]==nil) and classifies it asNode_IGNORE.- But
build.gostill keys only onlen(stmt.OnDuplicateUpdate) > 0, so it routesINSERT IGNOREthrough the ODKU FK path. - The modern FK path uses
assert(...)filters for child->parent existence checks, so a missing parent becomes a hard error instead of “skip this row”. - Existing behavior for
INSERT IGNOREon FK violations is to ignore the offending row, not fail the statement (seetest/distributed/cases/dml/insert/insert_ignore.sql/.result). - Suggestion: distinguish the nil IGNORE sentinel from real ODKU at planner entry. Either keep FK-table
INSERT IGNOREon the legacy path, or teach the modern FK path to drop/warn offending rows instead of asserting.
-
ODKU child-FK validation regressed from row-scoped to whole-table checks
- For real
INSERT ... ON DUPLICATE KEY UPDATE,build.gonow falls back to whole-tableDetectSqlsgenerated bygenSqlsForCheckFKConstraints(...). - Those SQLs scan the entire child table (
SELECT DISTINCT ... FROM child ... EXCEPT SELECT DISTINCT ... FROM parent), not just the statement’s final row image. - That means a one-row upsert can fail because of an unrelated orphan row already in the table (for example, one inserted earlier under
FOREIGN_KEY_CHECKS=0), and validation cost now scales with table size. - The comments in
build.goalready acknowledge this exact false-positive problem for plain INSERT; ODKU still takes the whole-table path. - Suggestion: reuse a row-scoped FK check for the ODKU final image, rather than generating whole-table DetectSqls.
- For real
-
Test coverage is missing the highest-risk unhappy paths
- I do not see a regression test for
INSERT IGNOREon an FK child table staying row-skip / non-failing under the new path. - I also do not see a test showing ODKU only validates the statement’s final row image rather than failing on unrelated pre-existing orphan rows.
- Suggestion: add both tests before merge; they directly protect the two regressions above.
- I do not see a regression test for
Given the semantic regression on INSERT IGNORE and the table-wide ODKU FK validation regression, I think this should be changes requested before merge.
…d tables Addresses two regressions in the modern insert path's child→parent foreign-key handling, both now enforced row-scoped and in-plan over the statement's own rows: - ON DUPLICATE KEY UPDATE used a whole-table DetectSql (genSqlsForCheckFKConstraints) that scanned the entire child table. A one-row upsert could fail on an unrelated orphan row (e.g. inserted earlier under FOREIGN_KEY_CHECKS=0) and its cost scaled with table size. ODKU now asserts parent existence over the materialized final merged image, the same row-scoped in-plan check plain INSERT already uses (modernInsertFkCheckEnabled + appendForeignConstrantPlan, deferred to finishIrregularIndexMaintenance). - INSERT IGNORE lost its row-skip semantics: routed through the ODKU FK path, a missing parent became a hard error instead of skipping the offending row. New buildInsertIgnoreFkFilter LEFT JOINs each referenced parent and FILTERs out rows whose foreign key has no parent (NULL FK satisfies MATCH SIMPLE and is kept), feeding only the surviving rows to the MULTI_UPDATE. It is built with binding tags so it survives the full optimizer, unlike the tagless assert sub-plan, and so can gate the inserted rows. build.go now emits only self-referencing FK DetectSqls for both plain INSERT and ODKU. The now-dead genSqlsForCheckFKConstraints, the childFkCheckPrefix constant, and the compile.go CHILD_FK_CHK: handling are removed. Tests: new TestInsertOnDupChildParentFKUsesInPlanCheck and TestInsertIgnoreChildParentFKDropsRows; TestInsertOnDupFKUsesModernPath / TestInsertOnDupSelfReferFKUsesModernPath updated (ODKU child→parent FK is now in-plan, so DetectSqls is empty). BVT on_duplicate_key_modern gains an ODKU case proving it ignores a pre-existing orphan and still fails on a real violation, and an INSERT IGNORE case proving missing-parent rows are skipped. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…key FK tables A plain INSERT (or INSERT IGNORE) into a foreign-key child table that also carries a unique key panicked with "unsafe slice cast: from length 16 ... 72" (e.g. join/fulljoin_constraints.sql:198). The modern path materialized the new-row image with appended index-helper columns (a unique key's serial) and set modernFkCheck, so finishIrregularIndexMaintenance ran the legacy appendForeignConstrantPlan over that image; its tagless child pass-through gets mis-typed by column pruning, crashing the FK hash join. - Add buildModernChildFkAssert: assert child->parent FK existence in the data flow with a binding-tagged parent LEFT JOIN + FILTER (mirrors buildInsertIgnoreFkFilter), robust to the appended index-helper columns. - Route plain INSERT (Node_FAIL) through it instead of the deferred modernFkCheck / appendForeignConstrantPlan path. - Guard "modernFkCheck = odkuNeedFkCheck" with onDupAction == UPDATE so plain INSERT and INSERT IGNORE (already enforced in-flow) no longer also run the panicking legacy assert. This also fixes the latent INSERT IGNORE crash on a unique-key FK child. - Drop the now-constant needFkCheck; relax TestInsertIgnoreChildParentFKDropsRows to accept the optimizer's LEFT->RIGHT join rewrite. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…iplication The in-flow plain-INSERT / INSERT IGNORE child-FK check used a LEFT join against the parent table. When the foreign key references a non-unique parent column (e.g. the leading prefix of a composite primary key, `FOREIGN KEY(f_a) REFERENCES f1(a)` where f1's PK is `(a, b)`), the LEFT join multiplied each child row by the number of matching parent rows, corrupting the inserted data (foreign_key/foreign_key.sql:255 and friends). Replace it with a MARK join (via insertMarkJoin), which emits exactly one output row per input row carrying a boolean "parent matched" marker, so existence is checked without multiplying rows. Factor the shared parent-existence build into appendModernChildFkMarkOks, returning a per-FK boolean used by: - buildModernChildFkAssert: assert(ok) per FK (plain INSERT, fail on missing parent); - buildInsertIgnoreFkFilter: keep rows where every FK ok (INSERT IGNORE row-skip). A NULL foreign-key value still satisfies the constraint (MATCH SIMPLE). Update TestInsertIgnoreChildParentFKDropsRows to accept the MARK join. Co-Authored-By: Claude Opus 4.8 <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked the current head.
The earlier blockers around prefix-unique target resolution and MASTER/HNSW gating look improved, but I still see two substantive correctness regressions in the latest version.
-
INSERT IGNOREon FK child tables still loses IGNORE semanticsbind_insert.goencodesINSERT IGNOREas the nil-sentinel shape (len(OnDuplicateUpdate)==1 && OnDuplicateUpdate[0]==nil) and classifies it asNode_IGNORE.- But
build.gostill keys only onlen(stmt.OnDuplicateUpdate) > 0, so it routesINSERT IGNOREthrough the ODKU FK path. - The modern FK path uses
assert(...)filters for child->parent existence checks, so a missing parent becomes a hard error instead of “skip this row”. - Existing behavior for
INSERT IGNOREon FK violations is to ignore the offending row, not fail the statement. - Suggestion: distinguish the nil IGNORE sentinel from real ODKU at planner entry. Either keep FK-table
INSERT IGNOREon the legacy path, or teach the modern FK path to drop/warn offending rows instead of asserting.
-
ODKU child-FK validation still regressed from row-scoped to whole-table checks
- For real
INSERT ... ON DUPLICATE KEY UPDATE,build.gostill falls back to whole-tableDetectSqlsgenerated bygenSqlsForCheckFKConstraints(...). - Those SQLs scan the entire child table (
SELECT DISTINCT ... FROM child ... EXCEPT SELECT DISTINCT ... FROM parent), not just the statement’s final row image. - That means a one-row upsert can fail because of an unrelated orphan row already in the table (for example, one inserted earlier under
FOREIGN_KEY_CHECKS=0), and validation cost scales with table size. - Suggestion: reuse a row-scoped FK check for the ODKU final image instead of generating whole-table DetectSqls.
- For real
Additional coverage I still want
- a regression for
INSERT IGNOREon an FK child table staying row-skip / non-failing under the new path - a regression proving ODKU validates only the statement’s final row image, not unrelated pre-existing orphan rows
So on the current head, I still think this should remain changes requested.
|
@XuPeng-SH Thanks for the re-check. Both blocking points were already addressed on the current head (commit 1.
2. ODKU child→parent FK is row-scoped, not whole-table
3. Regression coverage already present
Plan-level UTs also assert the in-plan behavior: Could you re-load the latest head and re-check? Happy to add more coverage if anything still looks off. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-checked the latest head. The broader MASTER/HNSW gating concerns look improved, but the composite nullable-unique-key issue is still present.
In the current REPLACE path, skipUniqueIdx only stays true when every part of a unique index is statically NULL. That is still too narrow. For a composite UNIQUE(a,b), a row like (NULL, 1, ...) cannot conflict with any existing row, because the composite unique key serializes to NULL as soon as any input part is NULL. But the current fake-PK REPLACE privilege gate still treats that table as delete-capable and requires DELETE.
So the remaining blocker is unchanged:
- fake-PK + composite nullable unique key
- one component statically NULL
- REPLACE is still insert-only semantically
- frontend still over-requires DELETE
I would keep this at request changes until that composite-null case is handled and covered by a unit/BVT regression.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-checked the latest head. I still think this should stay at request changes, and this time I’m collecting the remaining blockers together.
-
Composite nullable unique-key REPLACE still over-requires DELETE.
The current static-null shortcut only skips a unique index when every part is NULL. For a compositeUNIQUE(a,b), a row like(NULL, 1, ...)still cannot conflict, because the composite unique key serializes to NULL as soon as any input part is NULL. But the fake-PK REPLACE privilege gate still treats that table as delete-capable and requiresDELETE. -
REPLACE on child FK tables still has no parent-existence check.
The modern REPLACE path now allows FK tables, but the build path only wires self-referencing FK checks. I do not see a REPLACE-side equivalent of the child→parent existence validation that plain INSERT / INSERT IGNORE now perform in-flow. So REPLACE can still insert orphan child rows. -
ODKU FK checking still skips other FKs when one FK column is NULL.
ODKU still routes child→parent FK checking throughappendForeignConstrantPlan, whose helper first builds one globalisnotnull(...)filter across all FK columns. If one nullable FK column is NULL, the entire row is filtered out of the check step, so other non-NULL FKs on that same row are never validated.
Concrete suggestions
- For (1), treat a composite unique index as insert-only when any nullable part is statically NULL, and add a unit/BVT case for that path.
- For (2), run a child→parent FK existence check for REPLACE’s final inserted image, analogous to the modern INSERT path.
- For (3), move ODKU child→parent FK checking onto the same per-FK MARK/null-aware logic you now use for INSERT / INSERT IGNORE, instead of one global NULL prefilter.
A fake-PK REPLACE whose composite unique key serializes to NULL (any part statically NULL) can never conflict and is never stored in the unique index table -- the same rule the INSERT path applies. But the REPLACE path computed skipUniqueIdx as "every part NULL" and never consumed it, so it still probed and maintained the index for such a row, inserting a NULL-key entry that INSERT skips. INSERT and REPLACE were therefore inconsistent for NULL composite keys. - Compute skipUniqueIdx as "any part statically NULL", for unique indexes only (serial(...) is NULL as soon as one part is NULL); non-unique indexes use serial_full (NULL preserved) and are never skipped. - Consume skipUniqueIdx in the unique-conflict probe, the old-RowID fetch and the index MULTI_UPDATE, so a NULL-key unique index is neither probed nor maintained -- matching bind_insert's NULL-key skip. The main-table LEFT JOIN is kept; its NULL join condition never matches, so no existing row is deleted and the new row is inserted. The plan also drops the now-unneeded index-table scans and DEDUP join for the skipped key. Tests: TestReplaceFakePKCompositeNullableUKSkipsNullKeyIndex (+ mock table fake_pk_comp) asserts the NULL-key unique index is not maintained while a fully non-NULL key still is; BVT replace.test covers no mis-delete, multiple NULL keys coexisting, and a real conflict replacing. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@XuPeng-SH Thanks. I've handled the composite-null case in Fixed: a NULL composite unique key is now consistent between INSERT and REPLACE You're right that
Coverage: unit test Two deliberate deviations — would like your read
Let me know your thoughts on (1) and (2). |
XuPeng-SH
left a comment
There was a problem hiding this comment.
I re-checked the latest head from the FK / unhappy-path angle. The legacy ODKU operator removal is moving in the right direction, but I still see two correctness blockers before I can approve.
Blocker 1: REPLACE on a non-self child FK table does not check parent existence
bindReplace() temporarily sets IgnoreForeignKey so REPLACE can use the modern path, but the modern REPLACE path never adds a child->parent parent-existence check for non-self FKs. After createQuery(), bindAndOptimizeReplaceQuery() only generates self-referencing FK DetectSqls / self-ref pre-check SQLs. There is no equivalent of the INSERT/ODKU row-scoped parent check for normal child FKs.
So a statement like:
create table p(id int primary key);
create table c(id int primary key, pid int, foreign key(pid) references p(id));
replace into c values (1, 999);can be planned without any parent-existence assert. That should fail with the normal child-row FK error. Please add a regression test for both insert-only REPLACE and conflict REPLACE producing a final child row that references a missing parent.
Blocker 2: ODKU final-image FK check can still skip a valid FK check when another FK column is NULL
ODKU sets builder.modernFkCheck and then finishIrregularIndexMaintenance() calls the old appendForeignConstrantPlan() over the materialized final image. That helper first builds a single FILTER containing isnotnull for every FK column across all FKs before it does the parent joins.
That is not per-FK MATCH SIMPLE semantics. With two child FKs, if FK1 is NULL and FK2 is non-NULL but points to a missing parent, the row is filtered out before FK2's parent join/assert runs. The statement can pass even though FK2 should fail.
Please replace this ODKU check with the same per-FK MARK-join logic used by the new INSERT / INSERT IGNORE path, or otherwise make the NULL handling per FK rather than a global pre-filter. A focused regression test should cover: one FK column NULL, another FK column non-NULL and invalid -> ODKU must fail; the same NULL FK with the other FK valid -> must pass.
The existing planner tests pass locally, but they do not cover either of these cases.
Two foreign-key correctness fixes on the modern DML path. 1. REPLACE on a non-self child FK table never validated parent existence. bindReplace bypasses the FK-table rejection to take the modern path, but the modern REPLACE path only emitted self-referencing FK DetectSqls, so an orphan reference (e.g. `replace into c values (1, 999)`) was planned without any parent-existence assert. REPLACE now runs the same row-scoped per-FK MARK-join assert as the modern INSERT (buildModernChildFkAssert) over its inserted image, covering both insert-only and conflict REPLACE. 2. ON DUPLICATE KEY UPDATE skipped valid FK checks when another FK column was NULL. ODKU routed its child->parent check through appendForeignConstrantPlan, which first builds one global isnotnull filter across ALL FK columns, so a row with any NULL FK column was dropped from the entire check -- a second FK pointing at a missing parent was never validated. ODKU now uses the per-FK MARK-join check (appendModernChildFkMarkOks: each FK is valid when its parent exists OR one of its own columns is NULL, correct MATCH SIMPLE) over the final merged image. Unlike plain INSERT it does NOT re-project to a fresh tag, so the downstream MULTI_UPDATE still sees both the merged image and the delete columns. The now-unused modernFkCheck plumbing is removed; appendForeignConstrantPlan stays for the legacy UPDATE path. Tests: TestReplaceChildParentFKUsesInPlanCheck (new) and an enhanced TestInsertOnDupChildParentFKUsesInPlanCheck assert the per-FK MARK join. BVT: on_duplicate_key_modern covers multi-FK ODKU (one FK NULL + another invalid fails, one FK NULL + the other valid passes); replace covers a REPLACE orphan reference failing for both insert-only and conflict REPLACE. Co-Authored-By: Claude Opus 4.8 <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-checked current head c2c95bc7b05fac03bd322affd826827c7b1ef1d8 from correctness and unhappy-path angles.
The previous blockers I raised look addressed now:
INSERT IGNOREon child FK tables now uses the in-flow MARK-join FK filter, preserving row-skip semantics instead of failing the whole statement.- ODKU child->parent FK checking is row-scoped over the final merged image, so it no longer false-positives on unrelated orphan rows and the multi-FK MATCH SIMPLE case is checked per FK.
- REPLACE now validates the inserted child row against its parent in the modern path, covering both insert-only and conflict REPLACE.
- The composite nullable unique-key REPLACE path now skips statically NULL unique keys correctly; runtime INSERT/ODKU NULL-key filtering still happens at index-table insert time.
I also checked the latest added BVT/UT coverage around orphan rows, INSERT IGNORE row skipping, multi-FK NULL handling, and REPLACE FK enforcement. PR CI is green. Local targeted go test ./pkg/sql/plan ... still cannot build in my environment because native headers (usearch.h, xxhash.h) are missing, so I am relying on code review plus CI for execution coverage.
Approved from my side.
|
Queued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 56 minutes 8 seconds in the queue, with no time running CI. ReasonPull request #24973 has been dequeued Queue conditions are not satisfied:
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Requeued — the merge queue status continues in this comment ↓. |
Resolve conflicts: - pipeline.pb.go: regenerate from merged proto (drops legacy OnDuplicateKey, keeps SessionInfo.lock_wait_timeout from mo/main) - bind_replace.go: keep our commented skipUniqueIdx 'any static-NULL part' logic (functionally equivalent to mo/main's independent fix) - mock.go: union both composite fake-PK test schemas (fake_pk_comp + fake_pk_composite_t), each referenced by its own test - index_table_dml_test.go: pass the new irregularIndexes arg to appendDedupAndMultiUpdateNodesForBindReplace Co-Authored-By: Claude Opus 4.8 <[email protected]>
Merge Queue Status
This pull request spent 1 hour 8 minutes 11 seconds in the queue, including 1 hour 7 minutes 53 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #24939
fixes #25000
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.with synchronous index maintenance: INSERT / LOAD / ON DUPLICATE KEY UPDATE /
REPLACE now keep the IVF/fulltext index consistent, so new or updated rows are
immediately searchable. This also fixes [Bug]: REPLACE on a table with a vector/fulltext index does not maintain the index (rows not immediately searchable) #25000 (REPLACE not maintaining the
index).
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