Problem with planner

Поиск
Список
Период
Сортировка
От hubert depesz lubaczewski
Тема Problem with planner
Дата
Msg-id 20110808155318.GA22870@depesz.com
обсуждение исходный текст
Ответы Re: Problem with planner  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Problem with planner  (pasman pasmański <pasman.p@gmail.com>)
Re: Problem with planner  (Cédric Villemain <cedric.villemain.debian@gmail.com>)
Список pgsql-general
Hi,
we have 8.3.11 installation on client site, with table, which looks like
this:

$ \d objects
                                              Table "public.objects"
         Column          |           Type           |                           Modifiers
-------------------------+--------------------------+---------------------------------------------------------------
...
 state                   | text                     |
...
 ending_tsz              | timestamp with time zone | default (now() + '4 mons'::interval)
...
Indexes:
    "objects_stat_user_id_creation_tsz" btree (state, user_id, creation_tsz)
    "objects_ending_tsz_active" btree (ending_tsz) WHERE state = 'active'::text
    "objects_ending_tsz_idx" btree (ending_tsz)
...


and we have a query:
select count(*) from objects where state='active'::text and ending_tsz <= ( select now() - '1 day'::interval );

Normally this query has been getting plan, using
objects_ending_tsz_active, which is sane and fast.

But today, without any sensible reason, it switched to:

                                                       QUERY PLAN
 

-------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=6719810.62..6719810.63 rows=1 width=0)
   InitPlan
     ->  Result  (cost=0.00..0.01 rows=1 width=0)
   ->  Bitmap Heap Scan on objects  (cost=1289719.58..6711422.56 rows=3355219 width=0)
         Recheck Cond: ((state = 'active'::text) AND (ending_tsz <= $0))
         ->  BitmapAnd  (cost=1289719.58..1289719.58 rows=3355219 width=0)
               ->  Bitmap Index Scan on objects_stat_user_id_creation_tsz  (cost=0.00..334318.95 rows=10065657 width=0)
                     Index Cond: (state = 'active'::text)
               ->  Bitmap Index Scan on objects_ending_tsz_idx  (cost=0.00..953722.77 rows=24986738 width=0)
                     Index Cond: (ending_tsz <= $0)
(10 rows)

running analyze objects 2 times in a row fixed the issue, but hour later
- the problem came back.

what can be wrong?

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
                                                             http://depesz.com/

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

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: Query with rightmost function does not use index
Следующее
От: sameera vhora
Дата:
Сообщение: JDBC driver throwing error while connecting to the slave server for partitioned table