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 1w8QcU-000WRx-2Y for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Apr 2026 22:34:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w8QcS-008VNR-1J for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Apr 2026 22:34:32 +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.96) (envelope-from ) id 1w8QcS-008VNH-0A for pgsql-bugs@lists.postgresql.org; Thu, 02 Apr 2026 22:34:32 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w8QcQ-00000000G0y-0ekS for pgsql-bugs@lists.postgresql.org; Thu, 02 Apr 2026 22:34:31 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 9D5143EBC4; Thu, 2 Apr 2026 22:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1775169267; 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=dcJFwuMq7M8hfmWEXnBK3W3E8NC9xVR0wdbr57NBpIc=; b=QRmvIaQGt9vkV1mP3HqwYZyVD6ZsUtdwiac6K/YtCka3mu/jov6Rj9lFbgYxUJ5Yl5HraI 7ifL+kbjexqj9YBOiuqOiCDKDCoL6qc1nJHe+VU2Yga36foP8B5wHOwyeOYOTLjQy/LILf DRpLT6ZpyawI1iJv//pz5IvaIPBFVbiFgfEY1fgKYl110z3PzDvjwoeXvt1fmJ7IA8x1br 7w/M3uAgik2ZFNj2SQZrbuYB00Qv8QxOMpJRe5eiyf17MfYRDDdSZxNCiZOyREDL9WbEQY 9rgcN2KpnnA7WTn9DTDYs37wBsaUDXdED3Lvu3Vlv+4bqAfVDLhlCK7mlXkziA== Message-ID: Date: Fri, 3 Apr 2026 00:34:25 +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) From: Tomas Vondra To: =?UTF-8?Q?Adrian_M=C3=B6nnich?= , Andres Freund Cc: pgsql-bugs@lists.postgresql.org, Tomas Vondra , Thomas Munro References: <19449-4fac687c06cc7def@postgresql.org> <43225458.20260402160627@cern.ch> <94712944.20260402164957@cern.ch> <2747373b-d188-43b1-8e49-66f9e23e3c24@vondra.me> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-Sasl: tomas@vondra.me X-GND-State: clean X-GND-Score: -100 X-GND-Cause: dmFkZTGcA2vVE6awgU3Ce2Me4mwUHHU/5SCbzrZ+GVGP6D2x8Iy/f9iZkcOilLwYFolBoYjEcaa0jDgCgduty7gZAVzn/S6l+HLD6EC1U38t774B3v/gvjv4BPMdgilFtUKoRZZ80GVseU/2o8wXr+XhKsZ8rQqaPd0aLa/q91BuY2Ck+JIifWafW2im8esl8PmmYcmaguuEAvskWJx5Sx3LkEbEVZLk4+95WnB5YtUPSgzRlr/mlBsT0TuEIXJSobPjQVJK7AqdEfiny9+ip1n8lS/JpIXYY3wf1V6uXx1cJdI1XjjEpBXbC/JkZUn9IYnX/xK1TqH66d3EGsiNr6Ae+Z1JbRxglK3Wp2K17FiAKXPFtLdI1BjpsFuJRBCshxLW/zdMsTr0yE6S0QALM+hh/lp6ox/PGiICLAbjkM2axb4VqsKWOOe4m3rrnnz6DJWf4rrcAai9EGBfElSy9kvfowwlZ1HrKMa+76tMs2D8v5tj1BQ4raHoQJyU4daE66ogzXZy+P4cGSolPiZgnQhFB9Qq55aUtwyj1tOuyRjt4hJGVgGw5+7hT/Z9TgA85ssZvhKRi4kW7z4sEorJgqbW6iofitxQi2vpiP5p+mof7pag8WtWEus/bEHH5w6SSxFaSMe4IoLRDWPOMNlCRnxMAQdpaGwna8WdV3DOmCpNfyecwQ List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/2/26 21:00, Tomas Vondra wrote: > ... > FWIW I think that's what's happening. If I add an elog(WARNING) into > ExecParallelHashJoinSetUpBatches, I see this: > > WARNING: 0x55dbe375a5e8 initializing 16 batches > WARNING: 0x7f3868a3a978 initializing 32 batches > WARNING: 0x7f3868a3ab80 initializing 4 batches > WARNING: 0x55dbe36148c0 initializing 4 batches > WARNING: 0x7f3868a3b230 initializing 16 batches > WARNING: 0x7f3868a3a978 initializing 64 batches > WARNING: 0x55dbe36144b0 initializing 128 batches > WARNING: 0x55dbe36144b0 initializing 256 batches > WARNING: 0x55dbe36144b0 initializing 512 batches > WARNING: 0x55dbe36144b0 initializing 1024 batches > WARNING: 0x7f3868a3a978 initializing 2048 batches > WARNING: 0x7f3868a3a978 initializing 4096 batches > WARNING: 0x55dbe36144b0 initializing 8192 batches > WARNING: 0x55dbe36144b0 initializing 16384 batches > WARNING: 0x55dbe36144b0 initializing 32768 batches > WARNING: 0x7f3868a3a978 initializing 65536 batches > WARNING: 0x55dbe36144b0 initializing 131072 batches > WARNING: 0x7f3868a3a978 initializing 262144 batches > > so we're ending with 256k batches, for this one join. I'm not sure how > exactly this maps to the 2M files from pg_stat_database, but it means > ~0.5M tuplestores and ~10GB virtual memory (at lest per top). > > I don't know what triggers the batch increase, but I still suspect it's > similar to the explosion we fixed (or mitigated) in PG18, but only for > serial (non-parallel) joins. > An interesting question is "What changed in PG16?" causing the query to fail, when it worked OK on earlier versions. I guess the main suspect is this item from release notes Allow parallelization of FULL and internal right OUTER hash joins So I guess it might be interesting to flip the joins to inner, see if it still fails like that, and then see if that crashes on PG15 too. Although the query has only inner and left outer joins, which seems unrelated to the change. It might be simply a consequence of the planner picking a different join tree (due to some general optimizer changes). It might be interesting to try forcing the same join tree (which might be possible with join_collapse_limit=1) on PG15. Maybe it'll crash the same way? Maybe it'd be easier to try reducing the query first, before doing any of this. Start removing the joins one by one from the "top" (per the explain), until it stops failing. That might leave a much smaller query. regards -- Tomas Vondra