On Mon, Feb 21, 2011 at 03:37:50PM +0100, Sven L scratched on the wall:

> I've learnt that COUNT(*) is slower than COUNT(ID),

  That's usually not true.

> since * means the engine has to traverse all columns 

  Actually, count(*) is the one case when the engine does *not* need to
  traverse any columns.

> and it might even return another value if there are NULL-values...

  Yes, but that's how count() is defined to work.

  The expression "count(id)" only counts rows where id is not NULL. 
  This requires that the database engine retrieve the value of the id
  column from each row in order to test for NULL.
  
  The expression "count(*)" strictly counts rows, without concern over
  NULLs.  As such, there is no need to actually retrieve any row data,
  because there is no need to test any row values.  The count(*)
  function can scan the table tree, counting the number of rows,
  without actually loading or decoding the row data.

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Intelligence is like underwear: it is important that you have it,
 but showing it to the wrong people has the tendency to make them
 feel uncomfortable." -- Angela Johnson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to