Sinthia V
Sinthia V

Reputation: 2093

MySQL multi-field unique index

  1. If I declare a unique index on multiple fields, does that mean the combination has to be unique or that each field must be seperately unique.

  2. Is there a performance gain from specifying a unique constraint? I assume that this would allow the engine to stop searching and return the result if it is guaranteed to be unique.

Upvotes: 0

Views: 105

Answers (1)

Michael Mior
Michael Mior

Reputation: 28753

  1. This means the combination of fields must be unique.

  2. You will get the same performance gains on SELECT you would get from a regular composite index if you are using a prefix of the key. However, unique indices have an additional performance penalty on insert, since it must be checked that the value is unique.

Upvotes: 2

Related Questions