# 复合索引 (B)

+ 减小开销: 建一个复合索引 `(col1,col2,col3)`, 相当于建了三个索引: `(col1)`, `(col1,col2)`, `(col1,col2,col3)` 
+ 可以有效使用索引的场景 (I)
+ 部分使用索引的场景 (II)
+ 不能使用索引的场景 (III)
```
(I)
select * from t2 where c1 between 1 and 20;
select * from t2 where c1 = 3 and c2 > 5 and c2 < 10;
select * from t2 where c1 = 1 and c2 = 10 and c3 between 1 and 200;

(II)
select * from t2 where c1 between 1 and 20 and c2 = 100; -- (col1)
select * from t2 where c1 = 3 and c2 > 5 and c2 < 10 and c3 = 100; -- (col1, col2)

(III)
select * from t2 where c2 = 20 and c3 = 100;
select * from t2 where c3 = 100;
```
-------------------------------------------------------------
[no notes]