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 1vt8SS-004rVz-2t for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2026 18:09:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vt8RS-005AQm-1o for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Feb 2026 18:07:58 +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 1vt8RS-005AQe-0n for pgsql-hackers@lists.postgresql.org; Thu, 19 Feb 2026 18:07:58 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vt8RP-00000000B6V-0xcb for pgsql-hackers@lists.postgresql.org; Thu, 19 Feb 2026 18:07:57 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-4359a316d89so1164194f8f.0 for ; Thu, 19 Feb 2026 10:07:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771524474; cv=none; d=google.com; s=arc-20240605; b=aJWJh6L2FYXq/fdwJnSxXk4v9XnSjt1Cbxfxd7tYREs6dGcgkBlgJ/2zPnh6dds/4C Z42mOR2LN2nRLNEVUSVjIXHM+cBDV8W1ES+SuhgtJcA52XCesGJe+Hhv08X9tnG06p8z hrR9ySubY4Y3KXSiz17egau4ApPhU+qRlsgubJ3vdnuTKb5OOCJPpD+E/JMQfWdxXYki o1EB/EowwZAZXfn9Z6gE6UamsgdNszcqKmkM+d2y9gHnD14bNY5+Gr368MSNDP5LJo0a MT3sCaVGaWw7aNZ2pblfnS8sRaXRy/6MkEMmkjDR3xSTumKs1cAlsEiMkXWAv70RVynZ qdng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=5jK53pVUCODFBe23lXBwzl2pVh03d1+SV9EiJ4qwrSc=; fh=VVf4Z/llIxfOZ7ySgi0qx+OaJ47g08ZiEvKCqYD0SPE=; b=SCfpgF38HUJRLsYzFGEem4DxnFRbpUCb6JH9Jt/TZOJygzQ7PXIss3VT0tpQOTV15z j/4NlEGQCEAF4f8z90F9W3Fy1A+xhoT3qe6bB8omrrZK0BlrkSq6J3SUhP+mdA23dAuP Xrj74eDnGplpyTiU1bOK93Cyf0/mlt2YdX7/6/fdMFDtmZqX/CWz3/bo1roJoRseCzkq PTQx+08YKvAO5ZftranDbUtzW8feqx84aTBT5OZqLTvbkdgEQ+En2MLncSNuTebvadYg XuBLuyQrAnInViQko3xL02cyUEkx7ZVPOAzxfe/AKpW//pCE+Hj1WZFTxtBF7ft8W2d5 ghYg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1771524474; x=1772129274; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5jK53pVUCODFBe23lXBwzl2pVh03d1+SV9EiJ4qwrSc=; b=fyoTphQzRjlMmfXIX3NsK1ctGv5KNIDD98yX1U6s7kZo4vyIuFntFJDV2NKGenA1M8 UtFlIWQqKlD5Re5AV3U7Uw4wS9LVf88aXETFrlKzh2Pj5AXYlfpVceUjk/0yqNVltdA5 02xZl1zxhMe1ADeYiEWGL76JHVuzXCJ0YnWLlkh7iIhaaoVl2Z3nvikHtkYnFDsEKqtX DB4vJhZCYSUyauDdhT0qsBWy4mPnTpV80UMdDH/K40J6jfOVrI79JPW5CCPSwcUfdue4 Rv5nJrAgctRLAisqRF+SYlEmyHsWuz6nXbPQ3E07w+c0f3nRlZUVv2yXTUD44of3xRQA fLKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771524474; x=1772129274; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5jK53pVUCODFBe23lXBwzl2pVh03d1+SV9EiJ4qwrSc=; b=bBNMdG2Jihs17yvFtm5pE9AiecyInZeQdYr/fvlSX7JaB7a/fTCEgK1d5JeKkrzl3/ SY/UdxoTF5tOtDRnktqwaDuROk6E8wErMTGdPN4J/qRxZXbt/5K0gGTkdVd7GQ0HHk9o ZADHJ20u2f/xpf7453+YLeTA1W3Pm/zF4jrRct6BXV+BjeqXB5HppyPiX9teRJBtc43U shusSBUJPjXcQA2iQGl+RbAJaCvSglv4jhZhph31wnJVhRtQH8RxKNKfExvZBRGoQ2eP P5/U1XnlJTd+FyxHvH11xm/O4obU3Xp0XzGWXG6UrSSU3YpEfS9mIi5epO0S8CUuMO7V 030A== X-Forwarded-Encrypted: i=1; AJvYcCXwm9IEzHg/U47lYdmDIZbG+J6vwn5z1S4JbPEEnK8AHBWfIA+2KDWit9jxdb/NFh9frMmWfk1Xa+38NQqM@lists.postgresql.org X-Gm-Message-State: AOJu0YxA1bOjT8do9OIKmWVvftp/a9AhkiQn8n0zDec0S17X0jCTpskH 5OJL1tDzJL5bYmqD0LMRzHmWi2xZEaPG13jk/dzl/YQnu/vXNfbaO6ddXirjpspiI2jFMCYk8Jv uBiY0WR0zJQGaGkmivsr/zcfspGgiqcNA7Fbe+gU5zg== X-Gm-Gg: AZuq6aL4y7b22wCJBJ6itqZDo2fG984OzNyRxcgS588DDndnQ6FY5mMPrtqhkkqUONX 8apRsyGhY3hOPJrzBPhnZvze+66uGH8HxRfiRwBo4rEOVCW6NGCyzFgaWZX5Jb9aP0UkqRMYpYC 9ABFsKxdgb8n3RBXBiDrtpgXcy5Z52E3NNeL3jZVzN8dCaqcIKWcHQcut2zMidv3b8vPr2tq7hS s1ZwrykuixTVmJsWoSEXK4w4mB2IRY2Ehj7GLc2o9EtV0f/xlqqOpQL4+q/cr3TYidXPHojW0Ai K+2wP/76 X-Received: by 2002:a05:6000:4:b0:439:5c0b:1037 with SMTP id ffacd0b85a97d-4395c0b10bdmr6407838f8f.3.1771524474102; Thu, 19 Feb 2026 10:07:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ants Aasma Date: Thu, 19 Feb 2026 20:07:42 +0200 X-Gm-Features: AaiRm51DLvEys85Ngc5CP5kiWg4izk3gaRvMsMc2xxO_lUHL93O3I8CwbNhdYJk Message-ID: Subject: Re: Hash aggregate collisions cause excessive spilling To: Andres Freund Cc: Tomas Vondra , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 19 Feb 2026 at 19:30, Andres Freund wrote: > On 2026-02-19 19:06:04 +0200, Ants Aasma wrote: > > After turning leader participation off the problem no longer > > reproduced even after 10 iterations, turning it back on it reproduced > > on the 4th iteration. Is there any reason why the hash table couldn't > > have an unconditional iv that includes the plan node? > > You mean just use the numerical value of the pointer? I think that'd be pretty > likely to be the same between parallel workers. And I think it's not great for > benchmarking / debugging if every run ends up with a different IV. > > But we certainly should do something about the IV for the leader in these > cases. I was thinking more along the lines of hashing together the pointer value and worker number. But something more deterministic would indeed be better. How about this? --- a/src/backend/executor/execGrouping.c +++ b/src/backend/executor/execGrouping.c @@ -201,3 +201,3 @@ BuildTupleHashTable(PlanState *parent, MemoryContext oldcontext; - uint32 hash_iv = 0; + uint32 hash_iv = parent->plan->plan_node_id; I also figured out why this is not a more common issue. The iv randomization is predicated on the aggregate node not having a final function. Normally the partial hash aggregate will use randomized iv and the finalize will use 0. But in this case because it's implementing distinct, there is no finalize function on the upper hash aggregate so on the leader the upper hash aggregate gets the same iv as the one below gather. Are there any other cases where a hash aggregate would be fed from another hash aggregate using the same group key? Those could run into the same problem. Regards, Ants Aasma