Search code examples
mysqlsqlperformanceindexingquery-performance

If a field I'm accessing is part of a compound index do I still get the benefits of that index just referencing one of the fields?


In MySQL I have a compound index on 2 fields (a,b). If I'm accessing only field a as part of a query do I still get the benefits of the index?

Thanks


Solution

  • Think of a telephone book. It's basically a sorted index on last_name, first_name.

    Does the fact that the telephone book is sorted in that way help you to look up people even if you search only by last name?

    Yes, it does.