- Primary indexes
- Clustering indexes
- Secondary indexes
Primary Indexes (Indexed Sequential File)
- An indexed sequential file is characterized by
- Sequential organization (ordered on primary key)
- Indexed on primary key
- Moreover, An indexed sequential file both ordered and indexed.
- Records organized in sequence based on a key field, known as the primary key.
- Also, An index to the file added to support random access. Each record in the index file Moreover consists of two fields: a key field, which is the same as the key field in the main file.
- The number of records in the index file is equal to the number of blocks in the main file (data file) and not equal to the number of records in the main file (data file).
- Moreover, To create a primary index on the ordered file shown in the Fig. we use the rollno field as primary key. Also, Each entry in the index file has rollno value and a block pointer. The first three index entries are as follows.
- <101, address of block 1>
- <201, address of block 2>
- <351, address of block 3>
- The total number of entries in an index is same as the number of disk blocks in the ordered data file.
- Moreover, A binary search on the index file requires very few block accesses
- If records of a file ordered on a non-key field, we can create a different type of index known as clustering index.
- Also, A non-key field does not have the distinct value for each record.
- A Clustering index is also an ordered file with two fields.
Secondary indexes (Simple Index File)
- While the hashed, sequential and indexed sequential files are suitable for operations based on ordering key or the hashed key. Above file, organizations are not suitable for operations involving a search on a field other than ordering or hashed key.
- Also, If searching required on various keys, secondary indexes on these fields must maintain. Moreover, A secondary index is an ordered file with two fields.
- Some non-ordering field of the data file.
- A block pointer
- There could be several secondary indexes for the same file.
- One could use binary search on index file as entries of the index file ordered on the secondary key field. Records of the data file not ordered on the secondary key field.
- A secondary index requires more storage space and longer search time than does a primary index.
- A secondary index file has an entry for every record whereas primary index file has an entry for every block in the data file.
- There is a single primary index file but the number of secondary indexes could be quite a few.