0
13kviews
Indexing Techniques in a Database
1 Answer
0
202views

Indexing is a data structure technique to efficiently retrieve records from the database files based on some attributes on which the indexing has been done. Indexing in database systems is similar to what we see in books.

Indexing is defined based on its indexing attributes. Indexing can be of the following types −

  • Primary Index − Primary index is defined on an ordered data file. The data file is ordered on a key field. The key field is generally the primary key of the relation.
  • Single – level ordered indexes

Indexing is a data structure technique to efficiently retrieve records from database files based on some attribute on which the indexing is done.

Indexing can be one of the following types:

  1. Primary index:
  2. If index is built on ordering ‘keyfield’ of file it is called primary index.
  3. Generally it is the primary key of the relation.
  4. The second key is block pointer which gives the address of the disk block.
  5. Primary indexes are also called sparse indexes.
  6. The index file contains primary key along with the pointer to the address of data block where records are stored.
  7. The keys are matched with values stored in primary key-field of data file and the matching record is accessed without having to reach each field in entire file.
  8. Secondary Indexes
  9. In provides an alternative means to access file that contains database records.

  10. Secondary Index

    Secondary index may be generated from a field which is a candidate key and has a unique value in every record, or a non-key with duplicate values.

    These indexes are based on either candidate keys containing unique values or non-key attributes containing duplicate values.

  11. Secondary indexes can be considered as ordered files and having 2 fields.
  12. The data type of one field is the same to that of a non-ordering indexing field of file containing records.
  13. The data type of other field is a pointer that points to either a block or a record.
  14. A number of secondary indexes can be created for same file.
  15. Clustered indexes
  16. Clustering indexes are defined on file containing data in an ordered manner.
  17. These indexes use no key to order the records in the file
  18. Clustering indexes require every different value of n field to have a distinct entry for itself.
  19. Clustering indexes are also called sparse indexes.

enter image description here

enter image description here

enter image description here

Clustering Index − Clustering index is defined on an ordered data file. The data file is ordered on a non-key field.

Ordered Indexing is of two types: Dense Index and Sparse Index

3.1. Dense Index

In dense index, there is an index record for every search key value in the database. This makes searching faster but requires more space to store index records itself. Index records contain search key value and a pointer to the actual record on the disk.

enter image description here

3.2. Sparse Index

In sparse index, index records are not created for every search key. An index record here contains a search key and an actual pointer to the data on the disk. To search a record, we first proceed by index record and reach at the actual location of the data. If the data we are looking for is not where we directly reach by following the index, then the system starts sequential search until the desired data is found.

enter image description here

3.3. Multilevel Index

Index records comprise search-key values and data pointers. Multilevel index is stored on the disk along with the actual database files. As the size of the database grows, so does the size of the indices. There is an immense need to keep the index records in the main memory so as to speed up the search operations. If single-level index is used, then a large size index cannot be kept in memory which leads to multiple disk accesses.

enter image description here

Multi-level Index helps in breaking down the index into several smaller indices in order to make the outermost level so small that it can be saved in a single disk block, which can easily be accommodated anywhere in the main memory.

B+ Tree

A B+ tree is a balanced binary search tree that follows a multi-level index format. The leaf nodes of a B+ tree denote actual data pointers. B+ tree ensures that all leaf nodes remain at the same height, thus balanced. Additionally, the leaf nodes are linked using a link list; therefore, a B+ tree can support random access as well as sequential access.

Structure of B+ Tree

Every leaf node is at equal distance from the root node. B+ tree is of the order n where nis fixed for every B+ tree.

enter image description here

Please log in to add an answer.