加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

三种分页

发布时间:2020-12-12 15:18:39 所属栏目:MsSql教程 来源:网络整理
导读:比较了3种分页方式,分别是max方案,top方案,row方案 效率: ? 第1:row ? 第2:max ? 第3:top 缺点: ? max:必须用户编写复杂Sql,不支持非唯一列排序 ? top:必须用户编写复杂Sql,不支持复合主键 ? row:不支持sqlServer2000 测试数据: 共 320万 条数

比较了3种分页方式,分别是max方案,top方案,row方案

效率:
? 第1:row
? 第2:max
? 第3:top

缺点:
? max:必须用户编写复杂Sql,不支持非唯一列排序
? top:必须用户编写复杂Sql,不支持复合主键
? row:不支持sqlServer2000

测试数据:
320万条数据,每页显示10条数据,分别测试了2万页、15万页和32万页。

页码,top方案max方案row方案
2万,60ms46ms33ms
15万,453ms343ms310ms
32万,953ms720ms686ms


具体操作sql代码如下:

top方案:

SQL code
   
   
    
    
    
    select
    
     
    
    top
    
     
    
    10
    
     
    
    *
    
     
    
    from
    
     Table1 
    
    where
    
     Id 
    
    not
    
     
    
    in
    
    (
    
    select
    
     
    
    top
    
     开始的位置 Id 
    
    from
    
     Table1)
   
   


max:

SQL code
   
   
    
    
    
    select
    
     
    
    top
    
     
    
    10
    
     
    
    *
    
     
    
    from
    
     Table1 
    
    where
    
     Id
    
    >
    
    (
    
    select
    
     
    
    max
    
    (Id) 
    
    from
    
     (
    
    select
    
     
    
    top
    
     开始位置 Id 
    
    from
    
     Table1order 
    
    by
    
     Id)tt)
   
   


row:

SQL code
   
   
    
    
    
    select
    
     
    
    *
    
     
    
    from
    
     
    
    ( 
    
    select
    
     row_number()
    
    over
    
    (
    
    order
    
     
    
    by
    
     tempColumn)tempRowNumber,
    
    *
    
     
    
    from
    
     (
    
    select
    
     
    
    top
    
     开始位置
    
    +
    
    10
    
     tempColumn
    
    =
    
    0
    
    ,
    
    *
    
     
    
    from
    
     Table1)t )tt 
    
    where
    
     tempRowNumber
    
    >
    
    开始位置
   
   

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读