Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 5B4386333C0 for ; Wed, 14 Jul 2010 08:47:53 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 55934-08 for ; Wed, 14 Jul 2010 11:47:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 123F1633140 for ; Wed, 14 Jul 2010 08:47:45 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OZ0RC-0004Tt-RS for pgsql-performance@postgresql.org; Wed, 14 Jul 2010 13:47:42 +0200 Received: from lara.cc.fer.hr ([161.53.72.113]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Jul 2010 13:47:42 +0200 Received: from ivoras by lara.cc.fer.hr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Jul 2010 13:47:42 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-performance@postgresql.org From: Ivan Voras Subject: Understanding tsearch2 performance Date: Wed, 14 Jul 2010 13:47:52 +0200 Lines: 63 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: lara.cc.fer.hr User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.1.9) Gecko/20100518 Thunderbird/3.0.4 X-Enigmail-Version: 1.0.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/214 X-Sequence-Number: 39603 Here's a query and its EXPLAIN ANALYZE output: cms=> select count(*) from forum; count ------- 90675 (1 row) cms=> explain analyze select id,title from forum where _fts_ @@ 'fer'::tsquery; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------- Bitmap Heap Scan on forum (cost=29.21..361.21 rows=91 width=35) (actual time=2.946..63.646 rows=8449 loops=1) Recheck Cond: (_fts_ @@ '''fer'''::tsquery) -> Bitmap Index Scan on forum_fts (cost=0.00..29.19 rows=91 width=0) (actual time=2.119..2.119 rows=8449 loops=1) Index Cond: (_fts_ @@ '''fer'''::tsquery) Total runtime: 113.641 ms (5 rows) The problem is - tsearch2 seems too slow. I have nothing to compare it to but 113 ms for searching through this small table of 90,000 records seems too slow. The forum_fts index is of GIN type and the table certainly fits into RAM. When I issue a dumb query without an index, I get a comparable order of magnitude performance: cms=> explain analyze select id,title from forum where content ilike '%fer%'; QUERY PLAN ------------------------------------------------------------------------------------------------------------ Seq Scan on forum (cost=0.00..7307.44 rows=3395 width=35) (actual time=0.030..798.375 rows=10896 loops=1) Filter: (content ~~* '%fer%'::text) Total runtime: 864.384 ms (3 rows) cms=> explain analyze select id,title from forum where content like '%fer%'; QUERY PLAN ----------------------------------------------------------------------------------------------------------- Seq Scan on forum (cost=0.00..7307.44 rows=3395 width=35) (actual time=0.024..146.959 rows=7596 loops=1) Filter: (content ~~ '%fer%'::text) Total runtime: 191.732 ms (3 rows) Some peculiarities of the setup which might or might not influence this performance: 1) I'm using ICU-patched postgresql because I cannot use my UTF-8 locale otherwise - this is why the difference between the dumb queries is large (but I don't see how this can influence tsearch2 since it pre-builds the tsvector data with lowercase lexemes) 2) My tsearch2 lexer is somewhat slow (but I don't see how it can influence these read-only queries on a pre-built, lexed and indexed data) Any ideas?