Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found