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 46F805341A for ; Tue, 29 Mar 2005 14:13:08 +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 40410-03 for ; Tue, 29 Mar 2005 13:13:02 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id E002853409 for ; Tue, 29 Mar 2005 14:13:00 +0100 (BST) Received: (qmail 27953 invoked by uid 500); 29 Mar 2005 13:29:41 -0000 Date: Tue, 29 Mar 2005 07:29:41 -0600 From: Bruno Wolff III To: T E Schmitz Cc: Scott Marlowe , pgsql-sql@postgresql.org Subject: Re: cost of CREATE VIEW ... AS SELECT DISTINCT Message-ID: <20050329132941.GA27251@wolff.to> Mail-Followup-To: T E Schmitz , Scott Marlowe , pgsql-sql@postgresql.org References: <42487A6D.6020506@numerixtechnology.de> <1112047463.22988.25.camel@state.g2switchworks.com> <424928D8.7060705@numerixtechnology.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <424928D8.7060705@numerixtechnology.de> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.011 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/375 X-Sequence-Number: 20854 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.