HAYASHI Kentaro
hayas****@clear*****
2013年 8月 21日 (水) 19:02:51 JST
林です。 On Tue, 20 Aug 2013 21:11:56 +0900 Jiro Iwamoto <jirok****@gmail*****> wrote: > 林さん > > お世話になっております。岩本です。 > サンプルデータまで、、、ありがとうございます! > > データを作成してたところ、返答が遅くなってしまいました。申し訳ありません。 > > 作っていただいたデータだと確かに速いですね。 > 私の方も投入できるデータを作成しましたがデータ量を多くしてしまうとやはり遅いです。 > http://jirox.net/dumpForML.zip データをダウンロードして実際に試してみました。 > > mysql> select count(guid) from CombinedData where match(content) > against('事件' IN BOOLEAN MODE) and orgId='ee15e1b414ad4329b7d14c857bc91644' > and objId='e9823fae423b4b56859ba98cb8a3a8dc'; > +-------------+ > | count(guid) | > +-------------+ > | 172 | > +-------------+ > 1 row in set (11.20 sec) > > mysql> explain select count(guid) from CombinedData where match(content) > against('事件' IN BOOLEAN MODE) and orgId='ee15e1b414ad4329b7d14c857bc91644' > and objId='e9823fae423b4b56859ba98cb8a3a8dc'; > +----+-------------+--------------+----------+---------------+---------+---------+------+------+-------------+ > | id | select_type | table | type | possible_keys | key | > key_len | ref | rows | Extra | > +----+-------------+--------------+----------+---------------+---------+---------+------+------+-------------+ > | 1 | SIMPLE | CombinedData | fulltext | orgId,content | content | 0 > | | 1 | Using where | > +----+-------------+--------------+----------+---------------+---------+---------+------+------+-------------+ > 1 row in set (0.06 sec) > > mysql> show indexes from CombinedData; > +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------------+ > | Table | Non_unique | Key_name | Seq_in_index | Column_name | > Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | > Index_comment | > +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------------+ > | CombinedData | 0 | PRIMARY | 1 | guid | A > | 657378 | NULL | NULL | | BTREE | | > | > | CombinedData | 1 | orgId | 1 | orgId | A > | 29 | NULL | NULL | | BTREE | | > | > | CombinedData | 1 | orgId | 2 | objId | A > | 29 | NULL | NULL | | BTREE | | > | > | CombinedData | 1 | content | 1 | content | NULL > | NULL | NULL | NULL | | FULLTEXT | | > parser "TokenMecab" | > +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------------+ > 4 rows in set (0.06 sec) > > インデックス的には問題はないように思うのですが、、、 > > 問題なさそうですね。。。 データの件数に応じてどの程度で結果が得られたら妥当か、というのは環境によるのでなんとも言えないのですが、 なにかしらボトルネックになっている部分があるんじゃないかなぁ、という気がしています。 なので、クエリを実行中の状況をtopコマンドなどで確認してみるといいんじゃないかと思います。 参考までに、頂いたデータで試した結果を以下に示します。 試した環境は [groonga-dev,01630] Re: mroongaの全文検索がうまくできません で書いたものです。 環境1. Ubuntu 13.04 MySQL 5.5.31 mroonga 3.06 CPU i7-2640M メモリ8G mysql> select count(guid) from CombinedData where match(content) against('事件' IN BOOLEAN MODE); +-------------+ | count(guid) | +-------------+ | 89072 | +-------------+ 1 row in set (3.85 sec) mysql> select count(guid) from CombinedData where match(content) -> against('事件' IN BOOLEAN MODE) and orgId='ee15e1b414ad4329b7d14c857bc91644' -> and objId='e9823fae423b4b56859ba98cb8a3a8dc'; +-------------+ | count(guid) | +-------------+ | 172 | +-------------+ 1 row in set (3.88 sec) 上記からは全文検索が大半で、andによる絞り込みは誤差みたいな感じになっていることがわかります。 また、岩本さんほどクエリの実行結果が遅くない、という状態です。 続けてクエリを実行すると、 mysql> select count(guid) from CombinedData where match(content) against('事件' IN BOOLEAN MODE); +-------------+ | count(guid) | +-------------+ | 89072 | +-------------+ 1 row in set (0.00 sec) mysql> select count(guid) from CombinedData where match(content) against('事件' IN BOOLEAN MODE) and orgId='ee15e1b414ad4329b7d14c857bc91644' and objId='e9823fae423b4b56859ba98cb8a3a8dc'; +-------------+ | count(guid) | +-------------+ | 172 | +-------------+ 1 row in set (0.00 sec) キャッシュが効いているのですぐに結果がかえってきました。 (岩本さんの環境で二回目以降のクエリも遅いとかあるでしょうか?) topコマンドでクエリを実行中の状態を見てみると、CPU使用率も余裕があるし、I/Oの終了待ちがボトルネックになっているわけではない状態でした。 -- HAYASHI Kentaro <hayas****@clear*****>