{"id":174,"date":"2007-03-31T00:06:38","date_gmt":"2007-03-30T23:06:38","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/?p=174"},"modified":"2007-03-31T00:06:38","modified_gmt":"2007-03-30T23:06:38","slug":"sqlite-what-a-difference-transactions-make","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/174-sqlite-what-a-difference-transactions-make.html","title":{"rendered":"SQLite: what a difference transactions make"},"content":{"rendered":"<p>I received an email from something trying my <a href=\"http:\/\/www.itwriting.com\/sqlitesimple.php\" target=\"_blank\">simple Delphi wrapper<\/a> for <a href=\"http:\/\/www.sqlite.org\" target=\"_blank\">Sqlite<\/a>. He wanted to add a million rows to a table of 10 columns of doubles, but was disappointed with the speed.<\/p>\n<blockquote>\n<p>I tried with your SQL commands from the wrapper and just for 10000 elements it took me for ages&#8230;<\/p>\n<\/blockquote>\n<p>I had a hunch that wrapping the inserts in a transaction might solve this one, and so it proved. The difference is staggering.<\/p>\n<p>10,000 rows in 2 seconds, 1 million in under a minute.<\/p>\n<p>Without the transaction it takes, well, forever, as the email says.<\/p>\n<p>Worth noting if you use Sqlite; and&nbsp;in fact, many database engines behave like this. The reason I guess is that if you do not explicitly place a sequence of SQL statements within a transaction, then each statement is in effect its own transaction. That means the database engine has a lot of housekeeping to do&nbsp;in order to ensure that the changes were really written to disk, and in opening, writing and closing the journal file. <\/p>\n<p>&nbsp;<\/p>\n<div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:970c447b-961e-415c-b122-95078bef0bd8\" contenteditable=\"false\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati tags: <a href=\"http:\/\/technorati.com\/tags\/sqlite\" rel=\"tag\">sqlite<\/a>, <a href=\"http:\/\/technorati.com\/tags\/database\" rel=\"tag\">database<\/a>, <a href=\"http:\/\/technorati.com\/tags\/delphi\" rel=\"tag\">delphi<\/a>, <a href=\"http:\/\/technorati.com\/tags\/performance\" rel=\"tag\">performance<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I received an email from something trying my simple Delphi wrapper for Sqlite. He wanted to add a million rows to a table of 10 columns of doubles, but was disappointed with the speed. I tried with your SQL commands from the wrapper and just for 10000 elements it took me for ages&#8230; I had &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/174-sqlite-what-a-difference-transactions-make.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">SQLite: what a difference transactions make<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,80],"tags":[],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-delphi","category-software-development"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=174"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/174\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}