Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mDNuW-0005RN-Rp for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Aug 2021 09:19:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mDNuV-0002qX-I2 for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Aug 2021 09:18:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mDNuV-0002qP-9P for pgsql-bugs@lists.postgresql.org; Tue, 10 Aug 2021 09:18:59 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mDNuR-0000ws-4S for pgsql-bugs@lists.postgresql.org; Tue, 10 Aug 2021 09:18:58 +0000 Received: from [192.168.129.197] (unknown [94.25.177.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id C60D721C7FD0; Tue, 10 Aug 2021 12:18:53 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1628587134; bh=2HoK4GT7ho0LwTDs3A64esFursS71tUibv7QUgnp/Ds=; h=Subject:To:References:From:Date:In-Reply-To; b=Kr0lK0/+2/7Ctm/NDlgEWDdgTAMdNZDeJQ06cJPYNHIQ/2DurQQw0fqI5xV7Mdk+1 NiZ+lK4TZ7O8WR6dIBYTBpSHEE17J2LpZL4N4n4T17iIWqaBPNvf5JfH8SR50RjMR5 O8yjC4LRV6VW9gEEsRSz91VK8N/oOWGFGczf0tJk= Subject: Re: SEGFAULT on a concurrent UPDATE of mix of local and foreign partitions To: Heikki Linnakangas , PostgreSQL mailing lists , Amit Langote References: <1a6c8eab-87e5-2dce-590f-e4aef85d6e27@iki.fi> From: "Andrey V. Lepikhov" Organization: Postgres Professional Message-ID: <706b5033-d2cd-92b1-e44e-3349ff3053fb@postgrespro.ru> Date: Tue, 10 Aug 2021 14:18:52 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <1a6c8eab-87e5-2dce-590f-e4aef85d6e27@iki.fi> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/10/21 1:29 AM, Heikki Linnakangas wrote: > On 06/08/2021 08:34, Andrey Lepikhov wrote: >> Hi, >> Postgres SEGFAULT'ed on the UPDATE of mix of local and foreign >> partitions. >> Initialization - see t.sql >> For replaying this segfault just execute in parallel: >> UPDATE test SET x = x - 1; >> >> The problem was introduced by commit 1375422. >> ExecUpdate has found a concurrently updated tuples and starts subplan >> evaluation. This operation creates new EState for EPQState and sets >> es_result_relations in NULL value. Next, ExecInitNode(subplan) is >> launched and underlying ExecInitForeignScan tries to access to an >> element of es_result_relations. This causes SEGFAULT. > > Thanks for the report! > >> I studied this problem shortly. I think, EPQState can use >> es_result_relations of a parent EState. Patch in attachment fixes this. >> check-world passed clearly. > > Hmm, that seems to work, but I have a few questions: > > Can we be sure that the es_result_relations entry of the result relation > has been initialized when the EPQState is constructed? The general model > now is that you initialize them lazily, when needed. As I understand the code correctly - yes, because a ModifyTable node higher and will initialize this field earlier. But in many cases it is not needed. > > Does it ever make sense to re-evaluate a direct Foreign Update as part > of EvalPlanQual? It doesn't seem sane to me, you cannot just run an > UPDATE statement again and expect it to be idempotent. So I think it > would make sense skip this during EvalPlanQual processing altogether. > And no need to call the FDW's Begin/EndDirectModify functions either. Agree. It is my first dive into the EPQ code. After studying i think this makes no sense. > > It's not clear to me what guarantee there is that a direct-modify > Foreign Update/Delete node is never re-evaluated as part of > EvalPlanQual. Is it because the a ModifyTable node is always at the top > of the plan tree? Or is it because the FDW never uses direct-modify in > queries where EvalPlanQual might be needed? Or because we use > ROW_MARK_COPY in those cases? ModifyTable node may be found in an underlying CTE, for example. And, right now, it's not clear for me too. > > In any case, re-evaluating a direct-modify statement doesn't seem sane, > so I propose the attached patch to add some runtime checks for that and > to avoid the original segfaultYour patch looks much better. -- regards, Andrey Lepikhov Postgres Professional