To make a slow SELECT ... WHERE
query faster, the first thing to check is whether you can add an index. Set up indexes on columns used in the WHERE
clause, to speed up evaluation, filtering, and the final retrieval of results. To avoid wasted disk space, construct a small set of indexes that speed up many related queries used in your application.
優化select .. where 的查詢語句 ,第一步應該檢查是否添加了索引。在 where 從句的列中添加索引可以令求值,過濾,和對最終結果的檢索加速。為了避免磁盤的浪費,構造一小個索引的集合 可以使你應用中相關查詢加速。
- 最左最左匹配
If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to look up rows. For example, if you have a three-column index on(col1, col2, col3), you have indexed search capabilities on(col1),(col1, col2), and(col1, col2, col3). For more information, see Section 9.3.5, “Multiple-Column Indexes”.