Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 6E5379FB381 for ; Tue, 30 Jan 2007 05:13:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 92616-07 for ; Tue, 30 Jan 2007 05:12:58 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 3C2599FA5D8 for ; Tue, 30 Jan 2007 05:12:58 -0400 (AST) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 382AA73A28; Tue, 30 Jan 2007 09:12:52 +0000 (GMT) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id E457D274020; Tue, 30 Jan 2007 09:12:51 +0000 (GMT) Message-ID: <45BF0C13.3070003@archonet.com> Date: Tue, 30 Jan 2007 09:12:51 +0000 From: Richard Huxton User-Agent: IceDove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 To: Igor Lobanov Cc: pgsql-performance@postgresql.org Subject: Re: Querying distinct values from a large table References: <45BF02DE.7080605@swsoft.com> In-Reply-To: <45BF02DE.7080605@swsoft.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/414 X-Sequence-Number: 23015 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