Thanks!!!
El día Sunday 07 September 2003 7:59 a Bob Showalter mandó el siguiente 
correo:
> 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.

-- 
Pablo Fischer Sandoval ([EMAIL PROTECTED])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131  AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to