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 1uhamN-001fgk-Jm for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Jul 2025 21:25:35 +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 1uhamM-003a7V-Kd for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Jul 2025 21:25:34 +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.94.2) (envelope-from ) id 1uhamM-003a7M-CK for pgsql-bugs@lists.postgresql.org; Thu, 31 Jul 2025 21:25:34 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uhamJ-0004r6-2A for pgsql-bugs@lists.postgresql.org; Thu, 31 Jul 2025 21:25:33 +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 56VLPSba2128452; Thu, 31 Jul 2025 17:25:28 -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> <2121299.1753993453@sss.pgh.pa.us> Comments: In-reply-to Peter Geoghegan message dated "Thu, 31 Jul 2025 17:04:13 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2128450.1753997128.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 31 Jul 2025 17:25:28 -0400 Message-ID: <2128451.1753997128@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Geoghegan writes: > On Thu, Jul 31, 2025 at 4:24 PM Tom Lane wrote: >> 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. > I agree. Cool, will you do the legwork? > Is there a convenient choke point for this in the planner? I'd be inclined to do it as late as possible, in create_plan (so that we don't expend the effort if we don't choose that index path). So in or near fix_indexqual_references is probably a good spot. > I suspect that making this change will have a side-effect: it'll make > EXPLAIN show the array as sorted and deduplicated. That seems like a > minor positive to me, but it's something to consider. Indeed. We can make use of that in test cases, perhaps. >> An alternative thought is that maybe the run-time sort is expensive >> enough that the planner ought to account for it in its estimates. > I tend to doubt that this will ever make much sense. As you say, getting the cost estimates accurate enough is daunting, which is why I called it a research project. regards, tom lane