Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
This DBI statement is taking too long and I need to speed things up:
my $sth = $dbh->prepare("select * from campaigns where mw_export='yes' + and last_update > ?"); $sth->execute(last_transfer{'campaigns'}); while(my $result = $sth->fetchrow_hashref()) { print "It takes me over 30 minutes to print this!!!\n"; }
I have about 40,000 rows with each row containing about 200 fields. My program hangs for a loooooong time. So I know I have a few options:

1. Use indexes.
2. Use fetchrow_arrayref instead of fetchrow_hashref.

I created two indexes but didn't notice any speed improvement:

alter table campaigns add index mw_export (mw_export); alter table campaigns add index last_update (last_update);
Should I create a different type of index? Those are the SQL statements that I used.

The other option is to use fetchrow_arrayref. But I *need* to have $result as a hash ref. Would it be okay to convert the array ref to a hash ref? What would be the best way to do that?

I heard that fetchrow_arrayref is way faster than its hashref counterpart.

Any other things that I could try?


In reply to DBI speed up needed on MySQL by jacques

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (8)
    As of 2014-12-25 07:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (159 votes), past polls