pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: yaojia_0809@163.com
Subject: BUG #19375: PathTarget expression costs are being double-counted in the planner
Date: Mon, 12 Jan 2026 12:16:37 +0000
Message-ID: <19375-6173afae57e42a62@postgresql.org> (raw)

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?







Message-ID: <19375-6173afae57e42a62@postgresql.org>
Permalink:  ../19375-6173afae57e42a62@postgresql.org/
Also on:    postgresql.org/message-id/19375-6173afae57e42a62@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, yaojia_0809@163.com
  Subject: Re: BUG #19375: PathTarget expression costs are being double-counted in the planner
  In-Reply-To: <19375-6173afae57e42a62@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox