Same result :( Note that I have compiled SQLite with the following switches: SQLITE_ENABLE_STAT2 SQLITE_THREADSAFE=2 I've learnt that COUNT(*) is slower than COUNT(ID), since * means the engine has to traverse all columns and it might even return another value if there are NULL-values... Also, this is quite interesting: sqlite> EXPLAIN QUERY PLAN SELECT COUNT(ItemID) FROM Items; 0|0|0|SCAN TABLE Items (~1000000 rows) sqlite> EXPLAIN QUERY PLAN SELECT COUNT(*) FROM Items; sqlite>
I would expect an index scan on the first statement. The second statement tells me nada?! Thanks for your help! > From: slav...@bigfraud.org > Date: Mon, 21 Feb 2011 14:24:50 +0000 > To: sqlite-users@sqlite.org > Subject: Re: [sqlite] COUNT() extremely slow first time! > > > On 21 Feb 2011, at 2:23pm, Sven L wrote: > > > SELECT COUNT(ItemID) FROM Items; > > > > This takes around 40 seconds the first time! WHY?! > > Try again, doing everything identically except that instead of the above line > use > > SELECT COUNT(*) FROM Items; > > Simon. > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users