多种存储过程分页方法的速度对比
来源:互联网 发布:全世界失眠 知乎 编辑:程序博客网 时间:2024/06/05 04:58
四.SubQuery
There are 2 more methods I’ve taken into consideration, and they come from different resources. The first one is well known triple query or the SubQuery
method. The most thorough approach is the one I’ve found in the following article
http://www.winnetmag.com/Article/ArticleID/40505/40505.html
Although you'll need to be subscribed, a .zip file with the SubQuery
stored procedure variations is available. The Listing_04.SELECT_WITH_PAGINGStoredProcedure.txt file contains the complete generalized dynamic SQL. I used a similar generalization logic with all other stored procedures in this text. Here is the principle followed by the link to the whole procedure (I shortened the original code a bit, because a recordcount portion was unnecessary for my testing purposes).
SELECT ... FROMTableWHERE PK IN (SELECTTOP @PageSize PK FROMTableWHERE PK NOTIN (SELECTTOP @StartRow PK FROMTableORDERBY SortColumn) ORDERBY SortColumn)ORDERBY SortColumn
五.Cursor(游标)
I’ve found the last method while browsing through the Google groups, you can find the original thread here. This method uses a server-side dynamic cursor. A lot of people tend to avoid cursors, they usually have poor performance because of their non-relational, sequential nature. The thing is that paging IS a sequential task and whatever method you use you have to somehow reach the starting row. In all the previous methods this is done by selecting all rows preceding the starting row plus the desired rows and then discarding all the preceding rows. Dynamic cursor has the FETCH RELATIVE
option which does the “magic” jump. The base logic goes like this
DECLARE @PK /* PK Type */DECLARE @tblPK TABLE ( PK /* PK Type */NOTNULLPRIMARYKEY)DECLARE PagingCursor CURSOR DYNAMIC READ_ONLY FORSELECT @PK FROMTableORDERBY SortColumnOPEN PagingCursorFETCH RELATIVE @StartRow FROM PagingCursor INTO @PKWHILE @PageSize > 0AND @@FETCH_STATUS = 0BEGININSERT @tblPK(PK) VALUES(@PK) FETCH NEXT FROM PagingCursor INTO @PK SET @PageSize = @PageSize - 1ENDCLOSE PagingCursorDEALLOCATE PagingCursorSELECT ... FROMTableJOIN @tblPK temp ONTable.PK = temp.PK
ORDERBY SortColumn
- 多种存储过程分页方法的速度对比
- 多种存储过程分页方法的速度对比
- 多种存储过程分页方法的速度对比
- 存储过程的分页方法
- 很强的分页存储过程,速度超快!
- 很强的分页存储过程,速度超快!
- 邹建的分页存储过程,呵呵速度不错啊~!
- 【转载】Sql Server2005不同分页存储过程的性能对比
- 这个存储过程执行的速度还不错.500W速度分页只要2秒
- 分页的存储过程
- 分页的存储过程
- 分页的存储过程
- 分页的存储过程
- 分页的存储过程
- 分页的存储过程
- 分页的存储过程
- 存储过程的分页!!
- 分页的存储过程
- Spring声明式事务管理、Spring整合Hibernate
- 多种存储过程分页方法的速度对比
- C#操作Word完全功略!
- WinCE USB驱动架构及术语明析
- AIR2 Betal版可以下载了flash player10.1可以下载了
- 多种存储过程分页方法的速度对比
- 《JS语法字典》
- c#操作word
- C++建立多级文件目录
- 多种存储过程分页方法的速度对比
- SQl 实现动态交叉表查询
- 开始学习qt
- Flex学习--Object&&String
- asp.net中怎样写Log文件?