In attempting to load a log file into SQLite, it took 20 minutes of disk thrashing. Super search mostly pointed to the fact that databases typically include a loading utility, but it appears that SQLite doesn't have one. RTFM didn't help much, and I was about to post the speed question in SOPW when I found the answer on SQLite's benchmark page. The trick is to do it all in one transaction. The speed improvement was over 200x for loading 50k rows in my test case. Here it is in case someone else needs to know:

# first attempt ... my $start = time; my $dbh = DBI->connect("DBI:SQLite:$dbfile") or die; my $sth = $dbh->prepare( qq(INSERT INTO 'logentries' ('col1', 'col2', 'col3', 'col4') values (?,?,?,?) )); $sth->execute($_->[0], $_->[1], $_->[2], $_->[3]) for @rows; print "et: ", time - $start, " sec\n"; # et: 1082 seconds
# single transaction ... my $start = time; my $dbh = DBI->connect("DBI:SQLite:$dbfile") or die; $dbh->do('BEGIN'); my $sth = $dbh->prepare( qq(INSERT INTO 'logentries' ('col1', 'col2', 'col3', 'col4') values (?,?,?,?) )); $sth->execute($_->[0], $_->[1], $_->[2], $_->[3]) for @rows; $dbh->do('COMMIT'); print "et: ", time - $start, " sec\n"; # et: 5 seconds

Update:
Setting AutoCommit => 0 as suggested by Christoforo gives the same speed improvement. As I suspected there are limits on transaction size as noted by Jenda.


In reply to Loading bulk data into SQLite by hangon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.