How to create an index mysql- string (11)

First, create a complete index directly, but will take up a lot of space

        select * from t where a = "xxx"; this sql, if you create a fully-indexed, his process is: go to a index tree query, access to primary key id of a record; to the primary key based on the primary key id query line , a determination is correct, the result set is added; take a position index of a data tree, find the end of the cycle is not satisfied.

Two, mysql support prefix index

       That means you can define the index as part of a string, do not specify the default will create a complete index. But the prefix index will lead to a covering index failure (need to get back to the table data)

       select * from t where a = "abe"; this sql, if you create a prefix index words. If the index is a (2), there are three data abc, abd, abe, the query process is: the index tree to a query, the acquired adc line, back to the main line does not satisfy the query key discards a tree and then obtaining a location, get to the line abd, back to the primary key query found not to meet directly discarded continue to take found satisfied, then if. It has been circulating, until the end of the index tree is not to take "ab".

       To establish the prefix index to distinguish the first of several it, we need to distinguish between degrees of statistical data indexed columns: Use the following sql: select count (distinct email) as L from user; select count (left (email, 4)) as L4 from user ; .....

       This way is obvious, it will lead to increased query scan times.

Third, the inverted index of use

        For example, a field ID number is stored, we know that the greater the diversity index of the column, the higher the income the use of the index, if we use the prefix index case, because the area code before the ID number identified several repeat more If the establishment of the prefix index, then, to build 12 to meet certain distinction. But clearly a waste of space. Then we can build the inverted index data, when creating a new reverse insert data, query using select * from t where id_card = reverse (idCard) query.

 

Guess you like

Origin www.cnblogs.com/enchaolee/p/11671516.html