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 1w8LbZ-000Rcu-2E for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Apr 2026 17:13:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w8LbY-0077tp-1W for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Apr 2026 17:13:16 +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 1w8JN2-006UZN-2i for pgsql-bugs@lists.postgresql.org; Thu, 02 Apr 2026 14:50:09 +0000 Received: from mail-switzerlandnorthazon11020127.outbound.protection.outlook.com ([52.101.186.127] helo=ZRAP278CU002.outbound.protection.outlook.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w8JN0-00000000DTC-1Blr for pgsql-bugs@lists.postgresql.org; Thu, 02 Apr 2026 14:50:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GbE/Wwn3XXofSq8U/l2ARDidCoWQ5Ky2vL/YTOR36iZyNgajAvVVEilsSnZ2Z+uqNXqdcZ3Dsq2K1CERt5QcnmM13p/JasRJ2aTiZq1I9AkDRdIchZx/wmbNeug5HF2fUvUuUjt8dLsy62jrW9+u+OnuNnaDEKh3RncoEht4nrqxynBlXMEjEwOsw1qrKULd7whem9SpREp/oatNeRQI3W1h3AZOcU98lkh6BllgwL6ZHbUb95o2aGYqDOfI8bo3/Tw+WT5GFNaWnkHAcD63kJLF+2qxsp/HB3wlUVup3HudUIPbjya2xu81Duj22UwfAPfpGgdZy4lMBpYtWp57gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9p4UbHj7ahdIAMh09KwRHM0O4ATdEQn1uWEeX9jHiTk=; b=bv6zcJznacvDQclMs6N0P+7UemXO8ZtJysaYjzIqvc7s6jvdlqpu5pLnJyERcOwm5mw6M0mjfXlVsk12I66mTxD5AKDy5/nRxu/Unq43bq+U415VvuVKTH3c/grbZNZkM3cdNnxzQp6y8UEIGB5PlDeqxdE3ML84u2OyeGi2l9Gs24EuSe5XFw+4Dhrs5T7zHVnvJvOEpDilHvbdjaMSlaOBhzjH/V60GUn5ouzUiim9NQZjG6wdlnESNTw/QO+fPlhf8C1FM8OzT0OMKJvwjzxeXwWWk1JE6iKUDxIqlCP2bvQiyX47LcbndAHTZvXOJpLtKxqQraE+am02nGnsOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 51.103.219.121) smtp.rcpttodomain=anarazel.de smtp.mailfrom=cern.ch; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=cern.ch; dkim=pass (signature was verified) header.d=cern.ch; arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cern.ch; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9p4UbHj7ahdIAMh09KwRHM0O4ATdEQn1uWEeX9jHiTk=; b=UkKZhx9rBV8qiS+k5G+KX5OqVrluCvGbzBJuRn/LZ8ekmbY2ShPMv/Re0HqWJGZuydsVfatxDaJBYQx0i69CAeZMCg6s6YDZh5qFxyji+h3sBFL98rav5DNCNjWxzftt0TmuR1bYi/H1U9XhB4wv7yyPqlXve+hEBFBL5edXlb4= Received: from CWLP265CA0407.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1b6::20) by ZRZP278MB1937.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:ba::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.17; Thu, 2 Apr 2026 14:50:02 +0000 Received: from AM3PEPF0000A795.eurprd04.prod.outlook.com (2603:10a6:400:1b6:cafe::17) by CWLP265CA0407.outlook.office365.com (2603:10a6:400:1b6::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9745.31 via Frontend Transport; Thu, 2 Apr 2026 14:50:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 51.103.219.121) smtp.mailfrom=cern.ch; dkim=pass (signature was verified) header.d=cern.ch;dmarc=pass action=none header.from=cern.ch; Received-SPF: Pass (protection.outlook.com: domain of cern.ch designates 51.103.219.121 as permitted sender) receiver=protection.outlook.com; client-ip=51.103.219.121; helo=mx1.crn.activeguard.cloud; pr=C Received: from mx1.crn.activeguard.cloud (51.103.219.121) by AM3PEPF0000A795.mail.protection.outlook.com (10.167.16.100) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9745.21 via Frontend Transport; Thu, 2 Apr 2026 14:50:02 +0000 Authentication-Results-Original: auth.opendkim.xorlab.com; dkim=pass (1024-bit key; unprotected) header.d=cern.ch header.i=@cern.ch header.a=rsa-sha256 header.s=selector1 header.b=UkKZhx9r Received: from ZR1P278CU001.outbound.protection.outlook.com (mail-switzerlandnorthazlp17012050.outbound.protection.outlook.com [40.93.85.50]) by mx1.crn.activeguard.cloud (Postfix) with ESMTPS id 28B05FC062; Thu, 02 Apr 2026 16:50:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cern.ch; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9p4UbHj7ahdIAMh09KwRHM0O4ATdEQn1uWEeX9jHiTk=; b=UkKZhx9rBV8qiS+k5G+KX5OqVrluCvGbzBJuRn/LZ8ekmbY2ShPMv/Re0HqWJGZuydsVfatxDaJBYQx0i69CAeZMCg6s6YDZh5qFxyji+h3sBFL98rav5DNCNjWxzftt0TmuR1bYi/H1U9XhB4wv7yyPqlXve+hEBFBL5edXlb4= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cern.ch; Received: from GV0P278MB1846.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:6e::20) by ZR4P278MB2080.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:b5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.28; Thu, 2 Apr 2026 14:49:59 +0000 Received: from GV0P278MB1846.CHEP278.PROD.OUTLOOK.COM ([fe80::9e44:b100:363f:ed86]) by GV0P278MB1846.CHEP278.PROD.OUTLOOK.COM ([fe80::9e44:b100:363f:ed86%3]) with mapi id 15.20.9769.016; Thu, 2 Apr 2026 14:49:59 +0000 Date: Thu, 2 Apr 2026 16:49:57 +0200 From: =?iso-8859-1?Q?Adrian_M=F6nnich?= Message-ID: <94712944.20260402164957@cern.ch> To: Andres Freund CC: pgsql-bugs@lists.postgresql.org, Tomas Vondra , Thomas Munro Subject: Re: BUG #19449: Massive performance degradation for complex query on Postgres 16+ (few seconds -> multiple hours) In-Reply-To: References: <19449-4fac687c06cc7def@postgresql.org> <43225458.20260402160627@cern.ch> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: GV0P278CA0047.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:29::16) To GV0P278MB1846.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:6e::20) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: GV0P278MB1846:EE_|ZR4P278MB2080:EE_|AM3PEPF0000A795:EE_|ZRZP278MB1937:EE_ X-MS-Office365-Filtering-Correlation-Id: da471490-461d-4c58-7f2d-08de90c71ec4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0;ARA:13230040|366016|1800799024|19092799006|786006|376014|13003099007|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info-Original: WYFCR358Y6+pjo8T2SPN1lZXjl1Ayy25V4k7dXCGRyVEGXQvfzy7+kC5rFd+p7fNBydeZ3XtwdLIiZ2alqp4WiwgbKIml4iav4SAd76G46lH6XeipCjPb1qjOBbsxikl7G+ov7RQTjzYmUn5t7G1NHIQP88X5V7oSqMI3Mrj+M+9MWfvr8lQvQELwz1BGdUXIXEbSpJI+eCF+6x/gKeIufFGBC/v6pQ+rZGVi5sdZq0URjMGszOI73lv8DJ7PwFghLIlCCYCxHtJRGWjLACuuAiglLNOwvHyW6Z+Q3Atf4WoZfsqWdrHQLC2XJXXekEUjEZRWn39NF/s4Mhe/dQGmGLswSeZ7muuy9xcaw3AZ3oMpGV602jbQtPBr7CjSiO0YjCw2MTJVlfF4dRIp5Xe7n1O3LQnaG3+jTvikXSgxerfZkk+S9NzKDjDf90Alzxk4aWW187RfHKhgLwNYod9kuVSLz2V2dqAXsj7BlE2nxp/lHWNadMEOjgpTZsFLUxOs25dbQkQxrRBjk6Z4F/8oxbGrK49FsZ3didJUWwHNXcE7IxKKjKyoDTOKTQdj62qGqAxwb3Hcucw7/WT3f/ewt/LSP/fkDym/mZjnXCVccKJWvXkltMS0zVLZA8dWCGUwBik6YGomp8AAnTl0Pu82sFyxK+/hzksMyUWAuYT8tor7naTBw4bIB3c+q6f9cvL X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:GV0P278MB1846.CHEP278.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(19092799006)(786006)(376014)(13003099007)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-Exchange-RoutingPolicyChecked: jEyw5XvML/SUrxFZFHUVjoSaRcQNa1jywaXZKck+E5a07ORDVymB9xqomS26272ncYWKdLYsmgp/p6Q1PKMzVzdLu5UUHoYfw3NPXaof53y962BkpkcItqCvQBtp8HBOGOtv+FbEIxAcjt8URVcQ3oGbCPMdCZqnzOwT/WzoPgf59FU7Zckgt1Bj0iuDQ9oUmVmDWnBK8xqRztm5VYRCNsM3bZP7OG417xRTbiqlvid8MDb3mFC5ggMo8zLHR7IiCZnmK506C8E0oz0OhtHIw0zHvlvsggiy9ZpLe8WdAVLyg7IvntwQSLOZl4S+XmmU6hX5zEACuXwRhJYd0B1tYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: ZR4P278MB2080 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM3PEPF0000A795.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c92c669c-7e12-47c8-c537-08de90c71ce0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|19092799006|14060799003|786006|35042699022|36860700016|82310400026|376014|13003099007|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: ntbzHQMLDHmeDKKP6e8IKNGfxblUQVf7I0C8NMf+ZJGUoq0rQ+7/6sd6DEjB1dKE+pn3WsfpFOC/4Dxk+b3PZnbV2ZY7Qti039kMKv32+U9WynKpf896mUXIW4nGjjrPothhEzjzBWjqspuaKCLxDGTV8RQXrKkWAmz1HJ5R8gicA1aB870bLDmkksZDsNvmzxiztLEEAtpIulMyyFtBtKe/eiS4BCCGfmXIL4cFekxWrWTg3e4yzsMo44tdRw/7cDZeUCx+44tSXiTPj9VsTieDGLhggdwzwP58OBWX4SaV2ubMaE6nS6bfXTWq2bTzKwTgCAlX3yvOSxjEqRUoqUs21FFZkFGj6eev4ofRI6xEAxRdsKJRsZB8LKJa/bcgjeMm2CW2REYCF6Hb+N+GakPnLKZ36U9jpQmADkukQCuzdvme2D4SERdLq+8rp4gpjsrFmjVjDkLbtpgxaEi9eyi6/jbg0E+HHhA4izDc6HyVvnH9InK8mNLfYwn9PuvU+3moNRWPikS1YqPhCchCgorxtzj8HhuAFT2od9HWcn9eIjJLef3ki9MMoKPrI4gotRsvngYLv8yVIQfMjy7tdmdFvjfv2szCF3rw2kb+MiF4hhr/UUUP7yvRvyzG3N95q1P9F9vzIYzH/g2LPIUTDVXx646mG84OA3RcMmX5LhrGfiE9kR9OahDLLyOK7jG3O9hNXu6JIYJN0UuwVM3lYXZ8M1yQ+60Neuz2U1VD2Zs= X-Forefront-Antispam-Report: CIP:51.103.219.121;CTRY:CH;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:mx1.crn.activeguard.cloud;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(19092799006)(14060799003)(786006)(35042699022)(36860700016)(82310400026)(376014)(13003099007)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9nLvmL/8g/gRw5bLgRKogf2xUj+7jKZa82en6dKDQ4wkd91bZ6UHuhzEOaRTKOScP/yj2JbeBojn7+gqOlidmthLLz4ctneOyN+Sj9Eogef3WtW1mesdC9n6YLzM6oQbtXpyyzYdM2oQIYGGyaT0OP2nE4J7Ly8QPqsCF/BsRKMfbkYSYwg5UHY6r3hkcJfeblbCRE5aWF5JTG/Mgmr6PD2WVTnxg4D40wU6WRTl144wMmID16zLjdzDVhitmghBTjIBRE3cMB1fkQXrP0uDoeIi0rHClTFvqfuqoBXWHQ/glUi/s43pGXoXzGrh+F0eTEjTdt1J+eKXxq9qNB3f55j0Phkt78fdVBxTbtb1E/zPkPOi1Kt79Wwpr6PtP9EajBcD58AcslBn2pH4c0A4uwg+uG91oFGacMgcE543WLlX+x7fXIB2Ji9J8YEFHScz X-OriginatorOrg: cern.ch X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2026 14:50:02.1449 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da471490-461d-4c58-7f2d-08de90c71ec4 X-MS-Exchange-CrossTenant-Id: c80d3499-4a40-4a8c-986e-abce017d6b19 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=c80d3499-4a40-4a8c-986e-abce017d6b19;Ip=[51.103.219.121];Helo=[mx1.crn.activeguard.cloud] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF0000A795.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: ZRZP278MB1937 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Indeed, good catch. I was generating the test data from an older prod data = copy and not a more recent one. In any case, the performance was fine on that sa= me copy on 14/15 and got bad on 16. I just re-ran it with a larger database (and also replaced the gzipped SQL = file from my initial message with the latest one). PG14: https://explain.depesz.com/s/ysdJ PG16, 4M: massive cpu + disk usage and thus aborted after a few seconds PG16, 32M: https://explain.depesz.com/s/mYiY Cheers, Adrian > Hi, > On 2026-04-02 16:06:27 +0200, Adrian M=F6nnich wrote: >> thanks a lot, I just tried with work_mem set to 128MB on PG16 and it wor= ked fine: >> https://explain.depesz.com/s/7Zan >>=20 >> Likewise on PG18: >> https://explain.depesz.com/s/H15B >>=20 >> And with enable_memoize=3D0 (PG18, 128MB): >> https://explain.depesz.com/s/SaVI > That's good. >> So increasing work_mem seems like a good workaround for when we upgrade >> our production DB. But I guess there's still a but somewhere that result= s to the >> wrong estimate? > I don't even know if it's a misestimate that didn't happen in the earlier > versions - the join order is different in 14 than it's in the later ones.= I > don't know why that is at this point. > This means that we don't know if 14 would have had the same misestimation= if > the same join order had been chosen. > There also seem to be some data differences: > 14: https://explain.depesz.com/s/17Fp#source > -> Parallel Seq Scan on contributions contributions_1=20 > (cost=3D0.00..164891.13 rows=3D2687413 width=3D5) (actual time=3D0.013..4= 54.721 rows=3D2143186 loops=3D3) > 16: https://explain.depesz.com/s/7Zan > -> Parallel Seq Scan on contributions contributions_1=20 > (cost=3D0.00..37776.28 rows=3D1643228 width=3D5) (actual time=3D0.081..78= .499 rows=3D1314582.00 loops=3D3) > That's a pretty substantial difference in the number of rows. > Greetings, > Andres Freund