Does a UNIQUE constraint automatically create an INDEX on the field(s)?

A unique key is a special case of index, acting like a regular index with added checking for uniqueness. Using SHOW INDEXES FROM customer you can see your unique keys are in fact B-tree type indexes.

A composite index on (email, user_id) is enough, you don’t need a separate index on email only – MySQL can use leftmost parts of a composite index. There may be some border cases where the size of an index can slow down your queries, but you should not worry about them until you actually run into them.

As for testing index usage you should first fill your table with some data to make optimizer think it’s actually worth to use that index.

Leave a Comment