• ROW_NUMBER() 分页


    听说用ROW_NUMBER()分页100W条数据翻页只要2-3秒,有时间测试下

    --NORTHWND.MDF库
    DECLARE @pagenum AS INT@pagesize AS INT
    SET @pagenum = 2
    SET @pagesize = 3
    SELECT *
    FROM (SELECT ROW_NUMBER() OVER(ORDER BY EmployeeID DESCAS RowNum, 
            
    *
          
    FROM Employees) AS Employees
    WHERE RowNum BETWEEN (@pagenum-1)*@pagesize+1 AND @pagenum*@pagesize
    ORDER BY EmployeeID DESC

    2009年7月3日 23:30:20 测试
    CREATE procedure [dbo].[p_test] 
    @startIndex int,
    @endIndex int,
    @docount bit,
    @strwhere varchar(20)
    as

    if(@docount=1)
    select count(id) from tb_testtable
    else

    begin
     
    SET @strwhere = CHAR(34+ CHAR(42+ @strwhere + CHAR(42+ CHAR(34);
     
    with temptbl as (SELECT ROW_NUMBER() OVER (ORDER BY id desc)AS Row, * from tb_testtable where CONTAINS(*@strwhere))
     
    SELECT * FROM temptbl where Row between @startIndex and @endIndex
    end

    全文索引(模糊搜索)测试,共五百万条数据,耗时436毫秒。
    begin 
    set nocount on
    declare @timediff datetime 
    select @timediff=Getdate() 

    select count(id) as 总行数 from tb_testtable
    exec P_test @startIndex=1,@endIndex=20,@docount=0,@strwhere='爱情'

    select datediff(ms,@timediff,GetDate()) as 耗时 
    set nocount off
    end

    /*

    总行数         
    ----------- 
    5000001

    id          userName             userText                      
    ----------- -------------------- -----------------------------
    5080        admin                人们争执不休的爱情道理只是些没

    耗时          
    ----------- 
    446

    */
  • 相关阅读:
    javascript中replace()
    防止IE6出现BUG的十种常见解决方法
    IE6 重复字符的bug
    IE6 BUG大全
    display:inline
    JavaScript 图片上传预览效果
    用一行代码让w3wp进程崩溃,如何查找w3wp进程崩溃的原因
    近期学习任务
    气死我的存储过程和用户定义函数
    Damn,China Mobile!!!!
  • 原文地址:https://www.cnblogs.com/LCX/p/1508381.html
Copyright © 2020-2023  润新知