MYSQL数据库索引请教
安静写代码 2016-08-12 11:48:41 今天突然和同事聊到数据库索引的问题,突然发现虽然经常提到但是好像知之甚少,发帖请教:
场景如下:
数据库表: testA
字段:D1,B2,N3
索引1:D1_Index
索引2:B2_Index
索引4:D1_B2_Index
以下几句SQL执行时,是否会用到索引,使用的哪个索引?
1、select D1 from testA
2、select N3 from testA
3、select D1,N3 from testA
4、select D1,B2,N3 from testA
5、select D1 from testA where B2 ='xxx'
6、select N3 from testA where B2 ='xxx'
7、select D1,B2,N3 from testA where B2 ='xxx'
如果有一个SQL(S)查询中包含两个子查询 (S1、S2),S1与S2子查询单独执行时,可以使用索引索引,在执行S时,S1与S2的索引还会生效么?