Re: Searching for the cause of a bad plan

Поиск
Список
Период
Сортировка
От Csaba Nagy
Тема Re: Searching for the cause of a bad plan
Дата
Msg-id 1190384799.4661.217.camel@PCD12478
обсуждение исходный текст
Ответ на Re: Searching for the cause of a bad plan  (Simon Riggs <simon@2ndquadrant.com>)
Ответы Re: Searching for the cause of a bad plan  (Csaba Nagy <nagy@ecircle-ag.com>)
Re: Searching for the cause of a bad plan  (Simon Riggs <simon@2ndquadrant.com>)
Список pgsql-performance
[snip]

Ok, I was not able to follow your explanation, it's too deep for me into
what the planner does...

> Incidentally, the way out of this is to improve the stats by setting
> stats target = 1000 on column a of ta. That will allow the optimizer to
> have a better estimate of the tail of the distribution of a, which
> should then be more sensibly reflected in the cost of the Index Scan.
> That doesn't solve the actual problem, but should help in your case.

OK, I can confirm that. I set the statistics target for column "a" on
table_a to 1000, analyzed, and got the plan below. The only downside is
that analyze became quite expensive on table_a, it took 15 minutes and
touched half of the pages... I will experiment with lower settings,
maybe it will work with less than 1000 too.

db> explain analyze execute test_001(31855344);

QUERY
PLAN

------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.00..4499.10 rows=10 width=1804) (actual
time=103.566..120.363 rows=2 loops=1)
   ->  Nested Loop  (cost=0.00..344630.97 rows=766 width=1804) (actual
time=103.563..120.359 rows=2 loops=1)
         ->  Index Scan using pk_table_a on table_a ta
(cost=0.00..67097.97 rows=78772 width=16) (actual time=71.965..77.284
rows=2 loops=1)
               Index Cond: (a = $1)
         ->  Index Scan using pk_table_b2 on table_b2 tb
(cost=0.00..3.51 rows=1 width=1788) (actual time=21.526..21.528 rows=1
loops=2)
               Index Cond: (ta.b = tb.b)
 Total runtime: 120.584 ms

Thanks,
Csaba.



В списке pgsql-performance по дате отправления:

Предыдущее
От: "Dave Dutcher"
Дата:
Сообщение: Re: Upgraded from 7.4 to 8.1.4 QUERIES NOW SLOW!!!
Следующее
От: Denes Daniel
Дата:
Сообщение: Query planner unaware of possibly best plan