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 1tT99U-003f0K-Ma for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jan 2025 00:33:29 +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 1tT99T-00B1On-Bz for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jan 2025 00:33:27 +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 1tT99T-00B1OH-2i for pgsql-hackers@lists.postgresql.org; Thu, 02 Jan 2025 00:33:26 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tT99R-001dIA-0z for pgsql-hackers@lists.postgresql.org; Thu, 02 Jan 2025 00:33: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 5020XNgh160826; Wed, 1 Jan 2025 19:33:23 -0500 From: Tom Lane To: David Rowley cc: PostgreSQL Developers Subject: Re: Incorrect CHUNKHDRSZ in nodeAgg.c In-reply-to: References: <151884.1735773536@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Thu, 02 Jan 2025 13:23:54 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <160824.1735778003.1@sss.pgh.pa.us> Date: Wed, 01 Jan 2025 19:33:23 -0500 Message-ID: <160825.1735778003@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Thu, 2 Jan 2025 at 12:18, Tom Lane wrote: >> I thought for a bit about whether we shouldn't try to account for >> palloc power-of-2-block-size overhead here. That omission would >> typically be a far larger error than the one you are fixing. However, >> given that the inputs to hash_agg_entry_size are only estimates, >> I'm not sure that we can hope to do better than the current behavior. > Likely the most correct way would be to use GetMemoryChunkSpace(), but > there might be some additional overhead to consider there. Nah, you've got the wrong mental model. hash_agg_entry_size is trying to predict the average hash entry size in advance of seeing any actual data, so that we can estimate how many entries will fit in work_mem. By the time we can use GetMemoryChunkSpace on an actual entry, it's too late for that. >> Could we use a generation or even bump context? > Bump wouldn't work due to the SH_FREE() in SH_GROW() when resizing the > table. Meh. I guess we'd have to keep that structure in a context separate from the tuples. Might not be worth the trouble. > I think what would be more interesting is seeing if we can store the > TupleHashEntryData.firstTuple in a bump context. Are you saying the same as above, or something different? regards, tom lane