简单的MySQL查询太慢了

时间:2014-01-22 18:08:09

标签: mysql performance

我在MySQL 5.5 InnoDB中有一个1000万的记录表。它运行在具有良好CPU和快速HD的16GB RAM服务器中。当我运行以下查询

SELECT DISTINCT knowledge_id, 
                tag_order, 
                tag_weight, 
                total_title_direct_words, 
                total_title_parenthesis_words, 
                tag_level 
FROM   knowledge_tags 
WHERE  ( tag_text = 'washington' ) 
       AND ( tag_level < 10 ); 

本地大约需要9秒(首次运行)(localhost)。结果计数为640.字段'tag_text,tag_level'有一个Btree索引。我想要的查询时间是不可接受的。我该怎么办?

以下是EXPLAIN结果:

1   SIMPLE  knowledge_tags  range   tags_by_word_text   tags_by_word_text   308 [null]  344 Using index condition; Using temporary

CREATE TABLE语句:

CREATE TABLE `knowledge_tags` (
  `tag_id` int(11) NOT NULL AUTO_INCREMENT,
  `knowledge_id` int(11) DEFAULT NULL,
  `dictionary_word_id` int(11) DEFAULT NULL,
  `tag_text` varchar(100) DEFAULT NULL,
  `tag_order` int(11) DEFAULT NULL,
  `tag_level` int(11) DEFAULT NULL,
  `knowledge_family_id` int(11) DEFAULT NULL,
  `tag_weight` double DEFAULT '1',
  `total_title_direct_words` int(11) DEFAULT NULL,
  `total_title_parenthesis_words` int(11) DEFAULT NULL,
  PRIMARY KEY (`tag_id`),
  KEY `tags_by_knowledge_id` (`knowledge_id`),
  KEY `tags_by_word_text` (`tag_text`,`tag_level`) USING BTREE,
  KEY `tags_by_family_dictionary` (`knowledge_family_id`,`dictionary_word_id`,`tag_level`) USING BTREE,
  KEY `tags_by_family_word_text` (`knowledge_family_id`,`tag_text`,`tag_level`) USING BTREE,
  KEY `tags_by_dictionary` (`dictionary_word_id`,`tag_level`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3316 DEFAULT CHARSET=utf8;

0 个答案:

没有答案