Many online transaction processing applications have indexes on data where inserts happen in roughly sequential order. For example, order invoice numbers are typically monotonically increasing. For fast access to an invoice given the invoice number, an application may create an index on the invoice number. However, in a highly concurrent environment, inserts into the last page of an index face contention that causes scalability problems where insert operations may have to wait for other data insert operations to complete.
The subject matter claimed herein is not limited to embodiments that solve any disadvantages or that operate only in environments such as those described above. Rather, this background is only provided to illustrate one exemplary technology area where some embodiments described herein may be practiced.
Briefly, aspects of the subject matter described herein relate to optimized reverse key indexes. In aspects, a dispersion function disperses index values such that they are distributed across multiple pages of an index. The dispersion function utilizes a dispersion factor that indicates to what extent the index values are dispersed. Because the index values are dispersed, contention regarding inserts may be reduced or eliminated and other advantages realized.
This Summary is provided to briefly identify some aspects of the subject matter that is further described below in the Detailed Description. This Summary is not intended to identify key or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
The phrase “subject matter described herein” refers to subject matter described in the Detailed Description unless the context clearly indicates otherwise. The term “aspects” is to be read as “at least one aspect.” Identifying aspects of the subject matter described in the Detailed Description is not intended to identify key or essential features of the claimed subject matter.
The aspects described above and other aspects of the subject matter described herein are illustrated by way of example and not limited in the accompanying figures in which like reference numerals indicate similar elements and in which:
As used herein, the term “includes” and its variants are to be read as open-ended terms that mean “includes, but is not limited to.” The term “or” is to be read as “and/or” unless the context clearly dictates otherwise.
Aspects of the subject matter described herein are operational with numerous other general purpose or special purpose computing system environments or configurations. Examples of well known computing systems, environments, or configurations that may be suitable for use with aspects of the subject matter described herein comprise personal computers, server computers, hand-held or laptop devices, multiprocessor systems, microcontroller-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, personal digital assistants (PDAs), gaming devices, printers, appliances including set-top, media center, or other appliances, automobile-embedded or attached computing devices, other mobile devices, distributed computing environments that include any of the above systems or devices, and the like.
Aspects of the subject matter described herein may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, and so forth, which perform particular tasks or implement particular abstract data types. Aspects of the subject matter described herein may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
With reference to
The computer 110 typically includes a variety of computer-readable media. Computer-readable media can be any available media that can be accessed by the computer 110 and includes both volatile and nonvolatile media, and removable and non-removable media. By way of example, and not limitation, computer-readable media may comprise computer storage media and communication media.
Computer storage media includes both volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media includes RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile discs (DVDs) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by the computer 110.
Communication media typically embodies computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media. The term “modulated data signal” means a signal that has one or more of its characteristics set or changed in such a manner as to encode information in the signal. By way of example, and not limitation, communication media includes wired media such as a wired network or direct-wired connection, and wireless media such as acoustic, RF, infrared and other wireless media. Combinations of any of the above should also be included within the scope of computer-readable media.
The system memory 130 includes computer storage media in the form of volatile and/or nonvolatile memory such as read only memory (ROM) 131 and random access memory (RAM) 132. A basic input/output system 133 (BIOS), containing the basic routines that help to transfer information between elements within computer 110, such as during start-up, is typically stored in ROM 131. RAM 132 typically contains data and/or program modules that are immediately accessible to and/or presently being operated on by processing unit 120. By way of example, and not limitation,
The computer 110 may also include other removable/non-removable, volatile/nonvolatile computer storage media. By way of example only,
The drives and their associated computer storage media, discussed above and illustrated in
A user may enter commands and information into the computer 20 through input devices such as a keyboard 162 and pointing device 161, commonly referred to as a mouse, trackball, or touch pad. Other input devices (not shown) may include a microphone, joystick, game pad, satellite dish, scanner, a touch-sensitive screen, a writing tablet, or the like. These and other input devices are often connected to the processing unit 120 through a user input interface 160 that is coupled to the system bus, but may be connected by other interface and bus structures, such as a parallel port, game port or a universal serial bus (USB).
A monitor 191 or other type of display device is also connected to the system bus 121 via an interface, such as a video interface 190. In addition to the monitor, computers may also include other peripheral output devices such as speakers 197 and printer 196, which may be connected through an output peripheral interface 190.
The computer 110 may operate in a networked environment using logical connections to one or more remote computers, such as a remote computer 180. The remote computer 180 may be a personal computer, a server, a router, a network PC, a peer device or other common network node, and typically includes many or all of the elements described above relative to the computer 110, although only a memory storage device 181 has been illustrated in
When used in a LAN networking environment, the computer 110 is connected to the LAN 171 through a network interface or adapter 170. When used in a WAN networking environment, the computer 110 typically includes a modem 172 or other means for establishing communications over the WAN 173, such as the Internet. The modem 172, which may be internal or external, may be connected to the system bus 121 via the user input interface 160 or other appropriate mechanism. In a networked environment, program modules depicted relative to the computer 110, or portions thereof, may be stored in the remote memory storage device. By way of example, and not limitation,
Indexes
As mentioned previously, creating index entries in a highly concurrent environment may cause contention that degrades performance.
In an embodiment, the network 215 may comprise the Internet. In an embodiment, the network 215 may comprise one or more local area networks, wide area networks, direct connections, virtual connections, private networks, virtual private networks, some combination of the above, and the like.
The database 207 comprises a repository that is capable of storing data in a structured format. The term data is to be read broadly to include anything that may be stored on a computer storage medium. Some examples of data include information, program code, program state, program data, other data, and the like.
Data stored in the database 207 may be organized in tables, records, objects, other data structures, and the like. The data may be stored in HTML files, XML files, spreadsheets, flat files, document files, and other files. The database 207 may be classified based on a model used to structure the data. For example, the database 207 may comprise a relational database, object-oriented database, hierarchical database, network database, other type of database, some combination or extension of the above, and the like.
The database 207 may be accessed via a database management system (DBMS). A DBMS may comprise one or more programs that control organization, storage, management, and retrieval of data in the database 207. A DBMS may receive requests to access data in the database and may perform the operations needed to provide this access. Access as used herein may include reading data, writing data, deleting data, updating data, a combination including one or more of the above, and the like.
The database 207 may be stored on a data store. A data store may comprise any storage media capable of storing data. For example, a data store may comprise a file system, volatile memory such as RAM, other storage media described in conjunction with
The server 209 may be implemented on or as one or more computers (e.g., the computer 110 as described in conjunction with
Each of the clients 210-215 may be implemented on or as one or more computers (e.g., the computer 110 as described in conjunction with
The server 209 may host a local client 216. A local client may comprise one or more local processes that requests access to data on the database 207. Local, in this sense, refers to a process, component, or the like that executes on the same machine as the machine upon which the server 209 is implemented.
Although the terms “client” and “server” are used, it is to be understood, that a client may be implemented on a machine that has hardware and/or software that is typically associated with a server and that likewise, a server may be implemented on a machine that has hardware and/or software that is typically associated with a desktop, personal, or mobile computer. Furthermore, a client may at times act as a server and vice versa. At various times, a client and server may both be peers, servers, or clients.
The server 209 may include indexing components 220. Briefly, the indexing components 220 may disperse perform dispersion calculations on index values to access indexes in the database 207. Some exemplary indexing components are described in more detail in conjunction with
Each of the pages 310-312 may include multiple index entries. Although only three index entires are shown in each page, in practice, each page may include tens, hundreds, more, or less index entries. When multiple clients are interacting with a database in a manner to insert new monotonically increasing index values (e.g., invoice numbers), each of the inserts may be directed to a single page.
To update a page, a latch on the page may be acquired. A latch is a short term lock that gives the updator exclusive rights to the page while the latch is held. The latch may be held just long enough for an index entry to be added to the page. Unfortunately, when there is sufficient concurrency in attempts to update a given page, contention for the latch may arise that delays updates to the page. This may occur when sufficient numbers of clients are engaging in transactions that insert new index entries into a given page. With online transaction processing (OLTP) such as online Web retailers, ATMs, and other OLTP systems, where hundreds, thousands, or more users may be concurrently involved, contention may be a significant problem.
In response to this issue, database vendors have attempted to cause index entries to be inserted such that for monotonically increasing values the index entries do not generally get inserted on the same page. One approach that database vendors have used is called reverse key indexes.
In a reverse key index, all the bytes of each index value are reversed before inserting them into an index. For example, referring to 315, given an index of four bytes, with an order of B1, B2, B3, and B4, the system generates an index value having the four bytes reversed, with an order of B4, B3, B2, and B1. This causes values (represented in hexadecimal) such as 0x00000010, 0x00000011, and 0x00000012 to be represented as 0x1000000, 0x11000000, and 0x12000000, respectively. These values represent vastly different numbers than the originals.
When these values are concurrently inserted into a B-tree index, it is very likely that they will be inserted into different pages of the B-tree, thus avoiding contention.
Although this approach avoids contention, it has several problems. First adjacent keys get index values stored in “random” pages that may be anywhere in the index. Because of this random dispersion of index placement, inserting an index value for each sequential key may potentially involve a physical I/O operation which may be costly from a performance standpoint.
Second, it is common to delete keys within a data range. For example, a customer may desire to delete all invoices that are no longer relevant (e.g., invoices from last year). Due to the random distribution of index values corresponding to the keys, deleting such keys may leave fragmented pages in the index.
Third, index values for recently inserted keys are often accessed most frequently. For example, this week's invoices may be queried more often than last week's invoices. As another example, customers may be interested in tracking what they just purchased and may query the database to obtain tracking information for recent purchases. Due to the random distribution of the index values corresponding to the keys, however, each such query may result in physical I/O even though the invoice numbers are close in value.
Fourth, when these reverse keys are used, they may not be amenable for a range query. When index values for keys are stored in increasing order, querying a range of keys may involve finding the first index value for the range of keys and then simply moving forward through sequential pages until the index value for the last key in the range is found. This is very efficient from a querying perspective.
Unfortunately, when reverse keys are used, this mechanism is not available. Searching through index values corresponding to a range of keys may involve searching through an entire index table and sorting the results afterwards.
Derived index values are derived via a dispersion function 415 that accounts for a dispersion factor 420. The dispersion factor 420 indicates a number of bits to swap in a first index value to create a derived index value. For example, a dispersion factor of 8 may indicate that the 4 least significant bits (e.g., portion P4) are to be swapped with the adjacent bits (e.g., portion P3) to create a derived index value.
In one embodiment, the swapping may be performed by a circular shift of the bits involved. In a circular shift, all bits involved are shifted left or right. Bits that flow out of a sequence wrap around and are used to fill in the other side. For example, in a left shift, the most significant bit becomes the least significant bit while the other bits are shifted one bit to the left. As another example, in a right shift, the least significant bit becomes the most significant bit as the other bits are shifted one bit to the right. A circular shift may specify a shift value that indicates how many positions bits are to be shifted.
In another embodiment, the swapping may be performed by copying half of the bits that are to be swapped to a variable, swapping the other half of the bits in place, and then copying the bits from the variable back into the result in the appropriate location.
The above two mechanisms for swapping bits are not meant to be all-inclusive or exhaustive. Based on the teachings herein, those skilled in the art may recognize other mechanisms for swapping bits. These other mechanisms, however accomplished, may also be used without departing from the spirit or scope of aspects of the subject matter described herein.
The first index value may correspond to an index value that is obtained (using normal index value generation methods) based on a key for a record of a database. For example, an invoice number 46283 may correspond to an index value of 1011010011001011, which is simply a translation from decimal to binary.
The first index value is passed through the dispersion function 415 to create a derived index value of 1011010010111100 which is 46268 in decimal. The dispersion function 415 in this example swaps the least significant 4 bits of the first index value (e.g., 1011) with the adjacent 4 bits (e.g., 1100) to create the derived index value. Note that using this dispersion function, an invoice number 46283 maps to a derived index value of 46268 while an invoice number of 46284 (e.g., 1011010011001100 binary) maps to a derived index value of 46284. Depending on the page size of the database, the derived index value (i.e., 46268) for invoice number 46283 may be on a different page than the derived index value (i.e., 46284) for 46284 in an index table. To increase the dispersion, the dispersion factor 420 may be increased.
The first index values illustrated in the pages 425-427 may correspond to an index value that is normally generated from a key while the derived index values illustrated in the pages 410-412 may correspond to index values that are generated from the first index values via the dispersion function 415. Thus, the derived index value X1 may correspond to the index value Y7, the derived index value X2 may correspond to the index value Y5, and so forth. In the B-tree index 405, these derived index values may be stored in a sorted order.
To retrieve data associated with a key, the dispersion function 415 may be applied to an index value corresponding to the key. The application of the dispersion function 415 yields a derived index value which may then be used in the B-tree 405 to obtain a pointer to the data associated with the key.
Based on the dispersion factor 420, the pages to which the dispersion function 415 may distribute index values may be determined. For example, given the dispersion factor 420 as illustrated, the maximum dispersion may occur when the last 8 binary digits of a first index value is 11110000, which corresponds to 240 decimal. This index value may be distributed to a derived index value of 00001111 which represents a decimal value of 15. The maximal difference in this example is 225 and in general the maximal difference that a derived index value may be dispersed from its original index value is 2N when N represents the dispersion factor.
Using this knowledge, ranged queries on the dispersed index values may be satisfied by increasing the range on either side by the maximum dispersion value. While reading the index table in this manner, it is possible to find index values that are not part of the range. These index values are filtered (e.g., not used) in returning a result set in response to a query. Being able to do a range query on dispersed index values is a significant advantage compared to reverse keys that involve searching an entire index table to satisfy a range query.
Turning to
The communications mechanism 545 allows the apparatus 505 to communicate with other entities shown in
The store 540 is any storage media capable of storing an index. An index comprises one or more index entries. Each index entry may include an index value and data or a link to where data associated with the index value is located. Index entries may be stored on pages and may be referenced by a data structure that facilities fast retrieval (e.g., the B-tree of
The first index value generator 515 may be operable to derive a first index value from a key associated with a record of a database. Deriving may involve using the key as the first index value or creating the first index value using a function that operates on the key.
The dispersion component 520 is operable to generate a second index value from the first index value based on a dispersion factor. This may be done by swapping bits in the first index value, for example. The dispersion factor indicates a maximal potential difference between the first index value and the second index value as previously discussed. The dispersion factor may be directly related to the number of bits swapped.
The index interface 525 may access index entries in the store 540 based on index values. In accessing an index entry, the index interface 525 may insert a new index entry, delete or modify an existing index entry, or retrieve an index entry.
The range component 530 may be operable to work with range queries that involve index values that have been dispersed. In working with such queries, the range component 530 may determine a first location within an index that any of the index values in a range were potentially mapped to by the dispersion component 520. The range component 530 may also determine a last location within the index that any of the index values in the range were potentially mapped to by the dispersion component 520. The range component 530 may then access index entries between the first and last locations and filter retrieved entries that are not within the range. A retrieved entry may not be within the range, for example, if after performing an inverse dispersion calculation on the index value, the index value falls outside of the range. Where bits are swapped, an inverse dispersion calculation may be identical to a regular dispersion function.
At block 610, a request to access data in a database is sent. For example, referring to
At block 615, the request is received. For example, referring to
At block 620, a first index value corresponding to a key is obtained. There are cases in which the first index value is identical to the key. For example, an invoice number (e.g., the key) may be identical to the first index value. In this case, obtaining the first index value involves obtaining the key. In cases where the first index value is derived from the key, the key may be passed to a function that generates the first index value based on the key.
At block 625, a second index value is computed based on the first index value and a dispersion factor. For example, referring to
At block 630, an index is accessed using the second index value. For example, referring to
At block 635, a response is sent to the client. For example, referring to
At block 640, the client receives the response. For example, referring to
At block 645, other actions, if any, may occur.
At block 710, a query associated with a range of indexes is received. For example, referring to
At block 715, a determination is made as to a lower bound of a transformed range corresponding to the range included in the query. As described previously, because of dispersion, index entries may be distributed to various pages within an index. Based on the dispersion factor and the range, however, the lowest index value that could potentially be involved with the range may be calculated. In one embodiment, this may involve the formula:
LB=RL−D,
where LB=the lower bound for the transformed range, RL=the lowest value of the range included in the query, and D=the maximum dispersion value.
At block 720, a determination is made as to an upper bound of a transformed range corresponding to the range included in the query. For example, the upper bound for the transformed range may be calculated by the following formula:
UB=RU+D,
where UB=the upper bound for the transformed range, RU=the highest value of the range included in the query, and D=the maximum dispersion value.
At block 725, the index entries between (and inclusive of) the first and last index values calculated above are retrieved. For example, referring to
At block 730, entries that do not map to the range of index values are filtered. For example, for each index entry that does not fall within the range, the index entry is removed from the result set.
At block 735, other actions, if any, may occur.
As can be seen from the foregoing detailed description, aspects have been described related to optimized reverse key indexes. While aspects of the subject matter described herein are susceptible to various modifications and alternative constructions, certain illustrated embodiments thereof are shown in the drawings and have been described above in detail. It should be understood, however, that there is no intention to limit aspects of the claimed subject matter to the specific forms disclosed, but on the contrary, the intention is to cover all modifications, alternative constructions, and equivalents falling within the spirit and scope of various aspects of the subject matter described herein.
Number | Name | Date | Kind |
---|---|---|---|
5748952 | Chadha et al. | May 1998 | A |
5822749 | Agarwal | Oct 1998 | A |
5842224 | Fenner | Nov 1998 | A |
5875445 | Antonshenkov | Feb 1999 | A |
5956705 | Stevens et al. | Sep 1999 | A |
6631366 | Nagavamsi et al. | Oct 2003 | B1 |
6647386 | Hollines et al. | Nov 2003 | B2 |
6754662 | Li | Jun 2004 | B1 |
6778985 | Jenkins | Aug 2004 | B1 |
6785684 | Adbo | Aug 2004 | B2 |
7774346 | Hu et al. | Aug 2010 | B2 |
7941451 | Ritchie et al. | May 2011 | B1 |
20050165850 | Mosescu | Jul 2005 | A1 |
20050216518 | Hu et al. | Sep 2005 | A1 |
20070016582 | Kawamura et al. | Jan 2007 | A1 |
20070050381 | Hu et al. | Mar 2007 | A1 |
20070140486 | Haran | Jun 2007 | A1 |
20090157701 | Lahiri et al. | Jun 2009 | A1 |
Number | Date | Country | |
---|---|---|---|
20090300013 A1 | Dec 2009 | US |