Skip to content

What is batch, and why can't I use transaction instead? #987

Answered by simolus3
cervonwong asked this question in Q&A
Discussion options

You must be logged in to vote

You're correct, batches are a moor-specific feature. There are some docs on batch in the Dart documentation.

There are two major performance considerations when running a large number of updates. First, we want to avoid a write to disk for each statement. Transactions help here, since they effectively only store data when they're committed. Batches also use a transaction internally, so they also solve that problem.
Another issue is that we want to avoid preparing statements multiple times. Let's say that LIST_OF_RECORDS.length == 1000, and assume that each statement has the sql DELETE FROM table WHERE id = ?. With transactions, we'd compile that exact statement 1000 times and run each com…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@cervonwong
Comment options

@simolus3
Comment options

@cervonwong
Comment options

Answer selected by cervonwong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants