X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 89A989FA040 for ; Thu, 1 Jun 2006 11:53:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 11129-08 for ; Thu, 1 Jun 2006 11:53:29 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from alvh.no-ip.org (201-221-200-231.bk11-dsl.surnet.cl [201.221.200.231]) by postgresql.org (Postfix) with ESMTP id AAC9C9FA5DC for ; Thu, 1 Jun 2006 11:53:29 -0300 (ADT) Received: by alvh.no-ip.org (Postfix, from userid 1000) id 0D8F9C3A214; Thu, 1 Jun 2006 10:53:28 -0400 (CLT) Date: Thu, 1 Jun 2006 10:53:28 -0400 From: Alvaro Herrera To: Miroslav ?ulc Cc: pgsql-sql@postgresql.org Subject: Re: SELECT DISTINCT too slow Message-ID: <20060601145327.GA19388@surnet.cl> Mail-Followup-To: Miroslav ?ulc , pgsql-sql@postgresql.org References: <447EEAF1.7040305@startnet.cz> <20060601135310.GB18513@surnet.cl> <447EFE92.2070509@startnet.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <447EFE92.2070509@startnet.cz> User-Agent: Mutt/1.5.11+cvs20060403 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.127 tagged_above=0 required=5 tests=AWL, BAYES_00, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, FORGED_RCVD_HELO, RCVD_IN_SORBS_DUL X-Spam-Level: X-Archive-Number: 200606/6 X-Sequence-Number: 25242 Miroslav ?ulc wrote: > Well, "key" is not primary key from another table. It is just a column > in pair "key" => "value". > The structure of the table is this: > > Id (primary key) > MRTPContactId (id of contact from table MRTPContact) > Key (key from pair key => value) > Value (value from pair key => value) > > So I want the get the list of keys used in the table. The plan you get is the most efficient possible for that query. If you had a table of possible keys (which should of course be FK of "Key"), you could get a much faster version :-) -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.