Indexing Questions with Answers

39 practice questions on Indexing (DBMS) with answers and step-by-step solutions. Try 10 samples below, then practise all 39 free in the AptiNest app.

Sample questions

Question 1Easy

Which index type determines the physical order of rows in the table?

  1. Bitmap index
  2. Secondary dense index
  3. Clustered index
  4. Non-clustered index

Answer: C. Clustered index

Explanation

Rows are stored in clustered-index order, which is why a table can have only one clustered index.

Step-by-step solution

  1. A clustered index stores (or keeps) rows in index-key order.
  2. So it decides the physical row order.
  3. Hence only one per table.

Why the other options are wrong

  • A. Bitmap indexes are separate bit arrays.
  • B. Secondary indexes do not change row order.
  • D. Non-clustered indexes point to rows wherever they are.

Tip: Clustered = physical order.

Question 2Easy

The column or columns on which an index is built are called the:

  1. Search key
  2. Clustered table
  3. Partition
  4. Foreign key

Answer: A. Search key

Explanation

The search key need not be a primary key or even unique; it is simply the value the index is organised on.

Step-by-step solution

  1. An index is organised on the values of one or more columns.
  2. These columns are called the search key.
  3. It need not be unique or the primary key.

Why the other options are wrong

  • B. Clustered describes how the table is stored.
  • C. Partitioning splits a table across storage.
  • D. A foreign key is a referential constraint.

Tip: Search key = whatever the index is built on.

Question 3Easy

A secondary index (on a non-ordering field) must be:

  1. Sparse
  2. Dense
  3. Clustered
  4. Hash-based only

Answer: B. Dense

Explanation

The file is not sorted on that field, so every value (or record) needs its own index entry.

Step-by-step solution

  1. The file is not sorted on the secondary field.
  2. Records with nearby values can be in any block.
  3. So every record (value) needs its own index entry: dense.

Why the other options are wrong

  • A. Sparse indexes need the file ordered on that field.
  • C. A table can be clustered on only one field, usually not this one.
  • D. Secondary indexes are often B+ trees.

Tip: Secondary index = always dense.

Question 4Easy

A sparse index contains:

  1. Entries for only some search-key values, e.g. one per block
  2. An entry for every record
  3. Entries sorted in random order
  4. Only the primary key column

Answer: A. Entries for only some search-key values, e.g. one per block

Explanation

Sparse indexes need the data file to be sorted on the key; you find the nearest smaller entry and scan the block.

Step-by-step solution

  1. A sparse index has entries for only some key values.
  2. Usually one entry per data block (the block's first key).
  3. The file must be sorted on that key.

Why the other options are wrong

  • B. An entry for every record is a dense index.
  • C. Index entries are always sorted.
  • D. Sparse indexes are not restricted to the primary key.

Tip: Sparse = one entry per block; dense = one entry per record.

Question 5Medium

A dense index on a file of 50,000 records stores 100 entries per block. Binary search on the index takes how many block accesses, plus one to read the data block?

  1. 7 + 1 = 8
  2. 9 + 1 = 10
  3. 500 + 1 = 501
  4. 16 + 1 = 17

Answer: B. 9 + 1 = 10

Explanation

The index has 50,000 / 100 = 500 blocks; binary search needs ⌈log2 500⌉ = 9 accesses, then 1 more for the data block.

Step-by-step solution

  1. Index blocks = 50,000 / 100 = 500.
  2. Binary search: ceil(log2 500) = 9 (2^9 = 512).
  3. Plus one data block: 10.

Why the other options are wrong

  • A. 2^7 = 128 is less than 500 blocks.
  • C. 501 is a linear scan of the index.
  • D. 16 is log2 of the record count, not the index blocks.

Tip: Index blocks first, then ceil(log2), then + 1.

Question 6Medium

An index that contains every column a query needs, so the table itself is never read, is called a:

  1. Partial index
  2. Covering index
  3. Sparse index
  4. Clustered index

Answer: B. Covering index

Explanation

With a covering index the query is answered with an index-only scan.

Step-by-step solution

  1. The query needs certain columns.
  2. If the index contains all of them, the DBMS answers from the index alone.
  3. Such an index is a covering index (index-only scan).

Why the other options are wrong

  • A. A partial index covers only rows matching a condition.
  • C. Sparse refers to having entries for only some keys.
  • D. Clustered refers to physical row order.

Tip: All needed columns in the index = covering.

Question 7Medium

The search cost of a B+ tree with N keys and fan-out f is about:

  1. N/f node accesses
  2. log_f(N) node accesses
  3. f × N node accesses
  4. A constant number regardless of N

Answer: B. log_f(N) node accesses

Explanation

Each level divides the search space by the fan-out, so height grows logarithmically with base f.

Step-by-step solution

  1. Each node has up to f children.
  2. Each level down narrows the search by a factor of f.
  3. After h levels f^h covers N keys, so h is about log_f(N) node reads.

Why the other options are wrong

  • A. N/f would be a scan of leaf blocks, not a tree search.
  • C. This is more than a full scan.
  • D. Height grows with N, slowly.

Tip: With fan-out 100, three levels cover about a million keys.

Question 8Medium

A composite index on (last_name, first_name) can efficiently answer which query?

  1. WHERE last_name = 'Rao'
  2. WHERE first_name LIKE '%a'
  3. WHERE first_name = 'Asha'
  4. ORDER BY first_name only

Answer: A. WHERE last_name = 'Rao'

Explanation

A composite B+ tree index is ordered by the leading column first, so it helps queries that constrain a prefix of its columns.

Step-by-step solution

  1. A composite index is sorted by last_name, then first_name.
  2. A search on last_name uses the sorted prefix.
  3. first_name alone is scattered across the index.

Why the other options are wrong

  • B. A leading wildcard prevents using any sort order.
  • C. first_name is not the leading column.
  • D. Sorting by the second column alone does not follow the index order.

Tip: Composite index = leftmost prefix only.

Question 9Hard

A sorted data file has 40,000 records, 20 per block. A sparse primary index has one entry per data block, with 50 entries per index block. How many block accesses does a lookup need using binary search on the index plus one data-block read?

  1. 7
  2. 9
  3. 40
  4. 11

Answer: A. 7

Explanation

Data blocks: 2000.

Index blocks: ⌈2000/50⌉ = 40.

Binary search: ⌈log2 40⌉ = 6, plus 1 data block = 7.

Step-by-step solution

  1. Data blocks = 40,000 / 20 = 2,000, so 2,000 index entries.
  2. Index blocks = 2,000 / 50 = 40.
  3. ceil(log2 40) = 6, plus 1 data block = 7.

Why the other options are wrong

  • B. 9 uses the wrong number of index blocks.
  • C. 40 is a linear scan of the index blocks.
  • D. 11 is about log2 of the 2,000 data blocks, as if there were no index.

Tip: Sparse: entries = data blocks.

Question 10Hard

A B+ tree leaf node is a 1024-byte block holding (key, record pointer) pairs plus one 8-byte pointer to the next leaf. Keys are 10 bytes and record pointers 6 bytes. How many keys fit in a leaf?

  1. 64
  2. 101
  3. 63
  4. 62

Answer: C. 63

Explanation

16n + 8 ≤ 1024 gives n ≤ 63.50, so n = 63.

Step-by-step solution

  1. Each (key, record pointer) pair is 10 + 6 = 16 bytes.
  2. 16k + 8 <= 1024, so k <= 63.5.
  3. k = 63.

Why the other options are wrong

  • A. 64 pairs take 1024 bytes, leaving no room for the next-leaf pointer.
  • B. 101 = 1024 / 10 ignores pointers.
  • D. 62 fits but is not the maximum.

Tip: Leaf: k(K + Pr) + Pnext <= B.

Practise all 39 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all DBMS topics · All topics