Re: Possible SSI bug in heap_update

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Possible SSI bug in heap_update
Date: 2021-04-11 22:36:51
Message-ID: CA+hUKG+knqkD_2BAvYBxBKYKaCYDK_eQqCUpT-kUMLCLMCB-GQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Apr 12, 2021 at 4:54 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> While re-reading heap_update() in connection with that PANIC we're
> chasing, my attention was drawn to this comment:
>
> /*
> * Note: beyond this point, use oldtup not otid to refer to old tuple.
> * otid may very well point at newtup->t_self, which we will overwrite
> * with the new tuple's location, so there's great risk of confusion if we
> * use otid anymore.
> */
>
> This seemingly sage advice is being ignored in one place:
>
> CheckForSerializableConflictIn(relation, otid, BufferGetBlockNumber(buffer));
>
> I wonder whether that's a mistake. There'd be only a low probability
> of our detecting it through testing, I fear.

Yeah. Patch attached.

I did a bit of printf debugging, and while it's common that otid ==
&newtup->t_self, neither our regression tests nor our isolation tests
reach a case where ItemPointerEquals(otid, &oldtup.t_self) is false at
the place where that check runs. Obviously those tests don't exercise
all the branches and concurrency scenarios where we goto l2, so I'm
not at all sure about this, but hmm... at first glance, perhaps there
is no live bug here because the use of *otid comes before
RelationPutHeapTuple() which is where newtup->t_self is really
updated?

Attachment Content-Type Size
0001-Fix-SSI-bug-in-heap_update.patch application/x-patch 1.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2021-04-11 22:42:20 Re: Uninitialized scalar variable (UNINIT) (src/backend/statistics/extended_stats.c)
Previous Message Justin Pryzby 2021-04-11 21:23:00 Re: ALTER TABLE .. DETACH PARTITION CONCURRENTLY