Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Savepoint vs. transaction for performance?#283

hyperknot started this conversation inGeneral
Discussion options

I'd like to optimize performance for batch insert operations, for example when a database is restored from JSON dump (say 1000 INSERT statements are run).

I'm using OPFSCoopSyncVFS + sync build in a worker.

I have the following questions:

  1. With wa-sqlite (without using experimental WAL modes, etc.) is it better for performance to wrap the INSERT statements with BEGIN/COMMIT or SAVEPOINT/RELEASE?
  2. Is SAVEPOINT also helping with performance, or only BEGIN?
  3. What happens when I do the following?
    BEGIN
    SAVEPOINT
    ... 1k INSERT
    RELEASE
    COMMIT

Is there anything else I'm missing for optimizing batch inserts?

Python has a special commandexecutemany(), but I haven't seen an analogue of this in either node's better-sqlite3 nor in wa-sqlite.

I guess, outside of a special C-level batch insert function, our best bet is wrapping it in a transaction or savepoint?

You must be logged in to vote

Replies: 1 comment

Comment options

FYI, I have never had a need for a nested transaction so I have only played briefly with savepoints.

Answers:

  1. The SAVEPOINT docs say, "When a SAVEPOINT is the outer-most savepoint and it is not within a BEGIN then the behavior is the same as BEGIN DEFERRED TRANSACTION", so performance should be essentially the same.
  2. What really matters for performance is not creating a separate transaction for each insert.
  3. I think that the SAVEPOINT/RELEASE is unnecessary since there is already a transaction. SQLite could optimize it away but I don't know whether it does or not.

Is there anything else I'm missing for optimizing batch inserts?

I coincidentally posted adrive-by response about this last week.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
2 participants
@hyperknot@rhashimoto

[8]ページ先頭

©2009-2025 Movatter.jp