Re: UNION removes almost all rows (not duplicates) - in fresh build of pg17!

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: depesz(at)depesz(dot)com
Cc: pgsql-bugs mailing list <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: UNION removes almost all rows (not duplicates) - in fresh build of pg17!
Date: 2024-05-20 21:54:25
Message-ID: CAApHDvpDQh1NcL7nAsd3YAKj4vgORwesB3GYuNPnEXXRfA2g4w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, 21 May 2024 at 04:00, hubert depesz lubaczewski
<depesz(at)depesz(dot)com> wrote:
> $ explain (analyze) select count(*) from ( select * from pg_class where relkind = 'r' union select * from pg_class where relkind = 'i' );
> QUERY PLAN
> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> Aggregate (cost=42.43..42.44 rows=1 width=8) (actual time=0.108..0.109 rows=1 loops=1)
> -> Unique (cost=0.00..39.53 rows=232 width=236) (actual time=0.013..0.105 rows=1 loops=1)
> -> Append (cost=0.00..39.53 rows=232 width=236) (actual time=0.012..0.099 rows=232 loops=1)
> -> Seq Scan on pg_class (cost=0.00..19.19 rows=68 width=263) (actual time=0.012..0.058 rows=68 loops=1)
> Filter: (relkind = 'r'::"char")
> Rows Removed by Filter: 348
> -> Seq Scan on pg_class pg_class_1 (cost=0.00..19.19 rows=164 width=263) (actual time=0.002..0.030 rows=164 loops=1)
> Filter: (relkind = 'i'::"char")
> Rows Removed by Filter: 252

Thanks for the report.

It looks like it's a very simple fix. The problem is I wasn't setting
groupList when the grouping_is_sortable() returned false. In the
prior version, make_union_unique() always set that.

The attached should apply cleanly up to d2a04470a.

David

Attachment Content-Type Size
fix_union_planning.patch application/octet-stream 1.3 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Haifang Wang (Centific Technologies Inc) 2024-05-20 23:32:55 RE: [EXTERNAL] Re: Windows Application Issues | PostgreSQL | REF # 48475607
Previous Message Thomas Munro 2024-05-20 20:56:51 Re: [EXTERNAL] Re: Windows Application Issues | PostgreSQL | REF # 48475607