Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 46245476241 for ; Tue, 19 Nov 2002 14:47:42 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 319C3476171 for ; Tue, 19 Nov 2002 14:47:41 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id gAJJlfhR022626; Tue, 19 Nov 2002 14:47:41 -0500 (EST) To: cgg007@yahoo.com Cc: pgsql-sql@postgresql.org Subject: Re: Using VIEW to simplify code... In-reply-to: <20021119182940.91495.qmail@web13802.mail.yahoo.com> References: <20021119182940.91495.qmail@web13802.mail.yahoo.com> Comments: In-reply-to Chris Gamache message dated "Tue, 19 Nov 2002 10:29:40 -0800" Date: Tue, 19 Nov 2002 14:47:41 -0500 Message-ID: <22625.1037735261@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/285 X-Sequence-Number: 10427 Chris Gamache writes: > Right now I dynamicly generate the SQL for an incredibly ugly 4 table join > based on user information client-side. I got the bright idea to create a view > and then run a MUUUCH simpler client-side query on that view. The problem is > that PostgreSQL apparantly runs the view FIRST and then applies the criteria > AFTER assembling the whole view. Not necessarily; it starts with that (which after all is what you wrote) and tries to transform it into something more efficient. But it's not as smart as a person ;-). > If you MUST have the giant-and-hard-to-maintain-client-generated-sql > statement and its related explain, I'll produce it. If you want help, you must provide details. The PG version number is relevant also. regards, tom lane