GATE / CS ARCHIVE

GATE CSE 2011 / QUESTION 39

Hash versus ordered index queries

Database Management Systems · Indexing, Storage & Query Processing · Full GATE CSE 2011 paper

GATE 2011, Q39 2 marks · MCQ
Report issue

Indexing, Storage & Query Processing

Question 39, GATE 2011: A sufficiently large relation r has attributes A1,...,An, with 1≤p≤n. Q1 projects A1,...,Ap after selection Ap=c. Q2 projects the same attributes after selection c1≤Ap≤c2. The database may use ordered indexing or hashing on Ap. Which statement is intended to be TRUE?

(A) Ordered indexing always outperforms hashing for both
(B) Hashing always outperforms ordered indexing for both
(C) Hashing outperforms ordered indexing on Q1, but not Q2
(D) Hashing outperforms ordered indexing on Q2, but not Q1
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Our answer: C under the standard index cost model

Q1 is equality on the indexed attribute, where a well-distributed hash index normally locates its bucket in expected constant time and outperforms ordered search. Q2 is a range predicate, for which an ordered index finds the first qualifying entry and scans the interval; hashing lacks that order. Thus C is the conventional comparison. Actual performance also depends on collisions, selectivity, caching and index layout, so this is not a universal measured-time guarantee for every database.

Hashing sends equal keys to a bucket but does not put nearby numerical values in nearby buckets. Thus an equality predicate can use one hash lookup plus collision handling, whereas a range may require examining many buckets. A sorted index can locate the lower bound and walk adjacent entries until the upper bound. Projection of columns A1,...,Ap does not change this key distinction between the selection predicates. The source's absolute performance wording is stronger than what can be guaranteed without a storage cost model.

Original paper, page 10 · Answer key