perlquestion
jacques
This DBI statement is taking too long and I need to speed things up:
<code>
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";
}
</code>
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:
<p>
1. Use indexes.
<br>
2. Use fetchrow_arrayref instead of fetchrow_hashref.
<p>
I created two indexes but didn't notice any speed improvement:
<code>
alter table campaigns add index mw_export (mw_export);
alter table campaigns add index last_update (last_update);
</code>
Should I create a different type of index? Those are the SQL statements that I used.
<p>
<b>The other option</b> 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?
<p>
I heard that fetchrow_arrayref is way faster than its hashref counterpart.
<p>
Any other things that I could try?