A key is an attribute whose value can uniquely identify a record in the table T. A primary key is a key chosen to be used as the primary means to identify and search for a record in the table T. Each record in the table T can have one and only one primary key. In a cluster database, the primary key is also used to determine the distribution of the records among the storage nodes. Indices and/or search methods can be created to facilitate efficient search based on the primary key. A secondary key is an alternative key that can also be used to look up a unique record in the table T. The search based on a secondary key is usually less efficient than the search based on the primary key because the physical layout of the table T depends largely on the primary key.
With reference to
Each storage node Si has a node number i and stores a plurality of records. Each storage node Si further comprises a mapping table Mi for mapping a secondary key to a corresponding primary key.
The search term input means 210 is coupled to the plurality of storage nodes Si for retrieving a record on a storage node Si. The search term input means 210 calculates a first node number based on a hash function of the secondary key, queries the first storage node with the secondary key for retrieving a corresponding primary key, calculates a second node number based on the hash function of the primary key, and then queries the second storage node with the primary key for retrieving a corresponding record.
As shown in the
Each storage node Si maintains a local lookup table Ti that stores a subset of the records of table T, that is T0UT1UT2=T, where U represents the union operation. A record r is stored in storage node Si if the hash function h1( ) on the primary key of r maps it to i. That is: r belong to Ti if and only if h1(primary key of r)=i.
This is a well-known technique called hash partition that has been widely used in parallel database. With the hash partition, search based on the primary key can be efficiently done. To look up a record with a given primary key value A, the search system only needs to search on storage node h1(A), instead of all storage nodes.
The purpose of the invention is to facilitate efficient search based on secondary key. For this purpose, a mapping table Mi is created and maintained in each storage node Si. The mapping table Mi stores the (b,a) value pair for each record whose secondary key value is hashed to node Si. That is, for any record r of table T, (r.b, r.a) belongs to Mi if and only if h1(r.g)=i.
In step S320, the search term input means 210 applies hash function h1( ) to the primary key value of record r2 to determine on which storage node Si should be stored. Based on the hash function h1( ), this yield h1(r2.a)=h1(2)=2 mod 3=2, i.e., r2 should be stored on storage node S2. The search term input means 210 then forwards record r2 to storage node S2 and store the record r2 in the local lookup table T2.
In step S330, the search term input means 210 applies hash function h1( ) to the secondary key value of record r2 to determine on which storage node Si the (r2.b, r2.a) value pair should be stored. Based on the hash function h1( ), this yield h1(r2.b)=h1(5)=5 mod 3=2. Consequently, the value pair (r2.b, r2.a)=(5,2) is stored in the mapping table M2 on storage node S2.
To search for a record based on the primary key, it can simply follow the step S320 aforementioned to locate the storage node Si in which the record is stored.
In step S420, the search term input means 210 calculates a first node number based on a hash function with a secondary key. The server node Ck-1, applies hash function h1( ) to the given secondary key value b=2 to calculate which storage node it should contact to get more information. This yield h1(b)=h1(2)=2 mod 3=2. Consequently, the server node Ck-1 forwards the parameter b to storage node S2.
In step S430, the search term input means 210 queries a first storage node S2 corresponding to the first node number with the secondary key value b=2 for retrieving a corresponding primary key. The storage node S2, upon receiving the parameter b=2, looks up its local mapping table M2 for an entry (b,a) whose b column matches 2. In this example, the secondary entry (2,4) is found to be the match. Consequently, the value of the corresponding primary key value (secondary column a=4) is returned to the requesting server node Ck-1.
In step S440, the search term input means 210 calculating a second node number based on the hash function with the primary key. Upon receiving the primary key a=4 from the storage node S2, the search term input means 210 then applies the hash function h1( ) to calculate a second node number based on the hash function h1( ) with the primary key value a=4. This yield h1(a)=h1(4)=4 mod 3=1. Consequently, the storage node S1 actually stores the record.
In step S450, the search term input means 210 queries a second storage node S1 corresponding to the second node number with the primary key value a=4 for retrieving a corresponding record. The storage node S1, upon receiving the primary key value a=4, looks up its own local table T1 for a match. In this example, the first record r4 in the table T1 s found to be the match because the r4.a=4. Consequently, record r4 is returned to the search term input means 210, which in turn returns the record r4 to the client as the result.
In view of the foregoing, it is known that the invention has much better cost balance among record insertion, secondary key-based search, and the supporting data structures than the prior art. As shown in
Although the present invention has been explained in relation to its preferred embodiments, it is to be understood that many other possible modifications and variations can be made without departing from the spirit and scope of the invention as hereinafter claimed.
This application claims the benefit of U.S. Provisional Patent Application No. 60/852,424, filed Oct. 18, 2006, which is hereby incorporated herein by reference in its entirety.
Number | Date | Country | |
---|---|---|---|
60852424 | Oct 2006 | US |