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.92) (envelope-from ) id 1jHZbb-0000ti-Kb for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Mar 2020 20:59:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHZba-0005LF-Du for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Mar 2020 20:59:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jHZba-0005JC-4x for pgsql-hackers@lists.postgresql.org; Thu, 26 Mar 2020 20:59:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jHZbX-0003JE-RT for pgsql-hackers@postgresql.org; Thu, 26 Mar 2020 20:59:57 +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 02QKxojX021696; Thu, 26 Mar 2020 16:59:50 -0400 From: Tom Lane To: Andres Freund cc: Pavel Stehule , Amit Langote , PostgreSQL Hackers Subject: Re: plan cache overhead on plpgsql expression In-reply-to: <20200326184947.vniqm2kqa4hmv56x@alap3.anarazel.de> References: <1478.1584815045@sss.pgh.pa.us> <20200325211825.gf2ta424kwkfghbr@alap3.anarazel.de> <15634.1585173110@sss.pgh.pa.us> <20200325224903.pwsx4pccyktq7tx6@alap3.anarazel.de> <11118.1585231340@sss.pgh.pa.us> <10353.1585247879@sss.pgh.pa.us> <20200326184947.vniqm2kqa4hmv56x@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 26 Mar 2020 11:49:47 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21694.1585256389.1@sss.pgh.pa.us> Date: Thu, 26 Mar 2020 16:59:49 -0400 Message-ID: <21695.1585256389@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > On 2020-03-26 14:37:59 -0400, Tom Lane wrote: >> Testing that reminded me of the other regression test failure I'd seen >> when I first tried to do it: select_parallel.sql shows a WARNING about >> a plancache leak in a parallel worker process. When I looked into the >> reason for that, it turned out that some cowboy has split >> XACT_EVENT_COMMIT into XACT_EVENT_COMMIT and >> XACT_EVENT_PARALLEL_COMMIT (where the latter is used in parallel >> workers) without bothering to fix the collateral damage to plpgsql. >> So plpgsql_xact_cb isn't doing any cleanup in parallel workers, and >> hasn't been for a couple of releases. >> The bad effects of that are probably limited given that the worker >> process will exit after committing, but I still think that that part >> of this patch is a bug fix that needs to be back-patched. > Ugh. Lucky that we don't register many things inside those resowners. Yeah. I spent some time trying to produce a failure this way, and concluded that it's pretty hard because most of the relevant callbacks will be run during ExprContext shutdown, which is done during plpgsql function exit. In a non-transaction-abort situation, the simple EState shouldn't have any live ExprContexts left at commit. I did find a case where a memory context callback attached to the EState's query context doesn't get run when expected ... but it still gets run later, when the whole memory context tree is destroyed. So I can't demonstrate any user-visible misbehavior in the core code. But it still seems like a prudent idea to back-patch a fix, in case I missed something or there is some extension that's pushing the boundaries further. It's definitely not very cool that we're leaving behind a dangling static pointer to an EState that won't exist once TopTransactionMemoryContext is gone. I'll back-patch relevant parts of those comments about DO block management, too. regards, tom lane