HAYASHI Kentaro
hayas****@clear*****
2013年 8月 15日 (木) 00:09:04 JST
林です。 On Wed, 14 Aug 2013 09:44:55 +0900 Jiro Iwamoto <jirok****@gmail*****> wrote: > 岩本です。 > > 自己レスです。すいません、ちょっとデータのせいでわかりづらかったかもしれません。 > > 今試したところ、下記のクエリで12.77 secでした。ヒット件数は78件です。 > select guid, orgId, objId from CombinedData where match(content) > against('彼女' IN BOOLEAN MODE) > and orgId='ee15e1b414ad4329b7d14c857bc91644' and > objId='e9823fae423b4b56859ba98cb8a3a8dc'; > > 以上よろしくお願いします。 > インデックスの状態ってどうなっているでしょうか。 手元の環境でダミーデータを用意してちょっと試してみました。あくまでダミー なので、岩本さんの環境とは異なるかも知れません。 試したダミーデータ: 50万件 100件ヒットするケース http://packages.groonga.org/tmp/g01627.sql 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 | 500127 | NULL | NULL | | BTREE | | | | CombinedData | 1 | orgId | 1 | orgId | A | 17 | NULL | NULL | | BTREE | | | | CombinedData | 1 | orgId | 2 | objId | A | 17 | NULL | NULL | | BTREE | | | | CombinedData | 1 | content | 1 | content | NULL | NULL | NULL | NULL | | FULLTEXT | | | +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 4 rows in set (0.00 sec) mysql> explain select * 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.00 sec) ↑にあるように、FULLTEXT INDEXが使われています。 このときの結果は以下のようになりました。 環境1. Ubuntu 13.04 MySQL 5.5.31 mroonga 3.06 CPU i7 メモリ8G select * from CombinedData where match(content) against('彼女' IN BOOLEAN MODE) and orgId='ee15e1b414ad4329b7d14c857bc91644' and objId='e9823fae423b4b56859ba98cb8a3a8dc'; => 100 rows in set (0.01 sec) 環境2. CentOS 6.4 MySQL 5.1.69 mroonga 3.06 CPU Xeon E5645 メモリ2G select * from CombinedData where match(content) against('彼女' IN BOOLEAN MODE) and orgId='ee15e1b414ad4329b7d14c857bc91644' and objId='e9823fae423b4b56859ba98cb8a3a8dc'; => 100 rows in set (0.08 sec) mysql> select count(*) from Data; +----------+ | count(*) | +----------+ | 500000 | +----------+ 1 row in set (0.11 sec) mysql> select count(*) from CombinedData; +----------+ | count(*) | +----------+ | 500000 | +----------+ 1 row in set (0.09 sec) mysql> select count(*) from CombinedData where match(content) against('彼女' IN BOOLEAN MODE) and orgId='ee15e1b414ad4329b7d14c857bc91644' and objId='e9823fae423b4b56859ba98cb8a3a8dc'; +----------+ | count(*) | +----------+ | 100 | +----------+ mysql> select count(*) from CombinedData where match(content) against('彼氏' IN BOOLEAN MODE) and orgId='ee15e1b414ad4329b7d14c857bc91644' and objId='e9823fae423b4b56859ba98cb8a3a8dc'; +----------+ | count(*) | +----------+ | 499900 | +----------+ > > > 2013年8月13日 19:22 Jiro Iwamoto <jirok****@gmail*****>: > > > 林さん > > > > 岩本です。素早い回答ありがとうございます。 > > > > このクエリで動くようになりました。ありがとうございます。 > > > > もう一つ質問なのですが、パフォーマンスについてです。 > > 下記のようなテーブルでデータが50万件ほどある場合、 > > > > CREATE TABLE `CombinedData` ( > > `guid` varchar(36) NOT NULL, > > `orgId` varchar(36) NOT NULL, > > `objId` varchar(36) NOT NULL, > > `id` int(11) NOT NULL, > > `content` text NOT NULL, > > PRIMARY KEY (`guid`), > > KEY `orgId` (`orgId`,`objId`), > > FULLTEXT KEY `content` (`content`), > > CONSTRAINT `FK_CombinedData_Data` FOREIGN KEY (`guid`) REFERENCES `Data` > > (`guid`) ON DELETE CASCADE > > ) ENGINE=mroonga DEFAULT CHARSET=utf8 COMMENT='engine "innodb"' > > > > 下記のクエリを投げた時に15件データが取得できるのですが、50秒ほどかかります。これは正常な状態なのでしょうか? > > 転置インデックスで動作しているのであればもっと素早くとってこれるような気がしているのですが、、、、 > > > > select orgId, objId, guid from CombinedData where match(content) > > against('ポートピア連続殺人事件' IN BOOLEAN MODE) and orgId='9832' and objId='1234'; > > > > 質問ばかりで申し訳ありませんがよろしくお願いします。 > > snip -- HAYASHI Kentaro <hayas****@clear*****>