如何选择合适的列建立索引
1.在where从句,group by 从句,order by 从句中,on 从句中出现的列 2.索引字段越小越好 3.离散度大的列放到联合索引的前面 eg: select * from table where staff_id = 2 and customer_id = 588; 是index(staff_id,customer_id) 好? 还是 index(customer_id,staff_id)好? **判断谁的离散度大,如何判断?** select count(distinct customer_id),count(distinct staff_id) from table; **谁的值大就在创建索引的时候,把那个字段放在前面**