Page History
- 2007-May-05 11:55 drh
- 2007-May-05 09:41 anonymous
- 2006-May-18 05:34 anonymous
- 2005-Dec-29 00:21 drh
- 2005-Dec-28 21:23 anonymous
- 2005-May-16 00:03 anonymous
- 2005-May-13 12:57 anonymous
- 2005-Feb-17 21:00 anonymous
- 2005-Feb-17 20:57 anonymous
- 2004-Oct-06 10:52 anonymous
- 2004-Sep-26 13:45 anonymous
- 2003-Sep-06 01:19 drh
- 2003-Sep-05 09:09 anonymous
- 2003-Sep-05 09:06 anonymous
- 2003-Jul-11 15:42 anonymous
--Carl Youngblood
Transactions and performance
When doing lots of updates/inserts on a table it is a good idea to contain them within a transaction,
begin; insert into table values (..); insert into table values (..); insert into table values (..); .... commit;
This will make SQLite write all the data to the disk in one go, vastly increasing performance.
However, if you are writing to a temporary table, transactions have less effect because disk writes are not flushed to the table after each write.
I did a timed test with inserting 1000 records into a table in various ways to compare performance:
- main database table without transaction - 5 seconds
- main database table with transaction - 0.1 seconds
- temporary table without transaction - 2 seconds
- temporary table with transaction - 0.1 seconds
So, performance is still vastly quicker with a transaction when writing to a temporary, but transactions have the drawback of locking the entire database file for the duration of the transaction, even though only a temporary file is being written to, so, in multithreaded applications, it may be worth putting up with the lower performance to avoid this database locking behaviour.
--Paul Smith