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.94.2) (envelope-from ) id 1uhZq8-001UEG-Kb for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Jul 2025 20:25:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uhZp8-003Htp-P0 for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Jul 2025 20:24:22 +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.94.2) (envelope-from ) id 1uhZp8-003Hth-H8 for pgsql-bugs@lists.postgresql.org; Thu, 31 Jul 2025 20:24:22 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uhZp6-00053C-01 for pgsql-bugs@lists.postgresql.org; Thu, 31 Jul 2025 20:24:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 56VKOD7O2121300; Thu, 31 Jul 2025 16:24:13 -0400 From: Tom Lane To: Peter Geoghegan cc: Sajith Prabhakar Shetty , Andrei Lepikhov , "pgsql-bugs@lists.postgresql.org" , Todd Cook Subject: Re: Postgres: Queries are too slow after upgrading to PG17 from PG15 In-reply-to: References: <2a8243eb-a8e8-4c2d-9c46-7152782d84f8@gmail.com> Comments: In-reply-to Peter Geoghegan message dated "Wed, 30 Jul 2025 15:16:42 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2121298.1753993453.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 31 Jul 2025 16:24:13 -0400 Message-ID: <2121299.1753993453@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Geoghegan writes: > Perhaps Tom can weigh-in here. I removed code that generated these > alternative index paths from the planner because its original > justification (see bugfix commit a4523c5a, a follow-up to bugfix > commit 807a40c5) no longer applied. Perhaps this should be revisited > now, or perhaps the issue should be ameliorated on the nbtree side. Or > maybe we should just do nothing -- the issue can be worked around in > the application itself. Well, maybe it was a mistake to no longer consider such plans, but this example doesn't prove it. Quoting the submitted readme file, we selected this plan in v15: -> Index Scan using zsf_pkey on zsf sf (cost=3D1.49..1.51 rows=3D1= width=3D24) (actual time=3D0.001..0.001 rows=3D1 loops=3D47089) Index Cond: (id =3D sdo.sfi) Filter: (cid =3D ANY ('{...}'::bigint[])) versus this in v17: -> Index Only Scan using zsf_id_fpi_cid_key on zsf sf (cost=3D0.29= ..0.31 rows=3D1 width=3D24) (actual time=3D0.023..0.023 rows=3D1 loops=3D4= 7089) Index Cond: ((id =3D sdo.sfi) AND (cid =3D ANY ('{...}'::bigin= t[]))) IIUC you're saying the planner no longer even considers the first case --- but if it did, it'd surely still pick the second one, because the estimated cost is a lot less. So undoing that choice would not help the blackduck folks. I do think we should do something about this, though. My suggestion is that we should always presort in the planner if the SAOP argument is a Const array, and then skip the run-time sort if the executor sees the argument is a Const. Yes, there will be cases where the plan-time sort is wasted effort, but not too darn many. An alternative thought is that maybe the run-time sort is expensive enough that the planner ought to account for it in its estimates. However, that's a bit of a research project, and I don't think we'd dare shove it into v17 at this point even if it turns out to fix this particular case. But a pre-sort seems like a pretty safe change. regards, tom lane