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 1pnHq7-00067E-Bj for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Apr 2023 11:43:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pnHq6-0000Ds-7W for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Apr 2023 11:43: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 1pnHq5-0000Di-Sl for pgsql-hackers@lists.postgresql.org; Fri, 14 Apr 2023 11:43:37 +0000 Received: from mail1.dalibo.net ([51.159.93.128] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pnHq2-002qtd-W2 for pgsql-hackers@postgresql.org; Fri, 14 Apr 2023 11:43:37 +0000 Received: from karst (larco.ioguix.net [78.202.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 43D481FB35; Fri, 14 Apr 2023 13:43:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1681472602; bh=mz0yF8UGTBu8X8kPBkjAVFbkOI3kwjMR7c7J7GyD+Qo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=quOnJnE+LmgFSjfxogmZZi1c5Vf6jVhfkZ3yvc9+wrJDy0OvYo85AMrFk7/9qo+4N +JMECA7TrdlJmpkryeRnRxKZh9YZxlLwJ42zRy8Vsyxrg04la4MeU2jzyNpJkMSqv9 nvX25fSGv+JsEAexDPxTi+Fw+2oN7s1nRuWxZEj4= Date: Fri, 14 Apr 2023 13:43:21 +0200 From: Jehan-Guillaume de Rorthais To: Matthias van de Meent Cc: Konstantin Knizhnik , PostgreSQL Hackers Subject: Re: OOM in hash join Message-ID: <20230414134321.46fd18d3@karst> In-Reply-To: References: <94608e6b-caca-02d2-1bec-9806532c476d@garret.ru> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 14 Apr 2023 13:21:05 +0200 Matthias van de Meent wrote: > On Fri, 14 Apr 2023 at 12:59, Konstantin Knizhnik wrote: > > > > Hi hackers, > > > > Too small value of work_mem cause memory overflow in parallel hash join > > because of too much number batches. > > There is the plan: > > [...] > > > There is still some gap between size reported by memory context sump and > > actual size of backend. > > But is seems to be obvious, that trying to fit in work_mem > > sharedtuplestore creates so much batches, that them consume much more > > memory than work_mem. Indeed. The memory consumed by batches is not accounted and the consumption reported in explain analyze is wrong. Would you be able to test the latest patchset posted [1] ? This does not fix the work_mem overflow, but it helps to keep the number of batches balanced and acceptable. Any feedback, comment or review would be useful. [1] https://www.postgresql.org/message-id/flat/20230408020119.32a0841b%40karst#616c1f41fcc10e8f89d41e8e5693618c Regards,