MySQL EXPLAIN 不显示 FULLTEXT 的“使用索引”

Ant*_*Ant 6 mysql myisam full-text-search

我有一个基本表:

create table fullTextTest
(
    id INT(11) NOT NULL,
    superText CHAR(255) NOT NULL,
    superLongText TEXT NOT NULL,
    primary key (`id`),
    FULLTEXT KEY `superText` (`superText`),
    FULLTEXT KEY `superLongtext` (`superLongtext`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

insert into fullTextTest
    set id=1,
    superText="Hi guys, how is it goin'?",
    superLongtext="Please give me some dummy text to search on!!!"
;

show index from fullTextTest;
| fullTextTest |          0 | PRIMARY       |            1 | id            | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| fullTextTest |          1 | superText     |            1 | superText     | NULL      |        NULL |     NULL | NULL   |      | FULLTEXT   |         |
| fullTextTest |          1 | superLongtext |            1 | superLongText | NULL      |        NULL |     NULL | NULL   |      | FULLTEXT   |         |
Run Code Online (Sandbox Code Playgroud)

现在,让我们看看 MySQL 是否正确使用了这个索引:

EXPLAIN select * from fullTextTest where match(superText) AGAINST ("guys" IN BOOLEAN MODE);
| id | select_type | table        | type     | possible_keys | key       | key_len | ref  | rows | Extra       |
+----+-------------+--------------+----------+---------------+-----------+---------+------+------+-------------+
|  1 | SIMPLE      | fullTextTest | fulltext | superText     | superText | 0       |      |    1 | Using where |
Run Code Online (Sandbox Code Playgroud)

“Using Where”告诉我 EXPLAIN 不理解 FULLText .. 真的很遗憾。

我错过了什么 ?

Rol*_*DBA 2

我能理解为什么会发生这种情况

表中只有一行。

MySQL 查询优化器将围绕以下经验法则执行计划:如果通过索引检查查询完成情况所需的行数超过总行数的 5%,则查询优化器将不会使用该索引并将使用表扫描或索引扫描。

表中有多少行?一

有多少行被索引?一

由于您将检查 100% 的行,因此不会选择键控查找。将执行查询。您根本没有足够的行来证明在搜索中涉及索引是合理的。这通常适用于任何索引的内容。FULLTEXT 索引往往会在最不方便的时候被查询优化器抛弃。我早在 2012 年 1 月 26 日就写过此事

尝试将更多行加载到表中,至少 21 行,然后重试。