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!!!!!