Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 5454F2E0051 for ; Tue, 17 Jun 2008 08:01:15 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 48040-01 for ; Tue, 17 Jun 2008 08:00:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ppsw-0.csi.cam.ac.uk (ppsw-0.csi.cam.ac.uk [131.111.8.130]) by developer.postgresql.org (Postfix) with ESMTP id C9B442E0050 for ; Tue, 17 Jun 2008 08:00:37 -0300 (ADT) X-Cam-SpamDetails: Not scanned X-Cam-AntiVirus: No virus found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from flymine.sysbiol.cam.ac.uk ([131.111.60.120]:50117 helo=flymine.flymine.org) by ppsw-0.csi.cam.ac.uk (ppsw.cam.ac.uk [131.111.8.130]:25) with esmtp id 1K8YvI-0002Qf-2i (Exim 4.67) for pgsql-performance@postgresql.org (return-path ); Tue, 17 Jun 2008 12:00:24 +0100 Received: from host103 ([192.168.128.103] helo=aragorn.flymine.org ident=Debian-exim) by flymine.flymine.org with esmtp (Exim 4.12) id 1K8YvI-0004TV-00 for pgsql-performance@postgresql.org; Tue, 17 Jun 2008 12:00:24 +0100 Received: from mnw21 (helo=localhost) by aragorn.flymine.org with local-esmtp (Exim 4.69) (envelope-from ) id 1K8YvI-0004pR-LW for pgsql-performance@postgresql.org; Tue, 17 Jun 2008 12:00:24 +0100 Date: Tue, 17 Jun 2008 12:00:24 +0100 (BST) From: Matthew Wakeling X-X-Sender: mnw21@aragorn.flymine.org To: pgsql-performance@postgresql.org Subject: Re: Tsearch2 Initial Search Speed In-Reply-To: <485789C1.3000803@selestial.com> Message-ID: References: <4856A91F.1020001@selestial.com> <200806161124.57543@hal.medialogik.com> <485789C1.3000803@selestial.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/61 X-Sequence-Number: 30411 On Tue, 17 Jun 2008, Howard Cole wrote: > Alan Hodgson wrote: >> It's because everything is cached, in particular the relevant rows from the >> "email" table (accessing which took 22 of the original 27 seconds). > Thanks Alan, I guessed that the caching was the difference, but I do not > understand why there is a heap scan on the email table? The query seems to > use the email_fts_index correctly, which only takes 6 seconds, why does it > then need to scan the email table? It's not a sequential scan - that really would take a fair time. It's a bitmap heap scan - that is, it has built a bitmap of the rows needed by using the index, and now it needs to fetch all those rows from the email table. There's 14938 of them, and they're likely scattered all over the table, so you'll probably have to do 14938 seeks on the disc. At 5ms a pop, that would be 70 seconds, so count yourself lucky it only takes 22 seconds instead! If you aren't actually interested in having all 14938 rows splurged at you, try using the LIMIT keyword at the end of the query. That would make it run a bit faster, and would make sense if you only want to display the first twenty on a web page or something. Matthew -- For every complex problem, there is a solution that is simple, neat, and wrong. -- H. L. Mencken