MySQL提数据高分页效率代码
作者:[网上资料 ]
我的这段代码是大数据量时提高分页的效率的测试代码--提高分页效率:实现分页时只读取显示数据,需要先在数据库创建数据库“TestForPaging”use TestForPaginggo--创建表SomeDatacreate table SomeData(id int primary key,name varchar(30) null,description text)go--插入数据insert into SomeData values(1,'num1','第1条')goinsert into SomeData values(2,'num2','第2条')goinsert into SomeData values(3,'num3','第3条')goinsert into SomeData values(4,'num4','第4条')goinsert into SomeData values(5,'num5','第5条')go--数据条目总数select count(*) from SomeDatago--给每条记录添加一个数据级别select name,description,ROW_NUMBER() over(order by id desc)as dataLevel from SomeDatago
--查看指定的数据级别间的数据条目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 4go--实现查看指定的数据级别间的数据条目的存储过程create procedure GetDataPaged(@startRowIndex int,@maximumRows int,@sort varchar)AS--确保指定sortif len(@sort)=0set @sort='id'--带参数的查询select dataLevel,name,description from(select name,description,row_number() over(order by @sort desc)as dataLevel from SomeData) AS datawithleverlWHERE dataLeve
|
--查看指定的数据级别间的数据条目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 4go--实现查看指定的数据级别间的数据条目的存储过程create procedure GetDataPaged(@startRowIndex int,@maximumRows int,@sort varchar)AS--确保指定sortif len(@sort)=0set @sort='id'--带参数的查询select dataLevel,name,description from(select name,description,row_number() over(order by @sort desc)as dataLevel from SomeData) AS datawithleverlWHERE dataLeve
|