An Index is a copy of database table that has been reduced to certain fields and the copy is always in sorted form. The index also contains a pointer to the corresponding record of the actual table so that the fields not contained in the index can also be read. Index contains a value and a pointer to first record that contains data value.
Table of Contents
A Database Index is a data structure that speeds up certain operation on a file. The Operation involves a search key which is the set of record files( in most cases a single field). The elements of an index are called data entries. Data entries can be actual data record. A given file of data records can have several indexes, each with different search keys as showed in the table below.
|001||Mr Daniel||10,Bale str.||Maryland||Lagos||1011|
|002||Mrs Okon||5, Oju-ile||Ota||Ogun||1021|
|003||Mr David||26, Dalemo str.||Ikeja||Lagos||1023|
The search engine searches for a value in table or file in two ways. The table scan which is sequential and index which is random.
Indexes are special lookup tables that the database engine uses to speed up data retrieval. An index in a database is similar to an index in the back of a book.
An index table or file consists of records called index entries. It is of the form
The search key field is used to sort the rows (in the index column) and the pointer field (in index column) indicates where the actual data in the table will be retrieved. When a table has an index it simply means the records in that table has been sorted in one way or the other.
Indexes are automatically created when primary key and unique constraints are defined on table columns.
- What is an index?
- What are data entries?
Index can be classified as either clustered or uncluttered.
Clustered index is an index whose sorting order determines the order of how the rows/records in a table are stored. There could be only one clustered index in a table because there could always be one way of arranging the records in a table at a given time. For example, if you are asked to arrange some tables in a room, you could arrange them in a round form, row form or packed them close together, only one way at a time. Clustered index also means that related values in a table are stored close to each other according to the order of the index.
A Clustered index is when a file is organized so that the ordering of data records is the same as or closes to the ordering of data entries. A clustered index can take place only if the data records are sorted on the search key field. For example, suppose that students records are sorted by age; an index on age that stores data entries in sorted order by age is a clustered index.
Indexes that maintain data entries in sorted order by search key use a collection of index entries, organized into a tree structure to guide searches for data entries. Thus, clustered indexes are relatively expensive to maintain when the file is updated, when data entries are to be moved across pages, and if records are identified by a combination of page id and slot as is often the case, all places in the database that point to a moved record must also be updated to point to the new location.These additional updates can be time consuming.
The table below illustrate a clustered index file:
This an index whose sorting order does not determine the order of how the rows/records in a table are stored. This means that the search keys in the index column is sorted in one order while the actual records or rows are sorted in another order or are not sorted at all.
This is an index that is not clustered. A data file can contain several unclustered index. For example, supposing that students records are sorted by age; and if additional index on gpa field is included, it is called unclustered index.
(1)Explain a database index
(2) Explain clustered index versus unclustered index.
- ………. is a database table that has been reduced to certain fields.a) Table b) An index c) Table model d) Network model
- The copy of an index is always in …… form. a) duplicate b) field c) sorted d) domain
- The …………index can take place only if the data records are sorted on the search key field. a)unclustered b)insert c) update d) clustered
- A …………….. can contain several unclusterd indexes a) data file b) primary c) check d) index
- Index contain a value and ……. a)pointer b) sign c) update d) model
- Differentiate between clustered index and unclustered index.
- State two reasons why clustered index is expensive to maintain.
- What is an index?