SELECT*FROM test WHERE last_name ='Doe'; SELECT*FROM test WHERE last_name ='Doe'AND first_name ='John'; SELECT*FROM test WHERE last_name ='Doe'AND (first_name ='John'OR first_name ='Jane'); SELECT*FROM test WHERE last_name ='Doe'AND first_name >='M'AND first_name <'N';
而这些查询就无法使用这个索引:
1 2
SELECT*FROM test WHERE first_name ='John'; SELECT*FROM test WHERE last_name ='Doe'OR first_name ='John';
MySQL can use multiple-column indexes for queries that test all the columns in the index, or queries that test just the first column, the first two columns, the first three columns, and so on. If you specify the columns in the right order in the index definition, a single composite index can speed up several kinds of queries on the same table.