SQL语句及索引的优化

mysql优化(二)

mysql优化(二)

explain分析sql语句

mysql优化(二)

MySQL中explain的type类型

|  ALL              |  全表扫描

|  index            |  索引全扫描

|  range            |  索引范围扫描,常用语<,<=,>=,between等操作

|  ref                |  使用非唯一索引扫描或唯一索引前缀扫描,返回单条记录,常出现在关联查询中

|  eq_ref           |  类似ref,区别在于使用的是唯一索引,使用主键的关联查询

|  const/system  |  单条记录,系统会把匹配行中的其他列作为常数处理,如主键或唯一索引查询

|  null                |  MySQL不访问任何表或索引,直接返回结果

 

####由上至下,效率越来越高

https://www.cnblogs.com/xuanzhi201111/p/4175635.html(mysql explain 字段详情)

mysql优化(二)

mysql优化(二)

mysql优化(二)

mysql优化(二)

Count()和Max()的优化

mysql优化(二)

mysql优化(二)

注意:(1)在使用count(*)和count(id)时可能统计数是不一样的,因为count(id)查询的不包含值为null的情况,count(*)则包含值为null的情况。

在使用Max()时,对查询的字段加上索引能够提高查询效率。

子查询的优化

mysql优化(二)

Group by子句的优化

mysql优化(二)

mysql优化(二)

Limit查询优化

mysql优化(二)

mysql优化(二)

mysql优化(二)

如何选择合适的列做索引

mysql优化(二)

索引的维护及优化

mysql优化(二)

mysql优化(二)

mysql优化(二)

mysql优化(二)

 

 

相关文章:

  • 2022-12-23
  • 2021-06-27
  • 2021-09-19
  • 2021-07-31
  • 2021-12-14
  • 2021-07-01
  • 2022-02-08
  • 2022-02-15
猜你喜欢
  • 2021-09-25
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-12-25
  • 2021-11-27
相关资源
相似解决方案