Abstract:
A method, system and process for providing an improved database blocking technique for updatable and scrollable cursors is disclosed. The invention is facilitated by the operation of a process in the memory of a processor. The processor, under the control of the process, builds a reserved area in the memory of the computer. The reserved area in the memory contains an image of a portion of the information residing on disk in the database. When an application opens a cursor to a database, the type of blocking is specified for that cursor. The application issues a fetch request, and if the row is not in the block in the reserved area in the memory, then a remote procedure call is performed to get the required next block of rows and return the block containing the rows back to the application. Various lock data structures are employed to manage and control the processing.

Description:
FIELD OF THE INVENTION 
     This invention generally relates to improvements in database accesses and more particularly to reducing the overhead per accessed row using updatable and scrollable cursors. 
     BACKGROUND OF THE INVENTION 
     Databases have become the subject of significant recent interest, not only because of the increasing volume of data being stored and retrieved by computerized databases but also by virtue of the data relationships which can be established during the storage and retrieval processes. 
     Structured Query Language (SQL), and in particular ANSI SQL, has become a preferred language media for communicating queries to relational databases. As a consequence, there presently exist thousands of relational databases and thousands of related queries directed to such databases. Given an investment in such databases and queries, migration is not only a desirable feature, but a substantially necessary capability for new relational database systems and methods. 
     To a Database Manager (DBM) application program, each fetch of the next row is a separate SQL request. If each row fetch of the next row is implemented as a direct call to the SQL DBM, a large amount of overhead is accrued per request. For local applications resident on a server machine, the per request overhead is two process switches and a DBM Agent process attach and deattach. For a remote application running on a client machine, there is additional overhead associated with the round-trip message per request. 
     Blocking is an application transparent technique that allows multiple rows at a time to be moved between an application process and a DBM Agent process. Thus, blocking distributes the overhead burden over many rows. 
     SUMMARY OF THE INVENTION 
     Accordingly, it is a primary object of the present invention to provide a database blocking technique for updatable and scrollable cursors. 
     These and other objects of the present invention are accomplished by the operation of a process in the memory of a processor. The processor, under the control of the process, builds a reserved area in the memory of the computer. The reserved area in the memory contains an image of a portion of the information residing on disk in the database. When an application opens a cursor to the database, the type of blocking is specified for the cursor. If writethrough or writeback blocking is requested, then the application issues a fetch request, and if the row is in the reserved area in the memory, then the row is fetched and returned locally without going to the database manager. However, if the row is not in the reserved area in the memory, then a remote procedure call is performed to get the required next block of rows. The database manager modifies the locks on the previous block of information and gets the next block of rows and places them in memory with the appropriate lock structure. The database manager then returns the block containing the rows back to the application. Various lock data structures are employed to manage and control the processing. A row update is handled differently depending on whether writethrough or writeback blocking is selected. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     FIG. 1 is a block diagram of a host computer in accordance with the subject invention; 
     FIG. 2 illustrates three levels of database blocking in accordance with the subject invention; 
     FIG. 3 illustrates the efficiency benefits acheived through blocking in accordance with the subject invention; 
     FIG. 4 illustrates how a DX lock is related to other locks in accordance with the subject invention; 
     FIG. 5 is a flow diagram for an application process and a database manager process in accordance with the subject invention; 
     FIG. 6 is a flow diagram for an application process and a database manager process in accordance with the subject invention; 
     FIG. 7 is a flow diagram for an application process and a database manager process in accordance with the subject invention; 
     FIG. 8 is a flow diagram for an application process and a database manager process in accordance with the subject invention; and 
     FIG. 9 is an illustration of the data structures in accordance with the subject invention. 
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
     A representative hardware environment is depicted in FIG. 1, which illustrates a typical hardware configuration of a workstation in accordance with the subject invention having a central processing unit 10, such as a conventional microprocessor, and a number of other units interconnected via a system bus 12. The workstation shown in FIG. 1 includes a Random Access Memory (RAM) 14, Read Only Memory (ROM) 16, an I/O adapter 18 for connecting peripheral devices such as disk units 20 to the bus, a user interface adapter 22 for connecting a keyboard 24, a mouse 26, a speaker 28, a microphone 32, and/or other user interface devices such as a touch screen device (not shown) to the bus, a communication adapter 34 for connecting the workstation to a data processing network and a display adapter 36 for connecting the bus to a display device 38. 
     A source application program (APPL) can access a Database Manager (DBM) using embedded SQL or other database manager commands. After compilation, the SQL statements access the DBM using a set of library routines that execute in the APPL process. The DBM executes in a separate pool of processes from the APPL. Each request is assigned to one of the DBM processes which are referred to as DBM agents. For a local APPL, ie. the APPL executes in the same machine as the DBM, the overhead per DBM request is two process switches as well as an attach and deattach to a SQL process. For a remote APPL, ie. the APPL executes in a different client machine from the DBM, the overhead per DBM request also includes a round trip message. The APPL locally sees a row-at-a-time interface to the DBM. If row-at-a-time is reflected back to the DBM as a separate request, then there is a high overhead per row. 
     Blocking is a technique to distribute the overhead over many rows. Blocking is accomplished in a manner transparent to the APPL, but the library routines provide a reserved area in the memory management facility within the APPL process. That is, the APPL sees the row-at-a-time interface and the library routines provide reserved area in the memoryd rows without going back to the DBM until a block full of rows has been exhausted. When the block, ie. one or more pages of rows is exhausted, then the library routines send a single request to the DBM for another block of rows. Although multi-row interfaces may be provided directly to the APPL, they require more sophistication by the APPL programmer. Blocking is transparent to the programmer, so that current applications do not require change. 
     The current DBM for updateable or scrollable cursors provides blocking for read only cursors with only a one-way information flow. After data is used by the APPL, it is discarded. Updatable cursors refers to making a determination of which rows are to be updated at runtime as opposed to making the determination while compiling the application. FIG. 2 illustrates three levels of blocking. Level 0 200, no blocking, is the only option supported in the current DBM. Level I (writethrough) allows blocking only in the read direction, from APPL process to DBM Agent, and each update requires a separate message back to the DBM Agent to synchronously secure a write lock. Level 1 is always more efficient than Level 0. Level 2, writeback, allows blocking in both directions at the price of temporary overlocking. Level 2 can be employed when there are no interrow integrity constraints to be checked. 
     The benefit in these new blocking techniques is that they provide balancing between the following features: 
     distributing overhead between multiple row access operations; and 
     data contingency based on locking data for all reserved area in the memory operations. 
     FIG. 3 illustrates the benefits of these operations. A local APPL benefits from minimized DBM Agent attaching, deattaching and minimized process switching. A remote APPL also benefits from minimized messaging. 
     The tradeoff can be made by offering the following options to application developers: choice of level of blocking; and different block sizes. A smaller block size reduces both the advantages and disadvantages of blocking. 
     Blocking with updatable and/or scrollable cursors is like multiprocessor caching, but with the additional complexity of maintaining the correct level of isolation between transactions. The locking techniques required to maintain isolation between transactions is an important feature of the invention. The locking techniques also ensure reserved area in the memory consistency between transactions by preventing multiple transactions updates of the same data. Other important features of the invention are the additional reserved area in the memory consistency techniques required within a single transaction. 
     Locking Techniques 
     Writethrough and writeback blocking have the following complexities that are not encountered in readonly blocking. 
     Which row: an update must be efficiently returned to the DBM with enough information to include it in the database. This information includes which row and its updated value. 
     Locks: locks must be maintained efficiently while maintaining the specified level of isolation. For example, whether the lock is for a repeatable read or cursor stability. 
     It is critical to solve the &#34;which row&#34; problem by shipping between the DBM Agent process and the APPL process something with each row that uniquely identifies the row, and to solve the locks problem of overlocking data while it is being stored in the reserved area in the memory in the APPL process. 
     The following three levels of isolation are supported by the DBM: 
     Repeatable-read: two phase locking to guarantee serializability. 
     Cursor-stability: to guarantee the value of the row currently pointed to by the cursor will not change. It does not guarantee that the criteria for membership of rows in the cursor set will be kept consistent with the current database or with what has already been seen by the APPL. 
     Uncommitted read: guarantees only that the rows will not be accessed in the middle of another transaction&#39;s update. 
     The following three types of locks are used to implement the invention. S: shared lock, X: nondemotable exclusive lock, DX: demotable exclusive lock. The DBM already supports S and X locks. The DX lock is introduced here to support writethrough blocking. DX has all of the same characteristics as X, except that DX can be demoted to lower levels of locking and X cannot. The lock compatibility matrix and the lock upper bound matrix are illustrated in FIG. 4. The semantics of UPDATE/DELETE WHERE CURRENT OF, the command for updating or deleting the row currently pointed to by the specified cursor, is that a return code with a status 0K means that the UPDATE/DELETE WHERE CURRENT 0F was completed, which includes getting an X lock on the row. For writethrough blocking, the update or delete processing happens in the reserved area in the memory within the APPL process without going to the DBM Agent until the cursor exits the reserved area in the memory. Then, all updates are sent back together in a single message. To support this processing, DX locks are obtained on all rows that are stored in the reserved area in the memory on the APPL process to reserve the ability to get an X lock in case one is actually required. The distinction between DX and X is needed to note whether a row has actually been updated during a previous visit, for example during another cursor scan or in the same cursor scan with scrolling. 
     FIG. 5 is an illustration of a flow diagram showing the interaction between an APPL process and a DBM process for a FETCH operation using writeback blocking. The APPL issues a FETCH request via the library routines in the APPL process. The library routines manage the local reserved area in the memory for blocking operations. If the row is in the reserved area in the memory, then it is fetched and returned locally without going to the DBM Agent. Thus, the only overhead incurred is a procedure call to the library routine. If the row is not in the reserved area in the memory, the library routine sends an RPC to the DBM to return any updates in the previous block and to get the required next block of rows. The DBM Agent process assigned to that request receives the RPC. It first applies any updates in the previous block by modifying locks on all rows of the block. 
     The rules for locking under repeatable-read isolation are: 
     If the row had a DX lock on it and the lock was not updated, then demote the lock to S. 
     If the row had a DX lock on it and it was updated, then promote its lock to X. Note that a DX lock ensures that this is possible without waiting. 
     If the row had an X lock on it, then do not change the lock. 
     The rules for locking under cursor-stability isolation are: 
     If the row had a DX lock on it and it was not updated, then demote its lock to no lock. 
     If the row had a DX lock on it and it was not updated, then promote its lock to X. Note that a DX lock ensures that this is possible without waiting. 
     If the row had an X lock on it, then do not change the lock. 
     Next, the DBM Agent gets the next block of rows, which requires getting the appropriate locks. The rules for locking are: 
     If the row did not have an X lock, then get a DX lock. 
     If the row had an X lock, then no additional locks are necessary. 
     The DBM process then returns the block containing the rows with their unique identifiers back to the library routines in the APPL process. The APPL process then returns the next row to the APPL. This process continues until an EOF is reached. When this happens, the library routine sends an RPC request to the DBM to return any updates in this block. 
     FIG. 6 provides a flow diagram for an UPDATE/DELETE WHERE CURRENT OF request for writeback blocking. The APPL issues an UPDATE/DELETE WHERE CURRENT OF request via the library routines in the APPL process. The updated row will always be in the reserved area in the memory and have a DX lock in the DBM, so that the library routine can simply update it locally. 
     FIG. 7 provides a flow diagram between the APPL process and DBM process for a FETCH request for writethrough blocking. The APPL issues a FETCH request via the library routines in the APPL process. The library routines manage the local reserved area in the memory for blocking. If the row is in the reserved area in the memory, then it is simply fetched and returned locally without going to the DBM Agent, so the only overhead is a procedure call to the library routine. If the row is not in the reserved area in the memory, the library routine sends an RPC request to the DBM to get the required next block of rows. The DBM Agent process assigned to that request receives the RPC. It first modifies the locks on the previous block. 
     The rules for locking under repeatable-read isolation are: 
     Do nothing to the locks 
     The rules for locking under cursor-stability isolation are: 
     Release the S locks. 
     The DBM Agent gets the next block of rows, which requires getting at least an S lock on each row in the block. Note that U locks are substituted for S locks under normal conditions. The DBM process then returns the block containing the rows with their unique identifiers back to the library routines in the APPL process. The APPL process then returns the next row to the APPL. This process continues until an EOF is reached. 
     FIG. 8 is a flow diagram for an UPDATE/DELETE WHERE CURRENT OF request for writethrough blocking. The APPL issues an UPDATE/DELETE WHERE CURRENT OF request via the library routines in the APPL process. The updated row will always be in the reserved area in the memory, but the update must be synchronously sent to the DBM to be processes before returning to the APPL. The library routine sends an RPC to the DBM requesting the update. The DBM Agent process assigned to the request receives the RPC. It applies the update, which requires a promotion of the lock to X. Then, the DBM process returns the ack back to the library routines in the APPL process and onto the APPL. 
     Reserved Area in the Memory Consistency 
     If locking is not considered, then blocking can be considered as simply another occurrence of a reserved area in the memory management. However, locking assures consistency of data in the reserved area between transactions by preventing multiple transactions from updating the same data. This reduces to only intertransaction reserved area in the memory consistency problems. 
     In the current version of the Database Manager, only one application process can participate in a transaction, so no reserved area in the memory consistency problems can arise. In later releases, if multiple reserved areas in the memory are maintained for different application processes participating in a single transaction for the same table, then there is a possibility of reserved area in the memory inconsistencies. 
     When the reserved area in the memory manager detects an update to table TB from transaction TR, then it must invalidate all reserved area in the memory of cursors on TB within TR except the reserved area in the memory that was used with an UPDATE/DELETE WHERE CURRENT OF. That is, if a non-cursor update is requested to TB within TR, then the reserved areas in the memory must be invalidated for all cursors on TB within TR. If an UPDATE/DELETE WHERE CURRENT OF Ci is issues on TB within TR, then the reserved areas in the memory must be invalidated for all cursors on TB within TR except Ci. Reserved area in the memory invalidation requires the following extension to the flows: 
     which reserved areas in the memory to invalidate must be determined 
     the appropriate reserved areas in the memory are invalidated, which requires setting an invalidation flag for each reserved area in the memory in the APPL process. 
     the test of whether the next row is in the reserved area in the memory must first check the invalidation flag. 
     if the invalidation flag is set, then the request for the next block asks for the current block instead of the next block. 
     the invalidation flag is cleared when the block arrives. 
     FIG. 9 is an illustration of the data structures in accordance with the subject invention. For each open cursor, certain information must be maintained in the memory of the computer. First, the DBM assigns a contiguous row index number (RIN) 900 to the rows that qualify under the cursor predicated. An array 910 is also created to map the RIN to a Row identifier (RID). RINs are passed instead of RIDs between the application process and the DBM process, so that the application process cannot specify a row outside of those that qualify under a cursor predicate. 
     Then, the application process must maintain the RIN of the row corresponding to the cursor s current-row indicator and an index that maps RINs into the rows it has in the reserved area in the memory. The implementation of the index can be interchanged between a hash-table, B-Tree or a simple list based on user requirements. 
     While the invention has been described in terms of a preferred embodiment in a specific system environment, those skilled in the art recognize that the invention can be practiced, with modification, in other and different hardware and software environments within the spirit and scope of the appended claims.