Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 11DF24770C0 for ; Tue, 28 Jan 2003 12:29:49 -0500 (EST) Received: from smtp.web.de (smtp03.web.de [217.72.192.158]) by postgresql.org (Postfix) with ESMTP id DD21347713C for ; Tue, 28 Jan 2003 11:50:52 -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 18dYwo-00075t-00 for pgsql-performance@postgresql.org; Tue, 28 Jan 2003 17:50:55 +0100 Message-ID: <3E36B4F2.1020506@web.de> Date: Tue, 28 Jan 2003 17:50:58 +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: inefficient query plan with left joined view Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/371 X-Sequence-Number: 1018 What I'm doing on V7.3.1: select t1.keycol, t2.keycol from tab1 t1 LEFT join myview t2 on t1.keycol=t2.keycol where t1.keycol=1000001 t1 has 100 rows, t2 has 4000, both with keycol as PK. the view is created as CREATE myview AS SELECT keycol, 22::integer as calc_col FROM tab2 The query plan will show an ugly subquery scan on all tab2 rows. If the view is created without calculated columns, the query plan looks as expected showing and index scan on tab2 with the correct condition, inner join will always be ok. In real life, the view consists of a lot more tables, and the tables may contain >1,000,000 rows so you may imagine the performance...