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 1w8IVf-000OY4-3D for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Apr 2026 13:55: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 1w8IVe-006FFo-2d for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Apr 2026 13:54:59 +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 1w8IVe-006FFd-1o for pgsql-bugs@lists.postgresql.org; Thu, 02 Apr 2026 13:54:58 +0000 Received: from fhigh-b2-smtp.messagingengine.com ([202.12.124.153]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w8IVb-00000000CwN-3M9L for pgsql-bugs@lists.postgresql.org; Thu, 02 Apr 2026 13:54:58 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id 5FB997A0264; Thu, 2 Apr 2026 09:54:53 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Thu, 02 Apr 2026 09:54:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1775138093; x=1775224493; bh=EW+K601ZrL GZ3wHrZ8P/0Kl7vEWEtgmiwNiQc5tTqes=; b=Sp32yMS/o9AAZU6H+Ma0bmDKEL Ox8B5tu4whnlBqwFWo/PQ1pmvgacmB5QhwAu1wVveMVjiW4bWlJbrMyQp22Iailz PyVmIqTM9YaWNERcYt1gUp4cRFmd6dbQh/EsYGe0GYtzVS1pzf7n9xN+JyiYpc4E NYCsf0c1W/euNlHDrkN2Sb10nWsHVkMdFqfvhGQzCGsVrl5l4RTf91zoE1lgad9a cPcGlmfD2h9/aDpr+8XgA2yt3zORW3iV+aJfmFA74sOrj1RybnO2a8QcZoRPEfS8 IoOchAHhMzFSKjHO1iEBlxg4Og37Vf+ZpzVNWNmPxc6q41K6tEkrO6hm3xig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1775138093; x=1775224493; bh=EW+K601ZrLGZ3wHrZ8P/0Kl7vEWEtgmiwNi Qc5tTqes=; b=lnh/Lc7XT1HaxXxFWaitonlOj6XkfOwCNlUkoQNYVZNJCnEFZln 1ZnC466IH762PqxQJBMuPzYT9+YA1FRPf57RTFSKU2WKOcWCHPS9d1OPxQUc6qOD 1Gme7nLvCExvRDVGdKkiAdFWGId1qEbY2eEtoONKoDlOY7JmR2dT6mhJVHB5gxQo Tw2F0wOTGRsyBF9ip+6lEfA7LDtLFFCGV1u+FXd2U29rWhX3v47wjxVS32JTk8HD jngaNRiGCXJmXY/SfyLfSP08IQDn55nMuIpcrr5Q/0sE+DzPKXReOQkAI6eu2JKV 6sK+OMu1GpOxQO/Ol/pFxj8mCWMl3hqG2rQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdeivddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesthdtsfdttddtvd enucfhrhhomheptehnughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgii vghlrdguvgeqnecuggftrfgrthhtvghrnhepjeehtdffjeefvdegjeehudegteekkefgke ehgeduffdtjeffgeduueehteeihfetnecuffhomhgrihhnpeguvghpvghsiidrtghomhen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurh gvshesrghnrghrrgiivghlrdguvgdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhht phhouhhtpdhrtghpthhtoheprggurhhirghnrdhmohgvnhhnihgthhestggvrhhnrdgthh dprhgtphhtthhopehpghhsqhhlqdgsuhhgsheslhhishhtshdrphhoshhtghhrvghsqhhl rdhorhhg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 Apr 2026 09:54:52 -0400 (EDT) Date: Thu, 2 Apr 2026 09:54:52 -0400 From: Andres Freund To: adrian.moennich@cern.ch, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19449: Massive performance degradation for complex query on Postgres 16+ (few seconds -> multiple hours) Message-ID: References: <19449-4fac687c06cc7def@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <19449-4fac687c06cc7def@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-04-02 13:04:46 +0000, PG Bug reporting form wrote: > This is extreme both in general and compared to the performance we got on > 14/15, where the same > query took just a few seconds. > > Here are EXPLAIN ANALYZE outputs from when I tested this a few weeks ago on > 14 and 16 > using our real production database. > https://explain.depesz.com/s/17Fp > https://explain.depesz.com/s/0dHI A lot of time is wasted due to batching in the hash join in 16, seemingly due to a mis-estimate in how much batching we would need: -> Parallel Hash (cost=323037.00..323037.00 rows=1075136 width=10) (actual time=3267572.432..3267575.016 rows=1023098 loops=3) Buckets: 262144 (originally 262144) Batches: 262144 (originally 32) Memory Usage: 18912kB (note the 262144 batches, when 32 were originally assumed) I'd suggest trying to run the query with a larger work mem. Not because that should be necessary to avoid regressions, but because it will be useful to narrow down whether that's related to the issue... However, even on 14, you do look to be loosing a fair bit of performance due to batching, so it might be also worth running the query on 14 with a larger work mem, to see what performance you get there. It also looks like that the choice of using memoize might not be working out entirely here. Although I don't think it's determinative for performance, it might still be worth checking what plan you get with SET enable_memoize = 0; Greetings, Andres Freund