1. 在where 从句,group by 从句,order by 从句,on 从句中出现的列;

2. 索引字段越小越好;

3. 离散度大的列放到联合索引的前面;比如:

    select * from payment where staff_id = 2 and customer_id = 236;

    针对上面的查询是  index(sftaff_id, customer_id) 好?还是index(customer_id, staff_id)好?

    因为customer_id的离散度更大,因此用后面的更合适!!

那么问题来了。怎么判断离散度呢,可以使用 select count(distinct customer_id), count(distinct staff_id) from 表名

谁的值大,说明这一些列的离散度更高!

相关文章:

  • 2021-09-27
  • 2022-12-23
  • 2021-03-26
  • 2021-12-10
  • 2021-10-20
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2019-09-06
  • 2021-11-28
  • 2022-01-22
  • 2021-12-13
  • 2021-12-09
  • 2021-12-14
相关资源
相似解决方案