BUG #19375: PathTarget expression costs are being double-counted in the planner

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: yaojia_0809(at)163(dot)com
Subject: BUG #19375: PathTarget expression costs are being double-counted in the planner
Date: 2026-01-12 12:16:37
Message-ID: 19375-6173afae57e42a62@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19375
Logged by: yao jia
Email address: yaojia_0809(at)163(dot)com
PostgreSQL version: 18.0
Operating system: linux centos
Description:

explain verbose select (id+id) as idd from few group by idd;
QUERY PLAN
----------------------------------------------------------------
HashAggregate (cost=1.05..1.08 rows=3 width=4)
Output: ((id + id))
Group Key: (few.id + few.id)
-> Seq Scan on public.few (cost=0.00..1.04 rows=3 width=4)
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?

Browse pgsql-bugs by date

  From Date Subject
Next Message 开心小市民 2026-01-12 16:25:16 Inconsistent handling of signed zero (-0) between INNER JOIN and INTERSECT ALL
Previous Message Masahiko Sawada 2026-01-10 00:56:32 Re: BUG #19360: Bug Report: Logical Replication initial sync fails with "conflict=update_origin_differs" PG12 toPG18