How to increase the paging speed by using the average speed paging method in ASP

Source: Internet
Author: User

Average Speed Paging Method
I. Applicability
The average speed paging method is mainly applicable to ASP + ACCESS applications with fixed sorting methods such as article systems and news systems.
Ii. Features
Many people who have used some article systems or news systems know that a general article system or news system usually reads sorted data that meets the conditions in the database in the case of classification paging, then, based on the request page number, point to a piece of data through the positioning operation, and start to read several pieces of data after this piece of data as a page. This paging method is simple in principle, but the problem is that you need to read the data after sorting that meets the conditions in the database every time. If there are two thousand pieces of data, this is fine, what if there are 20 thousand? It indicates that this will occupy a large amount of memory and waste a lot of server resources. Of course, if there are conditions, you can use the SQL database, so it is much easier to do, and all the solutions will be done with a little stored procedure. However, many friends may still use the ACCESS database, so there is no way. Of course, there are some programs that generate HTML by page, just like many download sites. Have you ever thought about the problem? If I add a record at one time in the background, I have to re-generate HTML for all the pages in this category. This is for sure. Think about it, isn't it very efficient.
The average speed paging method is designed to solve the paging of a large amount of data in the ACCESS database. It has the advantages of HTML paging and traditional ADO paging. First, the program speed is the same, regardless of whether you are on the first page or on the 100th page. When adding data, you do not have to regenerate all pages. I will introduce the principles below
Iii. Paging Principle
There is an article table and a class table in the database. We do not consider whether it is an infinitely or two-level classification. This is irrelevant to us.
[Article] id int IDENTITY (1, 1) not null, classid int default 0, title varchar (100), addtime datetime
[Class] id int IDENTITY (1, 1) not null, classname varchar (20)
1. Generate pages
If one row of data in the class table is id 1 and classname is "ASP Classification", we first extract all the data with classid = 1 in all articles, then sort by addtime in ascending order, which is the same as normal ADO, but we need to do some processing below.
We dynamically generate a table in the database named [page_1]. 1 indicates the ID of the corresponding classname as "ASP classification.
[Page_1] pagenum int, pagestr text
We first generate a str for every 20 pieces of data. each str is actually a list of the 20 databases displayed, and then a number XXX for this str. If it is 0-19 records, then XXX is 001, 20-39, XXX is 002, and so on. Add str and its number to page_1. Assume that the maximum value is 84.
You will surely think that the data cannot always be divided into 19 (20 data should be mod 19). Of course, we have to deal with the problem, these headers should be the latest data (we sort by addtime. Let's create a dynamic table, [aritcle_1]
[Article_1] id int IDENTITY (1, 1) not null, artid int, classid int default 0, title varchar (100), addtime datetime
Add the extra zero-header data to this table.
2. Data Display
The number of records that define pagecount as [page_1]
There are two possible cases:
(1) If article_1 does not have a record (there is no zero-header data)
Page 1 is
Page 2:
Page 3 is 80, 79
......
Page N is: pagecount-(2 * N-2), pagecount-(2 * N-2)-1
(2) If article_1 has a record (with a null header)
Page 1: Call article_1 data, 84
Page 2
......
Page N is: pagecount-(2 * N-3), pagecount-(2 * N-3)-1
Note: The numbers 84,83 and so on are the corresponding str number XXX in page_1.
Speaking of this, you may understand that the principle of the average speed paging method is actually to divide the page, and directly splice the page when paging. This is more resource-saving than calling data directly from the database and then paging each time.
At the same time, it can be noted that you can save the str as HTML without creating a page_1 table, and then read and splice the HTML page during paging.
3. Add data
In traditional HTML pagination, after adding new data, all HTML pagination must be regenerated once. This is not required in the average speed paging method. We have already set that only 20 records are displayed on each small page. Therefore, only up to 19 records can be saved in the article_1 table. We add a new record and add it to article_1 at the same time. If the data in article_1 has exceeded 19, we will generate a str for the data, add the number and save it in [page_1]. Of course, if you generate HTML, you can generate an HTML directly. If the data in Article 1 has not exceeded 19, you don't need to worry about it.
Iv. Comparison between average speed paging and traditional Paging
I used a database with two thousand pieces of data for testing. In the XP system, the average speed of paging is 50 MS under the P3 1G, M memory hardware conditions, the speed of normal ADO paging is between 85 MS and 20-35 MS. It can be seen that the average speed paging method is good in terms of speed and stability.
Of course, when the database is small, this advantage may not be obvious, or it may be faster to use ADO paging, but if the page contains 20 thousand pieces of data, the average speed of the average speed paging method is half that of the normal ADO paging method.
Of course, the average speed paging method also has its own shortcomings. For example, the program complexity is higher than the traditional paging method, and the performance is inferior to ADO when the database is few.
5. last note:
This article mainly introduces the principle of the average speed paging method. It is feasible for me to spend one night using a program for practice. But I mainly read str After generating HTML, which is a little different from saving str in the database described in this article, but the principle is the same.
If you have the conditions to use SQL database, we recommend that you use stored procedures to accelerate paging.
If you have any questions, contact me at 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.