zoukankan      html  css  js  c++  java
  • mysql数据库优化之 如何选择合适的列建立索引

    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 表名

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

  • 相关阅读:
    php面向对象开发的学习
    我的php感悟
    说说面向对象
    session,上传文件
    PHP构造函数的用法分析
    生成图片
    上传文件
    fetch
    ajax2
    ajax1
  • 原文地址:https://www.cnblogs.com/lty-fly/p/9291275.html
Copyright © 2011-2022 走看看