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 1vDTaY-009qCm-Dm for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Oct 2025 20:13:09 +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 1vDTaX-009Bwt-80 for pgsql-bugs@arkaria.postgresql.org; Mon, 27 Oct 2025 20:13:08 +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 1vDTaW-009Bwl-W8 for pgsql-bugs@lists.postgresql.org; Mon, 27 Oct 2025 20:13:08 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vDTaT-004Zm5-1H for pgsql-bugs@lists.postgresql.org; Mon, 27 Oct 2025 20:13:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 59RKCupE2447090; Mon, 27 Oct 2025 16:12:56 -0400 From: Tom Lane To: Richard Guo cc: Lori Corbani , Thomas Munro , "pgsql-bugs@lists.postgresql.org" Subject: Re: [EXTERNAL]Re: BUG #19094: select statement on postgres 17 vs postgres 18 is returning different/duplicate results In-reply-to: <2441795.1761593103@sss.pgh.pa.us> References: <19094-6ed410eb5b256abd@postgresql.org> <1970841.1761402665@sss.pgh.pa.us> <2441795.1761593103@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 27 Oct 2025 15:25:03 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2447088.1761595976.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 27 Oct 2025 16:12:56 -0400 Message-ID: <2447089.1761595976@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > After a good deal of time bisecting, I find the first commit that > shows the problem is > Author: Richard Guo > Branch: master Release: REL_18_BR [aa86129e1] 2024-07-05 09:26:48 +0900 > Support "Right Semi Join" plan shapes After looking a little closer, we've got: if (node->js.jointype =3D=3D JOIN_RIGHT_SEMI && HeapTupleHeaderHasMatch(HJTUPLE_MINTUPLE(node->hj_CurT= uple))) continue; ... if (joinqual =3D=3D NULL || ExecQual(joinqual, econtext)) { if (!HeapTupleHeaderHasMatch(HJTUPLE_MINTUPLE(node->hj= _CurTuple))) HeapTupleHeaderSetMatch(HJTUPLE_MINTUPLE(node->hj_= CurTuple)); As far as I can see, in a parallel hash join node->hj_CurTuple will be pointing into a shared hash table, so that this code is fooling with a shared HasMatch flag bit with no sort of lock whatsoever. This query doesn't have any joinqual at the PHJ level if I'm reading EXPLAIN correctly, so the window to get it wrong isn't very wide. Nonetheless, if two parallel workers inspect the same inner tuple at about the same time, this code would allow both of them to return it. I'm unsure if we've got any infrastructure that'd allow setting the tuple's match bit in a more atomic fashion. We might have to revert aa86129e1. regards, tom lane