我有很多这样的查询...
SELECT colA, colB, colC, colD FROM table1
LEFT JOIN (
SELECT colD FROM table2 WHERE colE = 3225
) AS subquery
ON colD = colA ;
在我的服务器的“log-queries-not-using-indexes”日志中列出。
解释看起来像这样......
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
---+-------------+------------+-------+---------------+---------+---------+------+------+-------------
1 | PRIMARY | table1 | range | PRIMARY | PRIMARY | 3 | NULL | 58 | Using where
1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 1 |
2 | DERIVED | table2 | const | PRIMARY | PRIMARY | 3 | | 1 |
有什么办法可以重组查询,或者我应该添加任何新的索引来改进它?
仅供参考,表格的结构是这样的......
CREATE TABLE `table1` (
`colA` MEDIUMINT( 9 ) NOT NULL ,
`colB` VARCHAR( 100 ) DEFAULT NULL ,
`colC` VARCHAR( 6 ) DEFAULT NULL ,
some more columns removed to simplify things...
PRIMARY KEY ( `colA` ) ,
KEY `colB` ( `colB` ) ,
KEY `colC` ( `colC` )
) ENGINE = MYISAM DEFAULT CHARSET = latin1 ;
CREATE TABLE `table2` (
`colE` mediumint( 9 ) NOT NULL auto_increment ,
`colD` mediumint( 9 ) default '0',
some more columns removed to simplify things...
PRIMARY KEY ( `colE` ) ,
KEY `colD` ( `colD` )
) ENGINE = MyISAM DEFAULT CHARSET = latin1 ;
提前致谢,
你的
菲尔