Mysql Improve paging efficiency _mysql

Source: Internet
Author: User

The following is the test code for increasing the efficiency of paging when large data volumes are shared.

--Improve paging efficiency: When you implement paging, read only the display data, you need to create the database in the database "testforpaging" use testforpaging go--Create a table somedata the creation tables Somedata (ID int Prima Ry key, name varchar (a) null, description text) Go-inserts data insert into Somedata values (1, ' num1 ', ' 1th ') go inserts into Som Edata values (2, ' num2 ', ' 2nd ') go inserts into the Somedata values (3, ' num3 ', ' 3rd ') go inserts into Somedata values (4, ' num4 ', ' 4th ') Go insert to Somedata values (5, ' NUM5 ', ' 5th ') go--Total number of data entries select COUNT (*) from Somedata go-Add a data level select name to each record, Description,row_number () over (order by id DESC) as Datalevel from Somedata go--View data entry between specified data levels select Datalevel,name,desc Ription from (select Name,description,row_number () over (order by id DESC) as Datalevel from Somedata) as Datawithleverl wh  Ere datalevel between 2 and 4 go--A stored procedure that enables you to view data entries between specified data levels, CREATE PROCEDURE getdatapaged (@startRowIndex int, @maximumRows  int, @sort varchar) AS--ensures that sort if Len (@sort) =0 Set @sort = ' id '--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 D
 Atalevel <= (@startRowIndex *10 + @maximumRows) go

The above is the entire content of this article, I hope to help you learn.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.