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 1opibo-0004y9-6V for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Nov 2022 04:10:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1opibm-00044l-MO for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Nov 2022 04:10:38 +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 1opibm-00044c-Dk for pgsql-bugs@lists.postgresql.org; Tue, 01 Nov 2022 04:10:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opibk-0008HV-Hn for pgsql-bugs@lists.postgresql.org; Tue, 01 Nov 2022 04:10:38 +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 2A14A2S01073513; Tue, 1 Nov 2022 00:10:02 -0400 From: Tom Lane To: David Rowley cc: Andres Freund , lauri.laanmets@eesti.ee, pgsql-bugs@lists.postgresql.org Subject: Re: Memory leak on subquery as scalar operand In-reply-to: References: <1046179.1667263449@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Tue, 01 Nov 2022 16:48:50 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1073511.1667275802.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Nov 2022 00:10:02 -0400 Message-ID: <1073512.1667275802@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Tue, 1 Nov 2022 at 13:44, Tom Lane wrote: >> It's pretty odd though that it requires two >> sub-selects to cause the problem. > Perhaps that's just what it takes to bump the costs above the JIT thresh= old. I see JIT being invoked either way: regression=3D# explain verbose SELECT id, (SELECT count(*) FROM leak_test x WHERE x.id=3Dl.id) as x_result, = = (SELECT count(*) FROM leak_test y WHERE y.id=3Dl.id) as y_result FROM leak_test l; QUERY PLAN = = --------------------------------------------------------------------------= ---------------------------------- Seq Scan on public.leak_test l (cost=3D0.00..865943.00 rows=3D100000 wid= th=3D20) Output: l.id, (SubPlan 1), (SubPlan 2) SubPlan 1 -> Aggregate (cost=3D4.31..4.32 rows=3D1 width=3D8) Output: count(*) -> Index Only Scan using leak_test_pkey on public.leak_test x = (cost=3D0.29..4.31 rows=3D1 width=3D0) Output: x.id Index Cond: (x.id =3D l.id) SubPlan 2 -> Aggregate (cost=3D4.31..4.32 rows=3D1 width=3D8) Output: count(*) -> Index Only Scan using leak_test_pkey on public.leak_test y = (cost=3D0.29..4.31 rows=3D1 width=3D0) Output: y.id Index Cond: (y.id =3D l.id) JIT: Functions: 12 Options: Inlining true, Optimization true, Expressions true, Deforming = true (17 rows) regression=3D# explain verbose SELECT id, (SELECT count(*) FROM leak_test x WHERE x.id=3Dl.id) as x_result FROM = leak_test l; QUERY PLAN = = --------------------------------------------------------------------------= ---------------------------------- Seq Scan on public.leak_test l (cost=3D0.00..433693.00 rows=3D100000 wid= th=3D12) Output: l.id, (SubPlan 1) SubPlan 1 -> Aggregate (cost=3D4.31..4.32 rows=3D1 width=3D8) Output: count(*) -> Index Only Scan using leak_test_pkey on public.leak_test x = (cost=3D0.29..4.31 rows=3D1 width=3D0) Output: x.id Index Cond: (x.id =3D l.id) JIT: Functions: 7 Options: Inlining false, Optimization false, Expressions true, Deformin= g true (11 rows) Maybe the different "inlining" choice makes a difference? regards, tom lane