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 1vfJhF-000vIp-1l for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Jan 2026 15:19:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vfJhE-000oek-2V for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Jan 2026 15:19:09 +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 1vfGr8-000Q4k-2O for pgsql-bugs@lists.postgresql.org; Mon, 12 Jan 2026 12:17:11 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vfGr4-0001id-1c for pgsql-bugs@lists.postgresql.org; Mon, 12 Jan 2026 12:17:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=W9Dicloaj+O4k4RzJYrZe9AMr7lFPmBlplHVFq4+yX4=; b=Sc7Yaf6a9Wpw+chdTlmjNUIrGu jaSMw5sfaf0SYceQ8TfijU8rVmziKYPB3P7EcHdFK5WHty6AboooLWl+1ujALLAMPBWguRa8/G35V 4rz4/Dej7kqn7nXR+Gmg33V7TfLsXYo7rSV4ferEkFXHmqTfzox1xvaH2noPDHSPmNlRoSM1Ej5pK OZ8G+OyXGNBdknyds0hp8ceiDg1/W3wuJJEwg8134fYX0jEMg2rRzfu/Pt2NA8SeSqL2tUhM6qEWn qmR/FUMykPeVSBOnBt+E7fWdbJTPeG6crpo5CfndM+AQnsmYIWDjWX1nULoy71VkmBl70KC/SFLBi XYgqn6lA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vfGr1-000DeG-03 for pgsql-bugs@lists.postgresql.org; Mon, 12 Jan 2026 12:17:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vfGr0-0007zz-14 for pgsql-bugs@lists.postgresql.org; Mon, 12 Jan 2026 12:17:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19375: PathTarget expression costs are being double-counted in the planner To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: yaojia_0809@163.com Reply-To: yaojia_0809@163.com, pgsql-bugs@lists.postgresql.org Date: Mon, 12 Jan 2026 12:16:37 +0000 Message-ID: <19375-6173afae57e42a62@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19375 Logged by: yao jia Email address: yaojia_0809@163.com PostgreSQL version: 18.0 Operating system: linux centos Description: =20 explain verbose select (id+id) as idd from few group by idd; QUERY PLAN ---------------------------------------------------------------- HashAggregate (cost=3D1.05..1.08 rows=3D3 width=3D4) Output: ((id + id)) Group Key: (few.id + few.id) -> Seq Scan on public.few (cost=3D0.00..1.04 rows=3D3 width=3D4) Output: (id + id) In function grouping_planner, apply_scanjoin_target_to_paths will replace current_rel->reltarget->exprs(T_Var) with scanjoin_target->exprs(T_OpExpr), and add costs of operatpr "+" to seqscan, but create_grouping_paths will also add costs of operatpr "+" to sortgroupagg path and hashagg path because grouping_target->exprs is T_OpExpr. Actually, seqscan or indexscan has already computed the costs of operator "+", sortgroupagg and hashagg have contained the costs, there is no need to add the costs of expression again. Maybe it will choose the different best path because we add the costs of expression again to xxx_agg path? Maybe we should know the expression's costs have been computed at lower path node like seqscan, and don't add pathtarget's duplicate expression costs at higher path node like hashagg. Do you think it is a bug? And will you fix it if it does?