简体   繁体   中英

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.

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM