mikey1090
09-30-2006, 04:48 AM
which query is quickest.....
to count number of users in my database
do a mysql COUNT(id) on my table.
or select id, and do mysql_num_rows
which of those two will execute the fastest?
woutersteven
09-30-2006, 07:33 AM
The first COUNT(id) will execute faster because no result set has to be transfered.
Form1
09-30-2006, 11:45 AM
count(*) should be even faster - a well optimized DB backend will only count rows.
(Technically, the two are slightly different: count(id) only counts unique, non-null IDs - which shouldn't be an issue for a typical artificial primary key row, of course.)
Take it easy,
Dave
LoneWolfJack
09-30-2006, 06:29 PM
Look up the BENCHMARK() mysql command. This will help you.
grabmail
10-07-2006, 09:47 AM
The first COUNT(id) will execute faster because no result set has to be transfered.
only true for myisam.
for innodb, if i'm not wrong, the speed of select count(id) is almost the same as the speed of select id
mikey1090
10-07-2006, 05:17 PM
thanks for the help guys :)