Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVzvA-00DJkF-EF for pgsql-general@arkaria.postgresql.org; Thu, 09 Jan 2025 21:18:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tVzv9-008rhw-4Z for pgsql-general@arkaria.postgresql.org; Thu, 09 Jan 2025 21:18:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVvjH-004Vdp-Hf for pgsql-general@lists.postgresql.org; Thu, 09 Jan 2025 16:49:55 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tVvjE-000lRJ-1D for pgsql-general@postgresql.org; Thu, 09 Jan 2025 16:49:54 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5d3d479b1e6so1433813a12.2 for ; Thu, 09 Jan 2025 08:49:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736441391; x=1737046191; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8/YEsWULwkUCfB8yONmMUZ0TqTz8wDhMIFHkA9LRJeg=; b=HulogafF+Rs5hnGOCbPV6BPU08rsoyCf3Ju/SFjyVE70CJIvdPvMSoBXz8iqAs/bjN HUW/f4T1XQcnrbotRxZH0CkcszFeT5YlVjZV4QeS6evcck2ZSBeXaY65rV8qrGFmxuCx bgE63JxdfzMvPkUP4xhAa5phBySz2IdxiVn+8kfXkI9poLVAq5R3H2AqkI9HxAcd5PWW O9VXjlg+h8KmsWFwHqbJS3WEdI8heU6lHNhFSXlSoOcpQAbT5iq+60IpPEg8af3MHdAc RkARB/3+cBwJRaGPWx0pK+CNlnh2fdgdlSb1k3QEoSkNJOgqx+Pk0OHCXJqz+cFsVwev sXmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736441391; x=1737046191; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8/YEsWULwkUCfB8yONmMUZ0TqTz8wDhMIFHkA9LRJeg=; b=oUmQHiuxoySyDF6cD48yerJ181cbcN0F8E/ncFX+MqD81INVYdhh2QqbvgknsDlCiT zBK6Ep0tfn6iSaxNz4kkr17Q25dBXsc6JLL0mS8Gd5aq4aSDml4za9nNeBzx6WKaXYVX 3A0xbUjsckwbXT42HqToaAKmsjL/9rUZVT4qZz+qGPJhai7SJgCHG4CDPWtvcex2XLh3 76k9VNkH3zk5lAXs5VDVrFzTZIplTmRT3ZuuiBOfz9Cmg5CWgYFYdGiXQ/aVbpw2Re3u C3vXRALqDZIUZAnkt4iUpoSixA3AilQ2C7+LBfFuo7NIs/ccL2q3KEeg99HEjTbAUc89 WNYw== X-Gm-Message-State: AOJu0Yy9wpPJx3GJIjkn+eASAnLt3KALk91rkda4lj1TBGdJtP6Jj3dw WdOJbPpFQHlrdzg7KlzJEMPOSmjch8H+2NIwQVOlbja4RMl2pXFvNKp6WXd+WvVNOkVmJn/vgfe NrKcboPdOHgFor0ttmLNwoXPQBb85xogj X-Gm-Gg: ASbGnctScbGvOYhGaNafhxMuTUfKMyPWSiTYqCyWhgNPCrnN6UD+Psrm2UrzXHjMuDc 3u32anf3ihKUsdJO1fWf9Z2H0NjvYmYnRQKeYT/s= X-Google-Smtp-Source: AGHT+IGpTHVjMMHPc8NmLeqgQwILydgsQZc7yJDFBHrDRJZ66YdWHIaWYXd71ieqkL0/ZxcUYkopl6zTwjbw2+YQvv4= X-Received: by 2002:a05:6402:5251:b0:5d0:bf5e:eb8 with SMTP id 4fb4d7f45d1cf-5d972e63ddfmr15220478a12.23.1736441390885; Thu, 09 Jan 2025 08:49:50 -0800 (PST) MIME-Version: 1.0 References: <638683.1736015099@sss.pgh.pa.us> <1665866.1736355696@sss.pgh.pa.us> In-Reply-To: <1665866.1736355696@sss.pgh.pa.us> From: Andrii Novikov Date: Thu, 9 Jan 2025 18:49:38 +0200 X-Gm-Features: AbW1kvbg3IavWgCcXKvDrBDnk5XrtyxJNmij7STlbotH7mcRZCKqQEJ47H0zIJ0 Message-ID: Subject: Re: Unexpected results from a query with UNION ALL To: Tom Lane Cc: pgsql-general@postgresql.org Content-Type: multipart/alternative; boundary="00000000000046f31f062b48c46b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000046f31f062b48c46b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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. =D1=81=D1=80, 8 =D1=81=D1=96=D1=87. 2025=E2=80=AF=D1=80. =D0=BE 19:01 Tom L= ane =D0=BF=D0=B8=D1=88=D0=B5: > I wrote: > > Andrey writes: > >> ... but I would expect to get the same result as previously. Is it a b= ug > >> 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 > --00000000000046f31f062b48c46b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 iss= ue handled somehow, it's tricky and it was hard to spot and reproduce.<= /div>
=D1=81=D1=80, 8 =D1=81=D1=96=D1=87. 2025=E2=80=AF=D1= =80. =D0=BE 19:01 Tom Lane <tgl@sss= .pgh.pa.us> =D0=BF=D0=B8=D1=88=D0=B5:
I wrote:
> Andrey <adnyr= e@gmail.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 explaine= d 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.=C2=A0 At least one of them looks too invasive to consider for back-patch.=C2=A0 So don't hold your breath for a proper fix, but perhaps you could use UNION as a workaround?

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane
--00000000000046f31f062b48c46b--