哪个复合索引会使这个简单的 MySQL 查询更快,我将如何创建该复合索引?
SELECT *
FROM `Table1`
WHERE `col1` = '145307'
AND `col2` = '0'
AND col3 NOT
IN ( 130209, 130839 )
ORDER BY col4 DESC
LIMIT 0 , 5
col1
上面的每一列 ( to col4
)上已经有一个单独的索引。
编辑:
结果SHOW CREATE TABLE
:
CREATE TABLE `Table1` (
`primaryCol` int(11) NOT NULL AUTO_INCREMENT,
`col3` int(11) DEFAULT '0',
`col5` varchar(20) COLLATE utf8_bin DEFAULT NULL,
`col1` int(11) DEFAULT '0',
`col6` varchar(80) COLLATE utf8_bin DEFAULT NULL,
`col7` text CHARACTER SET utf8,
`col4` int(11) DEFAULT '0',
`col8` char(1) COLLATE utf8_bin DEFAULT 'N',
`col9` char(1) COLLATE utf8_bin DEFAULT 'N',
`col2` tinyint(1) NOT NULL,
`col10` tinyint(1) NOT NULL,
`col11` smallint(6) NOT NULL,
PRIMARY KEY (`primaryCol`),
KEY `col5` (`col5`),
KEY `col1` (`col1`),
KEY `col3` (`col3`),
KEY `col4` (`col4`),
KEY `col8` (`col8`),
KEY `col9` (`col9`),
KEY `CompIndex1` (`col1`,`col8`,`col4`),
KEY `col2` (`col2`),
KEY `col10` (`col10`),
KEY `col11` (`col11`),
FULLTEXT KEY `col7` (`col7`)
) ENGINE=MyISAM AUTO_INCREMENT=4575350 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
结果EXPLAIN EXTENDED
:
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE Table1 ref col1,col3,CompIndex1,col2 CompIndex1 5 const 226 100 Using where; Using filesort