zoukankan      html  css  js  c++  java
  • sql分页性能测试结果

    --方案一:

    declare @d datetime
    set @d = getdate()
    select top 10 * from Info where ID not in (select top 9990 ID from Info order by ID) order by ID 
    select [not in方法升序分页执行花费时间(毫秒)]=datediff(ms,@d,getdate()) --430ms

    --方案二:

    declare @s datetime
    set @s = getdate()
    select top 10 * from info where ID >=(select max(ID) from (select top 9991 ID from info order by ID) as T) order by ID
    select [Max方法升序分页执行花费时间(毫秒)]=datediff(ms,@s,getdate()) --13ms


    --方案三:

    declare @q datetime
    set @q = getdate()
    select top 10 * from Info where ID <=(select min(ID) from (select top 9991 ID from Info order by ID desc) as T) order by ID desc
    select [Min方法降序分页执行花费时间(毫秒)]=datediff(ms,@q,getdate())--10ms

    --方案四:

    declare @r datetime
    set @r = getdate()
    select top 10 * from 
    ( 
    select row_number()over( order by id desc) as rowNumber,* from info
    
    ) T
    where T.rowNumber>0 
    select [row_number()方法降序分页执行花费时间(毫秒)]=datediff(ms,@r,getdate())--3ms

    --方案五:

    with infos as
    (
    select r.*, row_number()over(order by r.id desc) as r 
    from [Info]  r
    ) 
    select * from infos where r between 1 and 30;

    方案五没有采取top的形式取数据,而是用了between,相同点都用了row_number()函数。根据平常的分页习惯,方案四、五效率最高,且性能相当.

  • 相关阅读:
    字符编码
    mahout 使用
    cloudera Manager使用总结
    HDFS 操作命令总结
    基于hive的日志分析系统
    hive 中的正则表达式
    hadoop 用户
    Java中设置classpath、path、JAVA_HOME的作用
    排序
    动手动脑
  • 原文地址:https://www.cnblogs.com/paulhe/p/3499920.html
Copyright © 2011-2022 走看看