Re: [EXTERNAL]Re: BUG #19094: select statement on postgres 17 vs postgres 18 is returning different/duplicate results - Mailing list pgsql-bugs

From Tom Lane
Subject Re: [EXTERNAL]Re: BUG #19094: select statement on postgres 17 vs postgres 18 is returning different/duplicate results
Date
Msg-id 2447089.1761595976@sss.pgh.pa.us
Whole thread Raw
In response to Re: [EXTERNAL]Re: BUG #19094: select statement on postgres 17 vs postgres 18 is returning different/duplicate results  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
I wrote:
> After a good deal of time bisecting, I find the first commit that
> shows the problem is

> Author: Richard Guo <rguo@postgresql.org>
> 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 == JOIN_RIGHT_SEMI &&
                    HeapTupleHeaderHasMatch(HJTUPLE_MINTUPLE(node->hj_CurTuple)))
                    continue;
                ...
                if (joinqual == 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



pgsql-bugs by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore
Next
From: Nathan Bossart
Date:
Subject: Re: BUG #19042: Option --help not recognized at the end of command line in pg_restore