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 1mDBuG-0003Ib-C5 for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Aug 2021 20:29:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mDBuF-0005jC-Bd for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Aug 2021 20:29:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mDBuF-0005iw-1E for pgsql-bugs@lists.postgresql.org; Mon, 09 Aug 2021 20:29:55 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mDBuB-0003Ql-HU for pgsql-bugs@lists.postgresql.org; Mon, 09 Aug 2021 20:29:53 +0000 Received: from [192.168.1.113] (dsl-hkibng22-54faa4-119.dhcp.inet.fi [84.250.164.119]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 29BA02004E; Mon, 9 Aug 2021 23:29:49 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1628540989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cWkIrLv2Fdm0gNiFIJLOHJZ9vEmNUSgyiYho3vzVwYU=; b=ajRoLXplxRuFba9EpOkx6bg+eOWALpMjxQpTumwCcmFN4kFUs1GSGwH1rt+4L6tPfsvPgD bNqsSsUszG7S2EWNeQa3b7xb6GMW6iO0r8JNyuigoPYebwtJHlRTp1yTsjdK+9ox5f/+Wr yCWbPv+G6qVc68Ul2iXh+qu+vEaDDkE= Subject: Re: SEGFAULT on a concurrent UPDATE of mix of local and foreign partitions To: Andrey Lepikhov , PostgreSQL mailing lists , Amit Langote References: From: Heikki Linnakangas Message-ID: <1a6c8eab-87e5-2dce-590f-e4aef85d6e27@iki.fi> Date: Mon, 9 Aug 2021 23:29:47 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------CDE573369EDE9BBEEE65B90B" Content-Language: en-US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1628540989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cWkIrLv2Fdm0gNiFIJLOHJZ9vEmNUSgyiYho3vzVwYU=; b=C2eMTc45RccXF0s4Zx6MB+QMJl93sQVgUTgyd0qpTT0SCLxzvUPbM+oTkqVLU1zpqUnfeI 73HfpBnaIH4hADf/f+2t/40irlvKy9tr4WGabndaWVUCneOzIHPbQrwmmaSoTteFD/i8IP VWdRxQpa7lw2SYS/HgPTns7Y3z9G+VM= ARC-Seal: i=1; s=meesny; d=iki.fi; t=1628540989; a=rsa-sha256; cv=none; b=VZs+JP8Ude2BWVMzACGVEFuLmhRJ9ZxZH0/83600g+16Z0Ktaj1iVPbuo1HMCccj+A1Trz yr1VCKKU85sxfkGBeIpA5YWkjpffHF1HfAtVY0B9wwTiDtSjh/TafWSrlRb+PmqnWutJPr 0GRHDD2XSGKlIOUrtoenQ28VbnI6km4= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------CDE573369EDE9BBEEE65B90B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. 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. 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? 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 segfault. - Heikki --------------CDE573369EDE9BBEEE65B90B Content-Type: text/x-patch; charset=UTF-8; name="0001-Fix-segfault-during-EvalPlanQual-with-mix-of-local-a.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-segfault-during-EvalPlanQual-with-mix-of-local-a.pa"; filename*1="tch"