MySQL_前缀索引_建立
-- 查看出現(xiàn)頻率
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位,性能顯著提高
轉(zhuǎn)載于:https://www.cnblogs.com/MarchThree/p/4622197.html
總結(jié)
以上是生活随笔為你收集整理的MySQL_前缀索引_建立的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell中的小括号与大括号
- 下一篇: MYSQL数据库学习十七 日志管理