BUG #19375: PathTarget expression costs are being double-counted in the planner - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #19375: PathTarget expression costs are being double-counted in the planner
Date
Msg-id 19375-6173afae57e42a62@postgresql.org
Whole thread Raw
List pgsql-bugs
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:

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?





pgsql-bugs by date:

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