Using the mean-speed paging method to improve paging speed in ASP

Source: Internet
Author: User
Tags datetime html page access database
Paging | Speed average Rate Paging method

I. Scope of APPLICATION
The mean-speed paging method is mainly applied to the asp+access application of the article system, the news system and other sorting methods.

Second, the characteristics of the description
Many people who have used some article systems or news systems know that general article system or news system, in the classification of pages, usually by reading the database in order to meet the criteria of the sorted data, and then according to the request page number, through the positioning operation, point to a piece of data, and start reading the data after a number of data as a page. This method of paging, the principle of simple, but the problem is that every time the database needs to meet the conditions of the sorting data are read out, if there are 2000 data, this is OK, if there are 20,000? Shows that this consumes a lot of memory and wastes many server resources. Of course, if there are conditions, you can use the SQL database, so that much better, with a little stored procedures are all resolved. But maybe a lot of friends are still using the Access database, so there's no way. Of course, there are some programs are the page to generate HTML, like a lot of download sites, have you ever thought about what will happen to the problem? If I add one record at a time in the background, then I have to regenerate all of the pages in this category once again HTML, that's for sure, think about it, so the efficiency is not very poor.
The mean-speed paging method is designed to solve the problem of paging through a large amount of data in an Access database. It has the advantage of both HTML paging and traditional ADO paging. One is the speed, the use of less resources, whether you are the first page or the 100th page, the program speed are the same. And when you add data, you don't have to regenerate all the paging. Let me introduce the principle

Three, the principle of paging
The database has a article table, a class table, we do not consider whether the infinite class or two-level classification, this has nothing to do with us.
[Article] ID int IDENTITY (1, 1) not NULL, ClassID int default 0, title varchar (MB), Addtime datetime
[Class] ID int IDENTITY (1, 1) not NULL, classname varchar (20)

1, raw Ingredients page
If there is one row of data in the class table that is ID 1,classname as "ASP Classification", we first take all the classid=1 data from all article and then sort by addtime in ascending order, which is the same as the normal ADO facet, but We'll do some processing here.
We dynamically generate a table in the database, named [page_1],1 is the corresponding classname for the "ASP category" ID autonumber.
[Page_1] Pagenum int, pagestr text

We first generate a str per 20 data, each str is actually displayed when the list of these 20 databases, and then for this str numbered XXX, if it is 0-19 records, then XXX is 001, if it is 20-39,xxx is 002, and so on. Add STR and its number to the page_1. Here we assume the biggest is 84.

You would think that the data could not always be divisible by 19 (20 data should be mod 19), of course, we have to deal with the fraction, which should be the latest data (we are by Addtime) arranged. We then dynamically build a table, [Aritcle_1]
[article_1] ID int IDENTITY (1, 1) not NULL, ArtID int, ClassID int default 0, title varchar (MB), Addtime datetime
Add the extra data to the table.


2, the data display
Defines the number of records that PageCount is [page_1]

We have two different situations.
(1) If Article_1 is not recorded (no fraction data)
The first page is 84,83.
The second page is 82,81
The third page is 80,79.
......
Nth page: pagecount-(2*n-2), pagecount-(2*n-2)-1

(2) If Article_1 is recorded (with a fraction of data)
First page, call Article_1 's data, 84
Page two, 83,82
......
Nth page: pagecount-(2*n-3), pagecount-(2*n-3)-1

Description: 84, 83 and so on these numbers, is in the page_1, your corresponding str number XXX

Speaking of here may be more understand, the principle of the average rate paging is actually the original page, in the page when the page is directly splicing. This is more resource-saving than paging the data directly from the database each time you page.
At the same time, it can be explained that you can not create a page_1 table, and these str saved as HTML, and then read the page out of the HTML page for stitching.

3, the addition of data
In traditional HTML paging, once you add new data, you need to regenerate all of the HTML paging, which is not necessary in the mean-speed paging method. We have previously set each small page to display only 20 records, then the Article_1 table, only save up to 19 records. We added a new record, and then add that record to the article_1, and if the data in Article_1 is already over 19, generate a str, add the number, and save it in [Page_1], and of course, if you're using HTML generated, You can generate an HTML directly. If the data in the article_1 is no more than 19, then don't worry about it.


Four, the average speed paging method and the traditional page comparison
I tested it with a database of 2000 data, under the XP system, the P3 1g,256m memory hardware condition, uses the average speed paging method mean velocity in 50MS, positive and negative does not surpass 10MS, uses the ordinary ADO paging, the speed in 85MS, positive and negative in 20-35ms, visible uses the average speed paging method, It's good for both speed and stability.

Of course, in the case of a small database, such advantages may not be obvious, or may use ADO paging faster, but if the 20,000 data in the paging, the average speed of the paging method is half the ordinary ADO page.

Of course, the average speed paging method has its own shortcomings, such as the complexity of the program than the traditional paging to the high, in the database less performance than ADO.


V. Final NOTE:
This paper mainly introduces a principle of the average speed paging method, I spent a night using the program to practice, is feasible. But my main idea is to read the HTML after the STR, which is a little different from the database that is described in this article, but the principle is the same.

If you have a condition for using a SQL database, I recommend that you use a stored procedure to speed up paging.


If you have any questions, you can communicate with me in http://www.showc.com/



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.