X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8EDB45294E for ; Tue, 29 Mar 2005 14:58:54 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53440-03 for ; Tue, 29 Mar 2005 13:58:47 +0000 (GMT) Received: from sunsite.dcc.uchile.cl (sunsite.dcc.uchile.cl [192.80.24.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9A7AD53AD6 for ; Tue, 29 Mar 2005 14:58:45 +0100 (BST) Received: from anakena.dcc.uchile.cl (anakena [192.80.24.6]) by sunsite.dcc.uchile.cl (8.12.11/8.12.11) with ESMTP id j2TDwNcE024870; Tue, 29 Mar 2005 09:58:28 -0400 (CLT) Received: by anakena.dcc.uchile.cl (Postfix, from userid 4151) id AFD2052715; Tue, 29 Mar 2005 09:58:23 -0400 (CLT) Date: Tue, 29 Mar 2005 09:58:23 -0400 From: Alvaro Herrera To: T E Schmitz Cc: Bruno Wolff III , Scott Marlowe , pgsql-sql@postgresql.org Subject: Re: cost of CREATE VIEW ... AS SELECT DISTINCT Message-ID: <20050329135823.GA23852@dcc.uchile.cl> References: <42487A6D.6020506@numerixtechnology.de> <1112047463.22988.25.camel@state.g2switchworks.com> <424928D8.7060705@numerixtechnology.de> <20050329132941.GA27251@wolff.to> <4249564B.1000807@numerixtechnology.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4249564B.1000807@numerixtechnology.de> User-Agent: Mutt/1.5.8i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.345 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE X-Spam-Level: X-Archive-Number: 200503/377 X-Sequence-Number: 20856 On Tue, Mar 29, 2005 at 02:21:15PM +0100, T E Schmitz wrote: > Bruno Wolff III wrote: > >On Tue, Mar 29, 2005 at 11:07:20 +0100, > > T E Schmitz wrote: > > > >>Would the "SELECT DISTINCT origin" always cause a sequential table > >>scan regardless whether there is an index on the origin column or > >>not? > > > >It's worse than that, SELECT DISTINCT cannot use a hash aggregate > >plan and will need to do a sort to eliminate duplicates. Unless the > >view is used in a way that restricts the candidate rows, this > >probably isn't going to be very fast. You might be better off > >changing the view to use GROUP BY instead of DISTINCT. > > As far as I can see (via EXPLAIN), both DISTINCT and GROUP BY will > lead to a sequentail scan. Is that correct? That (GROUP BY using a seqscan) may be caused by the small size of the table. Try populating it some more. -- Alvaro Herrera () "¿Qué importan los años? Lo que realmente importa es comprobar que a fin de cuentas la mejor edad de la vida es estar vivo" (Mafalda)