Method and system for caching data in database
By calculating the similarity of data pages and the number of visits co-occurrences, and determining the access mode in combination with the access history, optimizing the read-out and replacement strategies of the database cache pool, the problems of low cache hit rate and hotspot data being replaced are solved, and efficient data is achieved Access and memory utilization.
Patent Information
- Application Number
- CN202411163394.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-12-10
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In application scenarios with high concurrency and real-time requirements, the problem of low cache hit rate of the database and the replacement of hotspot data affects the speed and performance of the database.
By calculating the similarity of data pages and the number of visits, the correlation of data pages is determined, and the access mode is determined based on the access history. Different read-out and replacement strategies are adopted to manage young and elderly areas in partitions, and the data of the cache pool is optimized. Loading and replacing.
Improve cache hit rate, maximize memory utilization, ensure efficient data access and query performance, reduce latency and avoid waste of memory resources.
Smart Images

Figure CN119106059A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of databases, and in particular to a method and system for caching data in a database. Background Art
[0002] The explosion of information has brought about a huge amount of data. Databases are the carriers of data storage and are becoming the core of modern information technology. They provide structured storage and management solutions for large amounts of data, ensuring the organization and consistency of data, thereby supporting efficient query, update and maintenance. Whether it is the company's customer information, transaction records, or e-commerce data, industrial data, financial data and inventory management, database systems provide reliable guarantees for the secure storage and management of these key business data.
[0003] With the explosive growth of data volume and the increase in real-time processing needs, the speed requirements for databases are also getting higher and higher. For example, the flash sales activities of e-commerce websites need to process a large number of complex queries and transactions in a very short time. Therefore, the database system must have efficient data access, storage and retrieval capabilities. Whether it is real-time transaction processing on e-commerce platforms or second-level risk analysis in financial systems, the performance of the database directly affects the response speed of the business and user experience. In application scenarios with high concurrency and high real-time requirements, the role of cache is particularly important. Through effective cache management strategies, the database can prioritize the storage of hot data in the cache, reduce latency, and improve the query hit rate. However, the low cache hit rate and the replacement of hot data seriously affect the speed of the database. Summary of the invention
[0004] In order to solve the above problem, the present invention provides a method for caching data in a database, the method comprising the following steps: Calculating the similarity of the data pages according to the similarity of the records in the data pages in the same data table, and recording the number of times the data pages are accessed simultaneously in the access to the data table, and determining the relevance of the data pages according to the similarity and the number of times; when the target data page in the buffer pool is accessed, determining the access mode of the target data page and pre-reading the data page record based on the access history of the target data page; If the target data page is located in the young area, when the access mode of the target data page is random access, the data page with a correlation with the target data page greater than a threshold is loaded into the buffer pool; when the access mode of the target data page is sequential access, the adjacent data page is loaded into the buffer pool; If the target data page is located in the old area, when the access mode of the target data page is random access, the data page located in the pre-read data page record and in the old area is replaced with the data page with the greatest correlation with the target data page; when the access mode of the target data page is sequential access, the data page located in the pre-read data page record and in the old area is replaced with the data page closest to the target data page.
[0005] Preferably, the similarity of the data pages is calculated according to the similarity of the records in the data pages in the same data table, specifically: Different weights are set for different fields in the data table, and the similarity between each record in the data page and each record in another data page is recorded based on the weights. The average value of the similarities is used as the similarity between the record and another data page, and the average value of the similarities between all records in the data page and another data page is used as the similarity between the two data pages.
[0006] Preferably, the determining the relevance of the data pages according to the similarity and the number of times is specifically: The maximum number of simultaneous accesses of two data pages in the data table is obtained, the number of simultaneous accesses of the two data pages is standardized according to the maximum number, and the similarity and the standardized simultaneous access number are weighted to obtain the correlation of the two data pages.
[0007] Preferably, the threshold is determined as follows: An initial threshold is obtained, and based on the number of times that the continuous access mode of the target data page is random access, the initial threshold is continuously reduced as the number increases, and the reduced initial threshold is used as the threshold.
[0008] Preferably, the step of loading the data page having a correlation with the target data page greater than a threshold into the buffer pool is specifically as follows: Obtain a ratio of the sizes of the young area and the old area, and divide the data pages whose correlation is greater than a threshold into two parts according to the ratio and the correlation with the target data page. The correlation of the first part is greater than that of the second part. The first part is loaded into the young area of the buffer pool, and the second part is loaded into the old area of the buffer pool.
[0009] Preferably, the step of loading the adjacent data pages into a buffer pool is specifically as follows: Obtain a ratio of the sizes of the young area to the old area, divide the adjacent data pages into two parts according to the ratio and the distance from the target data page, wherein the distance from the first part to the target data page is smaller than that of the second part, load the first part into the young area of the buffer pool, and load the second part into the old area of the buffer pool.
[0010] In another aspect, the present invention provides a data cache system in a database, the system comprising the following modules: A pattern determination module is used to calculate the similarity of data pages according to the similarity of records in data pages in the same data table, and record the number of times the data pages are accessed simultaneously in the access to the data table, and determine the relevance of the data pages according to the similarity and the number of times; when a target data page in the buffer pool is accessed, determine the access pattern of the target data page and pre-read the data page record based on the access history of the target data page; A young area data page pre-reading module, for, if the target data page is located in the young area, when the access mode of the target data page is random access, loading the data page with a correlation with the target data page greater than a threshold into the buffer pool, and when the access mode of the target data page is sequential access, loading the adjacent data page into the buffer pool; The old area data page pre-reading module is used to replace the data page located in the pre-read data page record and located in the old area with the data page with the greatest correlation with the target data page if the target data page is located in the old area and the access mode of the target data page is random access; when the access mode of the target data page is sequential access, replace the data page located in the pre-read data page record and located in the old area with the data page closest to the target data page.
[0011] Preferably, the similarity of the data pages is calculated according to the similarity of the records in the data pages in the same data table, specifically: Different weights are set for different fields in the data table, and the similarity between each record in the data page and each record in another data page is recorded based on the weights. The average value of the similarities is used as the similarity between the record and another data page, and the average value of the similarities between all records in the data page and another data page is used as the similarity between the two data pages.
[0012] Preferably, the determining the relevance of the data pages according to the similarity and the number of times is specifically: The maximum number of simultaneous accesses of two data pages in the data table is obtained, the number of simultaneous accesses of the two data pages is standardized according to the maximum number, and the similarity and the standardized simultaneous access number are weighted to obtain the correlation of the two data pages.
[0013] Preferably, the threshold is determined as follows: An initial threshold is obtained, and based on the number of times that the continuous access mode of the target data page is random access, the initial threshold is continuously reduced as the number increases, and the reduced initial threshold is used as the threshold.
[0014] Preferably, the step of loading the data page having a correlation with the target data page greater than a threshold into the buffer pool is specifically as follows: Obtain a ratio of the sizes of the young area and the old area, and divide the data pages whose correlation is greater than a threshold into two parts according to the ratio and the correlation with the target data page. The correlation of the first part is greater than that of the second part. The first part is loaded into the young area of the buffer pool, and the second part is loaded into the old area of the buffer pool.
[0015] Preferably, the step of loading the adjacent data pages into a buffer pool is specifically as follows: Obtain a ratio of the sizes of the young area to the old area, divide the adjacent data pages into two parts according to the ratio and the distance from the target data page, wherein the distance from the first part to the target data page is smaller than that of the second part, load the first part into the young area of the buffer pool, and load the second part into the old area of the buffer pool.
[0016] Finally, the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method described above is implemented.
[0017] By calculating the similarity of data pages and recording the number of co-occurrences of accesses, the system can accurately determine which data pages are highly correlated; the system dynamically identifies the access mode (sequential or random) of the target data page based on its access history, and adjusts the pre-reading strategy accordingly. In addition, the present invention adopts different pre-reading and replacement strategies for young areas (Young areas) and old areas (Old areas). The Young area focuses on fast response and hot data retention, while the Old area avoids the waste of memory resources through replacement strategies. Through this partition management, the system can maximize memory utilization while maintaining efficient cache hits. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 This is a schematic diagram of the database cache pool; Figure 2 This is a flow chart of Embodiment 1; Figure 3 This is a structural diagram of the second embodiment. DETAILED DESCRIPTION
[0019] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0020] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0021] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0022] In order to improve the data access speed in the database, prefetching technology is used. The so-called prefetching is to load the data pages related to a data page in advance when accessing the data page. The data pages loaded into the buffer pool are the data pages that may be accessed next. There are random prefetching and sequential prefetching in database prefetching. Random prefetching is to randomly select data pages related to a data page and load them into the buffer pool. Sequential prefetching is to load data pages adjacent to a data page into the buffer pool. In the database engine, the buffer pool (also called the cache pool, BufferPool) is divided into a young area (young area) and an old area (old area), such as Figure 1 As shown, generally speaking, the young area is a data page that is frequently accessed, and the old area is a data page that is not frequently accessed. Each data page includes at least one record. The above content is the technical basis of the present invention.
[0023] The first embodiment, as Figure 2 As shown, the present invention provides a method for caching data in a database, the method comprising the following steps: S1, calculating the similarity of data pages according to the similarity of records in data pages in the same data table, and recording the number of times the data pages are accessed simultaneously in the access to the data table, and determining the relevance of the data pages according to the similarity and the number of times; when a target data page in the buffer pool is accessed, determining the access mode of the target data page and pre-reading the data page record based on the access history of the target data page; For the same data table, the fields are the same but the records are different, that is, the values corresponding to the same fields in each record may be different, the contents of different data table records are different, and the importance of the fields is different. For example, for the table in the Internet of Things database, the key fields are mainly the terminal number, the collection value, the date, etc., and for the table in the business website database, the key fields are mainly the product name, price, etc. When calculating the similarity of records in a data page in the same data table, different weights are set for different fields, and the similarity of each record in the data page and each record in another data page is recorded based on the weight, and the average value of the similarity is used as the similarity between the record and another data page, and the average value of the similarity between all records in the data page and another data page is used as the similarity between the two data pages.
[0024] For example, a data table has five fields, and the weights are 0.1, 0.2, 0.2, 0.4, and 0.1 respectively. There are 3 records in data page A and 2 records in data page B. When calculating the similarity of data pages A and B, the similarity between each record in data page A and each record in data page B is calculated based on the weight. The similarity between records in data page A and records in data page B is the multiplication of the similarity of the values of the same field and the weight of the field. Then, the multiplication results of the weights corresponding to all fields are added to obtain the similarity between a record in data page A and a record in data page B. Assuming that the similarities of records in data page A and data page B are s11, s12, s21, s22, s31, and s32 respectively, the similarity between data page A and data page B is the average of s11, s12, s21, s22, s31, and s32. The greater the similarity, the closer the records in the two data pages are, and the greater the possibility of being accessed at the same time. For example, when a user browses products, he or she may browse products with similar prices or names.
[0025] In historical access, if two data pages are frequently accessed, it indicates that the two data pages are likely to be accessed simultaneously or continuously in the future. When calculating the correlation between two data pages, the number of times the two data pages are accessed simultaneously also needs to be considered. The correlation of the data pages is determined based on the similarity and the number of times, specifically: The maximum number of simultaneous accesses of two data pages in the data table is obtained, the number of simultaneous accesses of the two data pages is standardized according to the maximum number, and the similarity and the standardized simultaneous access number are weighted to obtain the correlation of the two data pages.
[0026] A data table has multiple data pages, and the maximum number is the maximum number of times two data pages are accessed simultaneously among all the data pages in the data table. For example, a data table has 10 data pages, and the number of times the first and second data pages are accessed simultaneously is 90 times, and the number of times the first and third data pages are accessed simultaneously is 100 times, etc. Find the maximum value, and then standardize the number of times the two data pages are accessed simultaneously according to the maximum number, that is, the number of times the two data pages are accessed simultaneously / the maximum number. Set two weights, weight the similarity of the two data pages, and weight the standardized number of simultaneous accesses of the two data pages, and sum the two weighted results to get the correlation of the two data pages.
[0027] When a target data page in the buffer pool is accessed, the access mode of the target data page and the pre-read data page record are determined based on the access history of the target data page, wherein the access mode is random access or sequential access, and the pre-read data page record is a pre-read data page based on the target data page, for example, when data page A is accessed at a certain time or data page A meets a certain preset condition, the data page is pre-fetched by sequential pre-fetching or random pre-fetching. Pre-reading or pre-fetching refers to loading data pages that have not been accessed into the buffer pool. The access mode is determined as follows: if the continuously accessed data pages including the target data page are accessed one by one in a fixed order, it is a sequential mode; if the continuously accessed data pages including the target data page are irregular, it is a random mode. In one embodiment, the target data page is any data page in the buffer pool.
[0028] S2, if the target data page is located in the young area, when the access mode of the target data page is random access, the data page with a correlation with the target data page greater than a threshold is loaded into the buffer pool; when the access mode of the target data page is sequential access, the adjacent data page is loaded into the buffer pool; Data pages in the young area are more active, that is, they are accessed more frequently. If the target data page is in the young area and is accessed randomly, the data pages with a correlation greater than the threshold are loaded into the buffer pool. These highly correlated data pages may be used in the next access and are loaded into the memory in advance to speed up future access. Similarly, for sequential access, the adjacent data pages are loaded into the buffer pool.
[0029] As the number of accesses increases, the heat of the target data page will increase, and the possibility of accessing the data page related to the target data page will also increase. In one embodiment, an initial threshold is obtained, and based on the number of times the target data page is continuously accessed in random access mode, the initial threshold is continuously reduced as the number increases, and the reduced initial threshold is used as the threshold. For example, if the initial threshold is 5, when the number of random accesses is 1, the threshold is 5, and when the number of random accesses is 2, the threshold is 4.8. Then, more data pages related to the target data page are pre-read into the buffer pool. In one embodiment, a lower limit is also set for the threshold to avoid pre-reading too many data pages into the buffer pool, causing other hot data to be flushed out of the buffer pool.
[0030] Data pages with different relevance to the target data page have different probabilities of being accessed next. In one embodiment, the data pages with a relevance to the target data page greater than a threshold are loaded into the buffer pool, specifically: Obtain a ratio of the sizes of the young area and the old area, and divide the data pages whose correlation is greater than a threshold into two parts according to the ratio and the correlation with the target data page. The correlation of the first part is greater than that of the second part. The first part is loaded into the young area of the buffer pool, and the second part is loaded into the old area of the buffer pool.
[0031] For example, if the ratio of memory occupied by the young area and the old area in the buffer pool is 7:3, then according to this ratio, the data pages with a correlation greater than the threshold with the target data page are divided into two groups. The correlation of the first group is greater than that of the second group, and the ratio of the number of data pages in the first group to the number of data pages in the second group is 7:3. The data pages in the first group are loaded into the young area, and the data pages in the second group are loaded into the old area. If the data pages in the first group are in the old area, they are deleted from the old area and loaded in the young area. If the data pages in the second group already exist in the young area, they are no longer loaded in the old area. This avoids other reasons that cause the data pages in the second group to become hot spots and be replaced.
[0032] When the access mode is sequential, the adjacent data pages of the target data page are obtained, and then the adjacent data pages are loaded into the buffer pool, wherein the adjacent data pages may be determined in a variety of ways, including but not limited to the data table closest to the target data page in the data table, or according to the data page number, etc. In a specific embodiment, the adjacent data pages are loaded into the buffer pool, specifically: Obtain a ratio of the sizes of the young area to the old area, divide the adjacent data pages into two parts according to the ratio and the distance from the target data page, wherein the distance from the first part to the target data page is smaller than that of the second part, load the first part into the young area of the buffer pool, and load the second part into the old area of the buffer pool.
[0033] Similarly, if the data pages in the first part are in the old area, they are deleted from the old area and loaded in the young area. If the data pages in the second part already exist in the young area, they are no longer loaded in the old area.
[0034] S3, if the target data page is located in the old area, when the access mode of the target data page is random access, the data page located in the pre-read data page record and in the old area is replaced with the data page with the greatest correlation with the target data page; when the access mode of the target data page is sequential access, the data page located in the pre-read data page record and in the old area is replaced with the data page closest to the target data page.
[0035] If the target data page is located in the old area, the frequency of data page access is not as high as that in the young area. Regardless of whether the target data page is in random access mode or sequential access mode, the pre-read data page will be loaded into the old area, thereby reducing the impact on the high-frequency access data table in the young area. Specifically, the data page located in the pre-read data page record and in the old area is replaced with the data page with the greatest correlation with the target data page. For example, if there are 5 data pages located in the pre-read data page, and these 5 data pages are also in the old area, the 5 data pages with the greatest correlation with the target data page will replace the above 5 data pages. Similarly, if it is a sequential mode, the data page located in the pre-read data page record and in the old area is replaced with the data page closest to the target data page.
[0036] In a second embodiment, the present invention provides a data cache system in a database, such as Figure 3 As shown, the system includes the following modules: A pattern determination module is used to calculate the similarity of data pages according to the similarity of records in data pages in the same data table, and record the number of times the data pages are accessed simultaneously in the access to the data table, and determine the relevance of the data pages according to the similarity and the number of times; when a target data page in the buffer pool is accessed, determine the access pattern of the target data page and pre-read the data page record based on the access history of the target data page; A young area data page pre-reading module, for, if the target data page is located in the young area, when the access mode of the target data page is random access, loading the data page with a correlation with the target data page greater than a threshold into the buffer pool, and when the access mode of the target data page is sequential access, loading the adjacent data page into the buffer pool; The old area data page pre-reading module is used to replace the data page located in the pre-read data page record and located in the old area with the data page with the greatest correlation with the target data page if the target data page is located in the old area and the access mode of the target data page is random access; when the access mode of the target data page is sequential access, replace the data page located in the pre-read data page record and located in the old area with the data page closest to the target data page.
[0037] Preferably, the similarity of the data pages is calculated according to the similarity of the records in the data pages in the same data table, specifically: Different weights are set for different fields in the data table, and the similarity between each record in the data page and each record in another data page is recorded based on the weights. The average value of the similarities is used as the similarity between the record and another data page, and the average value of the similarities between all records in the data page and another data page is used as the similarity between the two data pages.
[0038] Preferably, the determining the relevance of the data pages according to the similarity and the number of times is specifically: The maximum number of simultaneous accesses of two data pages in the data table is obtained, the number of simultaneous accesses of the two data pages is standardized according to the maximum number, and the similarity and the standardized simultaneous access number are weighted to obtain the correlation of the two data pages.
[0039] Preferably, the threshold is determined as follows: An initial threshold is obtained, and based on the number of times that the continuous access mode of the target data page is random access, the initial threshold is continuously reduced as the number increases, and the reduced initial threshold is used as the threshold.
[0040] Preferably, the step of loading the data page having a correlation with the target data page greater than a threshold into the buffer pool is specifically as follows: Obtain a ratio of the sizes of the young area and the old area, and divide the data pages whose correlation is greater than a threshold into two parts according to the ratio and the correlation with the target data page. The correlation of the first part is greater than that of the second part. The first part is loaded into the young area of the buffer pool, and the second part is loaded into the old area of the buffer pool.
[0041] Preferably, the step of loading the adjacent data pages into a buffer pool is specifically as follows: Obtain a ratio of the sizes of the young area to the old area, divide the adjacent data pages into two parts according to the ratio and the distance from the target data page, wherein the distance from the first part to the target data page is smaller than that of the second part, load the first part into the young area of the buffer pool, and load the second part into the old area of the buffer pool.
[0042] A third embodiment, this embodiment provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in the first embodiment.
[0043] A fourth embodiment, this embodiment provides a computer program product, including a computer program. When the computer program is executed by a processor, the method described in the first embodiment can be implemented.
[0044] All or part of the steps of the above-mentioned method embodiments can be completed by hardware related to program instructions. The above-mentioned program can be stored in a readable memory. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the above-mentioned memory (storage medium) includes: read-only memory (ROM), random access memory (RAM), flash memory, hard disk, solid state drive, magnetic tape, floppy disk, optical disc and any combination thereof.
[0045] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processing unit of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
Claims
1. A method for caching data in a database, characterized in that: The method comprises the following steps: Calculating the similarity of the data pages according to the similarity of the records in the data pages in the same data table, and recording the number of times the data pages are accessed simultaneously in the access to the data table, and determining the relevance of the data pages according to the similarity and the number of times; when the target data page in the buffer pool is accessed, determining the access mode of the target data page and pre-reading the data page record based on the access history of the target data page; If the target data page is located in the young area, when the access mode of the target data page is random access, the data page with a correlation with the target data page greater than a threshold is loaded into the buffer pool; when the access mode of the target data page is sequential access, the adjacent data page is loaded into the buffer pool; If the target data page is located in the old area, when the access mode of the target data page is random access, the data page located in the pre-read data page record and in the old area is replaced with the data page with the greatest correlation with the target data page; when the access mode of the target data page is sequential access, the data page located in the pre-read data page record and in the old area is replaced with the data page closest to the target data page.
2. The method according to claim 1, characterized in that The similarity of the data pages is calculated according to the similarity of the records in the data pages in the same data table, specifically: Different weights are set for different fields in the data table, and the similarity between each record in the data page and each record in another data page is recorded based on the weights. The average value of the similarities is used as the similarity between the record and another data page, and the average value of the similarities between all records in the data page and another data page is used as the similarity between the two data pages.
3. The method according to claim 1, characterized in that The determining of the relevance of the data pages according to the similarity and the number of times is specifically: The maximum number of simultaneous accesses of two data pages in the data table is obtained, the number of simultaneous accesses of the two data pages is standardized according to the maximum number, and the similarity and the standardized simultaneous access number are weighted to obtain the correlation of the two data pages.
4. The method according to claim 1, characterized in that The threshold is determined as follows: An initial threshold is obtained, and based on the number of times that the continuous access mode of the target data page is random access, the initial threshold is continuously reduced as the number increases, and the reduced initial threshold is used as the threshold.
5. The method according to claim 1, characterized in that The step of loading the data page with a correlation greater than a threshold value with the target data page into the buffer pool is specifically as follows: Obtain a ratio of the sizes of the young area and the old area, and divide the data pages whose correlation is greater than a threshold into two parts according to the ratio and the correlation with the target data page. The correlation of the first part is greater than that of the second part. The first part is loaded into the young area of the buffer pool, and the second part is loaded into the old area of the buffer pool.
6. The method according to claim 1, characterized in that The step of loading the adjacent data pages into the buffer pool is specifically as follows: Obtain a ratio of the sizes of the young area to the old area, divide the adjacent data pages into two parts according to the ratio and the distance from the target data page, wherein the distance from the first part to the target data page is smaller than that of the second part, load the first part into the young area of the buffer pool, and load the second part into the old area of the buffer pool.
7. A data cache system in a database, characterized in that: The system includes the following modules: A pattern determination module, used to calculate the similarity of data pages according to the similarity of records in data pages in the same data table, and record the number of times the data pages are accessed simultaneously in the access to the data table, and determine the relevance of the data pages according to the similarity and the number of times; when a target data page in the buffer pool is accessed, determine the access pattern of the target data page and pre-read the data page record based on the access history of the target data page; A young area data page pre-reading module, for, if the target data page is located in the young area, when the access mode of the target data page is random access, loading the data page with a correlation with the target data page greater than a threshold into the buffer pool, and when the access mode of the target data page is sequential access, loading the adjacent data page into the buffer pool; The old area data page pre-reading module is used to replace the data page located in the pre-read data page record and located in the old area with the data page with the greatest correlation with the target data page if the target data page is located in the old area and the access mode of the target data page is random access; when the access mode of the target data page is sequential access, replace the data page located in the pre-read data page record and located in the old area with the data page closest to the target data page.
8. The system according to claim 7, characterized in that The similarity of the data pages is calculated according to the similarity of the records in the data pages in the same data table, specifically: Different weights are set for different fields in the data table, and the similarity between each record in the data page and each record in another data page is recorded based on the weights. The average value of the similarities is used as the similarity between the record and another data page, and the average value of the similarities between all records in the data page and another data page is used as the similarity between the two data pages.
9. The system according to claim 7, characterized in that The determining of the relevance of the data pages according to the similarity and the number of times is specifically: The maximum number of simultaneous accesses of two data pages in the data table is obtained, the number of simultaneous accesses of the two data pages is standardized according to the maximum number, and the similarity and the standardized simultaneous access number are weighted to obtain the correlation of the two data pages.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the method according to any one of claims 1 to 6.
