Re: Query Optimizer makes a poor choice

From: Filip Rembiałkowski <plk(dot)zuber(at)gmail(dot)com>
To: Tyler Hains <thains(at)profitpointinc(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query Optimizer makes a poor choice
Date: 2011-11-29 19:16:27
Message-ID: CAP_rwwkE8pGhGsOXt2LQgE9K9_B4LRaLe7=0pT3ZdRQYeEPixQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2011/11/29 Tyler Hains <thains(at)profitpointinc(dot)com>:
> # explain analyze select * from cards where card_set_id=2850 order by
> card_id limit 1;
>                                                                QUERY PLAN
> -----------------------------------------------------------------------------------------------------------------------------------------
>  Limit  (cost=0.00..105.19 rows=1 width=40) (actual time=6026.947..6026.948
> rows=1 loops=1)
>    ->  Index Scan using cards_pkey on cards  (cost=0.00..2904875.38
> rows=27616 width=40) (actual time=6026.945..6026.945 rows=1 loops=1)
>          Filter: (card_set_id = 2850)
>  Total runtime: 6026.985 ms

do you have autovacum enabled?

does the plan change when you push stats target for this column?
ALTER TABLE cards ALTER card_set_id SET STATISTICS 500;
ANALYZE cards ( card_set_id );

what happens when you do:
select * from ( select * from cards where card_set_id=2850 ) order by
card_id limit 1
?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Filip Rembiałkowski 2011-11-29 19:28:51 Re: initdb failure on Windows 2003
Previous Message Josh Berkus 2011-11-29 18:31:05 Re: [GENERAL] PostgreSQL poster