X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 17E5B5282E for ; Tue, 21 Jun 2005 11:50:37 -0300 (ADT) 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 20273-06 for ; Tue, 21 Jun 2005 14:50:28 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 8C4AB52812 for ; Tue, 21 Jun 2005 11:50:23 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id B42F740C18C; Tue, 21 Jun 2005 15:50:16 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id D577715EDB; Tue, 21 Jun 2005 15:48:42 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 00843-06; Tue, 21 Jun 2005 15:48:40 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 16FDC15ED6; Tue, 21 Jun 2005 15:48:40 +0100 (BST) Message-ID: <42B828C7.8040402@archonet.com> Date: Tue, 21 Jun 2005 15:48:39 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Amit V Shah Cc: "'pgsql-performance@postgresql.org'" Subject: Re: Do Views execute underlying query everytime ?? References: <0C072E7CC947D511AC9600A0CC7341200256CF51@vpn.tagaudit.com> In-Reply-To: <0C072E7CC947D511AC9600A0CC7341200256CF51@vpn.tagaudit.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.056 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200506/382 X-Sequence-Number: 13019 Amit V Shah wrote: > Hi all, > > I have like a repository table with is very very huge with atleast a few > hundreds of millions, may be over that. The information is stored in form of > rows in these tables. I need to make that information wide based on some > grouping and display them as columns on the screen. > > I am thinking of having a solution where I create views for each screen, > which are just read only. > > However, I donot know if the query that creates the view is executed > everytime I select something from the view. Because if that is the case, > then I think my queries will again be slow. But if that is the way views > work, then what would be the point in creating them .. That's exactly how they work. You'd still want them because they let you simplify access control (user A can only see some rows, user B can see all rows) or just make your queries simpler. Sounds like you want what is known as a "materialised view" which is basically a summary table that is kept up to date by triggers. You query the table instead of actually recalculating every time. Perhaps google for "postgresql materialized view" (you might want a "z" or "s" in materialised). -- Richard Huxton Archonet Ltd