From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Alexander Lakhin <exclusion(at)gmail(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)lists(dot)postgresql(dot)org, Richard Guo <guofenglinux(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Peter Geoghegan <pg(at)bowt(dot)ie> |
Subject: | Re: BUG #17798: Incorrect memory access occurs when using BEFORE ROW UPDATE trigger |
Date: | 2024-01-05 21:18:15 |
Message-ID: | CA+TgmoZz1fGaTnOSf1yQhwYovEEkJZ9iioQXnLgaJz+1fBip=g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Sun, Jul 9, 2023 at 11:00 AM Alexander Lakhin <exclusion(at)gmail(dot)com> wrote:
> I've found enough time this week to investigate the issue deeper and now
> I can answer your questions, hopefully.
This patch lacks a commit message, which I think would be a good thing
to add. Even if somebody doesn't use the message you write, it would
help with understanding the patch itself. Deleting the call to
ExecMaterializeSlot with no explanation in the patch file of why
that's OK to do is not ideal. But the real heart of this small patch
seems to be this:
+ /*
+ * We need to materialize newslot because 1) it might
share oldslot's,
+ * buffer, which might be released on fetching
trigtuple from oldslot
+ * if oldslot is the only owner of buffer,
+ * and 2) if some trigger returns/stores the old trigtuple,
+ * and the heap tuple passed to the trigger was located locally,
+ * newslot might reference that tuple storage, which
is freed at the
+ * end of this function.
+ */
Reading this, I found (1) to be very surprising. I would expect that
advancing the scan would potentially release the buffer pin, but
fetching the tuple shouldn't advance the scan. I guess this is
referring to the call, just below, to ExecFetchSlotHeapTuple. I'm
guessing that can end up calling tts_buffer_heap_materialize which,
after materializing copying the tuple, thinks that it's OK to release
the buffer pin. But that makes me wonder ... how exactly do oldslot
and newslot end up sharing the same buffer without holding two pins on
it? tts_heap_copyslot() looks like it basically forces the tuple to be
materialized first and then copies that, so you'd end up with, I
guess, no buffer pins at all, rather than 1 or 2.
I'm obviously missing something important here...
--
Robert Haas
EDB: http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | PG Bug reporting form | 2024-01-05 21:45:28 | BUG #18272: ERROR XX000 when selecting string_agg with distinct and subquery - occur in pg16.1 and not in pg15.4 |
Previous Message | Joe Conway | 2024-01-05 18:19:37 | Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG |