Database management method, database management program, and information processing device
By focusing on leaf node record creation first and strategic updating, the method addresses high processing loads in index reconstruction, enhancing query performance and reducing time in database management systems with write-once architectures.
Patent Information
- Application Number
- JP2023057072
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-03-31
- Publication Date
- 2024-10-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Database management systems using a write-once architecture face high processing loads during index reconstruction due to the accumulation of invalid records, leading to decreased query performance.
A method for index rebuilding that prioritizes creating records in leaf nodes first, followed by higher nodes, reducing the number of discrete storage area accesses and processing load, and updating the new index file only when necessary.
This approach significantly reduces the processing load and time required for index reconstruction, maintaining query performance and minimizing differential records between old and new index files.
Smart Images

Figure 2024144901000001_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to a database management method, a database management program, and an information processing device. [Background technology]
[0002] In database management systems, indexes are used to efficiently search huge amounts of data. For example, tree-structured indexes such as B-tree are widely used.
[0003] The following proposals have been made regarding database management using indexes. For example, a full-text search system has been proposed that crawls all files only once to create an index, and then updates the index only for files that are the subject of an event from the second time onwards. Also, an index update method has been proposed that removes unnecessary index update information stored in the stack area when updating index files in delayed update mode. [Prior art documents] [Patent documents]
[0004] [Patent Document 1] JP 2008-305352 A [Patent Document 2] Japanese Patent Application Publication No. 8-328924 Summary of the Invention [Problem to be solved by the invention]
[0005] Incidentally, some databases use a write-once architecture to manage tables and indexes. In such databases, when updating tables or indexes, the records to be updated are not deleted but new records are added. This means that the amount of data in tables and indexes tends to increase.
[0006] One method for reducing the amount of data in an index is to rebuild the index using only valid records. However, rebuilding an index imposes a high processing load. If the processing load of rebuilding an index is high, for example, the processing performance of queries to the database from a client application will decrease.
[0007] In one aspect, the present invention has an object to provide a database management method, a database management program, and an information processing device that are capable of reducing the processing load of index reconstruction. [Means for solving the problem]
[0008] One proposal provides a database management method in which a computer executes an index reconstruction process for reconstructing a first index having a tree structure in a database in which records are updated in an append-type manner to create a second index having a tree structure. In this database management method, the index reconstruction process includes an index creation process for creating a plurality of second records corresponding to a plurality of valid records included in a leaf node of a second index based on a plurality of valid records among a plurality of first records included in a leaf node of the first index, and, after the creation of the plurality of second records is completed, creating a plurality of third records included in a node higher than the leaf node in the second index based on the plurality of second records.
[0009] In addition, one proposal provides a database management program that causes a computer to execute processing similar to the above-mentioned database management method. Furthermore, in one proposal, an information processing device is provided that executes a process similar to the above-mentioned database management method. Effect of the Invention
[0010] On the one hand, the processing load of rebuilding indexes can be reduced. [Brief description of the drawings]
[0011] [Figure 1] 1 illustrates a configuration example and a processing example of an information processing device according to a first embodiment; [Diagram 2] FIG. 11 illustrates an example of a configuration of a database system according to a second embodiment; [Diagram 3] FIG. 2 illustrates an example of a hardware configuration of a DB server. [Figure 4] 2 is a diagram illustrating a configuration example of processing functions included in a DB server and a business server. [Diagram 5] FIG. 2 is a diagram illustrating an example of the structure of an index file. [Figure 6] 13 is an example of a flowchart showing an overall processing procedure for rebuilding an index. [Figure 7] 13 is a flowchart illustrating a comparative example of index creation processing. [Figure 8] FIG. 13 illustrates a comparative example of index updating processing. [Figure 9] FIG. 11 illustrates an example of an index creation process according to the second embodiment; [Figure 10] FIG. 11 is a diagram illustrating an index updating process according to the second embodiment. [Figure 11] 13 is a flowchart illustrating an example of an index creation process procedure according to the second embodiment. [Figure 12] 13 is a flowchart illustrating an example of an index update process procedure according to the second embodiment. [Figure 13] 13 is a flowchart illustrating an example of an index updating process procedure according to the second embodiment. [Figure 14] 13 is a diagram illustrating an example of an index updating process when update management information is lost. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0012] Hereinafter, an embodiment of the present invention will be described with reference to the drawings. First Embodiment 1 is a diagram showing an example of the configuration and processing of an information processing device according to a first embodiment. The information processing device 1 shown in FIG.
[0013] The storage unit 2 is a storage area secured in a storage device included in the information processing device 1. The storage unit 2 may be a storage area secured in a storage device connected to the outside of the information processing device 1. The storage unit 2 stores a database 10 and indexes 11 and 12. The database 10 is a relational database in which records are updated in an append-only manner. The indexes 11 and 12 are information for searching the database 10, and each has a tree structure. Like the database 10, the indexes 11 and 12 also update their records in an append-only manner. The index 12 is created by the processing unit 3 reconstructing the index 11, and is stored in the storage unit 2.
[0014] The processing unit 3 is, for example, a processor. The processing unit 3 manages the database 10 by executing software for a DBMS (DataBase Management System). The processing unit 3 executes an index reconstruction process to reconstruct the index 11 and create the index 12.
[0015] The index reconstruction process will be described below. First, a configuration example of the index 11 will be described. As described above, the index 11 has a tree structure. In the example of Fig. 1, the index 11 includes pages P1 to P3 as leaf nodes, pages P4 and P5 as intermediate nodes, and page P6 as a root node.
[0016] Page P1 includes records R1 to R3, page P2 includes records R4 and R5, and page P3 includes records R6 to R8. Records R1 to R8 store, for example, keys. Page P4 is a parent node to pages P1 and P2, and includes record R11 for managing page P1 and record R12 for managing page P2. Page P5 is a parent node to page P3, and includes record R13 for managing page P3. Page P6 is a parent node to pages P4 and P5, and includes record R21 for managing page P4 and record R22 for managing page P5.
[0017] Records are updated in the index 11 in an append-type manner. For example, when a request is made to update a record in the index 11, the processing unit 3 adds a new record to the index 11 without deleting the record. The processing unit 3 adds a deletion mark to the record before the update, indicating that the record has been invalidated.
[0018] Because of this append-type processing, the data size of index 11 increases every time index 11 is updated, and invalid records with deletion marks are accumulated in index 11. To prevent index 11 from becoming bloated, processing unit 3 executes index reconstruction processing in which only valid records with no deletion marks are extracted from index 11 to create a new index 12. In the index reconstruction processing, processing unit 3 creates new index 12, resets created index 12 as an index for searching database 10, and deletes the original index 11 to make the records of index 11 reusable.
[0019] Here, the creation process of the new index 12 can be executed, for example, in the following procedure. The processing unit 3 selects one valid record from the leaf node of the index 11, and copies the record to the leaf node of the index 12. The processing unit 3 creates a record of a higher node in the index 12 corresponding to the copied record. The processing unit 3 repeats such a process for each valid record of the leaf node of the index 11. However, such a procedure has a problem that the number of accesses to the discrete areas in the storage unit 2 increases, which increases the processing load and the time required for processing. Such an increase in the processing load leads to, for example, a decrease in the processing performance of queries to the database 10 from client applications.
[0020] To address this problem, in this embodiment, the processing unit 3 creates the index 12 in the following procedure. First, the processing unit 3 creates multiple records corresponding to multiple valid records included in the leaf node of the index 12, based on multiple valid records among the multiple records included in the leaf node of the index 11. That is, the contents of the multiple valid records are copied into the multiple created records. After completing the creation of these records, the processing unit 3 creates multiple records included in nodes higher than the leaf node in the index 12, based on the created records.
[0021] According to this procedure, only the records contained in the leaf node are created first, so that during this creation process, continuous storage areas in the storage unit 2 are accessed. As a result, the load of the creation process of the index 12 can be reduced, and the time required for the creation process can also be shortened.
[0022] 1, the processing unit 3 creates records for leaf nodes of the index 12 based on records R1, R3 to R5, R7, and R8, which are valid records among pages P1 to P3 of the index 11 (step S1). In the index 12, page P11 including records R1 and R3 copied from page P1, page P12 including records R4 and R5 copied from page P2, and page P13 including records R7 and R8 copied from page P3 are created as leaf nodes. Until record creation for these leaf nodes is completed, record creation for higher-level nodes is suppressed.
[0023] Then, after completing the creation of the records of the leaf nodes of index 11, the processing unit 3 creates the records of the upper nodes. Specifically, the processing unit 3 defines page P14 as the upper node corresponding to pages P11 and P12. The processing unit 3 creates a record R31 included in page P14 based on records R1 and R3 of page P11, and creates a record R32 included in page P14 based on records R4 and R5 of page P12. The processing unit 3 also defines page P15 as the upper node corresponding to page P13, and creates a record R33 included in page P15 based on records R7 and R8 of page P13. Furthermore, the processing unit 3 defines page P16 as the upper node corresponding to pages P14 and P15. The processing unit 3 creates a record R41 included in page P16 based on records R31 and R32 of page P14, and creates a record R42 included in page P16 based on record R33 of page P15.
[0024] According to this procedure, only the records R1, R3 to R5, R7, and R8 contained in the leaf nodes are created first, so that continuous access is performed in the storage unit 2 during the creation process. As a result, the load of the creation process of the index 12 can be reduced, and the time required for the creation process can also be shortened.
[0025] In an actual index reconstruction process, the creation process of the index 12 according to the above procedure may be followed by an update process of the index 12. For example, if updates to the original index 11 are accepted during the creation process of the index 12 according to the above procedure, the updates to the index 11 that were not reflected during the creation process of the index 12 are reflected in the index 12.
[0026] Second Embodiment Next, PostgreSQL (Structured Query Language) will be used as an example of a DBMS that employs an append-type architecture.
[0027] Fig. 2 is a diagram showing an example of the configuration of a database system according to the second embodiment. The database system shown in Fig. 2 includes a DB (database) server 100 and a business server 200. The DB server 100 and the business server 200 are connected via a network 210.
[0028] The DB server 100 is a server computer on which a DBMS runs. The DB server 100 manages a database, receives queries for operating the database from a client application, and executes processing according to the queries. In this embodiment, the DB server 100 manages the database using PostgreSQL.
[0029] The business server 200 is a server computer that executes a business application. The business application is an example of a client application for the DB server 100, and transmits queries to the DB server 100 to operate the database.
[0030] Fig. 3 is a diagram showing an example of the hardware configuration of a DB server. The DB server 100 is realized, for example, as a computer as shown in Fig. 3. The DB server 100 shown in Fig. 3 includes a processor 101, a random access memory (RAM) 102, a hard disk drive (HDD) 103, a graphics processing unit (GPU) 104, an input interface (I / F) 105, a reader 106, and a network interface (I / F) 107.
[0031] The processor 101 performs overall control of the entire DB server 100. The processor 101 is, for example, a central processing unit (CPU), a micro processing unit (MPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), or a programmable logic device (PLD). The processor 101 may also be a combination of two or more elements of a CPU, an MPU, a DSP, an ASIC, or a PLD. The processor 101 is an example of the processing unit 3 shown in FIG. 1.
[0032] The RAM 102 is used as a main storage device of the DB server 100. The RAM 102 temporarily stores at least a part of an OS (Operating System) program and application programs to be executed by the processor 101. The RAM 102 also stores various data necessary for processing by the processor 101.
[0033] The HDD 103 is used as an auxiliary storage device of the DB server 100. The HDD 103 stores an OS program, an application program, and various data. The HDD 103 is an example of the storage unit 2 shown in FIG. 1. Also, other types of non-volatile storage devices such as SSDs (Solid State Drives) can be used as the auxiliary storage device.
[0034] A display device 104a is connected to the GPU 104. The GPU 104 displays an image on the display device 104a in accordance with an instruction from the processor 101. The display device 104a is, for example, a liquid crystal display or an organic EL (ElectroLuminescence) display.
[0035] An input device 105a is connected to the input interface 105. The input interface 105 transmits a signal output from the input device 105a to the processor 101. A keyboard, a pointing device, or the like can be used as the input device 105a. A mouse, a touch panel, a tablet, a touch pad, a trackball, or the like can be used as the pointing device.
[0036] A portable recording medium 106a is detachably attached to the reading device 106. The reading device 106 reads data recorded on the portable recording medium 106a and transmits it to the processor 101. The portable recording medium 106a may be an optical disk, a semiconductor memory, or the like.
[0037] The network interface 107 transmits and receives data to and from other devices such as the business server 200 via a network 210 . The above hardware configuration can realize the processing functions of the DB server 100. The business server 200 can also be realized by a hardware configuration as shown in FIG.
[0038] FIG. 4 is a diagram illustrating an example of the configuration of processing functions provided in the DB server and the business server. First, the business server 200 includes a business application 201 that executes business processing. The processing of the business application 201 is realized by a processor included in the business server 200 executing a predetermined application program. The business application 201 is an example of a client application corresponding to the DB server 100.
[0039] The DB server 100 includes a shared memory unit 110, a data storage unit 120, a server processing unit 131, an index reconstruction unit 132, and a WAL (Write Ahead Logging) writing unit 133.
[0040] The shared memory unit 110 is a storage area secured in a volatile storage device provided in the DB server 100, such as the RAM 102, and is shared by the server processing unit 131 and the index reconstruction unit 132. The shared memory unit 110 stores update management information 111. Information indicating the content of updates made to the old index file during new index creation processing in the index reconstruction processing is written into the update management information 111.
[0041] The data storage unit 120 is a storage area secured in a non-volatile storage device included in the DB server 100, such as the HDD 103. The data storage unit 120 may also be a storage area secured in a non-volatile storage device connected to the outside of the DB server 100. The data storage unit 120 stores table files 121a, 121b,..., index files 122a, 122b,..., and a WAL file 123.
[0042] The table files 121a, 121b,... respectively contain data of individual tables. The index files 122a, 122b,... respectively contain data of individual indexes. Transaction logs for the table files 121a, 121b,... and the index files 122a, 122b,... are written to the WAL file 123.
[0043] The processes of the server processing unit 131, the index reconstruction unit 132, and the WAL writing unit 133 are realized, for example, by the processor 101 executing a predetermined program. The server processing unit 131 receives a query for operating the database from the business application 201, and executes processing according to the query. When a request is made to insert or update data in the database, the server processing unit 131 can update the index files 122a, 122b, .... The server processing unit 131 is implemented as a processing function that executes a "server process" of a Postgres instance.
[0044] The index reconstruction unit 132 executes an index reconstruction process for creating a new index file using valid records of the index file. When a transaction including operations on the table files 121a, 121b, . . . and the index files 122a, 122b, . . . is committed, the WAL writing unit 133 writes a log indicating the contents of the transaction into a WAL file.
[0045] The index reconstruction unit 132 and the WAL writing unit 133 are implemented as processing functions that execute a "worker process" of a Postgres instance. FIG. 5 is a diagram showing an example of the configuration of an index file. In PostgreSQL, one file (index file) is created for each index. The index file 122 shown in FIG. 5 is an example of the above-mentioned index files 122a, 122b, .... In this embodiment, the index file 122 is formed as a B-tree, and has a three-layered structure of leaf nodes, intermediate nodes, and root nodes. One or more records are stored in a page of a leaf node (leaf page), a page of an intermediate node (intermediate page), and a page of a root node (root page).
[0046] In the example of FIG. 5, the index file 122 includes at least leaf pages 141a and 141b in the leaf nodes, intermediate pages 142a and 142b in the intermediate nodes, and a root page 143 in the root node. The leaf page 141a includes records including key1 to key3 as keys. The leaf page 141b includes records including key101 to key103 as keys. The intermediate page 142a is an upper node of the leaf page 141a, and includes a record in which a pointer to the leaf page 141a is written. The intermediate page 142b is an upper node of the leaf page 141b, and includes a record in which a pointer to the leaf page 141b is written. The root page 143 includes a record in which a pointer to the intermediate page 142a is written, and a record in which a pointer to the intermediate page 142b is written.
[0047] By the way, PostgreSQL uses an append-type architecture. When a record in an index file is updated, the record to be updated is not deleted, but a new record is added to the index file. At this time, a delete mark is added to the old record to indicate that it has been invalidated.
[0048] Because of this type of append processing, invalid records marked for deletion accumulate in the index file with each update, causing the data size of the index file to increase. The expansion of the index file poses the problem of putting pressure on storage capacity and can degrade SQL performance.
[0049] PostgreSQL has implemented functions such as HOT (Heap-Only Tuples) and vacuum (VACUUM) to prevent index files from becoming bloated. HOT is a function that only changes the reference when the key of the index file is not updated, and does not directly update the index file. Vacuum is a function that collects invalid records and makes their storage space reusable. In addition, autovacuum (AUTOVACUUM) is implemented, which collects statistical information showing the occurrence of invalid records and automatically performs vacuum processing based on the statistical information.
[0050] However, even with this function, it cannot be said that the expansion of index files can be prevented reliably. In order to reliably prevent the expansion of index files, it is desirable to perform index rebuild (REINDEX) as appropriate, either by the operation of the database administrator or according to the results of automatic analysis of the occurrence of the expansion and fragmentation of index files.
[0051] FIG. 6 is an example of a flowchart showing the overall processing procedure for rebuilding an index. [Step S11] The index reconstruction unit 132 defines a new index file (hereinafter referred to as the "new index file").
[0052] [Step S12] The index reconstruction unit 132 creates records for a new index file using valid records included in the index file to be reconstructed (hereinafter referred to as the "old index file").
[0053] [Step S13] The process of this step is executed when updating of the old index file is permitted during the index creation process of step S12. The index reconstruction unit 132 detects the difference between the current old index file and the new index file, and reflects the difference in the new index file. This updates the new index file and makes it consistent with the old index file.
[0054] [Step S14] The index reconstruction unit 132 registers the new index file as a new reference destination for searching the corresponding database (table file). The index reconstruction unit 132 also excludes the old index file from the reference destinations for searching the corresponding database.
[0055] [Step S15] The index reconstruction unit 132 deletes the old index file, making the records contained in the old index file available for reuse. PostgreSQL has a function called "REINDEX CONCURRENTLY" that enables database operations from client applications even during index rebuild processing. With REINDEX CONCURRENTLY, if an update of the old index file is requested during the index creation processing in step S12, both the old index file and the new index file are updated.
[0056] A comparative example of index creation processing and index updating processing when REINDEX CONCURRENTLY is used will be described below with reference to FIGS. 7 is a flowchart showing a comparative example of index creation processing, which corresponds to the processing in step S12 in FIG.
[0057] [Step S21] The index reconstruction unit 132 selects one valid record included in the leaf page of the old index file, and inserts a copy of the selected valid record into the leaf page of the new index file.
[0058] [Step S22] The index reconstruction unit 132 creates a record in the upper node (intermediate node and root node) corresponding to the insertion destination page in step S21. In practice, for example, when a record is inserted into a leaf page newly created in the new index file in step S21, a record pointing to the leaf page may be created in the intermediate page corresponding to the leaf page. Also, when the destination of this record is a newly created intermediate page, a record pointing to the intermediate page may be created in the root page.
[0059] [Step S23] The index reconstruction unit 132 determines whether copies of all valid records included in the leaf pages of the old index file have been inserted into the new index file. If there is a valid record whose copy has not been inserted, the process proceeds to step S21, where one valid record whose copy has not been inserted is selected. On the other hand, if copies of all valid records have been inserted, the index creation process ends.
[0060] Through the above process, a new index file is created that does not contain invalid records and has a smaller data size than the old index file. Furthermore, according to the above processing procedure, the process of creating the new index file is executed in a state where the tree structure of the new index file is always maintained (a state where records added to leaf nodes can be searched from the root node). Therefore, when a client application requests the old index file to be updated, both the old index file and the new index file can be updated.
[0061] However, in the following cases, only the old index file can be updated, and the new index file cannot be updated. One is when an update occurs to a page where the record copy process (step S21) is currently in progress. The other is when an update occurs to a page where the record copy to the new index file has not yet been completed. In such cases, the update contents are not reflected in the new index file, so a process to update the new index file is required after the index creation process is completed.
[0062] 8 is a diagram showing a comparative example of index updating processing, which corresponds to the processing in step S13 in FIG. Fig. 8 shows an example of creating a new index file 122-2 by reconstructing an old index file 122-1. It is assumed that the old index file 122-1 has the same data structure as that shown in Fig. 5. It is also assumed that, in the new index file 122-2, the valid record of leaf page 141a is copied to leaf page 151a, and the valid record of leaf page 141b is copied to leaf page 151b, according to the procedure shown in Fig. 7. However, it is assumed that record 141b1 of leaf page 141b was not reflected in the new index file 122-2 in the index reconstruction process.
[0063] In the new index file 122-2, intermediate pages 152a and 152b and a root page 153 are created. At least a record pointing to the leaf page 151a is written in the intermediate page 152a, and at least a record pointing to the leaf page 151b is written in the intermediate page 152b. In the root page 153, a record pointing to the intermediate page 152a and a record pointing to the intermediate page 152b are written.
[0064] 7, the index reconstruction unit 132 updates the new index file 122-2 in the following manner. The index reconstruction unit 132 performs a full scan of the leaf nodes of the old index file 122-1 to read valid records. The index reconstruction unit 132 also performs a full scan of the leaf nodes of the new index file 122-2 to read records.
[0065] The index reconstruction unit 132 compares the records read from the old index file 122-1 and the new index file 122-2, respectively, and extracts difference records. In this comparison, for example, TIDs (Tuple IDs) indicating pointers to data records in the table file, which are recorded in the records, are compared. In the example of Fig. 8, since it is detected that the record 141b1 does not exist in the new index file 122-2, the index reconstruction unit 132 copies the record 141b1 to the leaf page 151b of the new index file 122-2.
[0066] The above comparative example has the following problems. In the index creation process shown in Fig. 7, the loop process of steps S21 to S23 is repeated for each valid record of the leaf node of the old index file 122-1. In this process, access to the record of the leaf node and access to the record of the higher node are repeated, and the number of accesses to discrete areas of the storage device increases. This causes problems in that the processing load is large and the time required for processing is long. Such an increase in processing load leads to a decrease in processing performance of queries from client applications, for example.
[0067] In addition, in the index update process shown in Fig. 8, leaf nodes in both the old and new index files are fully scanned to extract differential records. This results in a problem that the amount of data read to extract differential records increases, which in turn increases the processing load and the time required for processing.
[0068] Furthermore, in the above comparative example, when an index update is requested from a client application, both the old index file and the new index file are updated. Therefore, the response time to a query is longer than when only the old index file is updated. As a result, the speed of the client application's processing (business processing in this embodiment) may decrease. For example, in mission-critical business processing, a decrease in response performance to a query may not be acceptable.
[0069] On the other hand, if only the old index file is updated in response to an index update request from a client application, difference records are likely to occur between the old index file and the new index file during the index creation process. This causes a problem in that the number of records to be reflected in the new index file increases in the index update process after the index creation process is completed, which can further increase the time required for the index update process.
[0070] In response to such problems, in this embodiment, when an index update is requested by a client application, only the old index file is updated, and the load of the index creation process and index updating process is reduced by the following method.
[0071] Fig. 9 is a diagram showing an example of index creation processing in the second embodiment. The processing in Fig. 9 corresponds to the processing in step S12 in Fig. 6. In the following explanation, it is assumed that the old index file 122-1 is reconstructed to create the new index file 122-3.
[0072] First, the index reconstruction unit 132 copies all valid records included in the leaf nodes of the old index file 122-1 to the leaf nodes of the new index file 122-3. In this way, all the leaf nodes of the new index file 122-3 are created. In the example of FIG. 9, the valid records included in the leaf page 141a of the old index file 122-1 are copied to the leaf page 161a of the new index file 122-3. Also, the valid records included in the leaf page 141b of the old index file 122-1 are copied to the leaf page 161b of the new index file 122-3. However, it is assumed that the record 141b1 of the leaf page 141b (see FIG. 8) was not copied to the new index file 122-3 because it was added to the old index file 122-1 during the index creation process.
[0073] When the creation of the leaf nodes is completed as described above, the index reconstruction unit 132 then creates data for intermediate nodes in the new index file 122-3 based on each record of the created leaf nodes. In Fig. 9, for example, an intermediate page 162a is created at the parent node of the leaf page 161a, and a record pointing to the leaf page 161a is written to the intermediate page 162a. Also, an intermediate page 162b is created at the parent node of the leaf page 161b, and a record pointing to the leaf page 161b is written to the intermediate page 162b.
[0074] When the creation of the intermediate nodes is completed as described above, the index reconstruction unit 132 then creates data for the root node of the new index file 122-3 based on each record of the created intermediate nodes. In Fig. 9, a root page 163 is created in the root node, and a record pointing to intermediate page 162a and a record pointing to intermediate page 162b are written to the root page 163.
[0075] According to this procedure, first, only the records contained in the leaf nodes of the new index file 122-3 are created, and during the creation, the creation of higher-level nodes is suppressed. When creating records for such leaf nodes, continuous storage areas of the storage device are accessed. As a result, the processing load for index creation can be reduced and the processing time can be shortened compared to the comparative example shown in FIG. 7.
[0076] Here, as described above, in this embodiment, if an index update is requested from a client application during the above index creation process, only the old index file 122-1 is updated, and the new index file 122-3 is not updated. Therefore, at the time when the index creation process is completed, difference records may occur between the old index file 122-1 and the new index file 122-3. Reducing the index creation process time by the procedure of Fig. 9 also produces the effect of suppressing the number of such difference records.
[0077] However, compared to the above comparative example in which both the old and new index files are updated in response to an update request from a client application, the number of difference records is likely to increase, and the effect of suppressing the number of difference records is not sufficient. Therefore, the DB server 100 of this embodiment shortens the time required for index updating processing by the process shown in the following Figure 10 compared to the comparative example shown in Figure 8. This prevents the time required for the entire index reconstruction processing from becoming longer even if the number of difference records increases.
[0078] FIG. 10 is a diagram illustrating the index updating process according to the second embodiment. 10, it is assumed that a process of creating a new index file 122-3 based on the old index file 122-1 is being executed. From this state, it is assumed that in state 1, a request to update key1 included in the old index file 122-1 is generated from a client application. In this case, the server processing unit 131 updates key1 included in the old index file 122-1 and suppresses the update of the new index file 122-3. At the same time, the server processing unit 131 registers, in the update management information 111 stored in the shared memory unit 110, update information 111a indicating that key1 has been updated.
[0079] Also, in state 2, it is assumed that a request to update key2 included in old index file 122-1 occurs from the client application. In this case, server processing unit 131 updates key2 included in old index file 122-1 and suppresses the update of new index file 122-3. At the same time, server processing unit 131 registers update information 111b, which indicates that key2 has been updated, in update management information 111 stored in shared memory unit 110.
[0080] Then, in state 3, it is assumed that the index creation process is completed. Then, the index reconstruction unit 132 executes the update process of the new index file 122-3 by referring to the update management information 111. In state 3, update information 111a and 111b are registered in the update management information 111. The index reconstruction unit 132 reflects the update of key1 in the new index file 122-3 based on the update information 111a. Also, the index reconstruction unit 132 reflects the update of key2 in the new index file 122-3 based on the update information 111b.
[0081] For example, suppose that record 141b1 (see FIG. 8) is added to a leaf node of old index file 122-1 during index creation processing. In this case, update information (for example, update information 111a) indicating that record 141b1 has been added is registered in update management information 111. Then, in the index updating processing, record 141b1 is added to the leaf node of new index file 122-3 based on update information 111a.
[0082] In this way, when the index creation process is completed, the index reconstruction unit 132 can recognize the difference records and execute the index updating process simply by reading the update information registered in the update management information 111 during this creation process. Since the update information is registered only when an update of the old index file 122-1 is requested, the number of records is clearly smaller than the number of records contained in the leaf nodes of the old index file 122-1 and the new index file 122-3. Therefore, the amount of data read to recognize the difference records can be significantly reduced compared to the process of FIG. 8, which fully scans the leaf nodes of both the old and new index files. As a result, the time required for the index creation process can be shortened.
[0083] Therefore, even if the number of difference records increases as a result of updating only the old index file 122-1 in response to an update request from a client application, the shortened index creation processing time can prevent the overall time required for index reconstruction processing from increasing.
[0084] Next, the index creation process and index update process in this embodiment will be described with reference to a flowchart. 11 is a flowchart showing an example of an index creation process procedure in the second embodiment. The process in FIG. 11 corresponds to the process in step S12 in FIG.
[0085] [Step S31] The index reconstruction unit 132 selects one valid record from the leaf page of the old index file, and inserts a copy of the selected valid record into the leaf page of the new index file.
[0086] [Step S32] The index reconstruction unit 132 determines whether copies of all valid records included in the leaf pages of the old index file have been inserted. If there is a valid record whose copy has not been inserted, the process proceeds to step S31, where the valid record whose copy has not been inserted is selected. On the other hand, if copies of all the applicable valid records have been inserted, the process proceeds to step S33.
[0087] [Step S33] The index reconstruction unit 132 selects one leaf page of the new index file. The index reconstruction unit 132 creates a record of an intermediate page that manages the selected leaf page. At least a pointer to the selected leaf page is registered in this record.
[0088] [Step S34] The index reconstruction unit 132 determines whether all records for managing leaf pages included in the intermediate pages of the new index file have been created. If there are any uncreated records, the process proceeds to step S33, where one leaf page corresponding to a lower node of the uncreated record is selected. On the other hand, if all the corresponding records have been created, the process proceeds to step S35.
[0089] [Step S35] The index reconstruction unit 132 selects one intermediate page of the new index file. The index reconstruction unit 132 creates a record of the root page that manages the selected intermediate page. At least a pointer to the selected intermediate page is registered in this record.
[0090] [Step S36] The index reconstruction unit 132 determines whether all records for managing intermediate pages included in the root page of the new index file have been created. If there are any uncreated records, the process proceeds to step S35, where one intermediate page corresponding to a lower node of the uncreated record is selected. On the other hand, if all the corresponding records have been created, the index creation ends.
[0091] FIG. 12 is an example of a flowchart illustrating an index update process procedure according to the second embodiment. [Step S41] When an index update request occurs in response to a database operation request from a client application, the server processing unit 131 identifies the index file to be updated based on the definition information of the index file.
[0092] [Step S42] The server processing unit 131 updates the identified index file. [Step S43] The server processing unit 131 determines whether the index creation process for the identified index file is in progress. If the index creation process is in progress, the process proceeds to step S44. If the index creation process is not in progress, the index update process ends.
[0093] <Step S44> The server processing unit 131 writes, to the update management information 111 stored in the shared memory unit 110, update information indicating the update contents of the index file (old index file) in step S42.
[0094] Fig. 13 is an example of a flowchart showing an index updating process procedure in the second embodiment. The process in Fig. 13 corresponds to the process in step S13 in Fig. 6. That is, when the index creation process in step S12 (the process in Fig. 11) is completed, the process in Fig. 13 is started.
[0095] [Step S51] The index reconstruction unit 132 determines whether there is update information corresponding to the old index file by referring to the update management information 111. If there is corresponding update information, the process proceeds to step S52; if there is no corresponding update information, the index updating process ends.
[0096] [Step S52] The index reconstruction unit 132 selects one of the update information corresponding to the old index file. The index reconstruction unit 132 creates a record in the new index file based on the selected update information. After completing the record creation, the index reconstruction unit 132 deletes the selected update information from the update management information 111. After that, the process proceeds to step S51.
[0097] Note that the speed at which the old index file is updated in response to a request from a client application may be faster than the speed at which the update contents are reflected in the new index file in the index updating process. In this case, the index reconstruction unit 132 may, for example, execute multiple index updating processes to increase the speed at which the update contents are reflected in the new index file.
[0098] For example, the index reconstruction unit 132 calculates the size of update information (the number of pieces of update information) corresponding to the old index file registered in the update management information 111. At the same time, the index reconstruction unit 132 calculates the time required to reflect the update contents in the new index file based on the update information. Then, the index reconstruction unit 132 calculates the reflection speed V1 of the update contents in the new index file based on the calculated size and time. Also, the index reconstruction unit 132 calculates the update speed V2 of the old index file in response to a request from a client application based on the time interval at which the update information corresponding to the old index file is written in the update management information 111. Then, when V2>V1, the index reconstruction unit 132 generates index updating processes by the number calculated by {(V2 / V1)×predetermined coefficient} and executes these processes in parallel.
[0099] Incidentally, the above-mentioned update management information 111 is stored in the shared memory unit 110 secured in a volatile storage device. For this reason, there is a possibility that the update management information 111 may be lost due to a failure or power outage in the DB server 100. If such an event occurs, the index reconstruction unit 132 refers to the WAL file 123 to identify the difference records between the old index file and the new index file, and updates the new index file.
[0100] FIG. 14 is a diagram showing an example of index updating processing when update management information is lost. When a transaction including a database operation is committed, the WAL writing unit 133 writes a log indicating the contents of the transaction to the WAL file 123. As shown in Fig. 14, such a log is written to the WAL file 123 both when the old index file 122-1 is updated in response to a request from a client application and when the new index file 122-3 is updated by an index reconstruction process.
[0101] 14, it is assumed that a failure occurs in the DB server 100 when the index creation process is completed, and that the DB server 100 is subsequently restored in a state in which the update information in the update management information 111 has been lost. The index reconstruction unit 132 reads logs relating to the old index file 122-1 and the new index file 122-3 from the WAL file 123. The index reconstruction unit 132 compares the log relating to the old index file 122-1 with the log relating to the new index file 122-3 to determine the difference record, and registers update information indicating the contents of the difference record in the update management information 111. In the example of FIG. 14, it is determined by the comparison of the logs that the update of key1 in the old index file 122-1 has not been reflected, and update information 111c indicating this is registered in the update management information 111.
[0102] From this state, the index reconstruction unit 132 executes the index updating process shown in Fig. 13. As a result, the update of key3 is reflected in the new index file 122-3 based on the update information 111c. This process makes it possible to update the new index file 122-3 and achieve record consistency with the old index file 122-1 even if the update information in the update management information 111 is lost.
[0103] The autovacuum of PostgreSQL is equipped with a function for collecting statistical information indicating the occurrence status of invalid records, etc. The index reconstruction unit 132 can refer to the statistical information collected by this function to identify index files that require reconstruction processing, and execute index reconstruction with the identified index files as old index files. This makes it possible to automatically execute index reconstruction processing targeting the required index files as processing targets, without the database administrator having to identify index files that require reconstruction processing.
[0104] Furthermore, the processing functions of the devices (for example, the information processing device 1, the DB server 100, and the business server 200) shown in each of the above embodiments can be realized by a computer. In this case, a program describing the processing contents of the functions that each device should have is provided, and the above processing functions are realized on the computer by executing the program on a computer. The program describing the processing contents can be recorded on a computer-readable recording medium. Examples of computer-readable recording media include magnetic storage devices, optical disks, and semiconductor memories. Examples of magnetic storage devices include hard disk drives (HDDs) and magnetic tapes. Examples of optical disks include CDs (Compact Discs), DVDs (Digital Versatile Discs), and Blu-ray Discs (BD, registered trademark).
[0105] When distributing a program, for example, the program is recorded on a portable recording medium such as a DVD or CD and then sold. The program can also be stored in a storage device of a server computer and transferred from the server computer to other computers via a network.
[0106] A computer that executes a program stores, for example, a program recorded on a portable recording medium or a program transferred from a server computer in its own storage device. The computer then reads the program from its own storage device and executes processing according to the program. The computer can also read the program directly from a portable recording medium and execute processing according to the program. The computer can also execute processing according to the received program each time a program is transferred from a server computer connected via a network. [Explanation of symbols]
[0107] 1. Information processing device 2 Storage section 3 Processing section 10 Database 11,12 Index Pages P1-P6, P11-P16 R1~R8, R11~R13, R21, R22, R31~R33, R41, R42 Records S1, S2 steps
Claims
1. A computer executes an index reconstruction process for reconstructing a first index having a tree structure in a database in which records are updated in an append-type manner, and creating a second index having a tree structure; the index reconstruction process includes an index creation process for creating, based on a plurality of valid records among a plurality of first records included in a leaf node of the first index, a plurality of second records corresponding to the plurality of valid records included in a leaf node of the second index, and, after the creation of the plurality of second records is completed, creating, based on the plurality of second records, a plurality of third records included in a node higher than the leaf node in the second index; Database management methods.
2. when a request to update the first index occurs during the execution of the index creation process, the first index is updated based on the update request, and update information indicating the update content is recorded in a storage unit. The process is executed by the computer, the index reconstruction process includes, after the index creation process is completed, a process of aligning the second index with the first index based on the update information recorded in the storage unit.
2. The database management method according to claim 1.
3. In the process of aligning the second index, a record that was added to a leaf node of the first index during the index creation process is added to a leaf node of the second index based on the update information.
3. The database management method according to claim 2.
4. The update information is recorded in a volatile storage device; In the process of matching the second index, when the update information is lost, the second index is matched with the first index based on a transaction log file recorded in a non-volatile storage device.
3. The database management method according to claim 2.
5. In the index creation process, creation of the third records is inhibited until creation of the second records is completed.
2. The database management method according to claim 1.
6. a computer is caused to execute an index reconstruction process for reconstructing a first index having a tree structure in a database in which records are updated in an append-type manner, and creating a second index having a tree structure; the index reconstruction process includes an index creation process for creating, based on a plurality of valid records among a plurality of first records included in a leaf node of the first index, a plurality of second records corresponding to the plurality of valid records included in a leaf node of the second index, and, after the creation of the plurality of second records is completed, creating, based on the plurality of second records, a plurality of third records included in a node higher than the leaf node in the second index; A database management program.
7. a storage unit that stores a first index and a second index of a tree structure in a database in which records are updated in an append-type manner; a processing unit that executes an index reconstruction process that reconstructs the first index to create the second index; having the index reconstruction process includes an index creation process for creating, based on a plurality of valid records among a plurality of first records included in a leaf node of the first index, a plurality of second records corresponding to the plurality of valid records included in a leaf node of the second index, and, after the creation of the plurality of second records is completed, creating, based on the plurality of second records, a plurality of third records included in a node higher than the leaf node in the second index; Information processing device.
Citation Information
Patent Citations
Index updating system
JP1996328924A
Full text search system
JP2008305352A
