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 1x2LFm-005iVe-0o for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Sep 2026 04:10:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x2LFl-004BLA-0P for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Sep 2026 04:10:13 +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 1x2LFk-004BL1-2f for pgsql-hackers@lists.postgresql.org; Fri, 04 Sep 2026 04:10:12 +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 1x2LFi-00000002qLY-0yYR for pgsql-hackers@postgresql.org; Fri, 04 Sep 2026 04:10:12 +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 6844A30k1516160; Fri, 4 Sep 2026 00:10:03 -0400 From: Tom Lane To: "=?utf-8?B?Q2hlbmh1aU1v?=" cc: "=?utf-8?B?cGdzcWwtaGFja2Vycw==?=" Subject: Re: [RFC PATCH] Cost-based delayed projection for ORDER BY ... LIMIT In-reply-to: References: Comments: In-reply-to "=?utf-8?B?Q2hlbmh1aU1v?=" message dated "Fri, 04 Sep 2026 11:48:49 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1516158.1788495003.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Sep 2026 00:10:03 -0400 Message-ID: <1516159.1788495003@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "=3D?utf-8?B?Q2hlbmh1aU1v?=3D" writes: > The attached POC therefore also postpones individually cheap expressions= when: > total_expression_cost * (input_rows - limit_tuples) > > > 10 * cpu_operator_cost * limit_tuples > This roughly compares the expression work avoided on discarded rows with= a conservative threshold proportional to the rows that survive the Sort. So ... the problem with proposals like this is that our cost estimates for scalar expressions are pretty nearly useless, rendering planning decisions that are strongly dependent on them mostly junk. See for example the sad fate of commit db0d67db2, eventually reverted at f4c7c410e. (Read the commit message for f4c7c410e and the linked email discussion.) I'm not so worried about cost estimates where expression costs are only part of the total, but this proposal seems completely dependent on expression costs, so I think it's likely to be mostly garbage-in-garbage-out. What can we do to have more confidence in the choice? regards, tom lane