Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 879F6B5DC12 for ; Mon, 20 Jun 2011 15:59:24 -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 46546-08-3 for ; Mon, 20 Jun 2011 18:59:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from shrek.krogh.cc (2605ds1-ynoe.0.fullrate.dk [90.184.12.24]) by mail.postgresql.org (Postfix) with ESMTP id 835A6B5DC42 for ; Mon, 20 Jun 2011 15:59:11 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by shrek.krogh.cc (Postfix) with ESMTP id 962DE339C2A for ; Mon, 20 Jun 2011 20:59:08 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at shrek.krogh.cc Received: from shrek.krogh.cc ([127.0.0.1]) by localhost (shrek.krogh.cc [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PZx2rgZHFj98 for ; Mon, 20 Jun 2011 20:58:59 +0200 (CEST) Received: from [90.184.13.151] (2605ds1-ynoe.2.fullrate.dk [90.184.13.151]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jesper@krogh.cc) by shrek.krogh.cc (Postfix) with ESMTPSA id 240B3339C27 for ; Mon, 20 Jun 2011 20:58:59 +0200 (CEST) Message-ID: <4DFF9872.6030104@krogh.cc> Date: Mon, 20 Jun 2011 20:58:58 +0200 From: Jesper Krogh User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 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> In-Reply-To: <1308584339.2488.12.camel@dragflick> Content-Type: text/plain; charset=UTF-8; format=flowed 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/184 X-Sequence-Number: 44117 On 2011-06-20 17:38, 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. I set random_page_cost = 1.0 for > the database to favor index use. However, I still see that the cost > estimate for sequential scan of the entire table (23000) is cheaper than > the cost of using the index (33000). The time taken for sequential > access is 5200 ms and for index usage is only 85 ms. The cost-estimation code for gin-indices are not good in 9.0, this has hugely been improved in 9.1 http://git.postgresql.org/gitweb?p=postgresql.git&a=search&h=HEAD&st=commit&s=gincost I think the individual patches apply quite cleanly to 9.0 as far as I remember. -- Jesper