Skip site navigation (1) Skip section navigation (2)

Querying distinct values from a large table

From: Igor Lobanov <ilobanov(at)swsoft(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Querying distinct values from a large table
Date: 2007-01-30 08:33:34
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance

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.

I use following query:


but unfortunately, it takes forever to complete. Explaining gives me 
information that bottleneck is seqscan on 'tbl', which eats much time.

Creating compound index on this table using following statement:

CREATE INDEX tbl_a_b_idx ON tbl( a, b );

gives no effect, postgres simply ignores it, at least according to the 
EXPLAIN output.

Is there any way to somehow improve the performance of this operation? 
Table can not be changed.

Igor Lobanov
Internal Development Engineer
SWsoft, Inc.


pgsql-performance by date

Next:From: Richard HuxtonDate: 2007-01-30 09:12:51
Subject: Re: Querying distinct values from a large table
Previous:From: Tomas VondraDate: 2007-01-30 07:10:14
Subject: Re: Partitioning

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group