If you are inserting a lot of rows into the DB, combining all of the inserts into a single transaction will typically increase the performance dramatically. Batch inserts into the DB typically require a proprietary format of the data. Reducing the number of transactions usually speeds things up enough that further optimization is not necessary (YMMV).

The big performance hit is not in the execute() method itself, but in all of the "housekeeping" that the DB does to finalize the transaction. When you connected, the default would have been to set autocommit=1, that causes each execute() to be an independent transaction. You can temporarily override the autocommit, by explicitly starting a transaction as show below. Assuming that you have set RaiseError=1,:

my @data = ([11,12,13], [21,22,23], [31,32,33]); $sth = $dbh->prepare("insert into table values (?, ?, ?)"); # start new transaction # $dbh->begin_work(); #or perhaps $dbh->do("BEGIN"); foreach my $row (@data) { $sth->execute(@$row); } # end the transaction # $dbh->commit(); #or perhaps $dbh->do("COMMIT");

In reply to Re: Batch Upload/Insert – Row wise with Perl DBI by Marshall
in thread Batch Upload/Insert – Row wise with Perl DBI by shree

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.