mysql creates a joint index _mysql how to create multiple joint indexes

How to create multiple joint indexes in mysql: You can use the CREATE INDEX or ALTER TABLE statement to create them. When creating a union index, the order of the columns should be carefully considered.

2d83f5a800e2792273c370613008b077.png

Index rules in MySQL:

1. The fields that need to be indexed must be in the where condition

2. Fields with a small amount of data do not need to be indexed

3. If the where condition is an OR relationship, adding an index does not work

4. In line with the leftmost principle

What is a federated index?

A joint index is also called a compound index. For compound indexes, Mysql uses the fields in the index from left to right. A query can only use a part of the index, but only the leftmost part. For example, the index is key index (a,b,c). It can support three combinations of a | a, b| a, b, c for search, but does not support b, c for search. When the leftmost field is a constant reference , the index is very efficient.

An index on two or more columns is called a compound index

Additional columns in the index allow you to narrow your search, but using one index with two columns is not the same as using two separate indexes. The structure of a compound index is similar to that of a phone book, where a person's name consists of a first and last name, and the phone book is sorted first by pairs of last names, and then by first names for people with the same last name. A phone book is very useful if you know your last name; a phone book is even more useful if you know your first and last name, but is useless if you only know your first name and no last name.

So when creating a composite index, you should carefully consider the order of the columns. Compound indexes are useful when performing searches on all columns in the index, or only on the first few columns; only on any subsequent columns.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324094715&siteId=291194637