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 1qCIAI-0008LB-Sj for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jun 2023 11:07:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qCIAH-0001IH-NE for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jun 2023 11:07:49 +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 1qCIAH-0001I8-92 for pgsql-hackers@lists.postgresql.org; Thu, 22 Jun 2023 11:07:49 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qCIAD-003bjY-T0 for pgsql-hackers@lists.postgresql.org; Thu, 22 Jun 2023 11:07:48 +0000 Received: from mail.postgrespro.ru (webmail.mstn.postgrespro.ru [192.168.2.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.pyhalov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id EE7BCE20EA2; Thu, 22 Jun 2023 14:07:42 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1687432063; bh=+P9URZk6fUYnCd2wvokMBgWk5cvIErFnBj+enCLFt1A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:User-Agent: Message-ID:From; b=fumgNwGyb+fs0AQLWCmB+MjiXwfaZy4fGVmSddb0lWQj6ZYS02Za7uOafWYfcUqqX 5sGy//HUtKMZ4rsRhTp2fB8fzPKZYeSG9NpzOQTXLO6xsOdNGsuxLuK+z5tP0t8DN5 KZcgzPx3PWaeYqFvwWeeh2SDmCrAN7rxcHfltUSw/OmRhu10Nm29ymGmJgFgIVoHYU rwLmAf5yl2QyYuJS1fSlrDUBITFgj1aC+fbUfcnD5yXvN+WvqQDH4jkaZAsUVam4eU Mvngk8CXaFEMxS9xrEnARflJnNsZIZpxjRRuPLiXxDbLuagjYEZpdtVD1/mTnNII9h ZFfYH5Jzn7ITQ== MIME-Version: 1.0 Date: Thu, 22 Jun 2023 14:07:42 +0300 From: Alexander Pyhalov To: Tomas Vondra Cc: Andres Freund , Tom Lane , PostgreSQL Hackers Subject: Re: memory leak in trigger handling (since PG12) In-Reply-To: References: <222a3442-7f7d-246c-ed9b-a76209d19239@enterprisedb.com> <960113.1684859980@sss.pgh.pa.us> <20230524185559.un4dqfem3u3ktons@awork3.anarazel.de> User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: a.pyhalov@postgrespro.ru Content-Type: multipart/mixed; boundary="=_1a937a31e9443ace6a2a0771822b79f2" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=_1a937a31e9443ace6a2a0771822b79f2 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8; format=flowed Tomas Vondra писал 2023-05-25 17:41: > The attached patch does this - I realized we actually have estate in > ExecGetAllUpdatedCols(), so we don't even need a variant with a > different signature. That makes the patch much simpler. > > The question is whether we need the signature anyway. There might be a > caller expecting the result to be in CurrentMemoryContext (be it > ExecutorState or something else), and this change might break it. But > I'm not aware of any callers, so maybe that's fine. > Hi. Unfortunately, this patch has broken trigdata->tg_updatedcols usage in AFTER UPDATE triggers. Should it be if not fixed, but at least mentioned in documentation? Attaching sample code. After creating trigger, an issue can be reproduced as this: create table test (i int, j int); create function report_update_fields() RETURNS TRIGGER AS '/location/to/trig_test.so' language C; create trigger test_update after update ON test FOR EACH ROW EXECUTE FUNCTION report_update_fields(); insert into test values (1, 12); update test set j=2; -- Best regards, Alexander Pyhalov, Postgres Professional --=_1a937a31e9443ace6a2a0771822b79f2 Content-Transfer-Encoding: base64 Content-Type: text/x-c; name=trig_test.c Content-Disposition: attachment; filename=trig_test.c; size=1116 I2luY2x1ZGUgPHBvc3RncmVzLmg+CiNpbmNsdWRlIDxmbWdyLmg+CiNpbmNsdWRlIDxmdW5jYXBp Lmg+CiNpbmNsdWRlIDx1dGlscy9lbG9nLmg+CiNpbmNsdWRlIDxjb21tYW5kcy90cmlnZ2VyLmg+ CgojaWZkZWYgUEdfTU9EVUxFX01BR0lDClBHX01PRFVMRV9NQUdJQzsKI2VuZGlmCgoKdm9pZCBf UEdfaW5pdCgpCnsKfQoKUEdfRlVOQ1RJT05fSU5GT19WMShyZXBvcnRfdXBkYXRlX2ZpZWxkcyk7 CgpEYXR1bQpyZXBvcnRfdXBkYXRlX2ZpZWxkcyhQR19GVU5DVElPTl9BUkdTKQp7CglUcmlnZ2Vy RGF0YSAqdHJpZ2RhdGEgPSAoVHJpZ2dlckRhdGEgKikgZmNpbmZvLT5jb250ZXh0OwoJaW50CQkJ dGduYXJncywKCQkJCXJldDsKCWNoYXIJICAgKnJnaWRzLAoJCQkgICAqZ3RuYW1lLAoJCQkgICAq bnNwbmFtZSwKCQkJICAgKnJuYW1lOwoJSGVhcFR1cGxlCXJldHR1cGxlID0gTlVMTDsKCUxpc3QJ ICAgKnJnaWRsaXN0ID0gTklMOwoJTGlzdENlbGwgICAqbGM7CgoJaWYgKCFDQUxMRURfQVNfVFJJ R0dFUihmY2luZm8pIHx8IC8qIVRSSUdHRVJfRklSRURfQUZURVIodHJpZ2RhdGEtPnRnX2V2ZW50 KSB8fCAqLyBUUklHR0VSX0ZJUkVEX0ZPUl9TVEFURU1FTlQodHJpZ2RhdGEtPnRnX2V2ZW50KSB8 fCAhVFJJR0dFUl9GSVJFRF9CWV9VUERBVEUodHJpZ2RhdGEtPnRnX2V2ZW50KSkKCQllbG9nKEVS Uk9SLCAidXNhZ2UgdW5zdXBwb3J0ZWQiKTsKCQoJaWYgK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