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 

原文地址:https://www.cnblogs.com/firstdream/p/7732522.html