MySQL-- full-text indexing effect, principle and note

effect

  MySQL index can be divided into: primary key index, the general index, the only index, full-text indexing. Which should be the full-text index is special, it is only a handful of storage engine support, and only type char, vchar, text columns can be full-text indexed. Previously, only MyISAM engine supports full-text index, InnoDB can now also be used.

  Generally, in the case of fuzzy query most likely to think of where ... like% _... so. Indeed, like most of the keyword in the number of cases can be completed demand, but in the content of the column is very large, satisfactory performance can not be like, because this does not ensure that each keyword query can spend index . Therefore, the full-text index comes in handy. In addition to improving the performance of full-text indexes provide more flexible services, such as:

  1. like just pattern matching, but offers some full-text indexing syntax and semantics of queries, will have to check the word string operations, depending on the MySQL thesaurus.

  2. The full-text indexing can set up their own words minimum and maximum length, to ignore words which are written may be set.

  3. to investigate a string with a column full-text index, returns matching, can be understood as the number of keyword matching, is a floating-point number.

Anyway, because the full-text index were using the index, higher performance, word thesaurus support can be provided some semantic query function, there are words disabled list to ignore some words, there are words such as minimum and maximum values ​​can be set more flexible .

 

principle

  Full-text index of the object is a "full-text collection", if full-text indexing for multiple columns of a table, MySQL will these columns spliced ​​into a string and then indexed. Full-text indexing is actually a B + Tree structure, but rather special, it is a total of two layers, the first layer is all the keywords, the second layer is a set of documents refer to needle each keyword. To use the full-text index, meaning it on several parameters must be clear, full-text indexing control parameters are beginning to ft (FullText). Check these parameters and their meanings:

show variables like 'ft%'

ft_boolean_syntax: represents the symbol can be used when the Boolean queries. IN BOOLEAN MODE to change the character of the inquiry, without restarting the MySQL do not have to rebuild the index

ft_max_word_len: the longest string of the index, the default value is 84, modified to rebuild the index

ft_min_word_len: the shortest string index, the default value is 4, modified to rebuild the index

ft_query_expansion_limit: take several values ​​of the most relevant query comprises a query as a secondary exhibition

 ft_stopword_file (built-in): Stop word files will ignore this file when a query word

 

Using the methods and attention

First full-text indexed, the statement is as follows:

create fulltext index index name on table names (column names ...)

Use statement:

where match (column names ...) Against ( 'word 1 word 2'); // matching word 1 word 2

If you are using Boolean query or phrase query, if you use the phrase, then the speed will be much slower, because full-text indexing can not determine whether an exact match of the phrase, get back to the table filter. :

where match (column names ...) against ( '' phrase 1 '');   // single quotes with double quotes wrapped in a phrase, let returns the results match exactly the phrase specified 
where match (column names ...) against ( '+ words 1-- words 2' IN BOOLEAN MODE);   // return result must contain a word, but not by the word 2 
WHERE match (column names ...) against ( '> word 1 <word 2' IN BOOLEAN MODE );   // contains words 1, then increase the priority, if words containing lower priority 2

It can also return results that match the full text, which is a floating point number with the line matching on these words:

select id, match (column names ...) against ( 'words 1' ) .... AS factor from table WHERE     // return the matching words in each row Match 1

 

The negative impact of full-text index:

  1. occupy more storage space, if a memory fit all indexes, the performance will be very poor

  2. The cost of larger additions and deletions, modify the text in 10 words, will have to operate and maintain an index of 10, rather than a general index

  3. If you have a column on the full-text index will spend, even with better performance of other indexes will not spend. Since only store documents pointer, will not have access index covering

In short, it is not as good as the performance of the general index, to weigh in use.

 

Guess you like

Origin www.cnblogs.com/shen-qian/p/11883442.html