Рассмотрим следующую таблицу и ее индексы:
CREATE TABLE 'Interaction' (
'oid' bigint(20) NOT NULL,
'archieved' datetime DEFAULT NULL,
'content' longtext COLLATE utf8_bin,
'contentSentiment' int(11) DEFAULT NULL,
'createdAt' datetime DEFAULT NULL,
'id' varchar(255) COLLATE utf8_bin DEFAULT NULL,
'interactionSource' longtext COLLATE utf8_bin,
'link' varchar(255) COLLATE utf8_bin DEFAULT NULL,
'source' varchar(255) COLLATE utf8_bin DEFAULT NULL,
'title' varchar(255) COLLATE utf8_bin DEFAULT NULL,
'type' int(11) DEFAULT NULL,
'authorKloutScore' int(11) DEFAULT NULL,
PRIMARY KEY ('oid'),
KEY 'createdAt' ('createdAt'),
KEY 'fullMonitorFeedSearch' ('criteria_oid','createdAt','authorKloutScore','archieved','type')
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
Почему следующий запрос выполняется медленно, если существует индекс (fullMonitorFeedSearch), который его покрывает? Кстати, если 'interactio0_.TYPE = 2' удален, sql запускается через 0,01 с.
SELECT interactio0_.oid
FROM Interaction interactio0_
WHERE interactio0_.criteria_oid = 21751021
AND interactio0_.createdat = 10
AND interactio0_.archieved IS NULL
AND interactio0_.TYPE = 2
ORDER BY interactio0_.createdat DESC
Это объяснение для sql:
+----+-------------+--------------+-------+--------------------------------------------------------------------------+-----------------------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+-------+--------------------------------------------------------------------------+-----------------------+---------+------+---------+-------------+
| 1 | SIMPLE | interactio0_ | range | FKD15475F24AA96F7,createdAt,fullMonitorFeedSearch | fullMonitorFeedSearch | 18 | NULL | 2323027 | Using where |
+----+-------------+--------------+-------+--------------------------------------------------------------------------+-----------------------+---------+------+---------+-------------+