dolthub / go-mysql-server

A MySQL-compatible relational database with a storage agnostic query engine. Implemented in pure Go.
Apache License 2.0
2.32k stars 199 forks source link

fix insert id #2616

Closed jycor closed 1 month ago

jycor commented 1 month ago

The logic setting the InsertID in OkResult, did not match results returned from last_insert_id(). This was made apparent due to changes from https://github.com/dolthub/go-mysql-server/pull/2614. For a single insert statement, MySQL sets InsertID exactly once when the AutoIncrement on the column is first triggered. While the linked PR fixes that issue and properly sets the session variable, our insertRowHandler (which is responsible for returning OkResult structs) was setting InsertID incorrectly.

The fix is to just read the LastInsertID from the session, since it is already set to the right value.