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 1mxACk-0002L8-SI for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Dec 2021 15:59:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxACj-00020U-IC for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Dec 2021 15:59:01 +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 1mxACj-0001zw-AG for pgsql-bugs@lists.postgresql.org; Tue, 14 Dec 2021 15:59:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxACh-0008Hg-0j for pgsql-bugs@lists.postgresql.org; Tue, 14 Dec 2021 15:59:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1BEFwtRM261066; Tue, 14 Dec 2021 10:58:56 -0500 From: Tom Lane To: Klaudie Willis cc: pgsql-bugs@lists.postgresql.org, Peter Geoghegan Subject: Re: When Update balloons memory In-reply-to: References: <3484560.1638889073@sss.pgh.pa.us> <189763.1639437451@sss.pgh.pa.us> Comments: In-reply-to Klaudie Willis message dated "Tue, 14 Dec 2021 08:16:08 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <261064.1639497535.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 14 Dec 2021 10:58:55 -0500 Message-ID: <261065.1639497535@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk [ redirecting to pgsql-bugs ] Klaudie Willis writes: > Turns out the base case is simpler than I thought. Not involving partiti= ons at all > CREATE TABLE public.part_main ( > txid bigint, > actiondate timestamp without time zone NOT NULL > ); > insert into part_main > select x, '2019-06-01'::timestamp + x%365 * interval '1 day' > from generate_series(1, 30 * 1E6) as x; > CREATE INDEX partindx ON public.part_main USING btree ((actiondate)::dat= e); -- mem bug? > -- mem runaway follows > update part_main set txid =3D txid + 1; ITYM "((actiondate::date))", but yeah, this leaks memory like there's no tomorrow. I traced it to 9dc718bdf (Pass down "logically unchanged index" hint), which has added a function index_unchanged_by_update() that (a) looks fairly expensive, (b) leaks a copy of every expression tree it examines, and (c) is invoked over again for each row, even though AFAICS the answer shouldn't change across rows. This seems very poorly thought through. Peter? regards, tom lane PS: personally I would have used pull_varnos() instead of reinventing that wheel. But in any case the real problem is repeated invocation.