Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0283D63291E for ; Wed, 14 Jul 2010 10:57:42 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 23436-09 for ; Wed, 14 Jul 2010 13:57:33 +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 8F18D6324AF for ; Wed, 14 Jul 2010 10:57:34 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OZ2Sm-0000of-4U for pgsql-performance@postgresql.org; Wed, 14 Jul 2010 15:57:28 +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:57:28 +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:57:28 +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:57:35 +0200 Lines: 38 Message-ID: References: <20100714134928.GL21875@tamriel.snowman.net> 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: <20100714134928.GL21875@tamriel.snowman.net> 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/220 X-Sequence-Number: 39609 On 07/14/10 15:49, Stephen Frost wrote: > * Ivan Voras (ivoras@freebsd.org) wrote: >> Total runtime: 0.507 ms > [...] >> Total runtime: 118.689 ms >> >> 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. > > What you've shown is that it takes 0.5ms for 10 rows, and 118ms for 8500 > rows. Yes, but... > Now, maybe I've missed something, but that's 0.05ms per row for > the first query and 0.01ms per row for the second, and you've added a > sort into the mix. The performance of going through the data actually > improves on a per-record basis, since you're doing more in bulk. > > Since you're ordering by 'id', PG has to look at every row returned by > the index scan. That's not free. This part of the processing is going on on the backend, and the backend needs to sort through 8500 integers. I don't think the sort is significant here. > Regarding the statistics, it's entirely possible that the index is *not* > the fastest way to pull this data (it's nearly 10% of the table..), if > the stats were better it might use a seq scan instead, not sure how bad > the cost of the filter itself would be. I think that what I'm asking here is: is it reasonable for tsearch2 to extract 8,500 rows from an index of 90,000 rows in 118 ms, given that the approximately same task can be done with an unindexed "LIKE" operator in nearly the same time?