Method and apparatus for determining a data base address

Abstract: A data hashing arrangement (100) particularly suitable for efficient database (105) storage and fast retrieval of large numbers of character strings. A database address is determined for a character string by replacing individual characters with random numbers selected from a predefined table (104) of random numbers. The table locations of the selected random numbers are uniquely defined by the characters. The selected numbers are combined by interactive bit reordering and exclusive-OR operations to form a result, which is then used to derive the database address where the character string is stored.

Description: This invention relates to methods and apparatus for determining a data base address. Data are commonly stored in a database in a relation or table where rows in the table are called tuples and columns are attributes having unique names. A named attribute in a specific tuple is referred to as an item. A key is a subset of attributes whose values are used to uniquely identify a tuple. One method for storing and retrieving tuples involves ordering the tuples sequentially based on their keys, for example, in alphabetical or numerical order. However, the best technique of searching for a tuple in a sorted table requires at least an average of log₂ M probes, where M is the size of the table. For example, an average of at least 10 probes are required to find a tuple in a table having 1024 entries. One can do much better than this using a table referred to as a scatter storage table. The fundamental idea behind scatter storage is that the key associated with the desired tuple is used to locate the tuple in storage. Some transformation is performed on the key to produce the database address where the tuple is stored. Such transformations are referred to as "hash functions" and the data storage and retrieval procedures associated with scatter storage are known as data hashing. A good hash function is one that spreads the calculated addresses uniformly across the available addresses. If a calculated address is already filled with another tuple because two keys happen to be transformed into the same address, a method of resolving key collisions is used to determine where the second tuple is stored. For example, with a known method referred to as linear probing, the second tuple is stored at the next available address. A number of hash functions have been developed for transforming keys comprising character strings. Such functions are useful, for example, in hashing symbol tables for computer program compilers and typically form various numerical or logical combinations of bits representing the string characters to determine a positive integer. The database address is then derived as a function of the positive integer. For example, the database address may be obtained by dividing the positive integer by a constant and taking the remainder. However, with known hash functions, patterns in the data frequently result in a significant clustering of data rather than a uniform distribution. When the data are stored in pages on a disk, the clustering can result in many tuples being stored on overflow pages other than those defined by the calculated addresses. This leads to slow data access since retrieving particular tuples will frequently require more than one disk access operation. Increasing the total available storage such that the data are more sparsely packed can improve data access times but only at substantial expense. In view of the foregoing, a recognized problem in the art is the clustering of data that occurs when character strings are hashed by performing manipulations and combinations of the individual characters. According to one aspect of this invention there is provided a method as claimed in claim 1. According to another aspect of this invention there is provided apparatus as claimed in claim 7. In an exemplary data hashing arrangement the characters of a character string are advantageously replaced by numbers selected from a predetermined table of numbers at table locations uniquely defined by the characters. A data hashing arrangement using this technique allows uniformly distributed database addresses to be derived even if the data are highly patterned, thus allowing data to be relatively densely packed in the database while still achieving fast data access. In a preferred embodiment, the data item is a tuple key and the data units are characters each represented by an eight-bit byte encoded according to the well-known ASCII code. Each character is replaced by the number stored at the table location defined by the ASCII representation of that character. Significantly, the numbers in the predefined table of numbers are independent of the characters of the key, i.e., they cannot be derived therefrom by predetermined manipulations. The numbers in the predefined table are statistically random. The selected numbers are combined by initializing a register, reordering the bits in the register, generating a combination of one of the selected numbers with bits in the register, storing the combination in the register, and then repeating the reordering, generating, and storing steps for each of the selected numbers. The database address is derived by dividing the result formed in the register by a positive integer and taking the remainder. In the preferred embodiment, the bit reordering step comprises a circular shift of the register bits and the generated combinations are exclusive-OR combinations. Drawing Description FIG. 1 is a block diagram of a computer system implementing an exemplary data hashing method in accordance with the invention; FIG. 2 is a high-level flow diagram of a database address generation program used in the computer system of FIG. 1; FIG. 3 is a more detailed flow diagram of a portion of the database address generation program used in the computer system of FIG. 1; and FIG. 4 is a block diagram of a database address generation apparatus implementing the exemplary data hashing method. Detailed Description An exemplary hashing arrangement embodying the invention is used for data storage and retrieval of a relation on a disk 105 (FIG. 1). Disk 105 is included as part of computer system 100 which operates as the system central control in a telephone switching system. The key for the relation is an authorization code comprising a character string of 15 ASCII characters. Each tuple of the relation also includes information defining one of a set of possible dialing privileges. When a customer enters his or her assigned authorization code from a station set (not shown), a processor 101 of computer system 100 executes a program stored in a program block 103 of a memory 102 to determine the database address where the tuple identified by the entered authorization code is stored on disk 105. As is described herein, execution of the program involves the selection of random numbers from a table of random numbers stored in a table block 104. If the identified tuple is present in the relation stored on disk 105, the tuple is read by processor 101 to determine, for example, whether the customer can originate a telephone call from that station set. A high level flow diagram of the database address generation program stored in program block 103 is shown in FIG. 2. The program makes use of a table of 31-bit random numbers shown in abbreviated form in Table I. The complete table is included in Appendix A. The table has a 31-bit random number stored at each of 256 table locations. The 31-bit random numbers are shown in Table 1 and Appendix A in hexadecimal form. Execution of the program begins with block 200 during which the character string of N characters is stored, N being a positive integer greater than one. In the present example N is 15. During block 210, 15 random numbers are selected from the table of random numbers, one from each location defined by a character of the string. During block 220, the 15 random numbers are combined to form a result. Then during block 230, the database address for the character string is derived as a deterministic function of the result. A more detailed flow diagram of a portion of the database address generation program is shown in FIG. 3. The portion of the program shown in FIG. 3 would replace blocks 200, 210 and 220 of FIG. 2. Execution begins with block 301, where one or more keys are entered. Assume initially that a single key comprising 15 ASCII characters is entered, where each character is represented by an eight-bit byte. Execution proceeds to block 302 where a variable 1foldbit is initialized to zero. Execution then proceeds to decision block 303 where a branch is made depending on whether the key is a character array or a single character. Consistent with the assumption of a character array of 15 characters or bytes, execution proceeds from decision block 303 to block 304 where a variable reg is initialized to zero, and then to block 305 where the number of bytes in the key is calculated. The variable reg comprises 32 bits including an initial sign bit. The sequence of blocks 306, 307, 308, 309, and 310 effect a circular left shift of the 31 rightmost bits of the variable reg by seven bits. (Since the variable reg was initialized to zero, the circular left shift has no effect the first time blocks 306 through 310 are executed.) Then in block 311, an exclusive-OR combination is formed of the variable reg with the random number at the location of the random number table defined by the first character or byte of the key. In block 312, a determination is made as to whether there are more bytes of the key yet to be processed. Since, at this point only one byte has been processed, execution proceeds to block 313, where the second byte of the key is accessed and the sequence of blocks 306 through 311 is repeated. Again a circular left shift by seven bits is performed on the 31 rightmost bits of the variable reg. In block 311, an exclusive-OR combination is formed of the variable reg with the random number at the location of the random number table defined by the second byte of the key. The process is iterated for each of the 15 bytes of the key. After the last byte has been processed, execution proceeds from block 312 to block 314 where the contents of the variable reg are added to the variable 1foldbit. Execution proceeds to decision block 315 where it is determined whether there are more keys yet to be processed. Consistent with the present example of a single key, execution proceeds to block 316 where the sign bit of the variable 1foldbit is masked. Then in block 317, the variable 1foldbit is copied to a memory address defined by a pointer variable addrfoldbit. Finally the variable addrfoldbit is returned in block 318 as the pointer to the location where the result is stored. The program of FIG. 3 also includes provision for handling multiple keys and keys comprising a single character or byte. In the case of single-byte keys, execution proceed from decision block 303 to block 319, where the key is simply added into the variable 1foldbit. Multiple keys are processed by branching from decision block 315 to block 320, where the next key is obtained, and then repeating the above-described process beginning with block 303. It is important to note that the same result is obtained whether all 15 random numbers are selected first and then combined as in the flow chart of FIG. 2, or each random number is in turn selected and then combined with the contents of the variable reg as in the flow chart of FIG. 3. As discussed above, the result obtained by the program of FIG. 3 is then used to derive the database address both to initially store the tuple including the character string on disk 105, and to subsequently retrieve the tuple. In the present example, the relation is stored on disk 105 on M1 pages each comprising space for M2 tuples per page, where M1 and M2 are engineered quantities. If the result of execution of the program of FIG. 3 for a particular character string is denoted by R, the tuple including the character string is stored on page R mod M1 at location R mod M2, where R mod M1 is the remainder of the division of R by M1 and R mod M2 is the remainder of the division of R by M2. If the derived database address is being used to store another tuple, a linear probing of the other addresses on that page is effected and the next available address on the page is used (including returning to the beginning of the page if necessary). If the derived database address defines a page which is completely filled with other tuples, the next tuple is stored on an overflow page. The exemplary data hashing arrangement described above has been used to store 100,074 tuples on disk 105 at a packing density of 73% with only one tuple being stored in overflow. Reducing the packing density to 69% resulted in no tuples being stored in overflow. FIG. 4 is a block diagram of a database address generator 400 implementing the above-described data hashing method for generating a database address from an N-byte key, where N is a positive integer greater than one. In the present example, N is 15. Generator 400 includes a register 401, which stores the 15-byte key, and further includes a memory 402 used to store the table of 31-bit random numbers of Appendix A. Register 401 transmits the first byte of the key to an ADDRESS input port of memory 402. A read control unit 407 first effects a seven-bit circular left shift operation on the contents of a 31-bit circulating shift register 405 by transmitting seven clock pulses thereto. Read control unit 407 then effects the reading of a 31-bit random number from memory 402 at the addressed location defined by the byte from register 401. The random number is stored in a 31-bit register 403. An exclusive-OR unit 404 then performs an exclusive-OR combination of the contents of register 403 and shift register 405 and overwrites the result back into shift register 405. The procedure is repeated for each of the 15 bytes of the key. A divider unit 408 then derives the database address as a function of the result formed in shift register 405. In the present embodiment, divider 408 generates the page of disk 105 (FIG. 1) according to R mod M1 and the location on that page according to R mod M2, where R is the result formed in shift register 405, M1 is the total number of pages available for storage, and M2 is the number of tuples that can be stored per page.

Claims: A method for determining a database address for a data item which is a key, said data item comprising N data units, N being a positive integer greater than one, said method comprising for each of said N data units, selecting a number from a predefined table of numbers at a location of said table determined from that data unit, combining said selected N numbers to form a result, and deriving said database address as a predetermined function of said result wherein each of said selected numbers comprises a plurality of bits, and said combining step comprises A) initializing a register for storing a plurality of bits, B) reordering bits in said register, C) generating a combination of one of said selected numbers with bits in said register, D) storing said combination in said register, and E) repeating steps B), C), and D) for other ones of said selected numbers to form said result in said register. A method in accordance with claim 1 wherein the numbers of said predefined table of numbers are each independent of said N data units. A method in accordance with claim 2 wherein the numbers of said predefined table of numbers are random numbers. A method in accordance with claim 1 wherein said reordering step comprises performing a circular shift operation on bits in said register. A method in accordance with claim 1 or 4 wherein said combination comprises an exclusive-OR combination. A method in accordance with claim 3 wherein said deriving step comprises deriving said database address from said result as a remainder of a division of said result by a positive integer greater than one. Apparatus (400) for determining a database address for a data item which is a key, said data item comprising N data units, N being a positive integer greater than one, said apparatus comprising means (402) for storing a predefined table of numbers, means (401,407) for selecting N numbers from said storing means at locations of said storing means determined from each of said N data units, means (404,405) for combining N numbers selected from said storing means to form a result, and means (408) for deriving said database address as a predetermined function of said result, wherein the numbers of said predefined table of numbers are random numbers each comprising a plurality of bits, and said combining means comprises register means (405) for storing a plurality of bits, and means (404) responsive to each number selected by said selecting means for generating a combination of said each selected number with bits in said register means and overwriting the generated combination into said register means, where said result is formed in said register means after N numbers have been selected by said selecting means and N generated combinations have been overwritten into said register means. Apparatus in accordance with claim 7 comprising means (406,405) for reordering bits in said register means. Apparatus in accordance with claim 8 wherein said reordering means comprises means (405) for performing a circular shift operation on bits in said register means.

Inventors: CHURM BRIAN RICHARD, DIESEL MICHAEL EVANS, CHURM, BRIAN RICHARD, DIESEL, MICHAEL EVANS
Applicants: AMERICAN TELEPHONE & TELEGRAPH, AMERICAN TELEPHONE AND TELEGRAPH COMPANY
Application year: 1987
Main classification: G06F15
IPC codes: G06F17