Consider the following table and its indexes:
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
Why is the following query slow to run if there is an index (fullMonitorFeedSearch) which covers it? BTW, if the 'interactio0_.TYPE = 2' is removed, the sql runs in 0.01 secs.
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
This is the explain for the 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 | +----+-------------+--------------+-------+--------------------------------------------------------------------------+-----------------------+---------+------+---------+-------------+