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 1rBlS7-00CHpj-8R for pgsql-performance@arkaria.postgresql.org; Sat, 09 Dec 2023 00:44:19 +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 1rBlS5-00DMZ4-UJ for pgsql-performance@arkaria.postgresql.org; Sat, 09 Dec 2023 00:44:17 +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 1rBlS5-00DMYw-Kd for pgsql-performance@lists.postgresql.org; Sat, 09 Dec 2023 00:44:17 +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.94.2) (envelope-from ) id 1rBlS3-009UdN-6N for pgsql-performance@lists.postgresql.org; Sat, 09 Dec 2023 00:44:16 +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 3B90iDLJ1566071; Fri, 8 Dec 2023 19:44:13 -0500 From: Tom Lane To: Jerry Brenner cc: pgsql-performance@lists.postgresql.org Subject: Re: 2 json explain plans for the same query/plan - why does one have constants while the other has parameter markers? In-reply-to: References: Comments: In-reply-to Jerry Brenner message dated "Fri, 08 Dec 2023 16:23:41 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1566069.1702082653.1@sss.pgh.pa.us> Date: Fri, 08 Dec 2023 19:44:13 -0500 Message-ID: <1566070.1702082653@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jerry Brenner writes: > We are currently on 13. We are capturing the explain plans for query > executions taking 1 second or longer and storing the json files. We are > most of the way through implementing a home grown solution to generate a > consistent hash value for a query plan, so we can find queries with > multiple plans. I've attached 2 query plans that we've captured that > differ in a seemingly strange way. (All executions are from the same exact > code path.) One of the plans has parameter markers in the predicates in > the values for "Recheck Cond" and "Index Cond", while the other does not. > Any insight into why we are seeing parameter markers in the body of the > query plan? The one with parameter markers is a "generic" plan for a parameterized query. When you get a plan without parameter markers for the same input query, that's a "custom" plan in which concrete values of the parameters have been substituted, possibly allowing const-simplification and more accurate rowcount estimates. The backend will generally try custom plans a few times and then try a generic plan to see if that's meaningfully slower -- if not, replanning each time is deemed to be wasteful. regards, tom lane