索引是提高查询效率,目的是防止全表扫描,
索引会降低 修改 插入 数据的效率
对于开始说的,频繁查询和频繁插入数据,数据量很大采用读写分离。只是频繁查询大数据,你用分区,加索引就可以了。索引影响插入效率不会很大。
很多大系统处理这种情况,一般采用方式是读写分离解决这种情况
一.普通索引 这是最基本的索引,它没有任何限制 index
1. create index t_hash_name on t_hash(name(10));
二.唯一索引 unique index (组合索引是 列值必须是唯一)
1. create unique index t_hash_name_unique on t_hash(name);
三. 组合索引
1. ....t_hash(id,name)
2. 查询一 select * from t_hash where id=1 and name='zz' 用到索引
查询二 select * from t_hash where id=1 用到索引
查询三 select * from t_hash where name='zz' 没用到索引
MySQL组合索引为“最左前缀”的结果,简单的理解就是只从最左面的开始组合。
mysql 索引
最新推荐文章于 2023-07-30 16:45:49 发布