Mysql复合索引

当索引由多个字段组成时,称为复合索引或组合索引。当where谓词条件包含非等值匹配的操作时,如>,< ,!= 等,索引中此字段之后的谓词条件将不会使用索引。

例如:索引abc_ck由字段(a,b,c)组成。谓词条件为where a=‘aaa’ and b>100 and c=‘ccc’

此查询a,b字段可以使用到索引,c字段无法使用索引。

在表emps的(gender,birth_date,first_name)字段上创建一个组合索引

mysql> create index gbn_ck on emps(gender,birth_date,first_name); Query OK, 0 rows affected (2.18 sec) Records: 0 Duplicates: 0 Warnings: 0