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 1ktp81-00055X-TS for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Dec 2020 09:47:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ktp80-0006po-Qx for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Dec 2020 09:47:48 +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 1ktp7z-0006pe-RU for pgsql-hackers@lists.postgresql.org; Mon, 28 Dec 2020 09:47:48 +0000 Received: from wforward3-smtp.messagingengine.com ([64.147.123.22]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ktp7w-0004eq-8E for pgsql-hackers@postgresql.org; Mon, 28 Dec 2020 09:47:46 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailforward.west.internal (Postfix) with ESMTP id 3E5854F2; Mon, 28 Dec 2020 04:47:42 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 28 Dec 2020 04:47:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=KWI+0jWMzDLbPPOMVwjosixntZKVm5Fvsoa9MQKKZ IQ=; b=bfnBKITiMgyej61Q3IPIvjOyAVaxABNW0DHw3zMHpHZINzrcSxyG6Rqdb DVAGmuxvyvb3PpOLU8RNgmxDrxcey4kMvBM1jF2aRCeVvNm/kdPlFLlIyZG/2hHy txdd0SCTD/PzqU3x8wk4aXrcb0ZdoVvcW93+JDGoXppQVVkQIIc18okoccd0tuKn uQZLhfJldHjesTLYk154cC33dfZHFC5+gld0gMhU5kt6/tS/bXZzP0BE7SXW8oMQ xiTtsKf2ZgH7En0drZcDOuYn2HqaXPf6eC0vbDFyRrAe97A4UxpIQsmUV6M9TQPQ 1MyGDeTfLciulFxu0wIfzctdDYt1A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdduledgtdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhfhokffffgggjggtgfesth ejredttdefjeenucfhrhhomheprfgvthgvrhcugfhishgvnhhtrhgruhhtuceophgvthgv rhdrvghishgvnhhtrhgruhhtsegvnhhtvghrphhrihhsvggusgdrtghomheqnecuggftrf grthhtvghrnhepveevieeltddvueejteefheejgeekffffgeegvdelkeegffegudetheeu udekteefnecuffhomhgrihhnpehpohhsthhgrhdrvghspdhpohhsthhgrhgvshhqlhdroh hrghenucfkphepkeejrddujeejrdejvddrudegvdenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpehpvghtvghrrdgvihhsvghnthhrrghuthesvg hnthgvrhhprhhishgvuggsrdgtohhm X-ME-Proxy: Received: from april.pezone.net (p57b1488e.dip0.t-ipconnect.de [87.177.72.142]) by mail.messagingengine.com (Postfix) with ESMTPA id 53BF124005C; Mon, 28 Dec 2020 04:47:40 -0500 (EST) Subject: Re: pgsql: Fix memory leak in plpgsql's CALL processing. To: Tom Lane , pgsql-hackers References: From: Peter Eisentraut Organization: EnterpriseDB Message-ID: Date: Mon, 28 Dec 2020 10:47:38 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: 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: Precedence: bulk This change has broken the following test case (reduced from actual production code): CREATE OR REPLACE PROCEDURE prc_inout_test_inner(INOUT x integer) LANGUAGE plpgsql AS $procedure$ BEGIN COMMIT; x := 2; END; $procedure$; CREATE OR REPLACE PROCEDURE prc_inout_test_main() LANGUAGE plpgsql AS $procedure$ DECLARE y INTEGER := 1; BEGIN CALL prc_inout_test_inner(y); END; $procedure$; CALL prc_inout_test_main(); With the patch, it fails like this: ERROR: XX000: unsupported target type: 0 CONTEXT: PL/pgSQL function prc_inout_test_main() line 5 at CALL LOCATION: exec_move_row_from_fields, pl_exec.c:7196 On 2020-09-29 17:18, Tom Lane wrote: > Fix memory leak in plpgsql's CALL processing. > > When executing a CALL or DO in a non-atomic context (i.e., not inside > a function or query), plpgsql creates a new plan each time through, > as a rather hacky solution to some resource management issues. But > it failed to free this plan until exit of the current procedure or DO > block, resulting in serious memory bloat in procedures that called > other procedures many times. Fix by remembering to free the plan, > and by being more honest about restoring the previous state (otherwise, > recursive procedure calls have a problem). > > There was also a smaller leak associated with recalculation of the > "target" list of output variables. Fix that by using the statement- > lifespan context to hold non-permanent values. > > Back-patch to v11 where procedures were introduced. > > Pavel Stehule and Tom Lane > > Discussion: https://postgr.es/m/CAFj8pRDiiU1dqym+_P4_GuTWm76knJu7z9opWayBJTC0nQGUUA@mail.gmail.com > > Branch > ------ > master > > Details > ------- > https://git.postgresql.org/pg/commitdiff/a6b1f5365d58356b5d42829e9cd89a6c725d7a0a > > Modified Files > -------------- > src/pl/plpgsql/src/pl_exec.c | 91 ++++++++++++++++++++++++++++++++++---------- > 1 file changed, 70 insertions(+), 21 deletions(-) >