nerdexam
MongoDB

C100DBA · Question #68

If you have created a compound index on (A,B, C) which of the following access pattern will not be able to utilize the index?

The correct answer is C. B, C. Option C (B, C) cannot use the index because compound indexes follow the leftmost prefix rule - queries must include the first field (A) in the index to utilize it. Skipping field A means the database cannot traverse the index tree in a meaningful way, forcing a full collection…

Performance Tuning

Question

If you have created a compound index on (A,B, C) which of the following access pattern will not be able to utilize the index?

Options

  • AA, B, C
  • BA
  • CB, C
  • DA, B

How the community answered

(45 responses)
  • A
    7% (3)
  • B
    4% (2)
  • C
    78% (35)
  • D
    11% (5)

Explanation

Option C (B, C) cannot use the index because compound indexes follow the leftmost prefix rule - queries must include the first field (A) in the index to utilize it. Skipping field A means the database cannot traverse the index tree in a meaningful way, forcing a full collection scan instead.

Options A (A,B,C), B (A), and D (A,B) are all valid because they each begin with the leftmost field, A, forming valid prefixes of the index. The index supports any query that starts from the left and moves right through the fields, but cannot be entered from the middle or right.

Memory tip: Think of a compound index like a phone book sorted by (Last, First, Middle). You can look up by Last alone, Last+First, or all three - but you can't search by First name alone without scanning every page. The index is only useful when you start from the beginning.

Topics

#compound index#index prefix#query optimization#leftmost prefix rule

Community Discussion

No community discussion yet for this question.

Full C100DBA Practice