Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJ3Ab-0007ka-Ht for pgsql-hackers@arkaria.postgresql.org; Wed, 16 May 2018 20:37:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fJ3Aa-0004AO-4S for pgsql-hackers@arkaria.postgresql.org; Wed, 16 May 2018 20:37:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJ3AZ-0004AD-QF for pgsql-hackers@lists.postgresql.org; Wed, 16 May 2018 20:37:07 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJ3AW-0002d9-T1 for pgsql-hackers@postgresql.org; Wed, 16 May 2018 20:37:06 +0000 Received: from ip-64-134-177-29.public.wayport.net ([64.134.177.29] helo=[192.168.9.2]) by meldrar.postgresql.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJ3AP-0003eU-DQ; Wed, 16 May 2018 20:37:00 +0000 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: Removing unneeded self joins From: "Jonathan S. Katz" In-Reply-To: <20180516185840.a7crgjho7txxqmi4@alap3.anarazel.de> Date: Wed, 16 May 2018 15:36:51 -0500 Cc: Robert Haas , Tom Lane , Alexander Kuzmenkov , PostgreSQL-development Content-Transfer-Encoding: quoted-printable Message-Id: References: <64486b0b-0404-e39e-322d-0801154901f3@postgrespro.ru> <3295.1526486926@sss.pgh.pa.us> <20180516185840.a7crgjho7txxqmi4@alap3.anarazel.de> To: Andres Freund X-Mailer: Apple Mail (2.3273) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On May 16, 2018, at 1:58 PM, Andres Freund wrote: >=20 > Hi, >=20 > On 2018-05-16 12:26:48 -0400, Robert Haas wrote: >> Also, I'm not sure that I believe that it's always easy to avoid >> generating such queries. >=20 > Yea. There's obviously plenty cases where ORMs just want to make the > database hurt. But especially when building a join between a number of > tables based on various fields, it's not going to be easy for the ORM = to > figure out which ones can be safely omitted. It'd need similar > optimization as we'd have to do, without having the infrastructure = core > PG has. And then there's, as you say, views etc=E2=80=A6 Are there specific examples of what the ORM code is that generated the SQL? I=E2=80=99m more curious to see what people are writing that generates such code. As earlier mentioned we could always report back to the specific ORM maintainer(s) such examples and see if they could tweak. Jonathan=