mysql index types: the difference FULLTEXT, NORMAL, SPATIAL, UNIQUE of

1. Normal general index

2. Unique Unique Index

3. Full Text Full-Text Index

4. SPATIAL spatial index

5. btree index difference and the hash index

6. In actual operation, should be selected as the index table in which fields?

Normal Normal Index

Represents the general index, in most cases you can use

Unique unique index

Represents a unique, does not allow duplicate index, if the field is to ensure that information is not repeated, for example ID number as an index, it can be set unique.

Constraint uniquely identifies each record in the database table, each record that is used is not unique (e.g., unique ID that is), in a single table of Unique (unique requirements columns) and Primary Key (primary key = null unique + not the only row) constraints are set to provide a column or columns guarantee uniqueness, has a unique Primary Key constraint is automatically defined, but each table can have multiple unique constraints, but only one Primary Key constraint.
mysql create Unique constraint.

Full Text Full-Text Indexing

Represents a full closing cable, long text retrieval time, the best, short text recommended Index, but when a large amount of data retrieved when the data is now placed in a global index is not in the table, and then with many Full Text index create index created, than to build Full Text is a table and write data much faster

FULLTEXT searching for a long time an article, the best results. Used in a relatively short text, if it is a line or two of ordinary INDEX can.

SPATIAL spatial index

Spatial index is an index of spatial data type field established in the spatial data types MYSQL There are four, namely GEOMETRY, POINT, LINESTRING, POLYGON. MYSQL using the SPATIAL keyword expansion, making the syntax for creating a spatial index can be used to create a regular index type. Create a spatial index column, it must be declared as NOT NULL, only the spatial index table storage engine MYISAM created

The difference between the index btree and hash indexing

1, BTREE (B tree (tree may be multi))} {mainstream use

2, HASH (key, value) in this way was not very good support range queries

particularity hash index structure, the retrieval efficiency is very high, the index can be retrieved once positioned, unlike B-Tree index needs from the root to the branch node, and finally to access to this page many times IO access node, the index Hash the query efficiency is much higher than B-Tree index.
Many people may have doubts, since high efficiency Hash B-Tree indexes than many, why we do not have a Hash indexes also use B-Tree index it? Everything has two sides of, Hash index is the same, although the high efficiency Hash index, but the index itself because of its specificity Hash also brought a lot of limitations and drawbacks, mainly the following:

(1) Hash index can satisfy only "=", "IN" and "<=>" query, the query can not be used range.
Since the Hash index Hash value comparison is carried out after the Hash operation, it can only be used for filtering equivalent, based on the range of the filter can not be used, because the size relationship Hash values after processing via the corresponding Hash algorithm, and can not be exactly the same as before and ensure Hash operation.

(2) Hash index can not be used to avoid the data sorting operations.

Because the index is stored Hash Hash value calculated through the following Hash, Hash value and the magnitude relationship and values ​​are not necessarily exactly the same as before the Hash operation, so the database can not use the index data to avoid any sort of operation;

(3) Hash indexes can not use part of the index key query.

For the combination of the time index, the index when calculating the Hash Hash value is calculated and then combined with the composite index key Hash value, instead of calculating the Hash value alone, the query index through the front of one or several of the composite index key, the index Hash can not be used.

(4) Hash index at any time can not avoid a table scan.

As already known, Hash index after the index key by the Hash operation, the Hash value Hash calculation results and row pointers corresponding to the information stored in a Hash table, due to the presence of the same Hash value different index keys, even if the take satisfies certain the number of records of data a Hash keys can not be done from Hash index directly query, or to make the appropriate comparisons by accessing the actual data in the table, and the corresponding results.

Performance will not necessarily higher than the index B-Tree (. 5) Hash index encountered large Hash values ​​are equal.

For relatively low selectivity index key, if you create an index Hash, then there will be a large number of records stored in the pointer information associated with a Hash value. In this way to locate one of the logs will be very troublesome, will waste many visits to the table data, resulting in poor overall performance.

In actual operation, should be selected as the index table in which fields?

In order to make more efficient use of the index, when creating the index, you must consider creating an index and what type of indexes created on which fields, there are seven principles:

  1. Select unique index
  2. It is often necessary to sort, group and joint field operations indexing
  3. Indexed field often as the query conditions
  4. Limit the number of indexes
  5. Try to use less data index
  6. Try to use the prefix to index
  7. Remove unused or little-used index
  8. Updated frequently modified fields not to index (for mysql say, because an index field changes at the same time we must re-establish, sort, and Orcale there seems to be such a mechanism field values ​​change, it is not indexed, sorted index immediately, but according to change the number, the time period to do it in balance index)
  9. Not recommended to build multiple indexes on the same column

References: https://blog.csdn.net/guo_qiangqiang/article/details/88794971

Guess you like

Origin www.cnblogs.com/xzy-/p/12162586.html