使用结果集(ResultSet.absolute((2000)) )和 sql(top)分页的性能对比

sp页面两种分页模式: 

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

   ResultSet rs=stmt.executeQuery(sql);
		ResultSetMetaData md=rs.getMetaData();
		 
		rs.beforeFirst();			
		rs.absolute((2000);			
		}		
		int ii=0;  
		while(rs.next() &&ii<=20 )
		{	
                   rs.getString("xxx");
                   ii++;
                 }

第二种: 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 


转载自:http://sunnodbird.iteye.com/blog/507641

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值