Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id AABD46322EA for ; Wed, 14 Jul 2010 10:38:05 -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 86756-04 for ; Wed, 14 Jul 2010 13:37:56 +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 D8BBC632228 for ; Wed, 14 Jul 2010 10:37:57 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OZ29m-0005XJ-KI for pgsql-performance@postgresql.org; Wed, 14 Jul 2010 15:37:50 +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 15:37:50 +0200 Received: from ivoras by lara.cc.fer.hr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 14 Jul 2010 15:37:50 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-performance@postgresql.org From: Ivan Voras Subject: Re: Understanding tsearch2 performance Date: Wed, 14 Jul 2010 15:37:56 +0200 Lines: 60 Message-ID: References: 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 In-Reply-To: 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/218 X-Sequence-Number: 39607 On 07/14/10 15:25, Oleg Bartunov wrote: > On Wed, 14 Jul 2010, Ivan Voras wrote: > >>> Returning 8449 rows could be quite long. >> >> You are right, I didn't test this. Issuing a query which returns a >> smaller result set is much faster. >> >> But, offtopic, why would returning 8500 records, each around 100 bytes >> long so around 8.5 MB, over local unix sockets, be so slow? The machine >> in question has a sustained memory bendwidth of nearly 10 GB/s. Does >> PostgreSQL spend much time marshalling the data through the socket >> stream? > > It's disk access time. > in the very bad case it could take ~5 ms (for fast drive) to get one just > one row. No, it's not that. The table fits in RAM, I've verified there is no disk IO involved. Something else is wrong: cms=> explain analyze select id,title from forum where _fts_ @@ 'fer'::tsquery limit 10; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..43.31 rows=10 width=35) (actual time=0.194..0.373 rows=10 loops=1) -> Index Scan using forum_fts on forum (cost=0.00..394.10 rows=91 width=35) (actual time=0.182..0.256 rows=10 loops=1) Index Cond: (_fts_ @@ '''fer'''::tsquery) Total runtime: 0.507 ms (4 rows) cms=> explain analyze select id,title from forum where _fts_ @@ 'fer'::tsquery order by id limit 10; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------- Limit (cost=363.18..363.20 rows=10 width=35) (actual time=118.358..118.516 rows=10 loops=1) -> Sort (cost=363.18..363.40 rows=91 width=35) (actual time=118.344..118.396 rows=10 loops=1) Sort Key: id Sort Method: top-N heapsort Memory: 25kB -> Bitmap Heap Scan on forum (cost=29.21..361.21 rows=91 width=35) (actual time=3.066..64.091 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.106..2.106 rows=8449 loops=1) Index Cond: (_fts_ @@ '''fer'''::tsquery) Total runtime: 118.689 ms (9 rows) See in the first query where I have a simple LIMIT, it fetches random 10 rows quickly, but in the second one, as soon as I give it to execute and calculate the entire result set before I limit it, the performance is horrible.