0% found this document useful (0 votes)
37 views2 pages

CMP 312

An index allows users to efficiently search for information within a database or document. It works similar to an index at the back of a book by listing keywords and the locations of associated information. Indices are critical for efficient database querying as they avoid reading the entire database. There are different types of indices including primary, clustering, and secondary indices that are used to organize data and support fast searching.

Uploaded by

vyktoria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

CMP 312

An index allows users to efficiently search for information within a database or document. It works similar to an index at the back of a book by listing keywords and the locations of associated information. Indices are critical for efficient database querying as they avoid reading the entire database. There are different types of indices including primary, clustering, and secondary indices that are used to organize data and support fast searching.

Uploaded by

vyktoria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Indexing

An index for a file in a database system works in much the same way as the index textbooks. If
we want to learn about a particular topic (specified by a word or a phrase), we can search for
the topic in the index at the back of the book, find the pages where it occurs, and then read the
pages to find the information for which we are looking. The words in the index are in sorted
order, making it easy to find the word we want. Moreover, the index is much smaller than the
book, further reducing the effort needed.

Indices are critical for efficient processing of queries in databases. Without indices, every query
would end up reading the entire contents of every relation that it uses; doing so would be
unreasonably expensive for queries that only fetch a few records, for example, a single student
record, or the records in the takes relation corresponding to a single student. An attribute or set
of attributes used to look up records in a file is called a search key. Note that this definition of
key differs from that used in primary key.

Types of Index

1. Primary Index

A primary index file is an index that is constructed using the sorting attribute of the main file.
In the primary index file, we store the value of the sorting attribute of the main file in the first
record in each block of the main file. Dense and spare index are two types of primary indices

Types of primary indices

a. Dense index: In a dense index, an index entry appears for every search-key value in
the file which makes an index record for every search key value available in the
database. This makes searching faster but requires more space to store index records
itself. Index record contains search key value and a pointer to the actual record on
the disk.
b. Sparse index: In a sparse index, an index entry appears for only some of the search
key values. Sparse indices can be used only if the relation is stored in sorted order
of the search key. As is true in dense indices, each index entry contains a search-
key value and a pointer to the first data record with that search-key value. To locate
a record, we find the index entry with the largest search-key value that is less than
or equal to the search-key value for which we are looking. We start at the record
pointed to by that index entry and follow the pointers in the file until we find the
desired record.
2. Clustering Index

A clustered index can be defined as an ordered data file. Sometimes the index is created on
non-primary key columns which may not be unique for each record. In this case, to identify
the record faster, we will group two or more columns to get the unique value and create
index out of them. This method is called a clustering index.

The records which have similar characteristics are grouped, and indexes are created for these
group.

3. Secondary Index

In the sparse indexing, as the size of the table grows, the size of mapping also grows. These
mappings are usually kept in the primary memory so that address fetch should be faster. Then
the secondary memory searches the actual data based on the address got from mapping. If the
mapping size grows then fetching the address itself becomes slower. In this case, the sparse
index will not be efficient. To overcome this problem, secondary indexing is introduced.

In secondary indexing, to reduce the size of mapping, another level of indexing is introduced.
In this method, the huge range for the columns is selected initially so that the mapping size of
the first level becomes small. Then each range is further divided into smaller ranges. The
mapping of the first level is stored in the primary memory, so that address fetch is faster. The
mapping of the second level and actual data are stored in the secondary memory (hard disk).

You might also like