明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

MySQL如何提高數(shù)據(jù)分頁(yè)效率

[摘要][導(dǎo)讀] 我的這段代碼是大數(shù)據(jù)量時(shí)提高分頁(yè)的效率的測(cè)試代碼--提高分頁(yè)效率:實(shí)現(xiàn)分頁(yè)時(shí)只讀取顯示數(shù)據(jù),需要先在數(shù)據(jù)庫(kù)創(chuàng)建數(shù)據(jù)庫(kù)“TestForPaging”use TestForPaginggo--創(chuàng)建表SomeDatacreate table SomeData(id int我的這段代碼是大數(shù)據(jù)量...
[導(dǎo)讀] 我的這段代碼是大數(shù)據(jù)量時(shí)提高分頁(yè)的效率的測(cè)試代碼--提高分頁(yè)效率:實(shí)現(xiàn)分頁(yè)時(shí)只讀取顯示數(shù)據(jù),需要先在數(shù)據(jù)庫(kù)創(chuàng)建數(shù)據(jù)庫(kù)“TestForPaging”use TestForPaginggo--創(chuàng)建表SomeDatacreate table SomeData(id int

我的這段代碼是大數(shù)據(jù)量時(shí)提高分頁(yè)的效率的測(cè)試代碼
--提高分頁(yè)效率:實(shí)現(xiàn)分頁(yè)時(shí)只讀取顯示數(shù)據(jù),需要先在數(shù)據(jù)庫(kù)創(chuàng)建數(shù)據(jù)庫(kù)“TestForPaging”
use TestForPaging
go
--創(chuàng)建表SomeData
create table SomeData
(
id int primary key,
name varchar(30) null,
description text
)
go
--插入數(shù)據(jù)
insert into SomeData values(1,'num1','第1條')
go
insert into SomeData values(2,'num2','第2條')
go
insert into SomeData values(3,'num3','第3條')
go
insert into SomeData values(4,'num4','第4條')
go
insert into SomeData values(5,'num5','第5條')
go
--數(shù)據(jù)條目總數(shù)
select count(*) from SomeData
go
--給每條記錄添加一個(gè)數(shù)據(jù)級(jí)別
select name,description,ROW_NUMBER() over(order by id desc)as dataLevel from SomeData
go

--查看指定的數(shù)據(jù)級(jí)別間的數(shù)據(jù)條目
select dataLevel,name,description from
(select name,description,row_number() over(order by id desc)as dataLevel from SomeData)
as datawithleverl where dataLevel between 2 and 4
go
--實(shí)現(xiàn)查看指定的數(shù)據(jù)級(jí)別間的數(shù)據(jù)條目的存儲(chǔ)過(guò)程
create procedure GetDataPaged
(
@startRowIndex int,
@maximumRows int,
@sort varchar
)
AS
--確保指定sort
if len(@sort)=0
set @sort='id'
--帶參數(shù)的查詢
select dataLevel,name,description from
(select name,description,row_number() over(order by @sort desc)as dataLevel from SomeData) AS datawithleverl
WHERE dataLevel > (@startRowIndex*10) AND dataLevel <= (@startRowIndex*10 + @maximumRows)
go

以上就是 MySQL如何提高數(shù)據(jù)分頁(yè)效率的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!


學(xué)習(xí)教程快速掌握從入門到精通的SQL知識(shí)。