MySQL创建复合索引
2016-01-29 10:28
501 查看
在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);
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 SHOW 语句大全
- Kill 所有MySQL进程
- MySQL 简洁连接数据库方式
- MySQL复制
- MySQL Server-id的作用
- mysql无法创建数据库
- MYSQL 配置slave故障
- mysql 配置主从
- MYSQL-查看数据库或表的大小
- MYSQL-给带特殊符号的数据库创建用…
- MYSQL创建多张表,相同表结构,不…
- mysql笔记
- Mysql Binlog快速遍历搜索记录及binlog数据查看的方法
- 使用YUM安装MySQL 5.5
- mysql-5.6.23-winx64.zip版本安装记录
- MySql的存储过程
- MYSQL绿色安装
- 修复./mysql/proc
- MySQL 5.6.24 for Windows 解压缩版配置安装
- MySQL页面访问统计及排名情况