当前位置:Gxlcms > 数据库问题 > mysql前缀索引的应用

mysql前缀索引的应用

时间:2021-07-01 10:21:17 帮助过:27人阅读

在mysql中有时需要索引的列很长,如果直接应用索引会造成索引过大的问题。因此我们可以取其中一部分字段来做索引,例:

添加索引:alter table * add key (field(3));    //field索引字段, 3索引字符数

 

但是我们怎样确定取多长的字符数的为最合理的索引长度:

通过:select count(field)/count(*) from table;语句获取选择率,

然后:select count(distinct left(field, n))/count(*) from table

通过此条语句适配出最为合理的n。

 

mysql前缀索引的应用

标签:tin   需要   bsp   前缀   ble   lte   count   sel   索引   

人气教程排行