下表提供了 FULLTEXT 索引的元数据:The following tables provide metadata for
FULLTEXT indexes:
mysql> SHOW TABLES FROM INFORMATION_SCHEMA LIKE 'INNODB_FT%';
+-------------------------------------------+
| Tables_in_INFORMATION_SCHEMA (INNODB_FT%) |
+-------------------------------------------+
| INNODB_FT_CONFIG |
| INNODB_FT_BEING_DELETED |
| INNODB_FT_DELETED |
| INNODB_FT_DEFAULT_STOPWORD |
| INNODB_FT_INDEX_TABLE |
| INNODB_FT_INDEX_CACHE |
+-------------------------------------------+
表概览Table Overview
INNODB_FT_CONFIG:提供有关FULLTEXT索引及InnoDB表相关处理的元数据。INNODB_FT_CONFIG: Provides metadata about theFULLTEXTindex and associated processing for anInnoDBtable.INNODB_FT_BEING_DELETED:提供INNODB_FT_DELETEDtable;仅在OPTIMIZE TABLE维护操作时使用。当OPTIMIZE TABLE时,INNODB_FT_BEING_DELETED表被清空,DOC_ID的值从INNODB_FT_DELETEDtable。由于INNODB_FT_BEING_DELETED通常较短,该表在监控或调试方面的实用性有限。关于在具有OPTIMIZE TABLE”的信息,请参见 第 14.9.6 节,“微调 MySQL 全文搜索”。INNODB_FT_BEING_DELETED: Provides a snapshot of theINNODB_FT_DELETEDtable; it is used only during anOPTIMIZE TABLEmaintenance operation. WhenOPTIMIZE TABLEis run, theINNODB_FT_BEING_DELETEDtable is emptied, andDOC_IDvalues are removed from theINNODB_FT_DELETEDtable. Because the contents ofINNODB_FT_BEING_DELETEDtypically have a short lifetime, this table has limited utility for monitoring or debugging. For information about runningOPTIMIZE TABLEon tables withFULLTEXTindexes, see Section 14.9.6, “Fine-Tuning MySQL Full-Text Search”.INNODB_FT_DELETED:存储从InnoDB表的FULLTEXT索引中删除的行。为了在对InnoDBFULLTEXT索引执行 DML 操作时避免昂贵的索引重组,新删除的单词信息会被单独存储,在执行文本搜索时从搜索结果中过滤,并且只有在对InnoDB表执行OPTIMIZE TABLE语句时才会从主搜索索引中移除。INNODB_FT_DELETED: Stores rows that are deleted from theFULLTEXTindex for anInnoDBtable. To avoid expensive index reorganization during DML operations for anInnoDBFULLTEXTindex, the information about newly deleted words is stored separately, filtered out of search results when you do a text search, and removed from the main search index only when you issue anOPTIMIZE TABLEstatement for theInnoDBtable.INNODB_FT_DEFAULT_STOPWORD:保存创建InnoDB表的FULLTEXT索引时默认使用的 停用词 列表。INNODB_FT_DEFAULT_STOPWORD: Holds a list of stopwords that are used by default when creating aFULLTEXTindex onInnoDBtables.有关
INNODB_FT_DEFAULT_STOPWORD表的详细信息,请参见 第 14.9.4 节,“全文停用词”。For information about theINNODB_FT_DEFAULT_STOPWORDtable, see Section 14.9.4, “Full-Text Stopwords”.INNODB_FT_INDEX_TABLE:提供有关用于处理针对InnoDB表的FULLTEXT索引的文本搜索的倒排索引的信息。INNODB_FT_INDEX_TABLE: Provides information about the inverted index used to process text searches against theFULLTEXTindex of anInnoDBtable.INNODB_FT_INDEX_CACHE:提供有关FULLTEXT索引中新插入行的标记信息。为了在 DML 操作期间避免昂贵的索引重组,新索引词的信息被单独存储,仅在运行OPTIMIZE TABLE时、服务器关闭时,或缓存大小超过由innodb_ft_cache_size或innodb_ft_total_cache_size系统变量定义的限制时,才会与主搜索索引合并。INNODB_FT_INDEX_CACHE: Provides token information about newly inserted rows in aFULLTEXTindex. To avoid expensive index reorganization during DML operations, the information about newly indexed words is stored separately, and combined with the main search index only whenOPTIMIZE TABLEis run, when the server is shut down, or when the cache size exceeds a limit defined by theinnodb_ft_cache_sizeorinnodb_ft_total_cache_sizesystem variable.
除了 INNODB_FT_DEFAULT_STOPWORD 表之外,这些表初始都是空的。在查询它们之前,将 innodb_ft_aux_table 系统变量的值设置为包含 FULLTEXT 索引的表的名称(包括数据库名称)(例如 test/articles)。With the exception of the
INNODB_FT_DEFAULT_STOPWORD table,
these tables are empty initially. Before querying any of them,
set the value of the
innodb_ft_aux_table system
variable to the name (including the database name) of the table
that contains the FULLTEXT index (for
example, test/articles).
示例 17.5 InnoDB FULLTEXT 索引 INFORMATION_SCHEMA 表Example 17.5 InnoDB FULLTEXT Index INFORMATION_SCHEMA Tables
本示例使用一个带有 FULLTEXT 索引的表来演示 FULLTEXT 索引 INFORMATION_SCHEMA 表中包含的数据。This example uses a table with a FULLTEXT
index to demonstrate the data contained in the
FULLTEXT index
INFORMATION_SCHEMA tables.
创建一个带有
FULLTEXT索引的表并插入一些数据:Create a table with aFULLTEXTindex and insert some data:mysql>
CREATE TABLE articles (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,title VARCHAR(200),body TEXT,FULLTEXT (title,body)) ENGINE=InnoDB;mysql>INSERT INTO articles (title,body) VALUES('MySQL Tutorial','DBMS stands for DataBase ...'),('How To Use MySQL Well','After you went through a ...'),('Optimizing MySQL','In this tutorial we show ...'),('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),('MySQL vs. YourSQL','In the following database comparison ...'),('MySQL Security','When configured properly, MySQL ...');将
innodb_ft_aux_table变量设置为带有FULLTEXT索引的表名。如果未设置此变量,InnoDBFULLTEXTINFORMATION_SCHEMA表将为空,唯一的例外是INNODB_FT_DEFAULT_STOPWORD。Set theinnodb_ft_aux_tablevariable to the name of the table with theFULLTEXTindex. If this variable is not set, theInnoDBFULLTEXTINFORMATION_SCHEMAtables are empty, with the exception ofINNODB_FT_DEFAULT_STOPWORD.mysql>
SET GLOBAL innodb_ft_aux_table = 'test/articles';查询
INNODB_FT_INDEX_CACHE表,该表显示FULLTEXT索引中新插入行的信息。为了避免在 DML 操作期间进行昂贵的索引重组,新插入行的数据会保留在FULLTEXT索引缓存中,直到执行OPTIMIZE TABLE(或者直到服务器关闭或缓存限制被超过)。Query theINNODB_FT_INDEX_CACHEtable, which shows information about newly inserted rows in aFULLTEXTindex. To avoid expensive index reorganization during DML operations, data for newly inserted rows remains in theFULLTEXTindex cache untilOPTIMIZE TABLEis run (or until the server is shut down or cache limits are exceeded).mysql>
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE LIMIT 5;+------------+--------------+-------------+-----------+--------+----------+ | WORD | FIRST_DOC_ID | LAST_DOC_ID | DOC_COUNT | DOC_ID | POSITION | +------------+--------------+-------------+-----------+--------+----------+ | 1001 | 5 | 5 | 1 | 5 | 0 | | after | 3 | 3 | 1 | 3 | 22 | | comparison | 6 | 6 | 1 | 6 | 44 | | configured | 7 | 7 | 1 | 7 | 20 | | database | 2 | 6 | 2 | 2 | 31 | +------------+--------------+-------------+-----------+--------+----------+启用
innodb_optimize_fulltext_only系统变量,并对包含FULLTEXT索引的表运行OPTIMIZE TABLE。此操作会将FULLTEXT索引缓存的内容刷新到主FULLTEXT索引中。innodb_optimize_fulltext_only改变了OPTIMIZE TABLE语句在InnoDB表上的操作方式,旨在在对带有FULLTEXT索引的InnoDB表进行维护操作时临时启用。Enable theinnodb_optimize_fulltext_onlysystem variable and runOPTIMIZE TABLEon the table that contains theFULLTEXTindex. This operation flushes the contents of theFULLTEXTindex cache to the mainFULLTEXTindex.innodb_optimize_fulltext_onlychanges the way theOPTIMIZE TABLEstatement operates onInnoDBtables, and is intended to be enabled temporarily, during maintenance operations onInnoDBtables withFULLTEXTindexes.mysql>
SET GLOBAL innodb_optimize_fulltext_only=ON;mysql>OPTIMIZE TABLE articles;+---------------+----------+----------+----------+ | Table | Op | Msg_type | Msg_text | +---------------+----------+----------+----------+ | test.articles | optimize | status | OK | +---------------+----------+----------+----------+查询
INNODB_FT_INDEX_TABLE表以查看主FULLTEXT索引中的数据,包括刚刚从FULLTEXT索引缓存刷新出来的数据的信息。Query theINNODB_FT_INDEX_TABLEtable to view information about data in the mainFULLTEXTindex, including information about the data that was just flushed from theFULLTEXTindex cache.mysql>
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE LIMIT 5;+------------+--------------+-------------+-----------+--------+----------+ | WORD | FIRST_DOC_ID | LAST_DOC_ID | DOC_COUNT | DOC_ID | POSITION | +------------+--------------+-------------+-----------+--------+----------+ | 1001 | 5 | 5 | 1 | 5 | 0 | | after | 3 | 3 | 1 | 3 | 22 | | comparison | 6 | 6 | 1 | 6 | 44 | | configured | 7 | 7 | 1 | 7 | 20 | | database | 2 | 6 | 2 | 2 | 31 | +------------+--------------+-------------+-----------+--------+----------+INNODB_FT_INDEX_CACHE表现在为空,因为OPTIMIZE TABLE操作已经刷新了FULLTEXT索引缓存。TheINNODB_FT_INDEX_CACHEtable is now empty since theOPTIMIZE TABLEoperation flushed theFULLTEXTindex cache.mysql>
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE LIMIT 5;Empty set (0.00 sec)从
test/articles表中删除一些记录。Delete some records from thetest/articlestable.mysql>
DELETE FROM test.articles WHERE id < 4;查询
INNODB_FT_DELETED表。该表记录从FULLTEXT索引中删除的行。为了避免在 DML 操作期间进行代价高昂的索引重组,新删除记录的信息会单独存储,在进行文本搜索时会从搜索结果中过滤掉,并且在执行OPTIMIZE TABLE时从主搜索索引中移除。Query theINNODB_FT_DELETEDtable. This table records rows that are deleted from theFULLTEXTindex. To avoid expensive index reorganization during DML operations, information about newly deleted records is stored separately, filtered out of search results when you do a text search, and removed from the main search index when you runOPTIMIZE TABLE.mysql>
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DELETED;+--------+ | DOC_ID | +--------+ | 2 | | 3 | | 4 | +--------+运行
OPTIMIZE TABLE以删除已删除的记录。RunOPTIMIZE TABLEto remove the deleted records.mysql>
OPTIMIZE TABLE articles;+---------------+----------+----------+----------+ | Table | Op | Msg_type | Msg_text | +---------------+----------+----------+----------+ | test.articles | optimize | status | OK | +---------------+----------+----------+----------+INNODB_FT_DELETED表现在应该是空的。TheINNODB_FT_DELETEDtable should now be empty.mysql>
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DELETED;Empty set (0.00 sec)查询
INNODB_FT_CONFIG表。该表包含有关FULLTEXT索引及相关处理的元数据:Query theINNODB_FT_CONFIGtable. This table contains metadata about theFULLTEXTindex and related processing:optimize_checkpoint_limit:OPTIMIZE TABLE操作停止前的秒数。optimize_checkpoint_limit: The number of seconds after which anOPTIMIZE TABLErun stops.synced_doc_id:下一个要分配的DOC_ID。synced_doc_id: The nextDOC_IDto be issued.stopword_table_name:用户定义的停用词表的database/table名称。如果没有用户定义的停用词表,则VALUE列为空。stopword_table_name: Thedatabase/tablename for a user-defined stopword table. TheVALUEcolumn is empty if there is no user-defined stopword table.use_stopword:指示是否使用停用词表,该项在创建FULLTEXT索引时定义。use_stopword: Indicates whether a stopword table is used, which is defined when theFULLTEXTindex is created.
mysql>
SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_CONFIG;+---------------------------+-------+ | KEY | VALUE | +---------------------------+-------+ | optimize_checkpoint_limit | 180 | | synced_doc_id | 8 | | stopword_table_name | | | use_stopword | 1 | +---------------------------+-------+禁用
innodb_optimize_fulltext_only,因为它只打算临时启用:Disableinnodb_optimize_fulltext_only, since it is intended to be enabled only temporarily:mysql>
SET GLOBAL innodb_optimize_fulltext_only=OFF;