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 50C7253391 for ; Tue, 29 Mar 2005 11:10:49 +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 82185-10 for ; Tue, 29 Mar 2005 10:10:44 +0000 (GMT) Received: from web1-glo.biscit.net (web1-glo.biscit.net [82.195.96.53]) by svr1.postgresql.org (Postfix) with ESMTP id 2D2D95338B for ; Tue, 29 Mar 2005 11:10:43 +0100 (BST) Received: from bolek.coachhouse (host62-6-116-133.webport.bt.net [62.6.116.133]) by web1-glo.biscit.net (8.10.2/8.10.2) with ESMTP id j2TAAVA00491; Tue, 29 Mar 2005 11:10:32 +0100 Received: (Exim 3.36) #1 (Debian)) protocol: esmtp id 1DGDd2-0001tA-00 ; Tue, 29 Mar 2005 11:07:20 +0100 Message-ID: <424928D8.7060705@numerixtechnology.de> Date: Tue, 29 Mar 2005 11:07:20 +0100 From: T E Schmitz Reply-To: mailreg@numerixtechnology.de User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Scott Marlowe Cc: pgsql-sql@postgresql.org Subject: Re: cost of CREATE VIEW ... AS SELECT DISTINCT References: <42487A6D.6020506@numerixtechnology.de> <1112047463.22988.25.camel@state.g2switchworks.com> In-Reply-To: <1112047463.22988.25.camel@state.g2switchworks.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.073 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/371 X-Sequence-Number: 20850 Hello Scott, Scott Marlowe wrote: > On Mon, 2005-03-28 at 15:43, T E Schmitz wrote: > >>How expensive would it be to maintain the following VIEW: >> >>CREATE VIEW origin AS SELECT DISTINCT origin FROM transaktion >> >>if there is in index on transaktion.origin; the table transaktion has >>thousands of records and there are only a few distinct origin? > > > The cost will only be encurred when running the view. if you want > materialized views (which WOULD have maintenance costs) you'll have to Thank you for the pointer - that might come in handy for another scenario. > The cost of executing that view should be the same as the cost of > running the query by hand. I did an EXPLAIN ANALYZE and a sequential scan was carried out despite the index I had on the column. Maybe this is because I only have very few records in my test DB. Would the "SELECT DISTINCT origin" always cause a sequential table scan regardless whether there is an index on the origin column or not? -- Regards/Gruß, Tarlika Elisabeth Schmitz