• edited by
40,488 views
100 100 votes

Consider a file of $16384$ records. Each record is $32\;\text{bytes}$ long and its key field is of size $6\;\text{bytes}$. The file is ordered on a non-key field, and the file organization is unspanned. The file is stored in a file system with block size $1024\;\text{bytes}$, and the size of a block pointer is $10\;\text{bytes}$. If the secondary index is built on the key field of the  file, and a multi-level index scheme is used to store the secondary index, the  number  of  first-level  and second-level  blocks  in  the  multi-level  index  are respectively

  1. $8$ and $0$
  2. $128$ and $6$
  3. $256$ and $4$
  4. $512$ and $5$

7 Answers

Best answer
111 111 votes
Content of an index will be <key, block pointer> and so will have size $6 + 10 = 16$.

In the first level, there will be an entry for each record of the file. So,total size of first-level index

$= 16384 \ast 16$

No. of blocks in the first-level $=$ Size of first-level index $/$ block size

$= 16384 \ast 16 / 1024$

$= 16 \ast 16 = 256$

In the second-level there will be an entry for each block in the first level. So, total number of entries $= 256$ and total size of second-level index

$=$ No. of entries $\ast$ size of an entry

$= 256 \ast 16$

No. of blocks in second-level index $=$ Size of second-level index $/$ block size

$= 256 \ast 16 / 1024$

$= 4$

Correct Answer: $C$
• edited by
38 38 votes

Secondary Index is created on key field, which is dense index.

Since we have 16384 records in data file, index is created for every entry in 1st level index file.

In 1st level index file size of each record is 10+6 = 16B

1st level index contains 16384 records

No of records/block in 1st level index = 1024/16 = 64 records

No of blocks in 1st level index = 16384/64= 256 

Now, we have another 2nd level index which contains 256 records(1 record for each block in 1st level index) 

No of blocks in 2nd level index= 256/64= 4

Hence option c) is correct

16 16 votes

No. of records = 16384, record size = 32 B

Key Field size = 6 B, Block Size = 1024 B, Block Pointer Size = 10 B

Secondary Indexing: Index is created for each record in the file (dense indexing).

No. of index entries per block = $\frac{Block\_Size}{keySize+Block Address Size}=\frac{1024}{6+10}=64$

First level index entries = $\frac{No\_of\_records}{Blocking\_factor\_for\_indexing}=\frac{16384}{64}=256$

Second level index entries = $\frac{First\_level\_entries}{Blocking\_factor\_for\_indexing}=\frac{256}{64}=4$

Hence, Answer is (C).

10 10 votes

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 !

• edited by
4 4 votes

We need an entry for each record in the index table.

16384 records = 2^14

Now 2^14 * (10+6) B =  2^14 * 2^4 = 2^18 B

Block size is 2^10
This whole index table should fit into one block. It cant be. So number of blocks = 2^18 / 2^10 = 2^8 = 256

Now we need another index table to index these 256 index tables.
2^8 * 2^4 = 2^12B

This table also cant fit in one block. Number of blocks = 2^12 / 2^10 =2 ^2 = 4 blocks

We need another table to index these 4 blocks... that table size will be 4*16B which can easily sit in another 1024B block now.
Hence C is the answer.

1 1 vote

it's very simple..

Block size is 210 bytes and if you see option C .. it's 256 and 4 which is 28 and 22 

So only option C satisfies ​​​​​​​​​​​​​​​.

Answer:
Position:
Show:

Related questions

74 74 votes
4 answers 4 answers
35.7k
35.7k views
Kathleen asked Sep 12, 2014
35,676 views
Which of the following are NOT true in a pipelined processor?Bypassing can handle all RAW hazardsRegister renaming can eliminate all register carried WAR hazardsControl h...
43 43 votes
5 answers 5 answers
20.6k
20.6k views
Kathleen asked Sep 11, 2014
20,595 views
A clustering index is defined on the fields which are of typenon-key and orderingnon-key and non-orderingkey and orderingkey and non-ordering
43 43 votes
3 answers 3 answers
21.1k
21.1k views
Arjun asked Nov 27, 2016
21,145 views
Consider the following $\text{ER}$ diagramThe minimum number of tables needed to represent $M$, $N$, $P$, $R1$, $R2$ is Which of the following is a correct attribute set ...
100 100 votes
8 answers 8 answers
47.6k
47.6k views
Kathleen asked Sep 12, 2014
47,586 views
Consider the following relational schemes for a library database:Book (Title, Author, Catalog_no, Publisher, Year, Price) Collection(Title, Author, Catalog_no)with the fo...