Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 1708D1337BF9 for ; Tue, 5 Apr 2011 23:04:03 -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 94008-04 for ; Wed, 6 Apr 2011 02:03:56 +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 D2D7513364DE for ; Tue, 5 Apr 2011 23:03:55 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id 47698320F3; Wed, 6 Apr 2011 14:03:54 +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 ALGCyq6abVEb; Wed, 6 Apr 2011 14:03:53 +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 8F2A531CC0; Wed, 6 Apr 2011 14:03:53 +1200 (NZST) Message-ID: <4D9BCA09.5020307@catalyst.net.nz> Date: Wed, 06 Apr 2011 14:03:53 +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: <4D9BA87B.4090500@catalyst.net.nz> In-Reply-To: <4D9BA87B.4090500@catalyst.net.nz> 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/37 X-Sequence-Number: 43099 On 06/04/11 11:40, Mark Kirkwood wrote: > 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. > > However trying with 9.0 gives me the (expected) same 8.3 behaviour: test=# CREATE INDEX indextest_stuff ON indextest(stuff) WHERE stuff = 'bark'; CREATE INDEX test=# explain analyze select * from indextest where stuff = 'bark'; QUERY PLAN -------------------------------------------------------------------------------------------- Index Scan using indextest_stuff on indextest (cost=0.00..284.20 rows=5873 width=9) (actual time=0.276..9.621 rows=8000 loops=1) Index Cond: (stuff = 'bark'::text) Total runtime: 16.621 ms (3 rows) regards Mark