MySQL_前缀索引_建立
生活随笔
收集整理的這篇文章主要介紹了
MySQL_前缀索引_建立
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
-- 查看出現頻率
select count(*) as cnt,city
from sakila.city_demo group by city order by cnt desc limit 10;
1.select count(distinct city)/count(*) from sakila.city_demo;
*完整列的選擇性
2. select count(distinct left(city,3))/count(*) as sel3 ,
count(distinct left(city,4))/count(*) as sel4 ,
count(distinct left(city,5))/count(*) as sel5 ,
count(distinct left(city,6))/count(*) as sel6 ,
count(distinct left(city,7))/count(*) as sel7
from sakila.city_demo;
*前綴輸出越貼近 1 輸出,性能越高
3. alter table sakilal.city_demo add key (city(7));
使用場景:
16進制唯一ID使用前綴索引。 通常使用前8位,性能顯著提高
轉載于:https://www.cnblogs.com/MarchThree/p/4622197.html
總結
以上是生活随笔為你收集整理的MySQL_前缀索引_建立的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell中的小括号与大括号
- 下一篇: MYSQL数据库学习十七 日志管理