MySQL优化

MySQL优化,第1张

MySQL优化

1.重复数据删除

关联删除:删除id更大的重复数据

delete t1 from table t1,table t2 where 1=1 and t1.id > t2.id and t1.name=t2.name;

2.count(*) count(id) count(1)新版MySQL效率一致

3.分页优化

当id连续:select * from student limit 1,3;

优化:

select * from student where id > 3 limit 3;

4.大数据量中查看某个数据是否存在

count(*) + where 来判断

优化:

select id from student where address=1 limit 1;

5.联合索引,遵循最左原则

在ABC列建立了联合索引,那么A,AB,ABC都可以使用到这个索引

*尽量不要再索引列计算 否则索引会失效

6.like模糊查询%..%会使索引失效

7.大数据量表分割

水平分割,按照时间等分割

垂直分割,频繁查询的列单独为一张表,其他列为一张表

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5706346.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存