Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaSO9-0007q4-Jm for pgsql-performance@arkaria.postgresql.org; Wed, 16 Apr 2014 16:08:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WaSO9-0002We-30 for pgsql-performance@arkaria.postgresql.org; Wed, 16 Apr 2014 16:08:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaSO8-0002WW-8e for pgsql-performance@postgresql.org; Wed, 16 Apr 2014 16:08:40 +0000 Received: from ns3099999.ip-37-59-8.eu ([37.59.8.46] helo=mail.linos.es) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaSO6-0006qe-4E for pgsql-performance@postgresql.org; Wed, 16 Apr 2014 16:08:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.linos.es (Postfix) with ESMTP id 764A86080972; Wed, 16 Apr 2014 18:08:36 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at ns3099999.ip-37-59-8.eu Received: from mail.linos.es ([37.59.8.46]) by localhost (ns3099999.ip-37-59-8.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bQXo8Jrk-c84; Wed, 16 Apr 2014 18:08:34 +0200 (CEST) Received: from [192.168.254.4] (9.Red-83-61-242.dynamicIP.rima-tde.net [83.61.242.9]) (using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: info@linos.es) by mail.linos.es (Postfix) with ESMTPSA id 1CF6A6080226; Wed, 16 Apr 2014 18:08:34 +0200 (CEST) Message-ID: <534EAB01.80405@linos.es> Date: Wed, 16 Apr 2014 18:08:33 +0200 From: Linos User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Heikki Linnakangas , pgsql-performance@postgresql.org Subject: Re: unneeded joins on view References: <534E9E14.5000304@linos.es> <534EA861.3020204@vmware.com> In-Reply-To: <534EA861.3020204@vmware.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) 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 16/04/14 17:57, Heikki Linnakangas wrote: > 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 > > You are right, I knew I was forgetting something important but I didn't know what was, thank you Heikki. Regards, Miguel Angel. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance