jacques has asked for the wisdom of the Perl Monks concerning the following question:
This DBI statement is taking too long and I need to speed things up:
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: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"; }
1. Use indexes.
2. Use fetchrow_arrayref instead of fetchrow_hashref.
I created two indexes but didn't notice any speed improvement:
Should I create a different type of index? Those are the SQL statements that I used.alter table campaigns add index mw_export (mw_export); alter table campaigns add index last_update (last_update);
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?
Back to
Seekers of Perl Wisdom