Re: max/min and index usage

Поиск
Список
Период
Сортировка
От Tobias Brox
Тема Re: max/min and index usage
Дата
Msg-id 20061206031713.GA26712@oppetid.no
обсуждение исходный текст
Ответ на max/min and index usage  (Tobias Brox <tobias@nordicbet.com>)
Список pgsql-performance
[Tobias Brox - Wed at 04:01:56AM +0100]
> We're using 8.1 - I thought such a construct was safe in pg 8.1:
>
>  select max(indexed_value) from huge_table;
>
> while earlier we had to use:
>
>  select indexed_value from huge_table order by indexed_value desc limit 1;
>
> seems like I was wrong:

The difference is all about those NULL values ... those columns are quite
sparsely populated in the table.  The second query gives NULL, which is
not much useful :-)

However, I made a partial index to solve this problem - this query is
able to use the partial index:

  select indexed_value from huge_table where indexed_value is not NULL
  order by indexed_value desc limit 1;

while this one is not:

  select max(indexed_value) from huge_table;

I guess this is a bug? :-)

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

Предыдущее
От: Tobias Brox
Дата:
Сообщение: max/min and index usage
Следующее
От: Tom Lane
Дата:
Сообщение: Re: max/min and index usage