From: Tobias Brox <tobias@nordicbet.com>
To: Tobias Brox <tobias@nordicbet.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: max/min and index usage
Date: Wed, 6 Dec 2006 04:17:13 +0100
Message-ID: <20061206031713.GA26712@oppetid.no> (raw)
[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? :-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tobias@nordicbet.com
Subject: Re: max/min and index usage
In-Reply-To: <20061206031713.GA26712@oppetid.no>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox