MySQL & InnoDB (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What is the Leftmost Prefix Rule for Composite Indexes?
senior LevelMost AskedSystem Design
In Simple Words:
If you define a composite index on (A, B, C):
- Queries using
WHERE A = 1-> Index used! - Queries using
WHERE A = 1 AND B = 2-> Index used! - Queries using
WHERE A = 1 AND B = 2 AND C = 3-> Full index used! - Queries using
WHERE B = 2 AND C = 3-> Index CANNOT be used! (violates leftmost prefix). - Queries using
WHERE A = 1 AND C = 3-> Uses index only for columnA.