pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Igor Lobanov <ilobanov@swsoft.com>
To: pgsql-performance@postgresql.org
Subject: Querying distinct values from a large table
Date: Tue, 30 Jan 2007 14:33:34 +0600
Message-ID: <45BF02DE.7080605@swsoft.com> (raw)

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.

I use following query:

SELECT DISTINCT a, b FROM tbl;

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.




view thread (26+ messages)  latest in thread

Message-ID: <45BF02DE.7080605@swsoft.com>
Permalink:  ../45BF02DE.7080605@swsoft.com/
Also on:    postgresql.org/message-id/45BF02DE.7080605@swsoft.com

 · 

reply

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: ilobanov@swsoft.com
  Subject: Re: Querying distinct values from a large table
  In-Reply-To: <45BF02DE.7080605@swsoft.com>

* 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