MySQL-创建和使用全文索引(FullText)

MySQL5.6后,除了 MyISAM 存储引擎,事务型的 Innodb 存储引擎也支持创建和使用全文索引了。

以下为测试过程:

--创建测试表

CREATE TABLE article ( 
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY, 
title VARCHAR(200), 
body TEXT
) engine=innodb;


--插入测试值:

insert into article values(null,'MySQL数据库权威指南','非常不错的书籍,值得一看');
insert into article values(null,'Oracle数据库精选','不妨看看');
insert into article values(null,'SQL Servr 数据库进阶','不容错过');
insert into article values(null,'postgreq 数据库进阶','知道了吗');


--创建复合键title,body全文索引(当然也可以创建单键)

create fulltext index ft_idx on article(title,body) with parser ngram;   --使用 ngram 解释器


--测试是否能走上全文索引的执行计划

mysql> explain select * from article where match(title,body) against('精 妨');
+----+-------------+---------+------------+----------+---------------+--------+---------+-------+------+----------+-------------------------------+
| id | select_type | table   | partitions | type     | possible_keys | key    | key_len | ref   | rows | filtered | Extra                         |
+----+-------------+---------+------------+----------+---------------+--------+---------+-------+------+----------+-------------------------------+
|  1 | SIMPLE      | article | NULL       | fulltext | ft_idx        | ft_idx | 0       | const |    1 |   100.00 | Using where; Ft_hints

你可能感兴趣的:(MySQL,mysql,index,全文索引,fulltext)