
In the above example ID is a KEY and Car is a NON KEY, and as we can see that the RELATION is sorted on NON KEY Car, here the key and a very Obvious observation is that
at once the relation can be sorted with respect to any one attribute i.e, if the relation is sorted wrt to some non-key then not necessarily but obviously it won't be sorted wrt to other attributes
now why secondery indexing here ?
- first go and read the question very carefully now, the relation is sorted but on a non key which is car here but the indexing is done on the key of the relation which is ID here and that's why the file is unordered as the search key is undordered (whihc is id here)
- and whenever the file is unordered (with respect to our search key) we use secondary indexing so this is unordered + key as search key
- and as the search key is unordered we can't use sparse indexing, we can't have a block anchor here as we don't know in which block the search key lies (due to search key being unordered)
so we'll use dense indexing and in dense indexing we have 2 fields the search key and the block pointer
\[
\text{Index entry size} = \text{Key size} + \text{Block pointer size} = 6 + 10 = 16 \text{ bytes}
\]
\[
\begin{array}{|c|c|}
\hline
\textbf{Search Key (6 bytes)} & \textbf{Block Pointer (10 bytes)} \\
\hline
\end{array}
\]
so as we are using dense indexing, we'll have a index entry correspongind all 16384 records lets first find block factor for index entries
\[
\text{Block factor of index record} = \frac{\text{Block size}}{\text{Size of index record}}
= \frac{1024}{6 + 10} = 64
\]
so we can store 64 index records per disk block
so no. of index blocks we'll need to store indexes corresponding all 16384 records is
\[
\frac{16384 \,\,records}{64 \,\,index \,records/block} = 256 \text{ index blocks}
\]
now again a very important point
index file is always sorted
and as index file is always sorted we can apply sparse indexing on the index file for multilevel indexing, as we can apply binary search on index files for more efficiency.
so no. of blocks needed to store 256 index blocks is
\[
\frac{256\,\, records}{64\,\, records/block} = 4 \text{ blocks}
\]
256 records because, we'll have index entry for 1 record per index block for multilevel indexing
and here we have the asnwer c) 256,4
reference to : index files are always sorted page no. 661
if my answer helped consider a upvote to show appreciation !