分页SQL语句的性能比较

数据量暂时在10来万,排序字段是几个索引里面的一个索引的二级索引
第一方案是比较传统的,
第二方案用了表变量,有说数据量大的时候应该用临时表,不知道这个量要多少。
感觉。。

DECLARE @pagesize int DECLARE @pageindex int DECLARE @docount bit DECLARE @this_id INT SET @this_id =114 SET @docount =3 SET @pagesize =10 set @pageindex =11983 –select count() from wn_pARTSnEWS where NEWSCLASSid=@this_id –where NEWSCLASSid=@this_id –方案一BEGIN select TOP 10 from wn_partsNews where partsNewsId not in (SELECT TOP 119830 PARTSNEWSID FROM WN_PARTSNEWS ORDER BY ADDTIME DESC )ORDER BY ADDTIME DESC END –方案二begin declare @indextable table (id int identity (1 ,1 ),nid int )
declare @PageLowerBound int declare @PageUpperBound int set @PageLowerBound =(@pageindex -1 )@pagesize –开始set @PageUpperBound =@PageLowerBound +@pagesize –结束set rowcount @PageUpperBound insert into @indextable (nid)select PARTSNEWSid from WN_PartsNews order by ADDTIME desc select a.from WN_PartsNews a,@indextable t where a.PARTSNEWSID =t.nid and t.id >@PageLowerBound and t.id

分页SQL语句的性能比较

Original: https://www.cnblogs.com/Blackie/archive/2008/07/01/1232809.html
Author: Blackie
Title: 分页SQL语句的性能比较

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/685415/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球