ISRO Scientist/Engineer CSE 2017Databases › Not yet assigned to a topic
ISRO Scientist/Engineer CSE 2017 PYQ: Consider the following query : $SELECT$ E.eno, $COUNT(*)$ $FROM$ Employees E $GROUP\, BY$ E.eno If an index…
Consider the following query :
$SELECT$ E.eno, $COUNT(*)$
$FROM$ Employees E
$GROUP\, BY$ E.eno
If an index on $eno$ is available, the query can be answered by scanning only the index if
- Athe index is only hash and clustered
- Bthe index is only $B+$ tree and clustered
- Cindex can be hash or $B+$ tree and clustered or non-clustered
- Dindex can be hash or $B+$ tree and clusteredCorrect answer
Answer
(D) index can be hash or $B+$ tree and clustered
Approach
For the query SELECT E.eno, COUNT(*) FROM Employees E GROUP BY E.eno, an index-only scan requires that all tuples of each group be reachable from the index alone. A clustered index on eno (whether hash or B+ tree) stores/orders entries by eno, so scanning the index directly yields the count per eno without touching the base table. A non-clustered index stores row pointers, so counting requires probing the data file and is not a pure index-only scan. Hence the index must be hash or B+ tree AND clustered, i.e., option D. Options A and B wrongly restrict the index type, and option C wrongly adds non-clustered.
Reviewed by ISRO IQ Editorial Team.