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.
優(yōu)化select .. where 的查詢語句 产捞,第一步應(yīng)該檢查是否添加了索引。在 where 從句的列中添加索引可以令求值栓始,過濾离赫,和對最終結(jié)果的檢索加速遣疯。為了避免磁盤的浪費(fèi),構(gòu)造一小個索引的集合 可以使你應(yīng)用中相關(guān)查詢加速。
- 最左最左匹配
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”.