On MySQL, the index Merge function is added, and two indexes can be used for one SQL statement.
The following is an example:
- Mysql> select * from t;
- + ------ +
- | A | B |
- + ------ +
- | 1 | 24 |
- | 4 | 1 |
- | 1 | 20 |
- | 4 | 26 |
- | 5 | 10 |
- | 4 | 13 |
- | 1 | 11 |
- | 2 | 15 |
- | 3 | 27 |
- | 1 | 25 |
- | 4 | 10 |
- | 2 | 21 |
- | 3 | 4 |
- | 2 | 1 |
- | 2 | 4 |
- | 5 | 5 |
- | 1 | 27 |
- | 2 | 16 |
- | 5 | 17 |
- | 2 | 30 |
- | 5 | 14 |
- | 4 | 1 |
- | 5 | 26 |
- | 3 | 14 |
- | 1 | 21 |
- | 3 | 2 |
- | 1 | 30 |
- | 5 | 6 |
- | 2 | 13 |
- | 5 | 4 |
- | 1 | 21 |
- | 2 | 27 |
- | 2 | 14 |
- | 4 | 26 |
- | 2 | 10 |
- | 3 | 14 |
- | 5 | 23 |
- | 2 | 12 |
- | 5 | 7 |
- | 3 | 25 |
- + ------ +
- 40 rows in set (0.02 sec)
Let's take a look at the performance of MySQL5.5:
Indexes cannot be used. After optimization, only one index can be used.
Let's look at the performance on 5.6:
The two indexes are used together and the index merging method is adopted.
Reference manual: