Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

MroongaがあればMySQLでもGroongaを使える

Groonga自体もSqliteよろしく気軽に扱えるDBです。
ただ、既に動いてるシステムだとか本気で巨大なデータを扱う時にはやっぱり単体では厳しい局面もあります。
そこで登場するのがMroonga!
なんとMySQL...そして今をトキメクMariaDBまで扱える拡張です。
コチラの環境の都合で今回はMySQLのみを扱います。

MacOSXで導入

$ brew install https://raw.github.com/mroonga/homebrew/master/mroonga.rb --use-homebrew-mysql
...
==> Caveats
To install mroonga plugin, run the following command:
   mysql -uroot -e 'INSTALL PLUGIN mroonga SONAME "ha_mroonga.so"; CREATE FUNCTION last_insert_grn_id RETURNS INTEGER SONAME "ha_mroonga.so"; CREATE FUNCTION mroonga_snippet RETURNS STRING SONAME "ha_mroonga.so"; CREATE FUNCTION mroonga_command RETURNS STRING SONAME "ha_mroonga.so"; CREATE FUNCTION mroonga_escape RETURNS STRING SONAME "ha_mroonga.so";'
...

MySQL側の設定

いつも通りログイン。

$ mysql -u root -p

まずはエンジンの一覧を確認します。

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

コマンドの出力では確かに設定してる筈なのですが...
どういうわけかbrewだと上手くいかないらしいので、末尾の指示通りプラグインを突っ込みます。

mysql> INSTALL PLUGIN mroonga SONAME "ha_mroonga.so"; CREATE FUNCTION last_insert_grn_id RETURNS INTEGER SONAME "ha_mroonga.so"; CREATE FUNCTION mroonga_snippet RETURNS STRING SONAME "ha_mroonga.so"; CREATE FUNCTION mroonga_command RETURNS STRING SONAME "ha_mroonga.so"; CREATE FUNCTION mroonga_escape RETURNS STRING SONAME "ha_mroonga.so";

Query OK, 0 rows affected (0.05 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)


確認すると...

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| mroonga            | YES     | CJK-ready fulltext search, column store                        | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
10 rows in set (0.00 sec)

やったぜ