Database dense indexes and sparse indexes

Source: Internet
Author: User

Dense index If the record is ordered, we can build a dense index on the record, which is a series of storage blocks: The key that holds only the record in the block and a pointer to the record itself, the pointer is a point to the record or storage block address. The index block in the dense index file holds the key in the same order as the sort order in the file. Now that we assume that the lookup key and pointer occupy much less storage space than the record itself, we can assume that storing the index file is a lot less than the storage block needed to store the data file. The advantages of the index are particularly noticeable when the memory does not fit the data file, but can hold the index file. At this point, by using the index file, we can find a record of the given key value each time we query with an I/O operation.
The www.2cto.com is shown as a dense index built on a sequential file. Figure 1 Dense index (left) on the sequential file (right) The first index block holds a pointer to the first four records, a second index block holds pointers to the next four records, and so on. Dense indexes support queries that find the corresponding record by the given key value. Given a key value of K, we first find K in the index block. When k is found, we find the corresponding record in the data file according to the corresponding pointer of K. It seems that before we find K we need to retrieve each chunk of the index file, or the average half of the storage block. However, because of the following factors, index-based lookups are more effective than it looks:
1. The number of index blocks is usually less than the number of blocks. 2. Because the keys are sorted, we can use the binary lookup method to find K. If there are n index blocks, we just need to find log2n blocks. 3. The index file may be small enough to be permanently stored in the main memory buffer. In this case, finding the key K involves only main memory access without the need to perform I/O operations.
Sparse Index Sparse index only sets a key for each block of data files-refers to, which saves more storage space than dense indexes, but it takes more time to find records of a given value. A sparse index established on the lookup key can be used only if the data file is sorted by a lookup key, and a dense index is applied to any lookup key. As shown in 2, the sparse index sets a key for each storage block only-refers to. The key value is the corresponding value of the first record in each block of data. Figure 2 The sparse index on the sequential file is the same as in the figure 1 example, we assume that the data file is sorted and that its key value is a multiple of successive 10, up to a larger number. We also continue to assume that each storage block can hold four keys-refers to. In this way, the first index storage block is the index entry for the first key value of the top four data storage blocks, which are 10, 30, 50, and 70, respectively. According to the previously assumed key-value pattern, the second index stores the index entries for the first key value of the fifth to eighth data-store block, which are 90, 110, 130, and 150, respectively. We also list the key values stored in the third index storage block, which are the first key values for the hypothetical nineth to 12th data storage blocks, respectively.
Www.2cto.com in the case of a sparse index, to find a record with a lookup key value of K, we have to find the maximum key value in the index that is less than or equal to K. Since the index file is sorted by key, we can use the binary lookup method to locate the index entry, and then find the corresponding data block according to its pointer. Now we have to search this data block to find a record with a key value of K. Of course, there must be enough formatting information in the data block to indicate the records and the contents of the records, which can be used with any of the techniques in sections 2.5 and 2.7.
Source: >  

From for notes (Wiz)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.