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.94.2) (envelope-from ) id 1tVvv1-00Ckut-JX for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jan 2025 17:02:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tVvv1-004mme-2V for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jan 2025 17:02:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tVvv0-004mcU-OH for pgsql-hackers@lists.postgresql.org; Thu, 09 Jan 2025 17:02:02 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tVvux-000jty-2T for pgsql-hackers@postgresql.org; Thu, 09 Jan 2025 17:02:01 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 7AF151C0002; Thu, 9 Jan 2025 17:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1736442116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jqehDdbSPtHb0ECFFrZD7mUC23eJkhv1dKuyJ9t/pSE=; b=emNf82XpsS9GyNIfCyWpwN/PV6t+Q+/Dtyuo9YP5SIzwqipzgxm+0DYMrY35EZgmh5B51X S1TDMKenGaoKjNINzi2n8XWuanEh4fsc1UPu5RiTzdBOtLAe1lHCpJf9ff7a7jJhcy8mOL 7Bst3NywsIaqhjqk5RAC3ns5EMA7WpivlbiIECtlOclY2rMnONR9OKVxyO07Jk4iaTpfGF FNwf9UtbdMTU0bNe292VJCltODw24QHVnARouGRF0woei5vb3D9+lfcJX2uUxkOzxCtf78 yckWqeGFiYNkgvKMMyQlc+nQdZXOfQyNmRMbmIR6i8vPbX1xpldyBv4Rep/fiw== Message-ID: <36af890e-464d-41ae-88a8-d06317f36a98@vondra.me> Date: Thu, 9 Jan 2025 18:01:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Adjusting hash join memory limit to handle batch explosion To: Melanie Plageman Cc: PostgreSQL Hackers References: <7bed6c08-72a0-4ab9-a79c-e01fcdd0940f@vondra.me> Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/9/25 17:17, Melanie Plageman wrote: > On Tue, Dec 31, 2024 at 6:07 PM Tomas Vondra wrote: >> >> So I decided to revisit the three patches from 2019. Attached are >> rebased and cleaned up versions. A couple comments on each one: >> >> >> 1) v20241231-adjust-limit-0001-Account-for-batch-files-in-ha.patch >> >> I believe this is the way to go, for now. The basic idea is to keep the >> overall behavior, but "relax" the memory limit as the number of batches >> increases to minimize the total memory use. >> >> This may seem a bit weird, but as the number of batches grows there's no >> way to not violate the limit. And the current code simply ignores this >> and allocates arbitrary amounts of memory. > > I'm just catching up on this thread and haven't read all the mails > yet. I started with looking at the patches in the first email and got > a bit confused. > > In this patch (v20241231-adjust-limit-0001-Account-for-batch-files-in-ha.patch), > I see that you've started accounting for the spill files in > hashtable->spaceUsed -- in the same way that is done for the tuples in > the hashtable. I know the other memory contexts (hashCxt and batchCxt) > in hashtable aren't appropriate for figuring out spaceUsed, but I was > wondering if the hashtable->spillCxt accurately reflects how much > memory is being used for these spill files at one time? Perhaps it > doesn't make sense to use this, but when we added it in 8c4040edf45, I > thought we might one day be able to use it for determining peak space > usage. Or perhaps you are imagining it only be used for observability? > Good question. Yes, the patch from 12/31 does look at all the memory, including the batch files. I thought about using the spillCtx too, but I don't think it it would work because the context tracks *current* memory usage, and we're interested in how much memory would be used *after* doubling the number of batches. regards -- Tomas Vondra