首页 > 数据库技术 > 详细

MySQL创建复合索引

时间:2016-01-29 20:32:37      阅读:209      评论:0      收藏:0      [点我收藏+]

在MySQL数据库中,创建复合索引的时候,不知道在创建过程中哪个列在前面,哪个列该在后面,用以下方式即可:


select count(distinct first_name)/count(*) as first_name_selectivity,
count(distinct last_name)/count(*) as last_name_selectivity,
count(*)
from actor\G


mysql> select count(distinct first_name)/count(*) as first_name_selectivity,
    -> count(distinct last_name)/count(*) as last_name_selectivity,
    -> count(*)
    -> from actor\G
*************************** 1. row ***************************
first_name_selectivity: 0.6400
 last_name_selectivity: 0.6050
              count(*): 200
1 row in set (0.01 sec)


first_name_selectivity: 0.6400,因此 first_name 列的选择性更高,所以答案将其作为索引列的第一列:

mysql> alter table yoon add key (first_name,last_name);

MySQL创建复合索引

原文:http://www.cnblogs.com/hankyoon/p/5169635.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!