Re: An "obvious" index not being used
От | Daniele Varrazzo |
---|---|
Тема | Re: An "obvious" index not being used |
Дата | |
Msg-id | 36573.82.111.147.97.1213884218.squirrel@www.develer.com обсуждение исходный текст |
Ответ на | Re: An "obvious" index not being used ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>) |
Список | pgsql-performance |
>>>> 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
В списке pgsql-performance по дате отправления: