From: Daniele Varrazzo <piro@develer.com>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: pgsql-performance@postgresql.org
Subject: Re: An "obvious" index not being used
Date: Thu, 19 Jun 2008 16:03:38 +0200 (CEST)
Message-ID: <36573.82.111.147.97.1213884218.squirrel@www.develer.com> (raw)
In-Reply-To: <485A1CA6.EE98.0025.0@wicourts.gov>
References: <4859B13F.3070103@develer.com>
<485A1CA6.EE98.0025.0@wicourts.gov>
>>>> Daniele Varrazzo <piro@develer.com> wrote:
>
>> select count(*) from foo
>> where foo.account_id in (
>> select id from accounts where system = 'abc');
>
>> Total runtime: 13412.226 ms
>
> Out of curiosity, how does it do with the logically equivalent?:
>
> select count(*) from foo
> where exists (select * from accounts
> where accounts.id = foo.account_id
> and accounts.system = 'abc');
I tried it: it is slower and the query plan still includes the seqscan:
Aggregate (cost=44212346.30..44212346.31 rows=1 width=0) (actual
time=21510.468..21510.469 rows=1 loops=1)
-> Seq Scan on foo (cost=0.00..44205704.40 rows=2656760 width=0)
(actual time=0.058..21402.752 rows=92790 loops=1)
Filter: (subplan)
SubPlan
-> Index Scan using accounts_pkey on accounts (cost=0.00..8.27
rows=1 width=288) (actual time=0.002..0.002 rows=0 loops=5313519)
Index Cond: (id = $0)
Filter: (("system")::text = 'abc'::text)
Total runtime: 21510.531 ms
Here the estimate is even more gross: 2656760 is exactly the 50% of the
records in the table.
--
Daniele Varrazzo - Develer S.r.l.
http://www.develer.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: piro@develer.com, Kevin.Grittner@wicourts.gov
Subject: Re: An "obvious" index not being used
In-Reply-To: <36573.82.111.147.97.1213884218.squirrel@www.develer.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox