<?xml version="1.0" encoding="windows-1252"?>
<node id="454953" title="DBI speed up needed on MySQL" created="2005-05-07 23:30:13" updated="2005-07-29 05:01:34">
<type id="115">
perlquestion</type>
<author id="223311">
jacques</author>
<data>
<field name="doctext">
This DBI statement is taking too long and I need to speed things up:
&lt;code&gt;
my $sth = $dbh-&gt;prepare("select * from campaigns where mw_export='yes' and last_update &gt; ?");
$sth-&gt;execute(last_transfer{'campaigns'});

while(my $result = $sth-&gt;fetchrow_hashref()) {

print "It takes me over 30 minutes to print this!!!\n";

}
&lt;/code&gt;
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:
&lt;p&gt;
1. Use indexes.
&lt;br&gt;
2. Use fetchrow_arrayref instead of fetchrow_hashref.
&lt;p&gt;
I created two indexes but didn't notice any speed improvement:
&lt;code&gt;
alter table campaigns add index mw_export (mw_export);
alter table campaigns add index last_update (last_update);
&lt;/code&gt;
Should I create a different type of index? Those are the SQL statements that I used.
&lt;p&gt;
&lt;b&gt;The other option&lt;/b&gt; 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?
&lt;p&gt;
I heard that fetchrow_arrayref is way faster than its hashref counterpart.
&lt;p&gt;
Any other things that I could try? 
</field>
</data>
</node>
