Skip to main content
InterviewHubPRO
Section Overview
Q19

Question 19 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

38%
SQL & Relational Databases (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What is a Composite Index and the Leftmost Prefix Rule?

senior LevelMost AskedSystem Design

In Simple Words: An index defined on multiple columns (e.g. INDEX (country, city, postal_code)):

  • The data is sorted by country first, then within each country by city, then by postal_code.
  • Leftmost Prefix Rule: The query optimizer can only use the index if the query filters on the leftmost columns in order:
    • WHERE country = 'US' -> Index used!
    • WHERE country = 'US' AND city = 'Chicago' -> Full index used!
    • WHERE city = 'Chicago' -> Index CANNOT be used! (violates leftmost prefix).