Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaSDN-0007Rg-UV for pgsql-performance@arkaria.postgresql.org; Wed, 16 Apr 2014 15:57:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WaSDN-0004FS-E6 for pgsql-performance@arkaria.postgresql.org; Wed, 16 Apr 2014 15:57:33 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaSDM-0004FM-Ii for pgsql-performance@postgresql.org; Wed, 16 Apr 2014 15:57:32 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaSDG-0007A2-12 for pgsql-performance@postgresql.org; Wed, 16 Apr 2014 15:57:31 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 0954528998; Wed, 16 Apr 2014 08:57:24 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id F26BD1A4D6; Wed, 16 Apr 2014 08:57:23 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id 5C19312000A; Wed, 16 Apr 2014 08:57:16 -0700 (PDT) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA; Wed, 16 Apr 2014 08:57:15 -0700 (PDT) Message-ID: <534EA861.3020204@vmware.com> Date: Wed, 16 Apr 2014 18:57:21 +0300 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.4.0 MIME-Version: 1.0 To: Linos , pgsql-performance@postgresql.org Subject: Re: unneeded joins on view References: <534E9E14.5000304@linos.es> In-Reply-To: <534E9E14.5000304@linos.es> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -6.2 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 04/16/2014 06:13 PM, Linos wrote: > I thought that Postgresql would optimize out joins on columns I > don't ask for when I use the view but it doesn't, this query: It doesn't, because it would be wrong. It still has to check that the tables have a matching row (or multiple matching rows). If you use LEFT JOINs instead, and have a unique index on all the ID columns, then the planner can do what you expected and leave out the joins. - Heikki -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance