> -----Original Message----- > From: Davide Copelli [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, October 02, 2002 8:58 AM > To: [EMAIL PROTECTED] > Subject: COUNT(*) performance > > > On a Mysql database of 60000 records performs better : > > my $sth = $dbh->prepare(qq|SELECT count(id) FROM log WHERE > (field1 = ? and > field2= ? )|); > $sth->execute( $a1, $a2 ); > $total = $sth->fetchrow_array(); > > or > > my $sth = $dbh->prepare(qq|SELECT id FROM log WHERE (field1 = > ? and field2= > ? )|); > $sth->execute( $a1, $a2 ); > $total = $sth->rows;
The latter will not work. $sth->rows will not have a meaningful value until you've fetched the data. Given that, the first method is almost certainly the most efficient. > > where "id" is a primary key field Doesn't really matter. What would affect the performance would be whether indexes are available on field1 and field2. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]