Skip to main content
1 of 2
ypercubeᵀᴹ
  • 98.7k
  • 13
  • 215
  • 305

With InnoDB tables, all secondary indexes include the PK columns (appended in the end). So your unique index has actually 4 columns, the 3 you have defined plus the 1 primary key column.

When running a query that needs a full table scan, both indexes have all the data needed, so the optimizer is free to choose any one of the two indexes. It's just coincidence that it chose that index this time. It may chose the primary key next time. It doesn't make a difference.

ypercubeᵀᴹ
  • 98.7k
  • 13
  • 215
  • 305