On Sep 24, 2010, at 3:13 PM, Michele Pradella wrote: > I have an SQLite DB of about 9GB with about 2.500.000 records. > I can't understand why the "select COUNT(*) from log" statement is > extremely slow, it takes me about 9-10 minutes!
In SQLite, count() is obliged to traverse the entire table structure. Or if the table has any indexes, it may choose to traverse an entire index (index structures are almost always smaller than the corresponding table). Either way, with such a large database this is going to take some time. The usual suggestion is to use triggers to store the number of rows in the table of interest in some other SQL table. i.e. use an INSERT trigger to increment a counter and a DELETE trigger to decrement it. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users