MySQL query is very slow. Count (*) in the indexed column

The table is in the InnoDB table. Here is some information that may be helpful.

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> 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)

Requesting an explanation gives me the result right there. But the actual query works for quite a while. How can i fix this? What am I doing wrong?

I basically need to figure out how much photosis in this table. Initially, the source encoder had a request that checked WHERE photo IS NOT NULL(which took 3 hours +), but I changed this request to check the column id, since it is the primary key. I expected a huge performance boost and expected a response in less than a second, but it doesn't seem like it.

? , , , .

: mysql Ver 14.14 5.1.52 redhat-linux-gnu (x86_64) readline 5.1

P.S: - . db table.

+5
1

? ?

MyISAM , , COUNT (*) .

InnoDB, , -: InnoDB , , , COUNT (*), . , .

EDIT: COUNT(ID) COUNT(*), ID - , NULL. .

EDIT2: longblob, , .

:

  • MyISAM InnoDB.
  • , , .
  • , , .
+9

All Articles