【问题标题】:Postgres Full Text Search performance questionPostgres全文搜索性能问题
【发布时间】:2010-11-17 03:50:20
【问题描述】:

Postgres 全文搜索性能似乎取决于您使用的字典,这是一个示例

我的表包含 60000 个条目

默认德语词典(我认为只有停用词)

SELECT title FROM sitesearch s, to_tsquery('german','holz') query WHERE query @@ searchtext LIMIT 10

查询计划

Limit  (cost=247.14..282.99 rows=10 width=21) (actual time=1.286..1.534 rows=10 loops=1)
  ->  Nested Loop  (cost=247.14..1358.57 rows=310 width=21) (actual time=1.278..1.512 rows=10 loops=1)
        ->  Function Scan on query  (cost=0.00..0.01 rows=1 width=32) (actual time=0.019..0.019 rows=1 loops=1)
        ->  Bitmap Heap Scan on sitesearch s  (cost=247.14..1354.68 rows=310 width=570) (actual time=1.237..1.452 rows=10 loops=1)
              Recheck Cond: (query.query @@ s.searchtext)
              ->  Bitmap Index Scan on sitesearch_searchtext_idx  (cost=0.00..247.06 rows=310 width=0) (actual time=0.871..0.871 rows=1144 loops=1)
                    Index Cond: (query.query @@ s.searchtext)
Total runtime: 1.815 ms
8 row(s)

Total runtime: 13.414 ms

很快

我的字典德语 ispell

CREATE TEXT SEARCH DICTIONARY pg_german (
    TEMPLATE = ispell,
    DictFile = german,
    AffFile = german,
    StopWords = german
);

支持复合词启用
字典文件:319018 字
词缀文件:1290行
停用词:264 个字

SELECT title FROM sitesearch s, to_tsquery('public.pg_german','holz') query WHERE query @@ searchtext LIMIT 10

查询计划

Limit  (cost=247.14..282.99 rows=10 width=21) (actual time=1.263..1.578 rows=10 loops=1)
  ->  Nested Loop  (cost=247.14..1358.57 rows=310 width=21) (actual time=1.255..1.556 rows=10 loops=1)
        ->  Function Scan on query  (cost=0.00..0.01 rows=1 width=32) (actual time=0.009..0.009 rows=1 loops=1)
        ->  Bitmap Heap Scan on sitesearch s  (cost=247.14..1354.68 rows=310 width=570) (actual time=1.229..1.495 rows=10 loops=1)
              Recheck Cond: (query.query @@ s.searchtext)
              ->  Bitmap Index Scan on sitesearch_searchtext_idx  (cost=0.00..247.06 rows=310 width=0) (actual time=0.896..0.896 rows=1144 loops=1)
                    Index Cond: (query.query @@ s.searchtext)
Total runtime: 1.818 ms
8 row(s)

Total runtime: 1,520.428 ms

查询计划很快……总运行时间为 1.5 秒?加载/初始化字典需要那么长时间吗?如何加快这个过程?

谢谢!

【问题讨论】:

    标签: performance postgresql full-text-search


    【解决方案1】:

    是的,ispell 字典在第一次加载时非常很慢。如果你正在使用这些,你真的需要使用连接池——它们只在第一次为每个连接加载时花费时间。

    对于 9.1,我们正在为此做一些工作,但对于当前版本,您会遇到该要求。

    【讨论】:

    • 因为 9.1 已经发布了,但是我找不到任何关于 ispell 速度的信息,有什么改进吗?谢谢!
    猜你喜欢
    • 1970-01-01
    • 2018-02-03
    • 2015-09-08
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    • 2014-01-05
    • 1970-01-01
    相关资源
    最近更新 更多