createtable`test1`(`id`int(11)notnull,`name`char(11),`age`int(11),`del_flag`varchar(22),primarykey(id,age))COLLATE='utf8_bin'ENGINE=InnoDB;1、EXPLAINSELECT id,name FROM test1 WHERE id =1//可以看出使用的是索引================================================================1SIMPLE test1 ref PRIMARYPRIMARY4 const 1100.002、EXPLAINSELECT id,name FROM test1 WHERE age =20//此处并没有走索引=======================================================1SIMPLE test1 ALL333.33Usingwhere3、EXPLAINSELECT id,name FROM test1 WHERE id =1or age =12//or会使索引失效==========================================================1SIMPLE test1 ALLPRIMARY366.67Usingwhere4、EXPLAINSELECT id,name FROM test1 WHERE id =1and age =12//此处走了索引============================================================1SIMPLE test1 const PRIMARYPRIMARY8 const,const 1100.00