MySQL index summary

1, the index is doing what?

Index is used to quickly find a specific value in a column in a row. Do not use an index, MySQL must start from Article 1 of the logs and read the entire list until you find the relevant rows.
The larger the table, the more time it takes. If the table has a column in the query of the index, MySQL can quickly get a position to find the middle of the data file, there is no need to look at all the data.
Most MySQL indexes (PRIMARY KEY, UNIQUE, INDEX, and FULLTEXT) are stored in B-trees. Just spatial column types use R- tree indexes, and MEMORY tables also support hash indexes.

2, a good index complex, I understand how the index, there is no one more example of the image point?

Yes, imagine that, before you have this dictionary, data is the text of the book, you're the cpu, and the index, the book is a directory

3, index the better?

Indexing can greatly improve query efficiency in most cases, but:
change data (CRUD) are required to maintain the index, so the more indexes mean more maintenance costs
more indexes means also need more space (a 100-page book, there are 50 catalog?)
is too small tables, indexing may be slower oh :) (read a two-page brochure, you first go to the directory?)

4, the index field types problem

text type, an index may be built (to be specified length)
MyISAM storage engine integrated index key can not exceed the length of 1000 bytes
is used to keep the value of the filter and the column index the same data type

5, like the index can not be used?

Minimizing the like, but not absolutely unavailable, "xxxx%" is used in the index,
imagine you are a build-to-order reading a phonetic idiom idiom dictionary, directory, query needs are, you're looking at "a "idiom word beginning (" one percent "), and comprising idiom word you want to find (the"% one percent ")
except like, the operator can also be used to index:
<, <=, =,>,> = , the BETWEEN, the iN
<>, not in,! = Versa

6, what kind of fields are not suitable for building an index?

In general, the value of the uniqueness of small columns (such as gender, type something), not suitable for construction index (how he may be too small? Half to say, the value of data with more than 15 percent of the table, then need the construction of the index)
is too long column, you can choose to create only a partial index (such as: just take the top ten indexed)
heavily-updated data suitable for indexing (raises the very sense)?

7, a query can use multiple indexes do?

Can not

8, multi-column query how to build the index?

A query can only use one index, so the first shot a, b each indexing scheme
a or b? Who higher degree of differentiation (with a minimum value), who built!
Of course, the joint index is a good program, ab, or ba, the above distinction between those with high front

9, joint index of the problem?

where a = "xxx" can use AB joint index
where b = "xxx" is not (re-imagine, this is the catalog of the book?)
So, in most cases, there is AB indexed, you can not go in to build a a indexed

10. What are the common situation can not use an index?

like "%xxx"
not in , !=

Where the columns calculation function (e.g. MD5 WHERE (password) = "XXXX")
the WHERE index = = 10. 1 OR A
stored numeric string type field (e.g., phone number), remember to keep the quotes query value, or you can not use the index-related field, otherwise it does not matter

select * from test where mobile = 13711112222 ;
but can not be used in the index field of mobile Oh (if the mobile is char or varchar type of words)
BTW, do not try to use int to store phone number (or else why they want to own?! try)

11, covering index (Covering Indexes) have higher efficiency

Index contains all of the required value, then just select them, in other words, only select the fields need to use, if not necessary, try to avoid select *

12, NULL problem

NULL index will lead to non-existent, so design table structure to avoid the presence of NULL (NULL expression in other ways you want to express, such as -1?)

13, how to view the index information, how to analyze correctly use the index?

index from TableName Show;
EXPLAIN the SELECT ......;
on explain, another day you can find time to write a special entry posts, before this, you can try google

14, sql injection

Never forget keywords sql injection

Reprinted from: https://www.jb51.net/article/81875.htm

Guess you like

Origin www.cnblogs.com/chen-chen-chen/p/11794852.html
Recommended