Rechercher dans le manuel MySQL

15.14.4 InnoDB INFORMATION_SCHEMA FULLTEXT Index Tables

The following tables provide metadata for FULLTEXT indexes:

  1. mysql> SHOW TABLES FROM INFORMATION_SCHEMA LIKE 'INNODB_FT%';
  2. +-------------------------------------------+
  3. | Tables_in_INFORMATION_SCHEMA (INNODB_FT%) |
  4. +-------------------------------------------+
  5. | INNODB_FT_CONFIG                          |
  6. | INNODB_FT_BEING_DELETED                   |
  7. | INNODB_FT_DELETED                         |
  8. | INNODB_FT_DEFAULT_STOPWORD                |
  9. | INNODB_FT_INDEX_TABLE                     |
  10. | INNODB_FT_INDEX_CACHE                     |
  11. +-------------------------------------------+

Table Overview

Note

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).

Example 15.5 InnoDB FULLTEXT Index INFORMATION_SCHEMA Tables

This example uses a table with a FULLTEXT index to demonstrate the data contained in the FULLTEXT index INFORMATION_SCHEMA tables.

  1. Create a table with a FULLTEXT index and insert some data:

    1. mysql> CREATE TABLE articles (
    2.          title VARCHAR(200),
    3.          body TEXT,
    4.          FULLTEXT (title,body)
    5.        ) ENGINE=InnoDB;
    6.  
    7. mysql> INSERT INTO articles (title,body) VALUES
    8.        ('MySQL Tutorial','DBMS stands for DataBase ...'),
    9.        ('How To Use MySQL Well','After you went through a ...'),
    10.        ('Optimizing MySQL','In this tutorial we will show ...'),
    11.        ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
    12.        ('MySQL vs. YourSQL','In the following database comparison ...'),
    13.        ('MySQL Security','When configured properly, MySQL ...');
  2. Set the innodb_ft_aux_table variable to the name of the table with the FULLTEXT index. If this variable is not set, the InnoDB FULLTEXT INFORMATION_SCHEMA tables are empty, with the exception of INNODB_FT_DEFAULT_STOPWORD.

    1. mysql> SET GLOBAL innodb_ft_aux_table = 'test/articles';
  3. Query the INNODB_FT_INDEX_CACHE table, which shows information about newly inserted rows in a FULLTEXT index. To avoid expensive index reorganization during DML operations, data for newly inserted rows remains in the FULLTEXT index cache until OPTIMIZE TABLE is run (or until the server is shut down or cache limits are exceeded).

    1. mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE LIMIT 5;
    2. +------------+--------------+-------------+-----------+--------+----------+
    3. | WORD       | FIRST_DOC_ID | LAST_DOC_ID | DOC_COUNT | DOC_ID | POSITION |
    4. +------------+--------------+-------------+-----------+--------+----------+
    5. | 1001       |            5 |           5 |         1 |      5 |        0 |
    6. | after      |            3 |           3 |         1 |      3 |       22 |
    7. | comparison |            6 |           6 |         1 |      6 |       44 |
    8. | configured |            7 |           7 |         1 |      7 |       20 |
    9. | database   |            2 |           6 |         2 |      2 |       31 |
    10. +------------+--------------+-------------+-----------+--------+----------+
  4. Enable the innodb_optimize_fulltext_only system variable and run OPTIMIZE TABLE on the table that contains the FULLTEXT index. This operation flushes the contents of the FULLTEXT index cache to the main FULLTEXT index. innodb_optimize_fulltext_only changes the way the OPTIMIZE TABLE statement operates on InnoDB tables, and is intended to be enabled temporarily, during maintenance operations on InnoDB tables with FULLTEXT indexes.

    1. mysql> SET GLOBAL innodb_optimize_fulltext_only=ON;
    2.  
    3. mysql> OPTIMIZE TABLE articles;
    4. +---------------+----------+----------+----------+
    5. | Table         | Op       | Msg_type | Msg_text |
    6. +---------------+----------+----------+----------+
    7. | test.articles | optimize | status   | OK       |
    8. +---------------+----------+----------+----------+
  5. Query the INNODB_FT_INDEX_TABLE table to view information about data in the main FULLTEXT index, including information about the data that was just flushed from the FULLTEXT index cache.

    1. mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE LIMIT 5;
    2. +------------+--------------+-------------+-----------+--------+----------+
    3. | WORD       | FIRST_DOC_ID | LAST_DOC_ID | DOC_COUNT | DOC_ID | POSITION |
    4. +------------+--------------+-------------+-----------+--------+----------+
    5. | 1001       |            5 |           5 |         1 |      5 |        0 |
    6. | after      |            3 |           3 |         1 |      3 |       22 |
    7. | comparison |            6 |           6 |         1 |      6 |       44 |
    8. | configured |            7 |           7 |         1 |      7 |       20 |
    9. | database   |            2 |           6 |         2 |      2 |       31 |
    10. +------------+--------------+-------------+-----------+--------+----------+

    The INNODB_FT_INDEX_CACHE table is now empty since the OPTIMIZE TABLE operation flushed the FULLTEXT index cache.

    1. mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE LIMIT 5;
    2. Empty set (0.00 sec)
  6. Delete some records from the test/articles table.

    1. mysql> DELETE FROM test.articles WHERE id < 4;
  7. Query the INNODB_FT_DELETED table. This table records rows that are deleted from the FULLTEXT index. 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 run OPTIMIZE TABLE.

    1. mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DELETED;
    2. +--------+
    3. | DOC_ID |
    4. +--------+
    5. |      2 |
    6. |      3 |
    7. |      4 |
    8. +--------+
  8. Run OPTIMIZE TABLE to remove the deleted records.

    1. mysql> OPTIMIZE TABLE articles;
    2. +---------------+----------+----------+----------+
    3. | Table         | Op       | Msg_type | Msg_text |
    4. +---------------+----------+----------+----------+
    5. | test.articles | optimize | status   | OK       |
    6. +---------------+----------+----------+----------+

    The INNODB_FT_DELETED table should now be empty.

    1. mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DELETED;
    2. Empty set (0.00 sec)
  9. Query the INNODB_FT_CONFIG table. This table contains metadata about the FULLTEXT index and related processing:

    • optimize_checkpoint_limit: The number of seconds after which an OPTIMIZE TABLE run stops.

    • synced_doc_id: The next DOC_ID to be issued.

    • stopword_table_name: The database/table name for a user-defined stopword table. The VALUE column is empty if there is no user-defined stopword table.

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

    1. mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_CONFIG;
    2. +---------------------------+-------+
    3. | KEY                       | VALUE |
    4. +---------------------------+-------+
    5. | optimize_checkpoint_limit | 180   |
    6. | synced_doc_id             | 8     |
    7. | stopword_table_name       |       |
    8. | use_stopword              | 1     |
    9. +---------------------------+-------+
  10. Disable innodb_optimize_fulltext_only, since it is intended to be enabled only temporarily:

    1. mysql> SET GLOBAL innodb_optimize_fulltext_only=OFF;


Find a PHP function

Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-innodb-information-schema-fulltext-index-tables.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:en Manuel MySQL : https://dev.mysql.com/

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut