Pablo Fischer wrote: > Hello! > > I have a questionto those lovers of DBI and Databases: which method > is faster to know the number of rows of a query: > > $sth->rows > > or > > my query but with a COUNT(id) and retrieve the value with: > > $query->bind_columns(undef, \$total); > > The table its 'big' cause it will manage like 12,000 rows. > > In $sth->rows I have this: > > SELECT idport FROM ports WHERE port='$portnumber'; > > in the bind_columns case I have > > SELECT COUNT(idport) FROM ports WHERE port='$portnumber'. > > I know that I can test it with EXPLAIN in MySql, however Im testing > it with 150 records, not with 12,000 (or more) that will be the real > size of the table.
The latter should be faster, because the server can do all the counting and doesn't have to pass each row back to the client for counting. If there's an index on "port", the count can be determined just by scanning the index, which could be even quicker. In general, you want your queries to return the mininum number of rows necessary. The second query will always return one row, so that's your best bet. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]