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.94.2) (envelope-from ) id 1udJJM-005q4x-N4 for pgsql-performance@arkaria.postgresql.org; Sun, 20 Jul 2025 01:57:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1udJJJ-00959z-QB for pgsql-performance@arkaria.postgresql.org; Sun, 20 Jul 2025 01:57:53 +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.94.2) (envelope-from ) id 1udJJJ-00959q-Fc for pgsql-performance@lists.postgresql.org; Sun, 20 Jul 2025 01:57:53 +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.96) (envelope-from ) id 1udJJH-008Czb-1k for pgsql-performance@postgresql.org; Sun, 20 Jul 2025 01:57:52 +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 56K1voA0159698; Sat, 19 Jul 2025 21:57:50 -0400 From: Tom Lane To: "=?utf-8?B?WHVhbiBDaGVu?=" cc: "=?utf-8?B?cGdzcWwtcGVyZm9ybWFuY2U=?=" Subject: Re: Question: Is it valid for a parent node's total cost to be lower than a child's total cost in EXPLAIN? In-reply-to: References: Comments: In-reply-to "=?utf-8?B?WHVhbiBDaGVu?=" message dated "Sat, 19 Jul 2025 19:03:14 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <159696.1752976670.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 19 Jul 2025 21:57:50 -0400 Message-ID: <159697.1752976670@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "=3D?utf-8?B?WHVhbiBDaGVu?=3D" writes: > In some cases, I noticed that a parent path node's total cost is less th= an that of one of its child path nodes. I initially expected that the tota= l cost of a node should be at least as large as the sum of its child nodes= =E2=80=99 total costs, or at least not smaller than any single child. That is true if we expect the parent node to run its child node(s) to completion, but there are cases where we don't. An obvious example is a Limit node. In the case at hand, the planner is betting that the Merge will not need to run one side to completion because the other side's largest join key value is less than the first side's largest value. The merge can stop as soon as either input is exhausted. regards, tom lane