I'm running a bunch of database queries using DBD::CSV and it runs pretty slow, does anyone have some suggestions on making this faster? Here's the DB part of my code:
my $dbh = DBI->connect("DBI:CSV:f_dir=.;csv_eol=\n;") or die "Cannot connect: " . $DBI::errstr; $dbh->{'csv_tables'}->{'bt'} = { 'file' => './X_Con.csv'}; $dbh->{'csv_tables'}->{'sec'} = { 'file' => './Y_Con.csv'}; $dbh->{'csv_tables'}->{'stats'} = { 'file' => './Z_Con.csv'}; my $sth_sec = $dbh->prepare("SELECT KEY, TEST, INSTANCE, ID, HID FROM +sec") or die "Can't prepare SQL statement: $DBI::errstr\n"; my $sth_bt = $dbh->prepare("SELECT NAME, STATE FROM bt WHERE ID =? AND + HID=?") or die "Can't prepare SQL statement: $DBI::errstr\n"; my $sth_stats = $dbh->prepare("SELECT CCS, kbps, MBytes FROM stats WHE +RE ID=? AND HID=? & INSTANCE=?") or die "Can't prepare SQL statement: $DBI::errstr\n"; $sth_sec->execute() or die "Can't execute SQL statement: $DBI::errstr\n"; open(TRAFFICSTATS,'>',"NoThroughput.csv") || die("Cannot Open File"); { my $old_sel = select(TRAFFICSTATS); $| = 1; # Auto-flush. select($old_sel); } print TRAFFICSTATS "KEY,ID,HID,NAME,STATE,CCS,kbps,MBytes\n"; while ( my @row = $sth_sec->fetchrow_array ) { my ( $keyId, $testCarrier, $instanceId, $id, $hId ) = @row; $sth_bt->execute( $id, $hId ); @row = $sth_bt->fetchrow_array; my ( $name, $state ) = @row; $sth_stats->execute($id, $hId, $instanceId ); @row = $sth_stats->fetchrow_array; my ( $CCS, $kbps, $mBytes ) = @row; print TRAFFICSTATS "$keyId,$id,$hId,$name,$state,$CCS,$kbps,$mBytes +\n"; } close TRAFFICSTATS;

In reply to How to make my DBD::CSV DB code faster. by awohld

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.