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 1wDRps-002zSJ-11 for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Apr 2026 18:53:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDRpr-006ers-0q for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Apr 2026 18:53:07 +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 1wDRpq-006erk-30 for pgsql-bugs@lists.postgresql.org; Thu, 16 Apr 2026 18:53:06 +0000 Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDRpn-00000001S3Y-1dxH for pgsql-bugs@lists.postgresql.org; Thu, 16 Apr 2026 18:53:06 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 387EB3ED70; Thu, 16 Apr 2026 18:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1776365577; 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=NGYz4tYJ16/lc11U9ZOIjPpUaZz8OTNtoSFBqXNZ2T4=; b=giVv5kYII9r0sFDXOxzerPkTdXT2tZnycHBscw3jUYz18nUg/QGitkIubGx15DV7QJmdNk T2fXHXQlBXG5lyt+aM3h2zoOQZaYA4TcS1qZQ0I81d1bLe5Lt7q25dL2GAmcGGjGaHGBRG 3PYcJFBfrVgf9vJ/42BqjNxSTEbwRf3psHMO62T0vtIDQ3z77VTdx38ZSp5JfMCJJriqyU Z3DNTk+hZRCScPzNm9FC6f3a+n4wfKZu+VY6lrUs3XVAKfO09zcl0nN7yfmDuvIj0Ycycy zwLnkebBYhVYp9INuTmUtDbiwl41WPVoWXPwEJWPxOnL1GNv58B3JHStG2VBqw== Message-ID: <298af5cb-5547-4c95-b988-7be0617b17b5@vondra.me> Date: Thu, 16 Apr 2026 20:52:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19449: Massive performance degradation for complex query on Postgres 16+ (few seconds -> multiple hours) To: Thomas Munro Cc: Tom Lane , =?UTF-8?Q?Adrian_M=C3=B6nnich?= , Andres Freund , pgsql-bugs@lists.postgresql.org, Tomas Vondra References: <19449-4fac687c06cc7def@postgresql.org> <43225458.20260402160627@cern.ch> <94712944.20260402164957@cern.ch> <2747373b-d188-43b1-8e49-66f9e23e3c24@vondra.me> <3675338.1775169816@sss.pgh.pa.us> <9f6b7a6d-62db-4a63-9fb7-5deee702a24f@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 X-GND-Cause: dmFkZTEu+p5aewzFRc3GKWnQlRn83B0AOkSaT+ebnPCAwQRv5edxIUFm6sFYiIDZR5EM3DWcV4AwV+spyQImh3s/oN5iehMrcHT0xICO+2N78m59IqGKU29CiJl1uYW1x7rz1PXdumoKpZm2PNQyj7+W7OkZ16sbrA0EerI5l5Pcmeq0xaEomDafgm3ODaRnZB70eGUb6cXy3Hbz6xVV1Aa2HJFQoIomq8Gxyexb8fuV+OPHZ8oBSh0ULy7BpGuSNPBQdArXFKRRKAOSvo6siJXctnVzFYqL3URqlejX6pipTiUc68/f0aLbapfexha3Y4tcXYSPZRyQU8y1XnPQLUMzyy4aIcT8C6KGEecJJxPcQwzjoZuuhELTEOADH1bOU9GM62K2Jk1OtqFg9EELBDD20fNRU78srgvvGqI+UnUqRAi2EYnI5XGKnoyPiVByfQ3Bis4c+NoZw2iVsIiI7Wl9SyvpFxM2if3cebuObJ/WGhpO0NhLS/plLZZkje6DseeTz0AJ0++eObyT2WHd7gYvFoHFxc8BfRRM10ZyOc/hvnOELX1LX9/z3XZZT2XbOozXp7qHZ/nwwNRX6Pp6afZgLCSdKFlhil5/NBh0LMMn8mRnluN1wfiVrwA/xzk5V4xD/jv4+B4auHvV6UHzBxaGKtSGrGoDUTywjmMazNBWuPOkmw X-GND-State: clean X-GND-Score: -100 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/16/26 07:25, Thomas Munro wrote: > On Sun, Apr 5, 2026 at 2:45 AM Tomas Vondra wrote: >> At this point I was suspecting the data distributions for the join >> columns may be somewhat weird, causing issues for the hashjoin batching. >> For events.contributions.id it's perfectly fine - it's entirely unique, >> with each ID having 1 entry. Unsurprisingly, because it's the PK. But >> for attachments.folders.contribution_id I see this: >> >> SELECT contribution_id, count(*) FROM attachments.folders >> GROUP BY contribution_id ORDER BY 2 DESC; >> >> contribution_id | count >> -----------------+-------- >> | 464515 >> 5492978 | 67 >> 4117499 | 42 >> 4045045 | 41 >> ... >> >> So there's ~500k entries with NULL, that can't possibly match to >> anything (right)? I assume we still add them to the hash, though. > > That's also the conditions required to prevent the > "stop-partitioning-it's-not-working" logic from triggering. That > thing where we know we need to pick a better lower than 100%. But > what? > > Did this commit help? > > commit 1811f1af98fb237fdd5adb588cd4b57c433b75f8 > Author: Tom Lane > Date: Thu Mar 19 15:21:36 2026 -0400 > > Improve hash join's handling of tuples with null join keys. Possibly. With the original (simplified) query, I get no failures with current master. And it starts failing after I revert 1811f1af98. With the alternative queries (with IS NOT NULL), it seems to work OK even after the revert. So maybe the queries are not failing for the same reason? regards -- Tomas Vondra