RE: [PHP] MySQL COUNT Won't Work

From: Date: Fri, 16 Feb 2001 20:24:53 +0000
Subject: RE: [PHP] MySQL COUNT Won't Work
Groups: php.general 
Request: Send a blank email to php-general+get-40217@lists.php.net to get a copy of this message
Addressed to: Javier Muniz <JavierM@corp.granicus.com> Joe Sheble (Wizaerd) [mailto:JustForMailingLists@wizaerd.com] php-general@lists.php.net ** Reply to note from Javier Muniz <JavierM@corp.granicus.com> Fri, 16 Feb 2001 10:14:29 -0800 > > You should use fieldnames in your selects... I'd imagine count(*) > would be slower just as select * is slower. I agree, SELECT should always specify only the fields you want returned, but COUNT(*) is an optimization. From the MySQL manual: http://www.mysql.com/doc/G/r/Group_by_functions.html COUNT(*) is somewhat different in that it returns a count of the number of rows retrieved, whether or not they contain NULL values. COUNT(*) is optimized to return very quickly if the SELECT retrieves from one table, no other columns are retrieved, and there is no WHERE clause. For example SELECT COUNT(*) FROM TableName will not even look at the table, it can get the number of entries from the index, and return it almost instantly. If you used SELECT COUNT(SomeField) FROM TableName MySQL would have to scan the table to make sure none of the SomeField values were NULL, which would not be included in the count. This can take quite a bit more time. Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.general (#40217) next »