Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A27A647933F for ; Tue, 28 Jan 2003 15:29:45 -0500 (EST) Received: from smtp.web.de (smtp02.web.de [217.72.192.151]) by postgresql.org (Postfix) with ESMTP id 8D35F476AD8 for ; Tue, 28 Jan 2003 14:31:48 -0500 (EST) Received: from p50818051.dip0.t-ipconnect.de ([80.129.128.81] helo=web.de) by smtp.web.de with asmtp (WEB.DE(Exim) 4.93 #1) id 18dbSV-0002QB-00 for pgsql-performance@postgresql.org; Tue, 28 Jan 2003 20:31:47 +0100 Message-ID: <3E36DAA2.4010003@web.de> Date: Tue, 28 Jan 2003 20:31:46 +0100 From: Andreas Pflug User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3a) Gecko/20021212 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: inefficient query plan with left joined view References: <3E36B4F2.1020506@web.de> <22633.1043778607@sss.pgh.pa.us> In-Reply-To: <22633.1043778607@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/373 X-Sequence-Number: 1020 Tom Lane wrote: >The subquery isn't pulled up because it doesn't pass the >has_nullable_targetlist test in src/backend/optimizer/plan/planner.c. >If we did flatten it, then references to calc_col wouldn't correctly >go to NULL when the LEFT JOIN should make them do so --- they'd be >22 all the time. > >As the notes in that routine say, it could be made smarter: strict >functions of nullable variables could be allowed. So if your real >concern is not '22' but something like 'othercol + 22' then this is >fixable. > > regards, tom lane > > > Tom, actually my views do use calculated columns (mostly concated strings, e.g. full name from title/1st/last name). As the example shows even columns that are never used will be taken into account when checking has_nullable_targetlist. Unfortunately I have a lot of views containing views which containing.... delivering a lot more columns than needed. But they are checked anyway... I'd expect the parser to look at the join construction only to find out about available data. Why should the selected (and even unselected) columns be evaluated if the join delivers no result? Maybe this can be achieved by checking only JOIN ON/WHERE columns with has_nullable_targetlist? Regards, Andreas