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.89) (envelope-from ) id 1gj52d-0005XU-VN for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Jan 2019 16:24:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gj52c-0005Hp-Jy for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Jan 2019 16:24:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gj52c-0005Hi-Ab for pgsql-bugs@lists.postgresql.org; Mon, 14 Jan 2019 16:24:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gj52Z-00068Z-Tz for pgsql-bugs@lists.postgresql.org; Mon, 14 Jan 2019 16:24:45 +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 x0EGOeMl026376; Mon, 14 Jan 2019 11:24:40 -0500 From: Tom Lane To: amdmi3@amdmi3.ru cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15592: Memory overuse with subquery containing unnest() and set operations (11.x regression) In-reply-to: <15592-cc5729f9ba02e31c@postgresql.org> References: <15592-cc5729f9ba02e31c@postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Mon, 14 Jan 2019 14:55:20 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26374.1547483080.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 14 Jan 2019 11:24:40 -0500 Message-ID: <26375.1547483080@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?utf-8?q?PG_Bug_reporting_form?=3D writes: > After upgrading from PostgreSQL 10.x to 11.x this query began to eat > inadequate amounts of memory (several gigabytes per hundred thousands ro= ws). > I've narrowed it down to this simple case which demonstrates the problem= : > CREATE TABLE test AS > SELECT generate_series(1,500000) AS id, '{a,b}'::text[] AS first, > '{a}'::text[] AS second; > SELECT DISTINCT EXISTS(SELECT unnest(first) INTERSECT SELECT unnest(seco= nd)) > FROM test; Ugh. Something is creating ExprContexts and not freeing them --- a memory context dump taken at ExecutorEnd shows ExecutorState: 100663296 total in 22 blocks; 4625424 free (19 chunks= ); 96037872 used ExprContext: 8192 total in 1 blocks; 7936 free (0 chunks); 256 use= d ExprContext: 8192 total in 1 blocks; 7936 free (0 chunks); 256 use= d ExprContext: 8192 total in 1 blocks; 7936 free (0 chunks); 256 use= d ... 499916 more child contexts containing 4095311872 total in 499916 b= locks; 3967322616 free (1 chunks); 127989256 used Not sure where the problem is, yet, but for sure this is a bug. Thanks for the report! regards, tom lane