Consider a relational table with sufficient number of records, having attributes and let . Two queries and are given below.
- where is a constant
- where and are constants.
The database can be configured to do ordered indexing on or hashing on . Which of the following statements is TRUE?
View worked solution
Answer: C
To determine which indexing technique is better suited for each query, let's analyze how Hashing and Ordered Indexing handle equality and range searches:
-
Query (Equality Search):
This query searches for records where the attribute is exactly equal to a constant .
- Hashing: A hash index uses a hash function to map the search key directly to its bucket, requiring average-case disk I/O operations.
- Ordered Indexing (e.g., B+ Tree): Finding a specific key requires traversing the tree from the root to a leaf, which takes disk I/O operations.
- Conclusion: Hashing outperforms ordered indexing for equality queries like .
-
Query (Range Search):
This query retrieves records where the attribute falls within a range .
- Hashing: Hash functions do not preserve the ordering of keys. To answer a range query, hashing cannot easily locate the range boundaries, often requiring a full scan of the index or table.
- Ordered Indexing: Since the keys are stored in sorted order, we can locate the starting point in time and then sequentially traverse the leaf nodes to retrieve all records up to .
- Conclusion: Ordered indexing outperforms hashing for range queries like .
Thus, hashing will outperform ordered indexing on , but not on .
Free practice · Your answers on this page are not saved.
