| test.opening_lines | optimize | status | OK | +--------------------+----------+----------+----------+ 1 row in set (0.01 sec) 

To avoid lengthy rebuild times for full-text indexes on large tables, you can use the innodb_ft_num_word_optimize  option to perform the optimization in stages. The innodb_ft_num_word_optimize  option defines the number of words that are optimized each time OPTIMIZE TABLE  is run. The default setting is 2000, which means that 2000 words are optimized each time OPTIMIZE TABLE  is run. Subsequent OPTIMIZE TABLE  operations continue from where the preceding OPTIMIZE TABLE  operation ended. 

## Rebuilding MyISAM Full-Text Indexes 

If you modify full-text variables that affect indexing ( ft_min_word_len , ft_max_word_len , or ft_stopword_file ), or if you change the stopword file itself, you must rebuild your FULLTEXT  indexes after making the changes and restarting the server. 

To rebuild the FULLTEXT  indexes for a MyISAM  table, it is sufficient to do a QUICK  repair operation: 

mysql> REPAIR TABLE tbl_name  QUICK; 

Alternatively, use ALTER TABLE  as just described. In some cases, this may be faster than a repair operation. 

Each table that contains any FULLTEXT  index must be repaired as just shown. Otherwise, queries for the table may yield incorrect results, and modifications to the table causes the server to see the table as corrupt and in need of repair. 

If you use myisamchk  to perform an operation that modifies MyISAM  table indexes (such as repair or analyze), the FULLTEXT  indexes are rebuilt using the default  full-text parameter values for minimum word length, maximum word length, and stopword file unless you specify otherwise. This can result in queries failing. 

The problem occurs because these parameters are known only by the server. They are not stored in MyISAM  index files. To avoid the problem if you have modified the minimum or maximum word length or stopword file values used by the server, specify the same ft_min_word_len , ft_max_word_len , and ft_stopword_file  values for myisamchk  that you use for mysqld . For example, if you have set the minimum word length to 3, you can repair a table with myisamchk  like this: 

myisamchk --recover --ft_min_word_len=3 tbl_name .MYI 

To ensure that myisamchk  and the server use the same values for full-text parameters, place each one in both the [mysqld]  and [myisamchk]  sections of an option file: 

[mysqld] ft_min_word_len=3 [myisamchk] ft_min_word_len=3 

An alternative to using myisamchk  for MyISAM  table index modification is to use the REPAIR TABLE , ANALYZE TABLE , OPTIMIZE TABLE , or ALTER TABLE  statements. These statements are performed by the server, which knows the proper full-text parameter values to use. 

## 12.10.7 Adding a User-Defined Collation for Full-Text Indexing 

This section describes how to add a user-defined collation for full-text searches using the built-in full-text parser. The sample collation is like latin1_swedish_ci  but treats the ’-’  character as a letter rather than as a punctuation character so that it can be indexed as a word character. General information about 

2221 

