INDEXING AND TYPES OF INDEXING
Indexing in a Database Management System (DBMS) is a data structure technique used to efficiently retrieve records from the database files based on some attributes on which the indexing has been done.
The first column i.e. the Search key contains a copy of the primary key or candidate keys or non-keys of the table.
The second column i.e., the pointer contains a pointer or the address of the block where that particular Search key value can be found.
TYPES OF INDEXING
Primary indexing in Database Management Systems (DBMS) is a type of indexing where the index is built on the primary key of a database table. This type of index helps in quickly accessing records based on the primary key, which is unique for each record in the table.
Data Elements must be Ordered and are Key values .
The primary index can be classified into two types: Dense index and Sparse index.
A dense index is an indexing method where there is an index entry for every search key value in the data file. This means that every record in the table has a corresponding index entry.
Consider a table Employee:
A dense index for the EmployeeID column would look like this:
A sparse index is an indexing method where index entries are not created for every search key value. Instead, index entries are created only for some of the search key values. Each index entry points to a block or a page of records.
Using the same Employee table:
A sparse index for the EmployeeID column might look like this:
Here, Block 1 might contain records for EmployeeID 1 and 2, and Block 2 might contain records for EmployeeID 3 and 4.
2. Clustering Indexing
In a clustered index, data elements are ordered and non-key values. This results in similar elements being grouped together into clusters. Each cluster, containing a group of similar values, is assigned a single key index. Clustered indexing utilizes only sparse indexing. The data in the search table is ordered and unique. The arrow from B1 to B2 is called block hanker .
3. Secondary Indexing
In databases, searches can be performed on both primary key and non-primary key values. Secondary indexing is used when the data is unordered, and the values can be either key elements or non-key elements. This approach involves using two indexes to facilitate quicker and easier searches.
For key values, a primary index is used, which is a sparse index. For non-key values, a secondary index is created. In this case, the non-key values are first ordered in a secondary table. Then, a separate index table with a dense index is prepared to manage these non-key values.