If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > select count(*) in innoDB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-12-03, 03:43
htseng htseng is offline
Registered User
 
Join Date: Sep 2003
Posts: 5
select count(*) in innoDB

When do a select count(*), is the performance better on MyIsam table than InnoDB table?
I read on the web that MyISAM stores total number of rows in MYI file header. It's read into memory when table is opened.
InnoDB doesn't store total number of rows anywhere.

If we have InnoDB tables and also need to do a lot of count(*), is there anyway to improve the count(*) on InnoDB?
Reply With Quote
  #2 (permalink)  
Old 09-12-03, 04:43
Mincer Mincer is offline
Registered User
 
Join Date: Sep 2003
Location: London
Posts: 56
You can improve performance of row counting in 2 ways.
  1. Store your own row counter that gets updated on INSERT/DELETE. This is entirely dependant on your database load as it creates overhead on every data altering operation. However, on the plus side, it makes row counting very fast. Another down side is that your queries are not immediately obvious as COUNT(*) FROM table.
  2. If you do COUNT(field) on an indexed column that has low(ish) cardinality, this seems to give a significant boost to performance on some columns. I'm not sure why it doesn't work for all, perhaps soneone can enlighten me. However, a total table scan of COUNT(*) on one of my tables takes 25 seconds, if I choose the right indexed colum, COUNT(column) takes less than 2 seconds.

Hope this helps.

Regards,
Matt.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On