MySQL Forums
Forum List  »  InnoDB

Re: COUNT(*) on innodb
Posted by: James Day
Date: November 24, 2005 08:00PM

One option you could try is to have an index on a small field or small part of a field and try counting with a use or force index option specifying that index. It would still be a full scan but of an amount of data which may more easily fit in RAM.

If you have an autoincrement field and deletes are uncommon, you could compare the minumum and maximum values of the indexed autoincrement column to get a reasonable count with only two index checks. If you need more accuracy, you could periodically store the counter and accurate record count and subtract that value from the current value.

If you know the timestamp of a saved count and have an index on a timestamp column you could relatively quickly count only the records with a timestamp greater than that using the index.

James Day
Support engineer, MySQL AB

Options: ReplyQuote


Subject
Views
Written By
Posted
12466
November 24, 2005 09:15AM
4777
November 24, 2005 09:46AM
4491
November 24, 2005 11:53AM
4181
November 24, 2005 12:16PM
4137
November 24, 2005 12:39PM
3777
November 24, 2005 12:55PM
4278
November 24, 2005 01:03PM
3285
November 24, 2005 01:11PM
3233
November 24, 2005 01:32PM
2977
November 24, 2005 02:07PM
Re: COUNT(*) on innodb
3518
November 24, 2005 08:00PM
2982
November 24, 2005 08:38PM
2833
November 25, 2005 05:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.