I know that this list has been over the issues of using ROWID to get the count. Nevertheless, I was thinking, if you never do any deletes the last ROWID should contain the count. It's too bad you can't do an offset of negative one so that it would start at the back. That should be darn fast. Something like:

select rowid from table limit 1 offset -1;

Nemanja Corlija wrote:
On 7/18/06, Sripathi Raj <[EMAIL PROTECTED]> wrote:
Hi Jay,

 I have a database whose size is around 250 MB. I have a table which has
around 140,000 records. Doing a count(*) on that takes me 473 seconds. I
believe it's not supposed to take that much time.

SQLite does not keep count of rows in a table. So when you execute
SELECT COUNT(*) FROM table;
what SQLite does is step through table row by row and count them.
Only way to get the total number of rows in a table faster is to keep
track of it yourself. This can easily be done using insert/delete
triggers that will increment/decrement row count in a separate table.
Complete examples of such code were posted to list before. Look for it
in archives.


Reply via email to