Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vZXgR-00E9SN-0C for pgsql-bugs@arkaria.postgresql.org; Sat, 27 Dec 2025 17:02:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vZXgP-00C5G1-05 for pgsql-bugs@arkaria.postgresql.org; Sat, 27 Dec 2025 17:02:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vZXgO-00C5Ft-2T for pgsql-bugs@lists.postgresql.org; Sat, 27 Dec 2025 17:02:25 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vZXgM-0036wU-2y for pgsql-bugs@lists.postgresql.org; Sat, 27 Dec 2025 17:02:25 +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 5BRH2Hnf1712094; Sat, 27 Dec 2025 12:02:17 -0500 From: Tom Lane To: Richard Guo cc: jinhui.lai@qq.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19363: PostgreSQL shared memory exhaustion during query execution involving views and parallel workers In-reply-to: References: <19363-8dd32fc7600a1153@postgresql.org> Comments: In-reply-to Richard Guo message dated "Sat, 27 Dec 2025 14:12:06 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1712092.1766854937.1@sss.pgh.pa.us> Date: Sat, 27 Dec 2025 12:02:17 -0500 Message-ID: <1712093.1766854937@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > The executor needs to build a hash table for 9.7 billion rows. That > requires a lot of memory. In practice, the executor splits the work > into 8192 batches, that still results in 1.2 million rows per batch. > To manage that many rows, the executor allocated 4194304 buckets. > This means the executor needs to allocate 32 MB just for the bucket > array, assuming you are on a 64-bit system. I guess your available > shared memory was less than 32 MB at that moment. On my machine, the query does complete, but it's ridiculously slow: about 15 sec to compute an empty result. AFAICT nearly all of that is being spent in hash table setup. What I'm wondering is why this plan was accepted at all. Does PHJ not consider work_mem or a similar limit on hash table size? regards, tom lane