数据库的优化方向:查询优化、索引优化、库表结构优化要齐头并进

第六章 查询性能优化

1.步骤 (1)检查是否像数据库请求了不必要的数据 * 检查查询是否查询了不需要的记录,加limit进行限定。 * 总是取出全部的列 总是取出全部列,会让优化器无法完成索引覆盖扫描这类优化,还会为 服务器带来额外的IO、内存和CPU的消耗。 总是取出全部列有如下两种经典案例: 多表关联取出全部列: select * from tablea innerjoin tableb on tablea.id=tableb.aid 可以改为: select column1,column2,column3,... from tablea innerjoin tableb on tablea.id=tableb.aid 或: select tablea.* from tablea innerjoin tableb on tablea.id=tableb.aid 单表查出全部列: select * from tablea 改为: select column1,column2,column3,...from tablea (2)检查查询是否