Primary Indices:
Primary index is an index structure typically associated with a sorted file organization, such as sequential or sorted files. It contains entries for each block of the data file, where each entry consists of a search key value and a pointer to the corresponding block in the data file.
- Structure: The primary index itself is usually stored as a separate file or structure, with each entry containing the search key value and a pointer to the corresponding block in the data file.
- Search: When searching for a record using the primary index, the search key is looked up in the index, and the corresponding block pointer is used to access the appropriate block in the data file.
- Efficiency: Primary indices provide efficient access to records based on their primary key values, allowing for direct access to specific blocks in the data file. However, they require the data file to be sorted based on the primary key.
Secondary Indices:
Secondary index is an index structure that provides an alternate access path to the records in a data file based on a non-primary key attribute. It allows for efficient retrieval of records based on attributes other than the primary key.
- Structure: Similar to primary indices, secondary indices contain entries with search key values and pointers to corresponding blocks in the data file. However, the search key values in secondary indices are based on non-primary key attributes.
- Search: When searching for a record using a secondary index, the search key value is looked up in the secondary index, and the corresponding block pointer is used to access the appropriate block in the data file.
- Efficiency: Secondary indices provide efficient access to records based on attributes other than the primary key, enabling queries and searches based on various criteria.
B+ Tree Index Files:
B+ tree is a balanced tree data structure commonly used for indexing in database systems. It is similar to a binary search tree but with additional properties that make it suitable for disk-based storage and retrieval.
- Structure: In a B+ tree index file, each node of the tree represents a block of the data file, and each leaf node contains pointers to actual records or blocks of records in the data file.
- Search: B+ trees support efficient search, insertion, and deletion operations. During a search, the search key is compared with keys in the nodes of the tree, and the search path leads to the leaf node containing the desired record or block pointer.
- Efficiency: B+ trees provide efficient access to records based on search key values, with logarithmic time complexity for search, insertion, and deletion operations. They are widely used in database systems for indexing and organizing large datasets.
B Tree Index Files:
B tree is a similar balanced tree data structure to B+ trees, commonly used for indexing in database systems. While similar in structure, B trees differ in some characteristics, particularly in how they handle data in internal nodes.
- Structure: In a B tree index file, each node of the tree represents a block of the data file, and both internal nodes and leaf nodes can contain actual records or record pointers.
- Search: B trees also support efficient search, insertion, and deletion operations, with search key comparisons leading to the desired record or block pointer.
- Efficiency: B trees offer similar efficiency to B+ trees in terms of search, insertion, and deletion operations. They are also widely used in database systems for indexing and organizing large datasets.
primary and secondary indices provide alternate access paths to records in a data file, with primary indices based on the primary key and secondary indices based on non-primary key attributes. B+ tree and B tree index files are balanced tree data structures commonly used for indexing in database systems, offering efficient access to records based on search key values. B+ trees are particularly well-suited for disk-based storage and retrieval, while B trees offer similar efficiency with some differences in internal node structure.