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

Re: Querying distinct values from a large table

From: Richard Huxton <dev(at)archonet(dot)com>
To: Igor Lobanov <ilobanov(at)swsoft(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Querying distinct values from a large table
Date: 2007-01-30 09:12:51
Message-ID: 45BF0C13.3070003@archonet.com (view raw or flat)
Thread:
Lists: pgsql-performance
Igor Lobanov 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.

> 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.

What version of PostgreSQL is it?

How many distinct values are you getting back from your 5 million rows? 
If there are too many, an index isn't going to help.

Can you share the EXPLAIN ANALYSE output? You might want to try 
increasing work_mem for this one query to speed any sorting.

How often is the table updated? Clustering might buy you some 
improvements (but not a huge amount I suspect).


   Richard Huxton
   Archonet Ltd

In response to

Responses

pgsql-performance by date

Next:From: Igor LobanovDate: 2007-01-30 09:33:11
Subject: Re: Querying distinct values from a large table
Previous:From: Igor LobanovDate: 2007-01-30 08:33:34
Subject: Querying distinct values from a large table

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