Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wxaL3-002r4I-1G for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Aug 2026 01:16:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wxaL2-00FU2u-1H for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Aug 2026 01:16:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wxaL2-00FU2l-0K for pgsql-hackers@lists.postgresql.org; Sat, 22 Aug 2026 01:16:00 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wxaKy-00000000axu-0BHl for pgsql-hackers@lists.postgresql.org; Sat, 22 Aug 2026 01:15:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 67M1FqSN4122161; Fri, 21 Aug 2026 21:15:52 -0400 From: Tom Lane To: Richard Guo cc: Pg Hackers Subject: Re: Wrong results from join removal with DISTINCT ON + SRF subquery In-reply-to: References: Comments: In-reply-to Richard Guo message dated "Sat, 22 Aug 2026 10:06:33 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4122159.1787361352.1@sss.pgh.pa.us> Date: Fri, 21 Aug 2026 21:15:52 -0400 Message-ID: <4122160.1787361352@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > Attached is a patch to not rely on DISTINCT ON for distinctness if > there are any tlist SRFs. This is more conservative than necessary, > since the SRFs are only postponed when there is an ORDER BY and none > of them is in a sort/group column, but I don't think it's worth > duplicating that logic in analyzejoins.c. I didn't study the patch in any detail, but I concur with your thinking here. SRFs in the tlist are kind of a legacy usage in the first place, so I don't feel a need to expend lots of effort on optimizing cases like this. regards, tom lane