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.98.2) (envelope-from ) id 1x8GIe-000000014R5-45K4 for pgsql-bugs@arkaria.postgresql.org; Sun, 20 Sep 2026 12:05:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x8GId-00000006UFf-1LhM for pgsql-bugs@arkaria.postgresql.org; Sun, 20 Sep 2026 12:05:39 +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.98.2) (envelope-from ) id 1x8GBK-00000006U6U-3wJu for pgsql-bugs@lists.postgresql.org; Sun, 20 Sep 2026 11:58:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x8GBI-00000000KGY-13va for pgsql-bugs@lists.postgresql.org; Sun, 20 Sep 2026 11:58:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=ubRxnUfewmWs5m0/ldhlbDozhvvgHh3wmFUY3BDC7fg=; b=ixCwkybo3MtmiwwGs/jtswsbZu 7ecbNKiQM3brxc36SyMgcn4+J5HVRBc4Ljm2wD7yN8OP4KejgkiAs1iHXLRDeETpZkd+pMmvvJUqd a+L6DCn58t1tYXOguMBfasiVVo2nCMcQi5u4zxrSAl+nw3PatRTxsteKvDu7UYApQajxRM+myO/3v EM9Cn1RAYdCH3mWKJ070r/Ea30qcFmk6+q+TFjlpl1/FrBO8+tYQ+9bzSvLPd97TZpb4RVGHgQw+O qGCiIYiRePC5EFWNAln4jyMQIu+jVch+jSVbyVcmmJNGff4XhFTp0Wn1Oe7l6QScFmhLP0jbo9qSp RfKN9JRA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x8GBH-000zW4-2v for pgsql-bugs@lists.postgresql.org; Sun, 20 Sep 2026 11:58:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x8GBG-00000002ntN-1NMl for pgsql-bugs@lists.postgresql.org; Sun, 20 Sep 2026 11:58:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19708: Hash Join becomes about 300x slower with higher work_mem To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: yanarnold5@gmail.com Reply-To: yanarnold5@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sun, 20 Sep 2026 11:57:37 +0000 Message-ID: <19708-bca71f8de0d45605@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19708 Logged by: iany Email address: yanarnold5@gmail.com PostgreSQL version: 18.6 Operating system: Ubuntu 22.04 Description: =20 Reproduced on PostgreSQL master 20devel, commit 9e17d25e79d4756be08b4a5521b4b58450217137. Source build used --without-readline --without-zlib. Reproducer (run with psql -X): CREATE TABLE a(); INSERT INTO a DEFAULT VALUES; SET enable_mergejoin =3D off; SET work_mem =3D '64kB'; EXPLAIN (ANALYZE, TIMING OFF, SUMMARY ON) WITH x AS ( SELECT g FROM a a1, a a2, generate_series(1,768) g ) SELECT l.g FROM x l JOIN x r USING (g); SET work_mem =3D '16MB'; EXPLAIN (ANALYZE, TIMING OFF, SUMMARY ON) WITH x AS ( SELECT g FROM a a1, a a2, generate_series(1,768) g ) SELECT l.g FROM x l JOIN x r USING (g); Observed runtimes on master: work_mem runtime 64kB 0.0248s 256kB 0.1290s 1MB 6.8825s 16MB 7.8372s All executions returned the same 768 rows. Increasing work_mem from 64kB to 16MB made the query approximately 315x slower. Could you please confirm whether this degree of slowdown as work_mem increases is expected for the same Hash Join and cardinality estimate? At 1MB, EXPLAIN ANALYZE reported 4,194,304 original/final hash buckets and 4,096 original/final hash batches. This appears related to the earlier "Fix overflow of nbatch" discussion.[https://www.postgresql.org/message-id/244dc6c1-3b3d-4de2-b3de-b= 1511e6a6d10%40vondra.me] That discussion noted that initial nbatch can increase with work_mem but considered it probably harmless because runtime batching could compensate. Runtime batch growth does not occur in this case.