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”.