Sql server 就缓存中的内容以及给定用户想要读取的内容而言,冷读将成为一个相对常见的用例,并且非常重要。至少,就销售和最初的客户感知而言,冷读可能很重要,除非你的init特别升温。在大型集成作业将对缓存造成压力的场景中,冷读可能会更频繁地发生。 DBCC DROPCLE

Sql server 就缓存中的内容以及给定用户想要读取的内容而言,冷读将成为一个相对常见的用例,并且非常重要。至少,就销售和最初的客户感知而言,冷读可能很重要,除非你的init特别升温。在大型集成作业将对缓存造成压力的场景中,冷读可能会更频繁地发生。 DBCC DROPCLE,sql-server,performance,tsql,pagination,Sql Server,Performance,Tsql,Pagination,就缓存中的内容以及给定用户想要读取的内容而言,冷读将成为一个相对常见的用例,并且非常重要。至少,就销售和最初的客户感知而言,冷读可能很重要,除非你的init特别升温。在大型集成作业将对缓存造成压力的场景中,冷读可能会更频繁地发生。 DBCC DROPCLEANBUFFERS; DBCC FREEPROCCACHE; DECLARE @Page_Size int; DECLARE @Page_Number int; DECLARE @Lower_Bound int; DECLARE @Uppe

就缓存中的内容以及给定用户想要读取的内容而言,冷读将成为一个相对常见的用例,并且非常重要。至少,就销售和最初的客户感知而言,冷读可能很重要,除非你的init特别升温。在大型集成作业将对缓存造成压力的场景中,冷读可能会更频繁地发生。
DBCC DROPCLEANBUFFERS; 
DBCC FREEPROCCACHE;

DECLARE @Page_Size int;
DECLARE @Page_Number int;
DECLARE @Lower_Bound int;
DECLARE @Upper_Bound int;

SET @Page_Size = 30;
SET @Page_Number = 30000;
SET @Lower_Bound = (@Page_Number - 1) * @Page_Size;
--SET @Upper_Bound = @Page_Number * @Page_Size;


WITH Customers AS--(Row_Numbr, Record_Id, First_Name, 
        Middle_Name, Last_Name, Email, Telephone) AS 
(

    SELECT ROW_NUMBER() 
        OVER 
         (ORDER BY Account.Customer.Record_Id) AS Row_Numbr, * 
    FROM Account.Customer 
)

SELECT top(@Page_Size) * 
FROM Customers 
WHERE Row_Numbr > @Lower_Bound-- 
    AND Row_Numbr <= @Upper_Bound -- This is suppose to be faster
--SELECT * FROM Customers 
--WHERE Row_Numbr > @Lower_Bound  
--   AND Row_Numbr <= @Upper_Bound
/* moving up */
SELECT top(@Page_Size) * 
FROM Account.Customer  
WHERE Record_Id > @lastPageRecordId
ORDER BY Record_Id;

/* moving down */
SELECT top(@Page_Size) * 
FROM Account.Customer  
WHERE Record_Id < @firstPageRecordId
ORDER BY Record_Id DESC;
CREATE PROCEDURE sp_PagedItems
    (
     @Page int,
     @RecsPerPage int
    )
AS

-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON


--Create a temporary table
CREATE TABLE #TempItems
(
    ID int IDENTITY,
    Name varchar(50),
    Price currency
)


-- Insert the rows from tblItems into the temp. table
INSERT INTO #TempItems (Name, Price)
SELECT Name,Price FROM tblItem ORDER BY Price

-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
       MoreRecords =
    (
     SELECT COUNT(*)
     FROM #TempItems TI
     WHERE TI.ID >= @LastRec
    )
FROM #TempItems
WHERE ID > @FirstRec AND ID < @LastRec


-- Turn NOCOUNT back OFF
SET NOCOUNT OFF