10bet网址
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr)- 41.9Mb
PDF (A4)- 42.0Mb
Man Pages (TGZ)- 266.1Kb
Man Pages (Zip)- 376.0Kb
Info (Gzip)- 4.0Mb
Info (Zip)- 4.0Mb
Excerpts from this Manual

15.15.4 InnoDB INFORMATION_SCHEMA FULLTEXT Index Tables

The following tables provide metadata forFULLTEXTindexes:

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

Note

With the exception of theINNODB_FT_DEFAULT_STOPWORDtable, these tables are empty initially. Before querying any of them, set the value of theinnodb_ft_aux_tablesystem variable to the name (including the database name) of the table that contains theFULLTEXTindex (for example,test/articles).

Example 15.5 InnoDB FULLTEXT Index INFORMATION_SCHEMA Tables

This example uses a table with aFULLTEXTindex to demonstrate the data contained in theFULLTEXTindexINFORMATION_SCHEMAtables.

  1. 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 ...');
  2. 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';
  3. 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).

    从INFORMATION_SCHEMA mysql > SELECT *。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 | +------------+--------------+-------------+-----------+--------+----------+
  4. 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 | +---------------+----------+----------+----------+
  5. 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.

    从INFORMATION_SCHEMA mysql > SELECT *。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 | +------------+--------------+-------------+-----------+--------+----------+

    TheINNODB_FT_INDEX_CACHEtable is now empty since theOPTIMIZE TABLEoperation flushed theFULLTEXTindex cache.

    从INFORMATION_SCHEMA mysql > SELECT *。INNODB_FT_INDEX_CACHE LIMIT 5; Empty set (0.00 sec)
  6. Delete some records from thetest/articlestable.

    mysql> DELETE FROM test.articles WHERE id < 4;
  7. 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.

    从INFORMATION_SCHEMA mysql > SELECT *。INNODB_FT_DELETED; +--------+ | DOC_ID | +--------+ | 2 | | 3 | | 4 | +--------+
  8. RunOPTIMIZE TABLEto remove the deleted records.

    mysql> OPTIMIZE TABLE articles; +---------------+----------+----------+----------+ | Table | Op | Msg_type | Msg_text | +---------------+----------+----------+----------+ | test.articles | optimize | status | OK | +---------------+----------+----------+----------+

    TheINNODB_FT_DELETEDtable should now be empty.

    从INFORMATION_SCHEMA mysql > SELECT *。INNODB_FT_DELETED; Empty set (0.00 sec)
  9. Query theINNODB_FT_CONFIGtable. This table contains metadata about theFULLTEXTindex and related processing:

    • optimize_checkpoint_limit: The number of seconds after which anOPTIMIZE TABLErun stops.

    • synced_doc_id: The nextDOC_IDto be issued.

    • stopword_table_name: Thedatabase/tablename for a user-defined stopword table. TheVALUEcolumn is empty if there is no user-defined stopword table.

    • use_stopword: Indicates whether a stopword table is used, which is defined when theFULLTEXTindex is created.

    从INFORMATION_SCHEMA mysql > SELECT *。INNODB_FT_CONFIG; +---------------------------+-------+ | KEY | VALUE | +---------------------------+-------+ | optimize_checkpoint_limit | 180 | | synced_doc_id | 8 | | stopword_table_name | | | use_stopword | 1 | +---------------------------+-------+
  10. Disableinnodb_optimize_fulltext_only, since it is intended to be enabled only temporarily:

    mysql> SET GLOBAL innodb_optimize_fulltext_only=OFF;