Loading

MySQL索引日常使用

EXPLAIN

SQL分析工具
image


EXPLAIN
SELECT
	* 
FROM
	invitation_assist_flow 
WHERE 
	  seller_id = 1
	AND activity_id = 1
	AND marketing_type = 1 
	AND new_user_id = 1 
	AND new_user_mobile = '1' 
	AND old_user_id = 1 
	AND old_user_mobile = '1'

分析:
image
可能使用了五种索引,涉及到2条数据,当涉及的数量大于75%左右时(自己用少数量测试)过多时,此时就会全表查,索引就会失效

说明:
id : 该SQL的唯一标识

select_type: 查询类型

  • simple:简单查询,常用于单表
  • primary:复杂查询中最外层的select
  • subquery: 包含在select中的子查询
  • derived:包含在from中的子查询,派生表
  • union:在union中的第二个和随后的select
  • union result:从union临时表检索结果的select

table: 表名

type: 联接类型 system > const > eq_ref > ref > range > index > ALL

  • null
  • const
  • system
  • eq_ref
  • ref
  • range
  • index
  • ALL

possible_keys: 可能的索引

key: 实际使用索引

key_len: 索引的长度

ref: 索引的哪一列被引用

rows: 估计扫描的行

filtered: 标识符合查询条件的数据百分比

Extra: 附加信息

  • Using index
  • Using where
  • Using where Using index
  • null
  • Using index condition
  • Using temporary
  • Using filesort
posted @ 2022-07-07 17:24  mainwoodの慢屋  阅读(25)  评论(0编辑  收藏  举报