论坛首页 入门技术论坛

Jsp页面,结果集分页和sql(top)分页的性能对比

浏览 1819 次
该帖已经被评为新手帖
作者 正文
   发表时间:2009-10-31   最后修改:2009-10-31
jsp页面两种分页模式:

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

          
   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


论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics