From: Bruno Wolff III <bruno@wolff.to>
To: Igor Lobanov <ilobanov@swsoft.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Querying distinct values from a large table
Date: Tue, 30 Jan 2007 10:44:35 -0600
Message-ID: <20070130164435.GA22099@wolff.to> (raw)
In-Reply-To: <45BF02DE.7080605@swsoft.com>
References: <45BF02DE.7080605@swsoft.com>
On Tue, Jan 30, 2007 at 14:33:34 +0600,
Igor Lobanov <ilobanov@swsoft.com> wrote:
> Greetings!
>
> I have rather large table with about 5 millions of rows and a dozen of
> columns. Let's suppose that columns are named 'a', 'b', 'c' etc. I need
> to query distinct pairs of ('a';'b') from this table.
>
> Is there any way to somehow improve the performance of this operation?
> Table can not be changed.
DISTINCT currently can't use a hash aggregate plan and will use a sort.
If there aren't many distinct values, the hash aggregate plan will run much
faster. To get around this limitation, rewrite the query as a group by.
Something like:
SELECT a, b FROM table GROUP BY a, b;
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: bruno@wolff.to, ilobanov@swsoft.com
Subject: Re: Querying distinct values from a large table
In-Reply-To: <20070130164435.GA22099@wolff.to>
* 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