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 1voAF4-00G5pV-1k for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 01:02:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1voAF3-001cSI-1y for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Feb 2026 01:02:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1voAF3-001cS5-10 for pgsql-hackers@lists.postgresql.org; Fri, 06 Feb 2026 01:02:37 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1voAF1-00000000lYY-0OuP for pgsql-hackers@postgresql.org; Fri, 06 Feb 2026 01:02:36 +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 61612VxX1674013; Thu, 5 Feb 2026 20:02:31 -0500 From: Tom Lane To: Andres Freund cc: pgsql-hackers@postgresql.org, David Rowley Subject: Re: Unfortunate pushing down of expressions below sort In-reply-to: <1668738.1770336789@sss.pgh.pa.us> References: <1668738.1770336789@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 05 Feb 2026 19:13:09 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1674011.1770339751.1@sss.pgh.pa.us> Date: Thu, 05 Feb 2026 20:02:31 -0500 Message-ID: <1674012.1770339751@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > Yeah. That's a hangover from an ancient decision that sort/limit > would always be applied at the top of the plan tree. I'm too > lazy to check the details right now, but I think we already relaxed > that in some cases (or maybe it was about evaluating stuff > before/after GROUP BY?). Ah, right: see make_sort_input_target() and its very extensive comment in planner.c. I wonder why that didn't trigger in your example. regards, tom lane