Home > Database > Mysql Tutorial > body text

MySQL improves data paging efficiency

黄舟
Release: 2017-02-20 11:48:31
Original
1257 people have browsed it

[Introduction] This code of mine is a test code to improve the efficiency of paging when there is a large amount of data--Improving the efficiency of paging: only reading the display data when implementing paging, you need to first create a database "TestForPaging" in the database use TestForPaginggo- -Create table SomeDatacreate table SomeData(id int

My code is a test code to improve the efficiency of paging when there is a large amount of data
--Improve paging efficiency: only read the display data when implementing paging, You need to first create the database "TestForPaging" in the database

use TestForPaging
go
Copy after login

--Create table SomeData

create table SomeData
(
id int primary key,
name varchar(30) null,
description text
)
go
Copy after login

--Insert data

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
Copy after login

-- Total number of data entries

select count(*) from SomeData
go
Copy after login

--Add a data level to each record

select name,description,ROW_NUMBER() over(order by id desc)as dataLevel from SomeData
go
Copy after login

--View data entries between specified data levels

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
Copy after login

--Implements the stored procedure for viewing data entries between specified data levels

create procedure GetDataPaged
(
@startRowIndex int,
@maximumRows int,
@sort varchar
)
AS
Copy after login

--Ensures that sort

if len(@sort)=0
set @sort='id'
Copy after login

--Query with parameters

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
Copy after login

The above is the content of MySQL to improve data paging efficiency. For more related content, please pay attention to the PHP Chinese website (www.php.cn)


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template