Re: counting records in db

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



----- Original Message ----- From: "Paul Novitski" <paul@xxxxxxxxxxxxxxxxxxx>

While we're talking about optimization, I'd want to check to make sure COUNT(*) didn't ask MySQL to generate a throw-away recordset consisting of all fields. I wonder if it would be more machine-efficient to use COUNT(`last_name`), specifying a single field, in this case the same field your query is examining anyway.


If the fields mentioned in the where clause are keys or if there is no where clause, a count(*) uses the index trees to make the count, it won't even access the data racords at all. Moreover, it won't even read the whole index tree node, just the header record of the block that indicates how many key records that block contains. I don't really know about MySql or any database engine, but these are techniques well known in the trade.

On the count(fieldname) issue, it is different from a count(*) and may give different results. When you mentione a field it will only count records where that field is not null. Select count(fieldname) from table is the same as doing a select count(*) from table where fieldname is not null. It will take just as longer as processing any additional where clause.

Satyam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux