So why not just create two indexes, one on last_name
and one on first_name
? You could do that, but MySQL won’t use them both at the same time. In fact, MySQL will only ever use one index per table per query—except for UNION
s.[3] This fact is important enough to say again: MySQL will only ever use one index per table per query.
那是因为,mysql通常一次查询只能使用一个索引,这是由B+树的结构决定的。而不是我们自以为的建两条单列的索引就能起到叠加的效果。MySQL will only ever use one index per table per query!!!!!