mssqlserver分页2种方法,很多人都选择了最差的一种
2013-01-30 18:24
344 查看
mssqlserver优化分页2种方法详细比较
1,测试条件: 写一个JDBC链接数据库的方法,执行查询;测试数据 1000 条;
采用存储过程procedure;
2,存储过程procedure:
-------------------> 分页-1代码
create procedure pro_page
@pagecont int,
@pageon int
as
select top(@pagecont) id,zifu from test_1 where id not in (select top(@pagecont*@pageon) id from test_1);
go
exec pro_page 10,4;
------------------------> 分页-2代码
create procedure pro_pages
@pagecont int,
@pageon int
as
select top(@pagecont) * from test_1
where (id > (select MAX(id) from (select top(@pagecont*@pageon) id from test_1 order by id) AS T)) order by ID
go
exec pro_pages 10,4;
3,测试结果:
分页-2经过测试无论显示第几页的数据效率都是一样在1-2s就显示出来。
分页-1经过测试当分页值越大就越慢,在得到第一页需要1-2s,如果显示第99页是大约1M才显示出来,如果数据更多瓶颈就更严重。
可以看出2种分页效率差距之大,但是很多人在分页时都用的方法-1。
4,纯sql语句分页:
A. select top(10) * from test_1 where id not in (select top(10*?) id from test_1);
B. select top(10) * from test_1 where (id > (select MAX(id) from (select top(10*?) id from test_1 order by id) AS T)) order by ID");
执行效率B>A, 当A分页数越大时效率就越差,B无论页数是多少效率都一样
注意:测试数据数量要足够多,100页以上。
相关文章推荐
- 79 1.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法?
- 一种页面jsp分页方法
- 优化分页系统的一种方法
- 怎样编写一个程序,把一个有序整数数组放到二叉树中? 编写实现链表排序的一种算法。说明为什么你会选择用这样的方法?
- 一种处理分页控件和绑定数据方法
- 在大数据情况下MySQL的一种简单分页优化方法
- 一种有效的关系数据库压缩方法 选择自 l1t 的 Blog
- GridView 始终显示 Pager 分页行的一种方法
- 一种Playfair密码变种加密方法如下:首先选择一个密钥单词(称为pair)(字母不重复,且都为小写字母),然后与字母表中其他字母一起填入至一个5x5的方阵中,填入方法如下1.首先按行填入密钥串。2
- 一种struts分页方法
- mybaties实现分页的一种方法
- 比较高效的一种分页方法
- 一种struts分页方法
- 一种简单方法实现页面导出(Excel)功能 选择自 xieyun1977 的 Blog
- 一种理论上最快的Web数据库分页方法
- 一种Playfair密码变种加密方法如下:首先选择一个密钥单词(称为pair)(字母不重复,且都为小写字母),然后与字母表中其他字母一起填入至一个5x5的方阵中,填入方法如下:
- aspnetpager的2种分页方法
- Web开发中一种用sql语句完成分页的高效率方法(1)
- 【转自csdn】Web开发中一种用sql语句完成分页的高效率方法,以jsp/asp为例
- 对于想用OS但又觉得单片机资源太过紧张,状态机是个不错的选择---分享一种状态机设计方法