Indexing in DBMS is a technique used to improve the speed of data retrieval operations on a database table. An index is a small, separate data structure that allows the DBMS to locate and access records faster, just like an index in a book.
Without indexing, a DBMS has to search through every record (called a full table scan), which is slow for large tables. Indexing reduces the time complexity of searching from O(n) to O(log n) or even O(1) depending on the type of index.
Indexing improves:
Search speed
Sorting and ordering
JOIN performance
Query optimization
Example:
Searching for a student with RollNo = 101 in a table of 1 million rows becomes very fast using an index.
An index stores:
Key (attribute value)
Pointer to the actual record
Example:
Index on RollNo stores:
| RollNo | Pointer |
|---|---|
| 101 | → record address |
| 102 | → record address |
DBMS uses the index to jump directly to the required record.
Created on the primary key of the table.
Entries are stored in sorted order.
Table must be stored in sequential file organization.
Student(RollNo, Name, Course)
Primary Index on RollNo.
Created on non-primary key attributes.
Supports faster access using attributes like Name or City.
Secondary index on Name to quickly search “Amit”.
Reorders the physical storage of data on disk.
Only one clustered index allowed per table.
Employees sorted physically by Department.
Does not change physical order of data.
Stores sorted index information separately.
Multiple non-clustered indexes can exist per table.
Index record exists for every record in the data file.
Fast access but requires more space.
Index record exists for some records only.
Less space but slower compared to dense index.
Large indexes split into multiple levels (like B-trees).
Improves search speed efficiently.
Level 0 → Actual data
Level 1 → Index of Level 0
Level 2 → Index of Level 1
Modern databases mostly use B+ Trees.
Data stored in internal and leaf nodes.
Data stored only in leaf nodes.
All leaves linked → supports fast range queries.
B+ Trees are preferred because they provide:
Faster search
Efficient insertion and deletion
Balanced height
| Feature | Dense Index | Sparse Index |
|---|---|---|
| Index entries | Every record | Some records |
| Speed | Faster | Slower |
| Storage | More | Less |
Speeds up retrieval operations
Improves performance of SELECT queries
Helps in sorting and grouping
Enhances JOIN performance
Essential for OLTP systems (banks, airlines, etc.)
Requires extra memory/storage
Slows down INSERT, DELETE, and UPDATE operations
Too many indexes can degrade performance
Needs regular maintenance (rebuilding)
Indexing is a powerful optimization technique in DBMS used to speed up search and query execution. By creating and maintaining indexes, we avoid full table scans and directly access required records. Modern DBMS systems rely heavily on clustered indexes, non-clustered indexes, and B+ tree structures for achieving high performance, especially in large databases. Proper index selection is vital for efficient database design.
Take quizzes related to this topic and see where you stand!
Start Quiz Now