This application claims priority under 35 U.S.C. §119 from Japanese Patent Application No. 2008-118099 filed Apr. 30, 2008, the entire contents of which are incorporated herein by reference.
1. Field of the Invention
The present invention relates to maintaining consistency between a view of a virtual table and a database, wherein the contents of the virtual table are defined by the result of a retrieval query sentence to the database.
2. Description of Related Art
A technique for efficiently performing query processing to a database is a method using a view (e.g., materialized view) of a virtual table. The view is a virtual table of which the contents are defined by the result of the retrieval query sentence to the database. By creating this table beforehand, it is possible to avoid directly accessing the database to make a retrieval process for the same kind of query sentence from an application server.
On the other hand, as a method for efficiently performing an update process for the database, there is a batch update. This method includes accumulating a plurality of data update operation sentences from the application server, organizing them into a single group at a fixed interval or for every data size, and sending it to the database for processing. Generally, when data is sent or written to a disk, the processing efficiency is optimized by keeping a fixed data size or a processing interval. Accordingly, if the fixed data size or processing interval is kept by the batch update, the communication between the application server and the database is optimized, whereby the system performance is greatly improved.
However, when there is a retrieval query request for the latest data set from the application server to the database, the batch update must be executed at that time (forced flush) to correctly respond to the retrieval request, even if the number of update requests or the processing interval for the database does not reach a sufficient amount, whereby the performance of the batch update may not be fully drawn out.
One of the methods for solving this problem may involve holding a view on the application server, and performing maintenance for the view upon every update request to keep the view updated so that the process can be performed without sending a retrieval query request to the database. However, with this method, all the retrieval results pertinent to the batch updated records must exist on the application server, and accordingly, if the data amount is larger than the storage capacity, this method could not be used.
Published Japanese Patent Application No. 2004-280494 describes that when there is a data update request, a server cache is searched and the data burst server cache is updated every time, whereby the update process request for the database frequently occurs.
A hardware-implemented caching mechanism for a central processing unit (CPU) is memory access caching, in which there is still a directory for solving the address similar to the view, but a complex retrieval result is not cached, and there is no mechanism for maintenance or the like which entails double processing. Further, even in the case where a write back mechanism is provided, it is unnecessary to hold the previous update as a batch log to generate an update process instruction, apart from an instance pool, because only the final result is written into the cache. Accordingly, it is not possible to obtain a solution to the problems specific to the application server from the configuration of the CPU.
In order to solve the above problem, the present invention provides a method and apparatus for managing a view having a virtual table for a database.
The method includes the following steps: (1) receiving a request to add an instance of record data to an instance pool of the view, (2) judging whether there is a free space for adding the instance in a storage area of the instance pool, (3) selecting a discard candidate instance from a discard candidate list table in accordance with an Least Recently Used (LRU) algorithm if it is judged that there is less free space than needed for adding the instance, (4) judging whether a revision wait flag is on for the discard candidate instance in the discard candidate list table, (5) deleting the discard candidate instance from the discard candidate list table if it is judged that the revision wait flag is on, (6) deleting the discard candidate instance from the instance pool and adding the instance to the instance pool if it is judged that the revision wait flag is not on, and (7) adding the requested instance to the instance pool if it is judged that there is enough storage area.
By preferentially holding the latest dataset or most recently accessed dataset in the view, even if the memory is not enough for the data amount of the retrieval result, it is possible to respond to a retrieval query without performing the batch update for the database at that time when there is a retrieval query request for the latest dataset.
Though the summary of the invention has been described above as the method, the invention also provides a system for managing a view having a virtual table for a database and a computer program product tangibly embodying computer readable instructions for causing a computer to execute the steps of the above method.
The application server 110 issues a retrieval request to the database (DB server). In practice, first, an instance ID is retrieved from the view pool by a retrieval key to check if there is a corresponding retrieval result. If there is a corresponding instance ID, record data with the corresponding instance ID is returned as the response from the instance pool, or if there is no corresponding instance ID, the DB server is directly searched. The retrieval result of the DB server is accumulated in the view pool and the instance pool. Also, when there is an update process from the application server 110, the view pool and the instance pool are updated, a write instruction into the database (DB server) is accumulated as a batch process, and the batch process is performed for the database in accordance with a predetermined rule.
The application program 201 sends an update request and a retrieval request to the database 250, but actually sends them to the view pool 211 and the instance pool 221. The view pool 211 includes a view 213 having an index 215 containing a retrieval key. The index 215 also includes the instance ID. An instance pool update part 217 adds or deletes the instance to or from the instance pool 221, as needed. The instance pool 221 has an instance 223 and a lock manager 225. The instance 223 may have a lock state flag and a revision wait flag in addition to data that is a part of the database record. The batch processing mechanism 231 holds the update request as a batch log 233, and performs a batch update process for the database 250 in accordance with a predetermined rule.
At step 311, it is judged whether the applicable key exists in the instance pool. If it is judged at step 311 that the instance of the applicable key does exist, then at step 313, the instance is acquired from the instance table in the instance pool with the applicable ID as the key. At step 315, the ID of the acquired instance is added to the retrieval result list to be sent back to the application program. On the other hand if it is judged at step 311 that the instance of the applicable key does not exist in the instance pool, then at step 317, the instance is acquired from the database with the ID as the key. Thereafter, the operation advances to step 315, where the ID of the acquired instance is added to the retrieval result list. If the acquisition of the instance is not ended for each ID at step 319, the operation returns to step 309. If the acquisition of the instance is ended for each ID, the operation advances to step 321. At step 321, the result list containing the instances is sent back to the application server. At step 341, the process of this flow is ended.
At step 509, it is judged whether the discard candidate instance is locked. If it is judged that the discard candidate instance is locked (Yes) at step 509, the discard candidate instance is deleted from the discard candidate list at step 513, and the operation returns to step 507. When the instance is locked, it is meant that the instance is accessed from another. On the other hand, if it is judged that the discard candidate instance is not locked (No) at step 509, the operation advances to step 511.
At step 511, it is judged whether the revision wait flag for the discard candidate instance is on. If it is judged at step 511 that the revision wait flag is on, the operation advances to step 541, where it is judged whether the number of update requests (batch log) for the batch processing mechanism exceeds a predetermined number. If it is judged at step 541 that the predetermined number is exceeded (Yes), the operation advances to step 543, where the batch log for each key is collected and arranged, and the newest (latest) data value is set to the batch update sentence (as will be detailed later). At step 545, the batch processing mechanism actually updates the database with the batch update sentence. The operation goes to step 513, where the applicable instance is deleted from the discard candidate list. If it is judged at step 541 that the predetermined number is not exceeded (No), the operation goes to step 513, where the applicable instance is deleted from the discard candidate list. The processing from step 541 to step 545 is performed to reflect the update content to the database through the batch process because there may be a number of instances where the revision wait flag is on, however, these steps may not be necessarily performed. The applicable instance is deleted from the discard candidate list at step 513 because, for the instance where the revision wait flag is on, the update contents are not reflected to the database, and the contents of the instance pool are newest, whereby it is required to prevent the deletion from the instance pool.
If it is judged at step 511 that the revision wait flag is not on, the operation goes to step 515, where the discard candidate instance is deleted from the instance pool. Again, to add the instance, the operation returns to step 505. If it is judged that the storage area is enough (Yes), the operation goes to step 521, where the instance is created and added to the instance pool. On the other hand, if it is judged that the storage area is not enough (No), the processing from step 507 to step 515 is repeated. The flow of
The data after update is written into the instance 623 of the instance pool 621. This update request is passed to a batch processing mechanism 625, and the update request is added to a batch update table (batch log) 627. The revision wait flag of the instance is set. If the transaction is ended, the lock is released. And this batch update request is reflected to the database 631 at a given time (e.g., periodically, or after a certain amount of update requests are accumulated).
From the above description, it can be easily understood that an information processing apparatus suitable for realizing the system according to the embodiment of the invention may be implemented in an ordinary personal computer, a workstation, or a main frame, or a combination thereof. These components are illustrative, and all the components may not be the essential components of the invention.
It will be apparent to a person skilled in the art that various changes in each hardware component of the information processing apparatus for use in the embodiment of the invention may be made by combining a plurality of machines, or distributing the functions over them. These changes should be naturally encompassed within the concept of the invention.
The system according to the embodiment of the invention can employ an operating system supporting a GUI (graphical user interface) multi-window environment such as Windows® operating system provided by Microsoft Inc., Mac OS® provided by Apple Computer Inc., UNIX® system having an X Window System (e.g., AIX® provided by International Business Machines Corporation).
From the above, it can be understood that the system for use in the embodiment of the invention may not be limited to the specific operating system environment.
Also, the invention may be implemented as hardware, software or a combination of hardware and software. As a typical example by the combination of hardware and software, a data processing system having a predetermined program is conceived. In such a case, the predetermined program is loaded into the data processing system and executed, whereby the program controls the data processing system to perform the processing according to the invention. This program is composed of an instruction group that can be represented by any language, code and notation. Such instruction group causes the system to perform the specific function directly, or after making any one or both of (i) conversion into another language, code and notation and (ii) copy to another medium.
The invention encompasses not only such program itself but also the medium storing the program. The program for performing the functions of the invention can be stored in any computer readable storage medium such as a flexible disk, MO, CD-ROM, DVD, hard disk drive, ROM, MRAM or RAM. Such program may be downloaded from another data processing system connected via the communication line or copied from another storage medium for storage into the storage medium. Also, such program may be compressed or divided into plural, and stored in a single medium or plural storage media. It should be noted that a program product for carrying out the invention may be naturally provided in various forms.
According to the embodiment of the invention, it is understood that even if the memory is not enough for the data amount of retrieval result, the latest dataset or most recently accessed dataset is preferentially held in the view, whereby even if there is a retrieval query request for the latest dataset, it is possible to respond to the retrieval query without performing the batch update for the database at that time.
It will be apparent to a person skilled in the art that various variations or modifications may be made to the above embodiment. It should be noted that such variations or modifications are included in the technical scope of the invention.
Number | Date | Country | Kind |
---|---|---|---|
2008-118099 | Apr 2008 | JP | national |