title: MySQL query very slow. Count(*) on indexed column
body: <p>The table is in InnoDB table. Here is some information that might be helpful.</p>
  
  <pre><code>EXPLAIN SELECT COUNT(*) AS y0_ FROM db.table this_ WHERE this_.id IS NOT NULL;
  
  +----+-------------+-------+-------+---------------+---------+---------+------+---------+--------------------------+
  | id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows    | Extra                    |
  +----+-------------+-------+-------+---------------+---------+---------+------+---------+--------------------------+
  |  1 | SIMPLE      | this_ | index | PRIMARY       | PRIMARY | 8       | NULL | 4711235 | Using where; Using index |
  +----+-------------+-------+-------+---------------+---------+---------+------+---------+--------------------------+
  1 row in set (0.00 sec)
  
  mysql&gt; DESCRIBE db.table;
  +--------------+--------------+------+-----+---------+-------+
  | Field        | Type         | Null | Key | Default | Extra |
  +--------------+--------------+------+-----+---------+-------+
  | id           | bigint(20)   | NO   | PRI | NULL    |       |
  | id2          | varchar(28)  | YES  |     | NULL    |       |
  | photo        | longblob     | YES  |     | NULL    |       |
  | source       | varchar(10)  | YES  |     | NULL    |       |
  | file_name    | varchar(120) | YES  |     | NULL    |       |
  | file_type    | char(1)      | YES  |     | NULL    |       |
  | created_date | datetime     | YES  |     | NULL    |       |
  | updated_date | datetime     | YES  |     | NULL    |       |
  | createdby    | varchar(50)  | YES  |     | NULL    |       |
  | updatedby    | varchar(50)  | YES  |     | NULL    |       |
  +--------------+--------------+------+-----+---------+-------+
  10 rows in set (0.05 sec)
  </code></pre>
  
  <p>The explain query gives me the result right there. But the actual query has been running for quite a while. How can I fix this? What am I doing wrong?</p>
  
  <p>I basically need to figure out how many <code>photos</code> there are in this table. Initially the original coder had a query which checked <code>WHERE photo IS NOT NULL</code> (which took 3hours+) but I changed this query to check the <code>id</code> column as it is a primary key. I expected a huge performance gain there and was expecting an answer in under a second but that seems to not be the case.</p>
  
  <p>What sort of optimizations on the database do I need to do? I think the query is fine but feel free to correct me if I am wrong.</p>
  
  <p>Edit: mysql Ver 14.14 Distrib 5.1.52, for redhat-linux-gnu (x86_64) using readline 5.1</p>
  
  <p>P.S: I renamed the tables for some crazy reason. I don't actually have the database named db and the table in question named table.</p>