2079 4

CSC475 ยท 2079 ยท 5 marks

Why indexing is important to store data in database? What's multilevel index?

Why indexing is important to store data in database? What's multilevel index? [5]

Advanced DatabaseChapter 1: Enhanced Entity Relationship Model and Relational ModelConcepts of File Structures, Hashing, and Indexing

Quick answer

When executing SQL queries, it takes some amount of time to access data from the disk. An index is a data structure that helps to find and access data in a table of a database quickly. Indexing technique reduces the number of disk accesses required to process queries.

Importance of Indexing in Database and Multilevel Index


Why Indexing is Important (2.5 marks)

The key reasons why indexing is important are:

ReasonExplanation
Faster Data RetrievalIndex allows the database engine to locate data without scanning every row in a table
Reduced Disk I/OFewer disk accesses are needed, which significantly speeds up query execution
Query OptimizationIndexing is one of the core optimization techniques that minimizes CPU usage, disk I/O, and network traffic
ScalabilityHelps the system handle growing workloads while maintaining consistent performance
Efficient SearchingOrdered indexing sorts data, making searching faster and more structured

Without indexing, the database would perform a full table scan for every query, which is extremely slow for large databases.


Multilevel Index (2.5 marks)

Definition

A multilevel index is an indexing scheme where the index itself is further indexed at multiple levels, creating a hierarchy of indexes. It is used when a single-level index becomes too large to fit in memory or becomes inefficient to search.

Why Multilevel Index is Needed

  • In a large database, it is not possible to search all the indexes at once to obtain the required data.
  • A single-level index on a very large table can itself become very large, making the index search slow.
  • Multilevel indexing solves this by creating an index over the index, reducing the search space at each level.

Structure

Level 3 (Top/Outer Index) --> very small, fits in memory
        |
Level 2 (Intermediate Index)
        |
Level 1 (Inner/Base Index)
        |
   Actual Data Blocks
  • Level 1 (Primary Index): Index on the actual data file.
  • Level 2 (Secondary Index): Index on the Level 1 index, further reducing search space.
  • Level 3 and beyond: Further levels are added as needed until the top-level index fits in a single disk block or memory.

Key Points

  • Each level reduces the number of entries to be searched.
  • The top-level index is small enough to be loaded into main memory.
  • Multilevel indexing is the foundation of B-Tree and B+ Tree index structures commonly used in DBMS.
  • Secondary indexing contains another level of indexing to minimize the size of mapping, which is a basic form of multilevel indexing.

Example

If a table has 1,000,000 records and each index block holds 100 entries:

  • Level 1 index: 10,000 blocks
  • Level 2 index: 100 blocks
  • Level 3 index: 1 block (fits in memory)

This reduces disk accesses from potentially 1,000,000 to just 3 levels, demonstrating the efficiency of multilevel indexing.


In summary, indexing is critical for fast and efficient data retrieval in databases, and multilevel indexing extends this concept to handle very large datasets by organizing indexes in a hierarchical manner, minimizing disk accesses at every level.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.