Avoid redundant SELECT in execute_insert#386
Open
pctablet505 wants to merge 2 commits into
Open
Conversation
execute_insert previously ran an extra "SELECT last_insert_rowid()" query after every insert. sqlite3's cursor already exposes this value via cursor.lastrowid, so we can return it directly and skip the round trip, cutting an insert's overhead noticeably. Fixes omnilib#379
Cover the execute_insert helper directly: normal single-row insert (asserting both the (rowid,) tuple shape and result[0] access), sequential inserts, multi-row insert returning the final rowid, and the no-insert cases where lastrowid retains the connection's last insert rowid or reports 0 when no insert has occurred.
pctablet505
marked this pull request as ready for review
July 17, 2026 12:47
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.
Description
execute_insertruns an insert and then issues a separateSELECT last_insert_rowid()query to fetch the new row id. That second query is unnecessary: sqlite3's cursor already exposes the same value viacursor.lastrowidright after the insert executes. This drops the extra round trip.The return type moves from a
sqlite3.Rowto a plain tuple, butresult[0](the common access pattern for reading the inserted id) keeps working the same way.Fixes: #379