我有一个查询没有使用正确的索引或根本没有任何索引的问题。
这是我的表创建
CREATE TABLE `data` (
`data_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`other_id` int(10) unsigned NOT NULL,
`author_text` varchar(255) DEFAULT NULL,
`sometext` text NOT NULL,
`somehash` char(32) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`longurl` varchar(255) NOT NULL,
`published` int(11) NOT NULL,
`language` varchar(3) DEFAULT NULL,
`level` enum('-1','0','1','2') CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT '2',
`day` int(11) NOT NULL,
`processed` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`data_id`),
UNIQUE KEY `unique_url` (`other_id`,`somehash`),
KEY `processed` (`processed`),
KEY `language` (`day`,`language`)
) ENGINE=MyISAM AUTO_INCREMENT=2576573 DEFAULT CHARSET=utf8
查询
SELECT COUNT( * ) AS `num` , `data`.`language` AS `language`
FROM `data`
WHERE `data`.`author_text` LIKE '%test%'
AND `data`.`day`
BETWEEN '1364342400'
AND '1372118399'
GROUP BY `data`.`language`
ORDER BY `data`.`language` ASC
解释
id|select_type|table|type|possible_keys|key |key_len|ref |rows |Extra
--|-----------|-----|----|-------------|----|-------|----|-------|--------------------------------------------
1 |SIMPLE |data |ALL |language |NULL|NULL |NULL|2563731|Using where; Using temporary; Using filesort