CREATE TABLE zichaxuntest
(
a
int(11) NOT NULL,
b
varchar(255) DEFAULT NULL,
c
varchar(255) DEFAULT NULL,
d
varchar(255) DEFAULT NULL,
PRIMARY KEY (a
),
KEY bIndex
(b
) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
实验1
SELECT a,b,c from (SELECT a,b,c FROM zichaxunTest
) gg where gg.b =1;
EXPLAIN SELECT a,b,c from (SELECT a,b,c FROM zichaxunTest
) gg where gg.a =1;
实验2
EXPLAIN SELECT a,b,c from (SELECT a,b,c FROM zichaxunTest
where b =2 ) gg where gg.b =1;
EXPLAIN SELECT a,b,c from (SELECT a,b,c FROM zichaxunTest
where b =2) gg where gg.a =1;
总结: 5.7.21-log 版本 , windows ,
外层有主键索引的话,走索引,否则不走