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 1rOLKp-003O0R-Uk for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jan 2024 17:28:48 +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 1rOLKp-004A9M-0s for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jan 2024 17:28:47 +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 1rOLKo-004A9E-Ot for pgsql-bugs@lists.postgresql.org; Fri, 12 Jan 2024 17:28:46 +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.94.2) (envelope-from ) id 1rOLKm-001EC6-Di for pgsql-bugs@lists.postgresql.org; Fri, 12 Jan 2024 17:28:46 +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 40CHSQZ7492827; Fri, 12 Jan 2024 12:28:26 -0500 From: Tom Lane To: Alexander Lakhin cc: Robert Haas , pgsql-bugs@lists.postgresql.org, Richard Guo , Andres Freund , Peter Geoghegan Subject: Re: BUG #17798: Incorrect memory access occurs when using BEFORE ROW UPDATE trigger In-reply-to: <17124cd9-6515-2076-6eac-40d44388f833@gmail.com> References: <17798-0907404928dcf0dd@postgresql.org> <87fe6c28-80b2-f709-a8db-d105e5240e39@gmail.com> <1849610.1682807087@sss.pgh.pa.us> <494cd7c4-c109-6886-c0e3-138a95e7e38b@gmail.com> <74335d44-819d-60e0-859a-efe74d9c84c2@gmail.com> <325298.1705009396@sss.pgh.pa.us> <94ca869c-472b-f1cf-3d7c-aa8530f5475d@gmail.com> <17124cd9-6515-2076-6eac-40d44388f833@gmail.com> Comments: In-reply-to Alexander Lakhin message dated "Fri, 12 Jan 2024 20:00:01 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <492825.1705080506.1@sss.pgh.pa.us> Date: Fri, 12 Jan 2024 12:28:26 -0500 Message-ID: <492826.1705080506@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alexander Lakhin writes: > 12.01.2024 17:56, Robert Haas wrote: >> I don't understand why it's ever safe to skip ExecMaterializeSlot >> here. IIUC, if we have no EPQ slot, newslot is still not materialized >> and thus dependent on oldslot ... and we're about to >> ExecFetchSlotHeapTuple on oldslot. > To my understanding, when we have no epqslot_candidate, it means that > newslot came from ExecBRUpdateTriggers's callers and it can't be dependent > on an internal oldslot's buffer. After sleeping on it, I'm inclined to the opinion that unconditionally materializing newslot here is a good idea. Given that we're about to call one or more trigger functions, the incremental cost ought to be pretty negligible. The reduction in the state space that we have to reason about seems fairly significant, too. Remember that a trigger function could do almost anything. So I like this not only for providing a straightforward fix for the current problem, but as a guard against unrecognized or future bugs in this area. 75e03eabe should be sufficient evidence that there's a lot of hazard here (and I especially like being able to revert that wart). regards, tom lane