Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id A66709FB3BB for ; Tue, 30 Jan 2007 04:59:30 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 81431-09 for ; Tue, 30 Jan 2007 04:59:24 -0400 (AST) X-Greylist: delayed 00:25:39.799682 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id BFD229FB318 for ; Tue, 30 Jan 2007 04:59:26 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail3.plesk.ru (gw-swsoft2.ll-nsk.zsttk.ru [82.200.65.190]) by svr4.postgresql.org (Postfix) with ESMTP id 282DD5AF988 for ; Tue, 30 Jan 2007 08:33:46 +0000 (GMT) Received: by mail3.plesk.ru (Postfix, from userid 426) id 3289A1A9BE3; Tue, 30 Jan 2007 14:33:58 +0600 (NOVT) Received: from [127.0.0.1] (Lobanov.plesk.ru [192.168.62.80]) by mail3.plesk.ru (Postfix) with ESMTP id C81F41A9BAF for ; Tue, 30 Jan 2007 14:33:57 +0600 (NOVT) Message-ID: <45BF02DE.7080605@swsoft.com> Date: Tue, 30 Jan 2007 14:33:34 +0600 From: Igor Lobanov User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Querying distinct values from a large table Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.451 tagged_above=0 required=5 tests=BAYES_50, FORGED_RCVD_HELO, SARE_MILLIONSOF X-Spam-Level: X-Archive-Number: 200701/413 X-Sequence-Number: 23014 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.