Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 48534B5DBDA for ; Mon, 20 Jun 2011 16:01:48 -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 02491-07 for ; Mon, 20 Jun 2011 19:01:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gransy.com (mail.gransy.com [82.208.29.194]) by mail.postgresql.org (Postfix) with ESMTP id 0A141B5DBC7 for ; Mon, 20 Jun 2011 16:01:41 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.gransy.com (Postfix) with ESMTP id 49BD54A2215 for ; Mon, 20 Jun 2011 21:01:37 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at nathalia.gransy.com Received: from mail.gransy.com ([127.0.0.1]) by localhost (Nathalka.gransy.com.gransy.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PzkKPIcbtMV8 for ; Mon, 20 Jun 2011 21:01:36 +0200 (CEST) Received: from [192.168.1.221] (ip-78-45-133-255.net.upcbroadband.cz [78.45.133.255]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTPSA id 0E8514A221C for ; Mon, 20 Jun 2011 21:01:36 +0200 (CEST) Message-ID: <4DFF990F.8080906@fuzzy.cz> Date: Mon, 20 Jun 2011 21:01:35 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110619 Lightning/1.0b3pre Thunderbird/3.1.10 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: sequential scan unduly favored over text search gin index References: <1308584339.2488.12.camel@dragflick> <4DFF27C5020000250003E9A4@gw.wicourts.gov> <1308585840.2488.13.camel@dragflick> In-Reply-To: <1308585840.2488.13.camel@dragflick> X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/185 X-Sequence-Number: 44118 Dne 20.6.2011 18:04, Sushant Sinha napsal(a): > > On Mon, 2011-06-20 at 10:58 -0500, Kevin Grittner wrote: >> Sushant Sinha wrote: >> >>> I have a tsvector column docvector and a gin index on it >>> docmeta1_docvector_idx >>> >>> I have a simple query "select * from docmeta1 where docvector @@ >>> plainto_tsquery('english', 'free');" >>> >>> I find that the planner chooses a sequential scan of the table >>> even when the index performs orders of magnitude. >> >> Did you ANALYZE the table after loading the data and building the >> index? > Yes and I mentioned that the row estimates are correct, which indicate > that the problem is somewhere else. Hi, I agree the estimates are damn precise in this case (actually the estimates are exact). The problem is the planner thinks the seq scan is about 30% cheaper than the bitmap index scan. I guess you could poke the planner towards the bitmap scan by lowering the random_page_cost (the default value is 4, I'd say lowering it to 2 should do the trick). But be careful, this will influence all the other queries! Those values should somehow reflect the hardware of your system (type of drives, amount of RAM, etc.) so you have to test the effects. regards Tomas