Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hyOP9-0002H9-CQ for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Aug 2019 22:39:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hyOP8-00021B-7N for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Aug 2019 22:39:34 +0000 Received: from makus.postgresql.org ([72.32.157.229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hyOP7-0001zy-Rt for pgsql-bugs@lists.postgresql.org; Thu, 15 Aug 2019 22:39:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hyOP1-0001CR-GR for pgsql-bugs@lists.postgresql.org; Thu, 15 Aug 2019 22:39:32 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7FMdOki032546; Thu, 15 Aug 2019 18:39:24 -0400 From: Tom Lane To: Thomas Munro cc: Piotr Gabriel Kosinski , PostgreSQL mailing lists Subject: Re: Segmentation fault during update inside ExecBRUpdateTriggers In-reply-to: References: Comments: In-reply-to Thomas Munro message dated "Fri, 16 Aug 2019 10:23:15 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32544.1565908764.1@sss.pgh.pa.us> Date: Thu, 15 Aug 2019 18:39:24 -0400 Message-ID: <32545.1565908764@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Munro writes: > Right, this happens on REL_11_STABLE but not on master (which rewrote > the relevant code quite a bit in the "slotification" project). We should probably trace back why it doesn't happen before v11. I have a vague memory of having touched this code a year or two back, so likely this is my fault, but I wonder why it doesn't fail before. > In a very quick test, the following change fixes the problem and > passes regression tests, but I'm not sure if it's the right fix. > - if (oldtuple != newtuple && oldtuple != slottuple) > + if (oldtuple != newtuple && oldtuple != slottuple && > oldtuple != trigtuple) My thoughts were headed in the same direction. It looks like the issue is that the first trigger returns OLD, ie "trigtuple", which gets assigned to "newtuple", and then the second iteration of the loop fails to deal with the aliasing. [ thinks some more... ] Actually, I'm beginning to recall that we made changes here because v11 plpgsql is capable of actually returning "trigtuple" where before it would always have made a copy. If that's accurate, then very likely the bug exists further back but requires some other PL than plpgsql to manifest. I'd be inclined to put a test case exercising this into all branches, even ones not currently showing the bug, because it's clearly a fragile area. regards, tom lane