zoukankan      html  css  js  c++  java
  • 2500万测试

    2500万条数据测试
    select count(id) as total from content where status=1;
      49秒钟,cpu暴涨
    select id from content where status=1;
      30秒钟左右
    select count(id) as total from content where status=1 and sort=1 and ifphoto = 1 and ifattr=1
      48秒钟,cpu暴涨20%
    select id as total from content where status=1 and sort=1 and ifphoto = 1 and ifattr=1 limit 100000,100
      14秒钟,cpu暴涨20%
    
      分页4种处理方法
      这样考虑的于是就有了下面四个优化的建议来提高性能
    首次查询的时候缓存结果。这样情况就变得简单了,无论是结果条目的数量,总共的页面数量,还是取出其中的部分条目。
    不显示总共有多少条目。Google搜索结果的分页显示就用了这个特性。很多时候你可能看了前几页,就够了。那么我可以这样,每次我都把结果限制在500条(这个数据越大 资源消耗越大)然后你每次查询的时候,都查询501条记录,这样,如果结果真有501个,那么我们就显示链接 “显示下500条记录”。
    不显示总页面数。只给出“下一页”的链接,如果有下一页的话。(如果用户想看上一页的话,他会通过浏览器来回到上一页的)。那你可能会问我“不显示总页面数”怎么知道是不是有下一页呢?这里有一个很好的小技巧:你在每次显示你当前页面条目的时候你都多查询一条,例如你要显示第11-20个条目时,你就取出11-21条记录(多取一条,并不显示这多取的内容),那么当你发现第21条存在的时候就显示“下一页的链接”,否则就是末页了。这样你就不用每次计算总页面数量了,特别是在做缓存很困难的时候这样做效率非常好。
    估算总结果数。Google就是这么做的,事实证明效果很好。用EXPLAIN 来解释你的SQL,然后通过EXPLAIN的结果来估算。EXPLAIN结果有一列”row”会给你一个大概的结果。(这个办法不是处处都行,但是某些地方效果是很好的)这些办法可以很大程度上减轻数据库的压力,而且对用户体验不会有什么影响。
      这些办法可以很大程度上减轻数据库的压力,而且对用户体验不会有什么影响。
      
    select count(id) as total from content where status=1 and sort=1 and ifphoto = 1 and ifattr=1 and id>100000 and id<100100
      0秒钟
    select id as total from content where status=1 and id>100000 and id<100100
      0秒钟
    select id as total from content where status=1 and ifphoto =1 and  id>100000 and id<100100
      0秒
    select * from content where status=1 and ifphoto =1 and  id>100000 and id<100100
      0秒
    select * from content where status=1 and ifphoto =1 and id>100000 and id<100100 order by ifphoto desc
      0秒
    select t.*,c.* from content as c join type as t where t.typeid = c.typeid and t.typeid = 1 and c.id>1000000 and c.id < 1001000 order by c.id desc
      0秒
    
    select * from content where id=2300000
      0秒
    select t.*,c.* from content as c join type as t where t.typeid = c.typeid and t.typeid = 1
      49秒
    select t.*,c.* from content as c join type as t where t.typeid = c.typeid and t.typeid = 1 order by c.id desc limit 100000,1000
      3秒
    select id from content order by id desc limit 1
      0秒
      
    between 介与两个已知值之间的值 select id from tb where price between 10 and 50
    in  符合给定列举值的那些值 select phone_num from tb where state IN ('北京','上海')
    做总数估算explain select * from content 
      0秒
    查看当前的数据量show table status like 'content';
    

      

  • 相关阅读:
    操作系统丶并发并行和线程
    网络基础补充,断点续传,以及如何添加进度条
    python小游戏之贪吃蛇
    python2和3的区别丶网络编程以及socketserver多线程
    面向对象之套接字(socket)和黏包
    面向对象多继承和网络编程
    约束,自定义异常,加密,日志
    方法和函数,isinstance/issubclass/type以及反射
    面向对象之组合的补充,主动调用其他类的成员,特殊成员
    关于卡尔曼滤波和粒子滤波最直白的解释
  • 原文地址:https://www.cnblogs.com/wangzong/p/3249829.html
Copyright © 2011-2022 走看看