| 57 |> +----------+------+----------+-------+
1 row in set (0.01 sec)
可以看到,查询出来的值所对应的table_id就是opening_lines所对应的table_id。
全文索引将文档内的单词过滤出来存放到不同的索引表里,此操作可能在高并发的情况下产生大量的I/O操作,从而影响系统性能。为此,MySQL设计了全文索引缓存。该缓存存储最近插入的数据索引,当缓存存满时,再将索引数据批量写入到磁盘中。由于存在缓存,在事务中,MySQL对全文索引有特殊的处理方式,全文索引必须在事务提交后才会生效。可以参考以下例子:
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO opening_lines(opening_line,author,title) VALUES
-> ('Call me Ishmael.','Herman Melville','Moby-Dick'),
-> ('A screaming comes across the sky.','Thomas Pynchon','Gravity\'s Rainbow'),
-> ('I am an invisible man.','Ralph Ellison','Invisible Man'),
-> ('Where now? Who now? When now?','Samuel Beckett','The Unnamable'),
-> ('It was love at first sight.','Joseph Heller','Catch-22'),
-> ('All this happened, more or less.','Kurt Vonnegut','Slaughterhouse-Five'),
-> ('Mrs. Dalloway said she would buy the flowers herself.','Virginia Woolf','Mrs. Dalloway'),
-> ('It was a pleasure to burn.','Ray Bradbury','Fahrenheit 451');
Query OK, 8 rows affected (0.02 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> SELECT COUNT(*) FROM opening_lines WHERE MATCH(opening_line) AGAINST('Ishmael');
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
1 row in set (0.02 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT COUNT(*) FROM opening_lines WHERE MATCH(opening_line) AGAINST('Ishmael');
+----------+
| COUNT(*) |
+----------+
| 1 |
+----------+
1 row in set (0.00 sec)
在提交前,查询不到关键词’Ishmael’,在提交后就查询到了。
哈希索引
启动哈希索引的参数为innodb_adaptive_hash_index。哈希索引将B-tree索引树上的关键字进行哈希处理存放到哈希表上。哈希索引主要用于精确查找,如=,IN等。像LIKE或通配符的查找不适合使用哈希索引。哈希索引由于是对索引关键字进行哈希操作,而变换之后的哈希值的大小关系无法与原始值相对应。所以哈希索引无法被用来避免数据的排序操作。