Repository navigation
fix(insert): exclude fake primary key from LAST_INSERT_ID (#29903) - #30004
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? |
|
mo-bot review · Commit: Assessment: request_changes Reviewed the complete four-file delta and its allocation, planning, process and frontend consumers. The gate introduces a visibility regression and leaves a reachable hidden-ID leak unresolved. Model: Session:
Validation:
Limitations:
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 7e5f08ebd4a5e0cbcdc4d4adac06af351ad2640a
Assessment: request_changes
Reviewed the complete four-file delta and its allocation, planning, process and frontend consumers. The gate introduces a visibility regression and leaves a reachable hidden-ID leak unresolved.
Model: gpt-6-astra / xhigh
Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0
-
P2
pkg/sql/colexec/preinsert/preinsert.go:700: Createt(pk int primary key, __mo_fake_pk_col bigint unsigned auto_increment)and executeinsert into t(pk) values (10).
Impact: The visible auto-increment column generates an ID, but the new name-only predicate suppresses it. LAST_INSERT_ID() retains its previous value and the statement reports no generated ID. This is a new compatibility regression.
Evidence: build_util.go:2614 permits this column name, and build_ddl.go preserves Hidden=false for user columns. incrservice.GetUserAutoColumnFromDef uses visibility, while store_sql.go:530 explicitly accounts for visible columns with this spelling. The source-extracted probe returned eligibility=false for this valid visible column. Use the existing visibility ownership rule rather than treating the name alone as proof of an internal column. -
P2
pkg/sql/colexec/preinsert/preinsert.go:673: Fort(id bigint auto_increment, v int)without an explicit primary key, executeinsert into t(v) values (1), theninsert into t(id,v) values (100,2).
Impact: The second insert generates only a hidden fake key, yet the gate publishes that key and changes LAST_INSERT_ID() from 1 to 2. This preexisting leak remains unresolved despite the stated contract that hidden IDs must never surface.
Evidence: build_ddl.go:4137 appends the hidden auto-increment key. column_cache.go:697 returns zero when all user values are explicit; table_cache.go:160-165 then selects the hidden column's nonzero result. Because the table also contains a user auto-increment column, the new gate accepts that result. The source-extracted composition probe confirmed this path with allocator returns 0 and 2. Filter the returned ID by its generating column's ownership; table-level existence is insufficient. The new mixed-column helper test does not exercise this behavior.
Validation:
-
Verified the assigned HEAD and clean source checkout. Frozen patch matches the Git delta apart from a terminal newline; diff whitespace and gofmt checks passed.
-
Reviewed every changed hunk, supplied comments, allocator result selection, DDL visibility, local/remote PRE_INSERT metadata, statement coordination, frontend publication, retry/error paths and test oracles.
-
Reused frozen successful exact-head build, Ubuntu/x86 UT, Linux/arm64 SCA, coverage and PROXY/pessimistic multi-CN BVT statuses. Skipped checks were not counted as passes.
-
Ran ownership_probe.go with Go 1.25.5 and CGO_ENABLED=0. Extracted production decision functions reproduced both defects; hidden-only and generated-user controls behaved correctly. Diagnostics are saved in the assigned attempt directory.
Limitations:
-
The probe uses minimal types and stubbed column-allocator returns grounded in the source trace; it is not a MatrixOne SQL or native package test. Source-derived SQL reproductions were saved but not executed.
-
Frozen evidence lacks per-test CI logs and the standalone linked-issue body. The PR's stated contract was reviewed; no performance benchmark was run.
…atrixorigin#29903) A table with no user primary key -- the hidden fulltext/vector index tables among them -- carries an allocator-owned hidden fake primary key (__mo_fake_pk_col) that is auto_increment. insertAutoValues returned the first generated value across ALL auto columns, so this internal key could become the statement's LAST_INSERT_ID: a base-table INSERT that synchronously populates a fulltext index surfaced the index's hidden key instead of the base table's business key. Return the first generated value among user-visible columns only, using the authoritative isInternal ownership flag (hidden fake PK, from the table definition) rather than a column name. This also fixes the two edge cases a name-based check got wrong: a user column that happens to be named __mo_fake_pk_col is visible and still surfaces, and a table whose user auto column is given an explicit value while only the hidden key generates publishes nothing. InsertValues' return is consumed solely by the LAST_INSERT_ID publish, so scoping it to user-visible columns has no other effect. Tests: - UT TestInsertValuesExcludesInternalFakePKFromLastInsertID (internal-only, user-only, visible __mo_fake_pk_col, mixed explicit-user+generated-hidden). - BVT fulltext/fulltext_last_insert_id (base table + synchronous fulltext index build) and auto_increment/last_insert_id_hidden_pk (the two edge cases). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
fixed |
|
mo-bot review · Commit: Assessment: approve Reviewed the complete six-file delta. Filtering LAST_INSERT_ID at the allocator’s existing column-ownership boundary resolves both prior findings: visible columns named __mo_fake_pk_col remain eligible, and hidden-only allocations cannot overwrite session state. No actionable defects remain. Model: Session: Validation:
Limitations:
|
Merge Queue Status
This pull request spent 25 minutes 17 seconds in the queue, with no time running CI. ReasonPull request #30004 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
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. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #29903
What this PR does / why we need it:
A
FULLTEXTindex carries a hiddenauto_incrementfake primary key (__mo_fake_pk_col) on its index table. When anINSERTinto the base table synchronously populates the index, the index table'sPRE_INSERTgenerates that fake key and the preinsert operator published it into the sessionLAST_INSERT_ID, soLAST_INSERT_ID()returned a hidden index value instead of the base table's business key.Fix. Only a user-visible
auto_incrementcolumn may setLAST_INSERT_ID. The publish is gated ontableHasUserAutoIncrColumn(...): a primary-key-less table — the hidden fulltext/vector index tables among them — carries a generated fake primary key that isauto_incrementbut internal, and its value must never surface. This enforces the contract already documented indml/insert/multi_insert("the hidden fake key must not count as an auto_increment target"). The prior behavior was only masked for equal-magnitude cases by the smallest-non-zero coordinator and still returned the wrong value when the base key outranked the index fake key (e.g. a table created withAUTO_INCREMENT=1000).Tests.
TestGenAutoIncrColFakePKDoesNotPublishLastInsertID(regression) andTestTableHasUserAutoIncrColumn(table-driven). 100% of changed blocks covered.test/distributed/cases/fulltext/fulltext_last_insert_id— single insert, sequential insert,AUTO_INCREMENT=1000latent case, multi-row first-key. Validated-g -n, 21/21.🤖 Generated with Claude Code