Single and Unique Indexes

1. Common index

  The only task of an ordinary index (an index defined by the keywords KEY or INDEX) is to speed up access to data. Therefore, indexes should be created only for those columns that appear most frequently in the query condition (WHEREcolumn=) or the sort condition (ORDERBYcolumn). Whenever possible, you should choose a data column with the most tidy and compact data (such as an integer type data column) to create an index.
2. Unique index
  Ordinary index allows the indexed data column to contain duplicate values. For example, because people may have the same name, the same name may appear twice or more in the same Employee Profile data table.
If you can determine that a data column will only contain values ​​that are different from each other, you should use the keyword UNIQUE to define it as a unique index when creating an index for this data column. The advantages of doing this: First, it simplifies MySQL's management of the index, and the index becomes more efficient; second, when a new record is inserted into the data table, MySQL will automatically check the value of this field in the new record Whether this field has already appeared in a record; if so, MySQL will refuse to insert that new record. That is, a unique index can guarantee the uniqueness of data records. In fact, in many cases, the purpose of creating a unique index is not to improve access speed, but to avoid data duplication.
3. Primary Index
  It has been repeatedly emphasized in the front: an index must be created for the primary key field, and this index is the so-called "primary index". The only difference between a primary index and a unique index is that the former uses the keyword PRIMARY instead of UNIQUE when it is defined.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324736532&siteId=291194637