The present invention relates to referential integrity in highly concurrent database environments, and more particularly to a method for ensuring referential integrity during concurrent transactions that update parent and dependent objects in which the relative location of dependent objects may change.
Relational databases allow for defining relationships between two objects and rules for their coexistence. This is referred to as referential integrity. When such a relationship is defined between two objects, one object is the parent object and the other is a dependent object. For example, relational databases make use of primary keys and foreign keys. A primary key uniquely identifies a row in a table, while a foreign key is an attribute of a table that forms a relationship with another table by storing a primary key value of the related table. Here, the primary key is the parent object and the foreign key is the dependent object. The problem of ensuring that the database does not include any invalid foreign key value is a referential integrity problem, while the database constraint that a value of a given foreign key must match the value of the corresponding primary key is known as a referential constraint.
Referential constraints are applied to database transactions that update or delete a parent object. When a parent object is updated, a constraint check is performed to ensure that there are no dependent objects dependent on the parent object being updated. If such a dependent object exists, then the update to the parent object is not allowed. The referential constraint also applies when a dependent object is updated or inserted to make sure the inserted or updated value matches a value in the parent object.
In a highly concurrent environment, it is always possible that multiple transactions are active in the system at any given time. For example, some transactions may be performing updates or deletes of parent objects, which includes checking for the existence of dependent objects. At the same time, some other transactions may be performing updates on these dependent objects.
One problem is that some updates to dependent objects may change the storage location of the updated object or its index entry, and current methods for performing constraint checks fail to take this possibility into account when searching for dependent objects during constraint checks. For example, assume that one transaction is performing an update or delete of a parent object and is in the process of searching for a dependent object in a particular table. Assume further that a second transaction has performed an update of the dependent object in the table that moves the dependent object from a location ahead of the current search location to a location in the table prior to the current search location. In this case, the first transaction's search for the dependent object will fail. And if the first transaction is a delete of parent object, the delete operation will leave behind a dependent object without a parent object, referred to as an orphan object, which violates the referential constraint.
Accordingly, what is needed is an improved method for ensuring referential integrity in a database environment that allows both concurrent transactions to parent objects and transactions to dependent objects that change the relative locations of the dependent objects.
The present invention provides a method for ensuring referential integrity in a concurrent transaction database environment. The method includes determining when an update to a dependent object requires special processing, and if special processing is required, locating and locking parent objects of the dependent object in share mode before moving the dependent object.
According to the method disclosed herein, the situation when a dependent object is moved during the constraint search of a transaction that updates a parent is avoided because the transactions for the parent objects must wait until the update transaction to the dependent object is completed. If the update/delete transaction to a parent object starts before the update to the dependent object, the two transactions will deadlock and one of the transactions will be rolled back. In either event, the present invention prevents non-detection of the existence of the dependent object.
The present invention relates to referential integrity. The following description is presented to enable one of ordinary skill in the art to make and use the invention and is provided in the context of a patent application and its requirements. Various modifications to the preferred embodiments and the generic principles and features described herein will be readily apparent to those skilled in the art. Thus, the present invention is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features described herein.
Unlike some existing databases, the DBMS 14 in the present environment allows multiple concurrent update transactions, which include update (i.e., modify), delete, and insert operations. Transactions for parent objects that need to perform criteria searches for the existence of dependent objects may perform the searches using different methods, such as table scan searches and index searches. The present invention provides the concurrent database system 10 with a mechanism to ensure that a change in location of a dependent object, or of an index entry for the dependent object, by one transaction does not prevent the detection of the dependent object's existence by another transaction that updates a parent object of the dependent object. The present invention is implemented as one or more software routines that may or may not be part of the DBMS 14.
In this example, the update transaction 76 qualifies for special processing because the first column 72a defines the partition boundaries for the table and therefore controls the location that the record or object resides in the table, and the update transaction 76 changes a value in the first column to one that causes the record to be moved.
Referring again to
If an update transaction for the parent table 82 attempts to change the Department Number value “25”, then a search would be made for a dependent object in the dependent table 82 by performing an index search on the Department Number column having a value of 25. Since the Department Number column in the dependent table is used to determine the existence of the dependent object in this transaction, the Department Number column is the pertinent part of the index.
Now consider an update transaction for the dependent table 82 that attempts to change a value in the Employee number column for a record that has a Department Number value of “25”. In this case, the update would require special processing because Department Number is still the pertinent part of the index because it is used to determine the existence of the record, but the update is to the non-pertinent part of the index because the Employee number column is not used to determine the existence of the dependent object.
Referring again to
If the update/delete transaction to a parent object starts before the update to the dependent object, the two transactions will deadlock and one of the transactions will be rolled back. In either event, the present invention prevents non-detection of the existence of the dependent object.
The present invention has been described in accordance with the embodiments shown, and one of ordinary skill in the art will readily recognize that there could be variations to the embodiments, and any variations would be within the spirit and scope of the present invention. Accordingly, many modifications may be made by one of ordinary skill in the art without departing from the spirit and scope of the appended claims.
Under 35 USC §120, this application is a continuation application and claims the benefit of priority to U.S. patent application Ser. No. 10/444,569, filed May 22, 2003, entitled “Method for Ensuring Referential Integrity in Highly Concurrent Database Environments,” which is incorporated herein by reference.
Number | Date | Country | |
---|---|---|---|
Parent | 10444569 | May 2003 | US |
Child | 12140959 | US |