Re: max/min and index usage - Mailing list pgsql-performance

From Tobias Brox
Subject Re: max/min and index usage
Date
Msg-id 20061206031713.GA26712@oppetid.no
Whole thread Raw
In response to max/min and index usage  (Tobias Brox <tobias@nordicbet.com>)
List 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 by date:

Previous
From: Tobias Brox
Date:
Subject: max/min and index usage
Next
From: Tom Lane
Date:
Subject: Re: max/min and index usage