Re: indexed column not working as fast as expected

Поиск
Список
Период
Сортировка
От Gregory S. Williamson
Тема Re: indexed column not working as fast as expected
Дата
Msg-id 71E37EF6B7DCC1499CEA0316A256832801057E43@loki.wc.globexplorer.net
обсуждение исходный текст
Ответ на indexed column not working as fast as expected  (Amir Zicherman <amir.zicherman@gmail.com>)
Список pgsql-general
Amir,

What gnari said!

The vacuum analyze is absolutely necessary to update the statistics that the query planner uses.

Says chapter 11 of the postgres 7.4.2 manual:
"A major motivation for partial indexes is to avoid indexing common values. Since a query searching for a common value
(onethat accounts for more than a few percent of all the table rows) will not use the index anyway, there is no point
inkeeping those rows in the index at all. This reduces the size of the index, which will speed up queries that do use
theindex. It will also speed up many table update operations because the index does not need to be updated in all
cases."

So this would not help for the other 4 values in this column, but would help queries for this other value.

Greg

-----Original Message-----
From:    gnari [mailto:gnari@simnet.is]
Sent:    Wed 8/18/2004 1:40 AM
To:    Amir Zicherman; pgsql-general@postgresql.org
Cc:
Subject:    Re: [GENERAL] indexed column not working as fast as expected
"Amir Zicherman" <amir.zicherman@gmail.com> wrote:
>
> i have a btree index on col1 in table1.  The column has either values
> 1,2,3, or 4.  4 does not appear that much in the table (only 5 times).
> there are about 20 million rows in the table.  when i do a "select *
> from table1 where col1=4" it takes very long time to get back to me
> (around 4 minutes).  why is it taking so long if i have an index on
> it?  I also tried this with a hash index and it was still slow.

you need to "analyze table1"

possibly a "select * from table1 where col1=4 order by col1 DESC" could
be faster, as this is the highest value, but i am not sure.

if it is known that the value 4 will always appear MUCH less frequently
then the others, you might try
  create index table1_partial on table1(col1) where col1=4;
then the select will definitively be faster for this value.

gnari




---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings




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

Предыдущее
От: "gnari"
Дата:
Сообщение: Re: indexed column not working as fast as expected
Следующее
От: Frank van Vugt
Дата:
Сообщение: manually setting a 'for each statement' to 'deferrable initially deferred' -> any unforeseen side effects?