sql性能优化 mysql

这里我只举例单表的性能优化

看了几篇文章总结出来,最好的方法是建立索引,索引就像一本字典的目录,能够快速的找到你想找的东西

索引分三种:

1、单值索引

      create index 索引名 on 表名(字段名)

      alter table 表名 add index 索引名(字段名)

2、唯一索引

      create unique index 索引名 on 表名(字段名)

      alter table 表名 add unique index 索引名(字段名)

3、复合索引

      create index 索引名 on 表名(字段1,字段2,...)

      alter table 表名 add index 索引名(字段名1,字段2,...)

索引的优点很明显,select的时候速度很快,但是索引又会占内存/硬盘;

缺点是少量的数据量和频繁更新的字段去使用索引效率低

猜你喜欢

转载自blog.csdn.net/obitosbb/article/details/115111205
今日推荐