Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pK75n-0004jN-Ml for pgsql-committers@arkaria.postgresql.org; Tue, 24 Jan 2023 00:23:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pK75m-0008Ga-C6 for pgsql-committers@arkaria.postgresql.org; Tue, 24 Jan 2023 00:23:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pK75m-0008GP-3W for pgsql-committers@lists.postgresql.org; Tue, 24 Jan 2023 00:23:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pK75h-0007wi-Mc for pgsql-committers@lists.postgresql.org; Tue, 24 Jan 2023 00:23:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 30O0N8V42149154; Mon, 23 Jan 2023 19:23:08 -0500 From: Tom Lane To: David Rowley cc: pgsql-committers@lists.postgresql.org, Richard Guo Subject: Re: pgsql: Fix LATERAL join test in test memoize.sql In-reply-to: References: <2144818.1674517061@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Tue, 24 Jan 2023 13:08:01 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2149152.1674519788.1@sss.pgh.pa.us> Date: Mon, 23 Jan 2023 19:23:08 -0500 Message-ID: <2149153.1674519788@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > You're right that OFFSET 0 would have been a better choice. I just > wasn't aware that we were considering changing the code so we pull up > subqueries with an ORDER BY. No such plan is in the offing AFAIK, but it doesn't seem entirely out of the question either. > In fact, I thought there were several > good reasons we're not doing that. e.g. allow aggregation in outer > query by some order specified by the subquery. But perhaps any changes > we make in this area would be more conditional than just ignoring the > fact that the subquery has an ORDER BY. Yeah, we've historically honored subquery ORDER BY and I doubt we'd want to stop. But I'm not sure that that that completely precludes subquery flattening, especially for single-relation subqueries such as these. You could imagine, for example, still doing the pull-up and then only accepting paths for the rel that satisfy the ORDER BY. This could still lead to better optimization of the outer query than what happens now, I think. Anyway, it's not something I expect to happen soon, but maybe someday. regards, tom lane