Repository navigation
feat(sqlite): add SqliteConnection::execute_batch for running bound queries in one worker command - #4511
Open
LeenHawk wants to merge 1 commit into
Open
feat(sqlite): add SqliteConnection::execute_batch for running bound queries in one worker command#4511LeenHawk wants to merge 1 commit into
LeenHawk wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
Does your PR solve an issue?
fixes #4510
Adds
SqliteConnection::execute_batch(), which runs a sequence of bound queries in one command to the worker thread instead of one command per query:Execute<'_, Sqlite>. Arguments are encoded andpersistent()is honoured exactly as infetch_many(). On the worker, each query goes through the sameexecute::iterasCommand::Execute, so repeating one SQL string with different arguments uses one cached statement.SqliteBatchErrorreports the index and converts intosqlx::Error. Earlier queries are not rolled back.SqliteBatchResultexposesrows_affected(),last_insert_rowid(),rows(),into_rows()andinto_parts(). Its fields are private, so it can be extended.Sender::is_canceled()before the next one.Executor, following the discussion in Discussion: deprecation ofexecute_many()andfetch_many()on prepared statement interfaces and potential replacement #3108.Inserting 100,000 three-column rows on a Ryzen 7 8745H, committing every N rows (
:memory:, median of 5 runs):executeper queryexecute_batchA WAL file database with
synchronous = NORMALshows the same shape (2.5x–11x).Tests in
tests/sqlite/sqlite.rscover:RETURNINGrows, and statement cache reuse;UPDATE,SELECTand a multi-statement string in one batch;Locally, with
DATABASE_URL=sqlite:tests/sqlite/sqlite.dband the CI feature set,sqlite,sqlite-typesandsqlite-anytests pass. The CIcargo clippy ... -- -D warningscommand andcargo fmt --checkpass too.Is this a breaking change?
No. It only adds a method and two types (
SqliteBatchResult,SqliteBatchError) tosqlx-sqlite, plus a variant to the private workerCommandenum.