Can MySQL use multiple indexes for a single query?

后端 未结 4 2001
[愿得一人]
[愿得一人] 2020-12-02 09:32

Imagine a table with multiple columns, say, id, a, b, c, d, e. I usually select by id, however, there are multiple queries in the client app that u

4条回答
  •  被撕碎了的回忆
    2020-12-02 09:52

    • Each SELECT in a query -- think UNION, subquery, derived table, etc -- is optimized separately. That is each might use different indexes.
    • One SELECT can use multiple indexes in what it calls "index merge". This is rarely used.
    • When the EXPLAIN says it is using Index merge (intersect), then it can almost always be improved by using a composite index containing the columns used by the intersected indexes.
    • Index merge (union) is sometimes (rarely) used for an OR. Such can perhaps be improved by rewriting the query to be the UNION of two SELECTs.

提交回复
热议问题