0% found this document useful (0 votes)
18 views

Types of Indexes

Uploaded by

kthpjm95l
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Types of Indexes

Uploaded by

kthpjm95l
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Types of Indexes

INDEXING is a data structure technique which allows you to quickly retrieve


records from a database file. An Index is a small table having only two
columns. The first column comprises a copy of the primary or candidate key
of a table. Its second column contains a set of pointers for holding the
address of the disk block where that specific key value stored.

An index -

 Takes a search key as input


 Efficiently returns a collection of matching records.

There are many types of indexes those are categorized as:


Primary Index

 If the index is created on the basis of the primary key of the


table, then it is known as primary indexing. These primary keys
are unique to each record and contain 1:1 relation between the
records.
 As primary keys are stored in sorted order, the performance of
the searching operation is quite efficient.
 The primary index can be classified into two types: Dense index
and Sparse index.
Dense Index

In a dense index, a record is created for every search key valued in the
database. This helps you to search faster but needs more space to store
index records. In this Indexing method, records contain search key value and
points to the real record on the disk.

Sparse Index

It is an index record that appears for only some of the values in the file.
Sparse Index helps you to resolve the issues of dense Indexing. In this
method of indexing technique, a range of index columns stores the same
data block address, and when data needs to be retrieved, the block address
will be fetched.

However, sparse Index stores index records for only some search-key values.
It needs less space, less maintenance overhead for insertion, and deletions
but it is slower compared to the dense Index for locating records.
Secondary Index

The secondary index can be generated by a field which has a unique value
for each record, and it should be a candidate key. It is also known as a non-
clustering index.

This two-level database indexing technique is used to reduce the mapping


size of the first level. For the first level, a large range of numbers is selected
because of this; the mapping size always remains small.

Example of Secondary Indexing

Here, you can have a secondary index for every search-key. Index record is a
record point to a bucket that contains pointers to all the records with their
specific search-key value.
Clustering Index

In a clustered index, records themselves are stored in the Index and not
pointers. Sometimes the Index is created on non-primary key columns which
might not be unique for each record. In such a situation, you can group two
or more columns to get the unique values and create an index which is
called clustered Index. This also helps you to identify the record faster.

Multilevel Indexing

With the growth of the size of the database, indices also grow. As the index
is stored in the main memory, a single-level index might become too large a
size to store with multiple disk accesses. The multilevel indexing segregates
the main block into various smaller blocks so that the same can stored in a
single block. The outer blocks are divided into inner blocks which in turn are
pointed to the data blocks. This can be easily stored in the main memory
with fewer overheads.
Index and Tree Structure

Here we will use the concept of data structure for creating indexes.

A BST (Binary Search Tree) is a data structure that has a property that all
the keys that are to the left of a node are smaller than the key value of the
node and all the keys to the right are larger than the key value of the node.
But B-Tree is more advantageous than the BST

B Tree

B Tree is a specialized m-way tree that can be widely used for disk access. A
B-Tree of order m can have at most m-1 keys and m children. One of the
main reason of using B tree is its capability to store large number of keys in
a single node and large key values by keeping the height of the tree
relatively small.

A B tree of order m contains all the properties of an M way tree. In addition,


it contains the following properties.

1. Every node in a B-Tree contains at most m children.


2. Every node in a B-Tree except the root node and the leaf node contain
at least m/2 children.
3. The root nodes must have at least 2 nodes.
4. All leaf nodes must be at the same level.

It is not necessary that, all the nodes contain the same number of children
but, each node must have m/2 number of nodes.

Operations: Searching

Searching in B Trees is similar to that in Binary search tree. For example, if


we search for an item 49 in the following B Tree. The process will something
like following:

1. Compare item 49 with root node 78. Since 49 < 78 hence, move to its
left sub-tree.
2. Since, 40<49<56, traverse right sub-tree of 40.
3. 49>45, move to right. Compare 49.
4. Match found, return.
Searching in a B tree depends upon the height of the tree. The search
algorithm takes O (log n) time to search any element in a B tree.

Multi-Key File Organization

Multi-Key file organization techniques are at the heart of database


implementation. There are numerous techniques that have been used to
implement multi-key file organization. Most of these techniques are based on
building indexes to provide direct access by the key value.

The ability to search on many keys is enabled by building multiple index files
(multikey file organisation) “on top of” the data file. The physical database
then consists of one or more data files and many index files, and each data
file contains either one or several record types. Each index file supports
access by a particular field or group of fields.

For example:

Select * from employee where deptid=20 and salary = 5000;

Two of the commonest techniques for this organization are:

 Multi-list file organization

 Inverted file organization


Need for Multiple Access Paths

In practice, most of the online information systems require the support of


multi-key files. For example, consider a banking database application having
many different kinds of users such as:

 Teller  Loan officers  Brach manager  Account holders

All of these users access the bank data however in a different way.

Let us assume a sample data format for the Account relation in a bank and
applications are trying to refer to the same data but using different key
values. Thus, all the applications as above require the database file to be
accessed in different format and order. The two approaches for this:

 By Replicating Data

 By providing indexes.

Replicating Data

One approach that may support efficient access to different applications may
be to provide access to each of the applications from different replicated files
of the data. Each of the file may be organized in a different way to serve the
requirements of a different application.

For example, for the problem above, we may provide an indexed sequential
account file having account number as the key to bank teller and the
account holders. A sequential file in the order of permissible loan limit to the
Loan officers and a sorted sequential file in the order of balance to branch
manager.

All of these files thus differ in the organization and would require different
replica for different applications. However, the Data replication brings in the
problems of inconsistency under updating environments. Therefore, a better
approach for data access for multiple keys has been proposed.

Support by Adding Indexes

Multiple indexes can be used to access a data file through multiple access
paths. In such a scheme only one copy of the data is kept, only the number
of paths is added with the help of indexes.

Multi-list file Organization


The basic approach to provide the linkage between an index and the file of
data records is called multi-list organization.

In a multi-lists organization, indexes are defined on the multiple fields that


are frequently used to search the record.

A multi-list file maintains an index for each secondary key. The index for
secondary key contains, instead of a list of primary keys related to that
secondary key, only one primary key value related to that secondary key.
That record will be linked to other records containing the same secondary
key in the data file.

To facilitate searching on the primary key as well as on secondary keys, it is


customary to maintain several indexes, one for each key. Using an index in
this way reduces the length of the lists and thus the search time.

This idea is very easily generalized to allow for easy secondary key retrieval.
We just set up indexes for each key and allow records to be in more than one
list. This leads to the multi-list structure for file representation.

Inverted File Organization

Inverted file organization is one file organization where the index structure is
most important. In this organization the basic structure of file records does
not matter much.
This file organization is somewhat similar to that of multi-list file organization
with the key difference that in multi-list file organization index points to a
list, whereas in inverted file organization the index itself contains the list.

Thus, maintaining the proper index through proper structures is an important


issue in the design of inverted file organization.

The index entries are of variable lengths as the number of records with the
same key value is changing, thus, maintenance of index is more complex
than that of multi-list file organization.

Similarities of Multi-list and Inverted file organization

 An index for primary and secondary key


 The pointers to data records may be direct or indirect and may or may
not be sorted.

Differences of Multi-list and Inverted file organization

 In a Multi-list organization an index entry points to the first data record


in the list, whereas in inverted index file an index entry has address
pointers to all the data records related to it.
 A multi-list index has fixed length records, whereas an inverted index
contains variable length records

You might also like