首页 > 数据库 >数据库性能优化调优

数据库性能优化调优

时间:2024-04-10 09:58:23浏览次数:16  
标签:优化 数据库 number 索引 调优 子句 where id select

0,创建的时候分库分表。表大小超过一定范围如2G

1,主键顺序插入,性能好于乱序插入。推荐使用自增。

2,合理索引设计,

  降低主键长度。

  在查询时,创建列的索引,然后查询用索引列升序降序查询。

  分页查询limit,最好覆盖索引。

  部分查询条件会使其索引失效,导致全盘扫描:

  •   where子句中使用!=或<>操作符
  •   where子句中使用or来连接条件,那么将引擎放弃使用索引而进行全表扫描。    如: select id from twhere number=30 or number=40    优化为selectid from t where number=30 union all select id from t where number=40
  •   in和not in 也要慎用,如: selectid from t where number in(12.3)对于连续的数值,能用 between就不要用in 了: selectid fron t where number between 1 and 3
  •   在like匹配时候使用双%:select id from t where name like ‘%abc%
  •   如果在where子句中使用参数
  •   应尽量避免在where子句中对字段进行表达式操作      如: select id fron t where num/2=100应改为: sectid fom t where num=100*2
  •   在where子句中对字段进行函数操作
  •   在where子句中对字段进行null值判断

标签:优化,数据库,number,索引,调优,子句,where,id,select
From: https://www.cnblogs.com/bky-wang/p/18125371

相关文章