[groonga-dev, 04465] Re: shared buffers hit vs read after >cat pgrn* /dev/null

Back to archive index

Kouhei Sutou kou****@clear*****
2017年 9月 11日 (月) 09:12:51 JST


須藤です。

In <012501d3284c$3b800eb0$b2802c10$@mirror.ocn.ne.jp>
  "[groonga-dev, 04460] shared buffers hit vs read after >cat pgrn* /dev/null" on Fri, 8 Sep 2017 11:43:20 +0900,
  <toshio_uchiy****@mirro*****> wrote:

> コマンドは
> 
> explain ( analyze, buffers ) SELECT id, video, track, content, starttime,
> theme
> 
> FROM manual AS P WHERE ( vc > 100000 OR sp = 1 ) and lower( content ) like
> 
> lower( '%algorithm%' ) and exists ( select video from manual AS C1
> 
> where ( vc > 100000 OR sp = 1 ) and lower( content ) like lower( '%search%'
> )
> 
> and P.video = C1.video ) ORDER BY vc DESC;

これ、インデックスはどうなっていますか?

CREATE INDEX xxx ON manual
  USING PGroonga (lower(content));

みたいな感じですか?

もし、そうならこれはムダがあります。

PGroongaの場合は自分で正規化する必要はありません。PGroongaが
自動でいい感じにやっているからです。

あと、LIKEよりも&@や&@~の方が速いです。

なので、

CREATE INDEX xxx ON manual
  USING PGroonga (content);

というインデックスにして、↓とする方が速いはずです。

SELECT id, video, track, content, starttime, theme
FROM manual AS P
WHERE ( vc > 100000 OR sp = 1 ) and
      content &@ 'algorithm' and
      exists (
        select video from manual AS C1
               where ( vc > 100000 OR sp = 1 ) and
                     content &@ 'search' and
                     P.video = C1.video )
ORDER BY vc DESC;

というか、このexists()ってなくせないですかねぇ。

SELECT id, video, track, content, starttime, theme
FROM manual
WHERE ( vc > 100000 OR sp = 1 ) and
      content &@~ 'algorithm search'
ORDER BY vc DESC;

これでも同じ結果にならないかしら。

> postgresql.conf の shared_buffers 8GB
> 
> shared hit 705 read 52559
> 
> 実行時間16秒

PGroongaはPostgreSQLのshared_buffersを使わないので、これを指
標にするのは適切ではありません。代わりに何を指標にすればよい
かは…特になくて、指標が欲しいなら普通のOSのページキャッシュ
のヒット率とかをみればよいです。で、どうやってみるか、だれか
知っている人います?

> 一度上記の SQL コマンドを実行してから再度 SQL コマンドを実行
> 
> postgresql.conf の shared_buffers 8GB
> 
> shared hit 53242 (read はなし)
> 
> 実行時間0.3秒

これで差がでているのは、PGroongaレベルではなくてPostgreSQLレ
ベルでのIOのキャッシュだと思うので、PostgreSQLのファイルも
cat XXX > /dev/nullしてページキャッシュに載せると速くなるん
じゃないかなぁと思いました。

PostgreSQL 9.4からはpg_prewarmという関数が追加されているみた
いなので、(PGroongaではなく)shared_buffersに関してはcatよ
りはこっちを使う方がPostgreSQLらしいと思います。

  https://www.postgresql.jp/document/9.6/html/pgprewarm.html


-- 
須藤 功平 <kou****@clear*****>
株式会社クリアコード <http://www.clear-code.com/>

Groongaベースの全文検索システムを総合サポート:
  http://groonga.org/ja/support/
パッチ採用 - プログラミングが楽しい人向けの採用プロセス:
  http://www.clear-code.com/recruitment/
OSS開発支援サービス:
  http://www.clear-code.com/blog/2016/6/27.html




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