MariaDB10.2.6啟用Mroonga存儲引擎用於全文索引
如同翻譯的那樣,Mroonga是一個適用於MySQL的存儲引擎。它為所有MySQL用戶提供了快速的全文搜索功能。
這裏直接演示怎麽在MariaDB上啟用mroonga存儲引擎
1)加載mroonga插件
MariaDB [(none)]>INSTALL SONAME ‘ha_mroonga‘;
MariaDB [(none)]> CREATE FUNCTION last_insert_grn_id RETURNS INTEGER SONAME ‘ha_mroonga.so‘;
2)建表測試一下
MariaDB [(none)]>create database jerry;
MariaDB [(none)]>
MariaDB [jerry]> create table t1 (id int not null,name varchar(100)not null,notes text,fulltext index(notes))engine=mroonga;
3)胡亂插入一些數據
MariaDB [jerry]> insert into t1 values(1,‘擦擦擦‘,‘我也不會告訴你‘);
Query OK, 1 row affected (0.00 sec)
MariaDB [jerry]> insert into t1 values(2,‘啦啦啦‘,‘我也不會告訴你‘);
Query OK, 1 row affected (0.01 sec)
MariaDB [jerry]> insert into t1 values(3,‘dashaba‘,‘森馬服飾‘);
Query OK, 1 row affected (0.00 sec)
MariaDB [jerry]> insert into t1 values(4,‘victor‘,‘大森馬投資有限公司‘);
Query OK, 1 row affected (0.00 sec)
MariaDB [jerry]> insert into t1 values(5,‘kukumimilulu‘,‘森馬跨境電商有限公司‘);
Query OK, 1 row affected (0.00 sec)
MariaDB [jerry]> insert into t1 values(6,‘王思聰‘,‘王爸爸聯合大森馬跨境電商有限公司‘);
Query OK, 1 row affected (0.00 sec)
4)用如下命令查詢
MariaDB [jerry]> select * from t1 where match(notes) against(‘大森馬‘ in BOOLEAN MODE);
+----+-----------+--------------------------------------------------+
| id | name | notes |
+----+-----------+--------------------------------------------------+
| 4 | victor | 大森馬投資有限公司 |
| 6 | 王思聰 | 王爸爸聯合大森馬跨境電商有限公司 |
+----+-----------+--------------------------------------------------+
2 rows in set (0.00 sec)
5 ) 通過執行計劃我們可以看到已經用到notes這個全文索引,並且只需要掃描一行
MariaDB [jerry]> explain select * from t1 where match(notes) against(‘大森馬‘ in BOOLEAN MODE);
+------+-------------+-------+----------+---------------+-------+---------+------+------+-----------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+----------+---------------+-------+---------+------+------+-----------------------------------+
| 1 | SIMPLE | t1 | fulltext | notes | notes | 0 | | 1 | Using where with pushed condition |
+------+-------------+-------+----------+---------------+-------+---------+------+------+-----------------------------------+
1 row in set (0.00 sec)
本文出自 “運維人生” 博客,請務必保留此出處http://jinyan2049.blog.51cto.com/881440/1942333
MariaDB10.2.6啟用Mroonga存儲引擎用於全文索引