[groonga-dev,01599] フィルタで関連の関連と && を組み合わせた場合の挙動

Back to archive index

Motoi Washida wm3****@w3ch*****
2013年 8月 11日 (日) 13:38:07 JST


初めまして、鷲田と申します。

分かりやすい検索エンジンを探しているうちに Groonga を知って、使い始めています。


今回は Groonga の挙動について気になった所があったので、相談のためにメールしました。


現象
----------------

「関連の関連で絞り込みつつ検索する」という事をフィルタで実現しようとしました。

具体的には、 a, b, c というテーブルを用意して a -> b -> c という関連を付けています。 a -> b は一対一ですが、 b -> c は一対多です。

「特定の c の要素に関連」していて、かつ「他の検索条件に引っかかる」 a を取得しようとしたのですが、 && の組み合わせ順によって結果が違ってしまいました。


例
----------------

以下のようにデータを構築しました。

% cat structure.txt
table_create A --key_type ShortText
table_create B --key_type ShortText
table_create C --key_type ShortText
column_create A b --type B
column_create A v --type ShortText
column_create B c --type C --flags COLUMN_VECTOR
column_create C b_i --flags COLUMN_INDEX --type B --source c
column_create B a_i --flags COLUMN_INDEX --type A --source b
load --table B
[
{ _key: "b1", c: [ "c1" ] }
]
load --table A
[
{ _key: "a1", b: "b1", v: "v1" }
]
% groonga -n x < structure.txt
[[0,1376189555.10777,0.00058293342590332],true]
[[0,1376189555.10841,0.000342845916748047],true]
[[0,1376189555.10876,0.000372171401977539],true]
[[0,1376189555.10915,0.000308990478515625],true]
[[0,1376189555.10948,0.000865936279296875],true]
[[0,1376189555.11036,0.00088810920715332],true]
[[0,1376189555.11127,0.00348997116088867],true]
[[0,1376189555.11478,0.0042719841003418],true]
[[0,1376189555.11908,0.000741958618164062],1]
[[0,1376189555.11984,0.000606060028076172],1]

この状態で、以下の問い合わせを実行します。

% groonga x
> select A --filter 'b.c @ "c1" && v == "v1"'
[[0,1376189713.05742,0.0075078010559082],[[[1],[["_id","UInt32"],["_key","ShortText"],["b","B"],["v","ShortText"]],[1,"a1","b1","v1"]]]]
> select A --filter 'v == "v1" && b.c @ "c1"'
[[0,1376189717.25227,0.000458955764770508],[[[0],[["_id","UInt32"],["_key","ShortText"],["b","B"],["v","ShortText"]]]]]

二つの select は && の順序を逆にしただけなのですが、結果が異なってしまいます。A の要素 a1 は v に "v1" を持ち b1 -> [c1] と関連しているので、前者のように検索に引っかかる事を期待していました。


追加の検証
----------------

Groonga 3.0.4 で同様のコードを実行した結果、二つの問い合わせは期待通りに引っかかってくれました。


環境
----------------

### 1. Mac OS X Mountain Lion 上でソースビルドした 3.0.6 ###

- Mac OS X 10.8.4 で、clang を使ってビルドしました。

% groonga --version
groonga 3.0.6 [darwin12.4.0,x86_64,utf8,match-escalation-threshold=0,nfkc,zlib,lzo,kqueue]

configure options: < 'CC=clang' 'CXX=clang++'>
% sw_vers
ProductName:	Mac OS X
ProductVersion:	10.8.4
BuildVersion:	12E55
% clang --version
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix


### 2. Ubuntu 12.04 上で apt でインストールした 3.0.6 ###

- Vagrant + VirtualBox 内で構築しました。
- 3.0.4 での検証もこの環境で行っています。

vagrant @ precise64:~$ groonga --version
groonga 3.0.6 [linux-gnu,x86_64,utf8,match-escalation-threshold=0,nfkc,mecab,zlib,lzo,epoll]

configure options: < '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--libexecdir=${prefix}/lib/groonga' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-zlib' '--with-lzo' '--with-munin-plugins' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2' 'LDFLAGS=-Wl,-Bsymbolic-functions' 'CPPFLAGS=' 'CXXFLAGS=-g -O2'>
vagrant @ precise64:~/groonga$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
vagrant @ precise64:~/groonga$ cat /proc/version
Linux version 3.2.0-23-generic (buildd @ crested) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu4) ) #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012


-- 
Motoi Washida <wm3****@mail*****>




groonga-dev メーリングリストの案内
Back to archive index