Re: Unexpected results from a query with UNION ALL

From: Andrii Novikov <adnyre(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Unexpected results from a query with UNION ALL
Date: 2025-01-09 16:49:38
Message-ID: CAOS4yi3eT2M-Wx576xRHEZnvHp9C_PrDP1NdXxmyZGB_sJwnMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks for the update. Actually I was able to rewrite the query to get rid
of the union. But anyway it would be good to have this issue handled
somehow, it's tricky and it was hard to spot and reproduce.

ср, 8 січ. 2025 р. о 19:01 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> пише:

> I wrote:
> > Andrey <adnyre(at)gmail(dot)com> writes:
> >> ... but I would expect to get the same result as previously. Is it a bug
> >> or am I doing something wrong here?
>
> > It's a surprising result for sure, but I believe it's explained by
> > the algorithm for READ COMMITTED [1], specifically the bit about
>
> Actually, on further thought I believe this really is a bug,
> because if you change the UNION ALL to UNION it works fine.
> It probably used to work with UNION ALL too, but that was a few
> decades ago before we started adding optimizations of UNION ALL :-(
>
> I've been poking at this off and on for the last few days, and I've
> found three different things that will need to be changed to make
> it work again. At least one of them looks too invasive to consider
> for back-patch. So don't hold your breath for a proper fix, but
> perhaps you could use UNION as a workaround?
>
> regards, tom lane
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2025-01-09 16:51:53 Re: recovery error while running any statement
Previous Message Ron Johnson 2025-01-09 16:48:52 Re: recovery error while running any statement