pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wei Sun <936739278@qq.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Subject: 回复: The issue of incorrect width estimation in UNION queries
Date: Wed, 24 Sep 2025 19:27:11 +0800
Message-ID: <tencent_6CF0214B232C068DD8FF3F735E6606F92A08@qq.com> (raw)
In-Reply-To: <CAApHDvofBH=aS5ZLz-Qcx0Tt9f2GH1xGLu8hdUYO69F3sY+37w@mail.gmail.com>
References: <tencent_34CF8017AB81944A4C08DD089D410AB6C306@qq.com>
	<CAApHDvofBH=aS5ZLz-Qcx0Tt9f2GH1xGLu8hdUYO69F3sY+37w@mail.gmail.com>

ok



Thank you for the reply,currently, we can also temporarily work around this issue by adding a hint,&nbsp;
look forward to the fix in the master branch.


Regards

Wei Sun


------------------&nbsp;原始邮件&nbsp;------------------
发件人:                                                                                                                        "David Rowley"                                                                                    <dgrowleyml@gmail.com&gt;;
发送时间:&nbsp;2025年9月24日(星期三) 晚上6:47
收件人:&nbsp;"Wei Sun"<936739278@qq.com&gt;;
抄送:&nbsp;"pgsql-bugs"<pgsql-bugs@lists.postgresql.org&gt;;
主题:&nbsp;Re: The issue of incorrect width estimation in UNION queries



On Wed, 24 Sept 2025 at 18:13, sunw.fnst <936739278@qq.com&gt; wrote:
&gt;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Append&nbsp; (cost=0.00..4082.00 rows=200000 width=38) (actual time=0.016..39.050 rows=200000 loops=1)
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Seq Scan on t1&nbsp; (cost=0.00..1541.00 rows=100000 width=11) (actual time=0.015..10.056 rows=100000 loo
&gt; ps=1)
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;&nbsp; Seq Scan on t2&nbsp; (cost=0.00..1541.00 rows=100000 width=11) (actual time=0.018..10.654 rows=100000 loo
&gt; ps=1)

This happens because in generate_union_paths() -&gt; create_pathtarget()
-&gt; set_pathtarget_cost_width() in get_expr_width(), the varno for the
union's RelOptInfo is 0, which results in using the get_typavgwidth()
result.

set_append_rel_size() does a better job of this for the UNION ALL code
path. Maybe we can copy the relevant parts of that.

Also, I think if we're doing this, then it'd be a master-only fix.
Changing this could result in plan changes in the back-branches, which
we normally try to avoid.&nbsp; The attached patch is against master. I
need to spend a bit longer on this as generate_nonunion_paths() might
need the same treatment. I've just run out of time for tonight.

David

Message-ID: <tencent_6CF0214B232C068DD8FF3F735E6606F92A08@qq.com>
Permalink:  ../tencent_6CF0214B232C068DD8FF3F735E6606F92A08@qq.com/
Also on:    postgresql.org/message-id/tencent_6CF0214B232C068DD8FF3F735E6606F92A08@qq.com

 · 

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: 936739278@qq.com, dgrowleyml@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: =?gb18030?B?u9i4tKO6IFRoZSBpc3N1ZSBvZiBpbmNvcnJlY3Qg?= =?gb18030?B?d2lkdGggZXN0aW1hdGlvbiBpbiBVTklPTiBxdWVy?= =?gb18030?B?aWVz?=
  In-Reply-To: <tencent_6CF0214B232C068DD8FF3F735E6606F92A08@qq.com>

* 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