Kouhei Sutou
kou****@clear*****
2017年 9月 15日 (金) 14:11:06 JST
須藤です。 In <043a01d32dba$e9174660$bb45d320$@mirror.ocn.ne.jp> "[groonga-dev,04477] 【ご報告】インデックスを使って検索したいときにシーケンシャルスキャン" on Fri, 15 Sep 2017 09:38:12 +0900, <toshio_uchiy****@mirro*****> wrote: > 何もしないで検索すると > -> Seq Scan on robot (cost=0.00..417224.88 rows=2920069 width=279) のcostの値の方が > とシーケンシャルスキャンします。set enable_seqscan to off; すると > -> Bitmap Heap Scan on robot (cost=1460.03..418684.91 rows=2920069 のcostの値より少し小さい 417224.88 → 418684.91 のでPostgreSQLはシーケンシャルスキャンを選択しています。 > -> Bitmap Index Scan on robot2_lower_r_delimmit_tags_idx (cost=0.00..0.00 rows=2595875 width=0) (actual time=17.836..17.836 rows=6238> loops=1) > Index Cond: (lower(tags) &@ 'iphone'::text) > -> Bitmap Index Scan on robot2_lower_r_mecab_title_idx (cost=0.00..0.00 rows=2595875 width=0) (actual time=21.514..21.514 rows=13623 loops=1) > Index Cond: (lower(title) &@ 'iphone'::text) の推定ヒット数(rowsのところの2595875)が実際のヒット数(actualの方の rowsのところ)とかけ離れているのが適切なプランを選択できない 原因です。 このデータを提供してもらえれば、推定ヒット数をだすロジックを 改良できるかもしれないのでご検討ください。もし改良できれば、 明示的にenable_seq_scanを変更しなくてもいい感じの実行プラン を選ぶようになります。 -- 須藤 功平 <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