zoukankan      html  css  js  c++  java
  • Jsp页面,结果集分页和sql(top)分页的性能对比

    jsp页面两种分页模式: 

    第一种: 结果集分页,主要代码见下面: 

              

    Java代码  收藏代码
    1.  ResultSet rs=stmt.executeQuery(sql);  
    2. ResultSetMetaData md=rs.getMetaData();  
    3.    
    4. rs.beforeFirst();             
    5. rs.absolute((2000);           
    6. }         
    7. int ii=0;    
    8. while(rs.next() &&ii<=20 )  
    9. {     
    10.                  rs.getString("xxx");  
    11.                  ii++;  
    12.                }  



    第二种: sql语句分页 

            sql=“selec top 20 id,name from table where id not in(select top 2000 id from table )”; 



    对这两种分页做了测试,在400万条数据的情况下,两者性能几乎一样,相差不大。大概速度在30秒左右。 

    测试数据(每页20条): 
    sql分页 

    页数     时间                                         用时 
    2--test2 starttime=Mon Oct 26 16:24:35 CST 2009 
    2--test2 endtime=Mon Oct 26 16:25:09 CST 2009          34 

    200--test2 starttime=Mon Oct 26 16:25:48 CST 2009 
    200--test2   endtime=Mon Oct 26 16:26:21 CST 2009     33 

    20000--test2 starttime=Mon Oct 26 16:27:04 CST 2009 
    20000--test2   endtime=Mon Oct 26 16:27:39 CST 2009   35 

    210000--test2 starttime=Mon Oct 26 16:28:22 CST 2009 
    210000--test2   endtime=Mon Oct 26 16:29:58 CST 2009   36 


    100000--test2 starttime=Mon Oct 26 16:30:30 CST 2009 
    100000--test2 endtime=  Mon Oct 26 16:31:10 CST 2009   40 


    ---- 结果集分页 

    2--11start time Mon Oct 26 16:33:37 CST 2009 

    2---55end time Mon Oct 26  16:34:12 CST 2009       35 


    200--11start time Mon Oct 26 16:34:59 CST 2009 

    200---55end time Mon Oct 26 16:35:32 CST 2009     33 


    20000--11start time Mon Oct 26 16:36:26 CST 2009 

    20000---55end time Mon Oct 26  16:36:59 CST 2009   33 


    210000--11start time Mon Oct 26 16:38:00 CST 2009 

    210000---55end time Mon Oct 26 16:38:33 CST 2009   33 


    100000--11start time Mon Oct 26 16:39:10 CST 2009 

    100000---55end time Mon Oct 26 16:39:43 CST 2009   33 

  • 相关阅读:
    MySQL Explain详解
    sql查询:存在A表而不在B表中的数据
    mybatis处理集合、数组参数使用in查询
    mysql日期范围查找(两个日期之间的记录)
    MYSQL查询数据表中某个字段包含某个数值
    springboot+jpa分页(Pageable+Page)
    MySQL单表能存储多少条数据?
    nosql几种热门数据库的优缺点及应用场景
    MySQL百万级数据分页查询及优化
    Redis cluster群集操作
  • 原文地址:https://www.cnblogs.com/firstdream/p/7732522.html
Copyright © 2011-2022 走看看