Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 8DEB31337B4E for ; Tue, 5 Apr 2011 20:41:05 -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 64733-03 for ; Tue, 5 Apr 2011 23:40:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.catalyst.net.nz (bertrand.catalyst.net.nz [202.78.240.40]) by mail.postgresql.org (Postfix) with ESMTP id 2C5161337B43 for ; Tue, 5 Apr 2011 20:40:47 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id EF88932204; Wed, 6 Apr 2011 11:40:44 +1200 (NZST) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3+cNUmkT9oDL; Wed, 6 Apr 2011 11:40:44 +1200 (NZST) Received: from [IPv6:2404:130:0:1000:222:15ff:fe5c:2471] (unknown [IPv6:2404:130:0:1000:222:15ff:fe5c:2471]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id 552B031EED; Wed, 6 Apr 2011 11:40:44 +1200 (NZST) Message-ID: <4D9BA87B.4090500@catalyst.net.nz> Date: Wed, 06 Apr 2011 11:40:43 +1200 From: Mark Kirkwood User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: Scott Marlowe CC: Thom Brown , pgsql-performance Subject: Re: Partial index slower than regular index References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 201104/36 X-Sequence-Number: 43098 On 06/04/11 11:31, Scott Marlowe wrote: > On Tue, Apr 5, 2011 at 4:35 PM, Thom Brown wrote: >> I'm using 9.1dev. > SNIP > >> DROP INDEX indextest_stuff; >> >> CREATE INDEX indextest_stuff ON indextest(stuff) WHERE stuff = 'bark'; >> >> postgres=# explain analyze select * from indextest where stuff = 'bark'; >> QUERY PLAN >> ------------------------------------------------------------------------------------------------------------------- >> Seq Scan on indextest (cost=0.00..143386.48 rows=5606 width=9) >> (actual time=164.321..1299.794 rows=8000 loops=1) >> Filter: (stuff = 'bark'::text) >> Total runtime: 1300.267 ms >> (3 rows) >> >> The index doesn't get used. There's probably a logical explanation, >> which is what I'm curious about. > Works fine for me: > > explain analyze select * from indextest where stuff = 'bark'; > QUERY > PLAN > ------------------------------------------------------------------------------------------------------------------------------------ > Index Scan using indextest_stuff on indextest (cost=0.00..837.01 > rows=13347 width=9) (actual time=0.226..6.073 rows=8000 loops=1) > Index Cond: (stuff = 'bark'::text) > Total runtime: 7.527 ms > > Even with a random_page_cost = 4 it works. Running 8.3.13 btw. > I reproduce what Thom sees - using 9.1dev with default config settings. Even cranking up effective_cache_size does not encourage the partial index to be used. Mark