X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7546BDB09D for ; Thu, 27 Oct 2005 08:02:15 -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 85198-01 for ; Thu, 27 Oct 2005 11:02:11 +0000 (GMT) Received: from cicero2.cybercity.dk (cicero2.cybercity.dk [212.242.40.53]) by svr1.postgresql.org (Postfix) with ESMTP id 613D2DB082 for ; Thu, 27 Oct 2005 08:02:12 -0300 (ADT) Received: from [192.168.0.79] (0x3e42eeca.adsl.cybercity.dk [62.66.238.202]) by cicero2.cybercity.dk (Postfix) with ESMTP id CCFAC191473 for ; Thu, 27 Oct 2005 13:00:51 +0200 (CEST) Message-ID: <4360B375.8000303@krap.dk> Date: Thu, 27 Oct 2005 13:01:09 +0200 From: Svenne Krap User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Perfomance of views References: <435FA002.4060509@krap.dk> <43609EF4.8060907@archonet.com> In-Reply-To: <43609EF4.8060907@archonet.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 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200510/412 X-Sequence-Number: 15180 What do you mean exactly but "pushing conditions inside" ? I don't think I will have the option of testing on the full queries, as these take many days to write (the current ones, they are replacing on a mssql takes up more that 5kb of query). The current ones are nightmares from a maintaince standpoint. Basicly what the application is doing is selecting some base data from the "large" table for a point in time (usually a quarter) and selects all matching auxilliare data from the other tables. They are made in a time-travel like manner with a first and last useable date. The ways I have considered was : 1) write a big query in hand (not preferred as it gets hard to manage) 2) write layers of views (still not prefered as I still have to remember to put on the right conditions everywhere) 3) write layers of sql-functions (returning the right sets of rows from the underlying tables) - which I prefer from a development angel .. it gets very clean and I cant forget a parameter anywhere. But I seem to remember (and I have used PGSQL in production since 7.0) that the planner has some problems with solution 3 (i.e. estimating the cost and rearranging the query), but frankly that would be the way I would like to go. Based on the current (non-optimal) design and hardware constraints, I still have to make sure, the query runs fairly optimal - that means the planner must use indexes intelligently and other stuff as if it was (well-)written using solution 1. What do you think of the three solutions ? And is there some ressource about the planners capabilites for someone like me (that is very used to write reasonably fast and complex sql, can read c-code, but does not really want to dig into the source code) Regards Svenne Richard Huxton wrote: > Svenne Krap wrote: > >> Hi there. >> >> I am currently building a system, where it would be nice to use >> multiple levels of views upon each other (it is a staticstics system, >> where traceability is important). >> >> Is there any significant performance reduction in say 10 levels of >> views instead of one giant, nested sql-statement ? I especially think >> exection planner-wise. > > > The planner tries to push conditions "inside" views where it can. It's > not perfect though, and if you're writing a big query by hand you > might be able to do better than it. > > In short, I'd test if you can.