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 1rBllA-00CIxr-0E for pgsql-performance@arkaria.postgresql.org; Sat, 09 Dec 2023 01:04:00 +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 1rBll8-00DUdE-1j for pgsql-performance@arkaria.postgresql.org; Sat, 09 Dec 2023 01:03:58 +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 1rBll7-00DUd6-O6 for pgsql-performance@lists.postgresql.org; Sat, 09 Dec 2023 01:03:57 +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.94.2) (envelope-from ) id 1rBll5-00AuHW-FB for pgsql-performance@lists.postgresql.org; Sat, 09 Dec 2023 01:03:57 +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 3B913pts1568644; Fri, 8 Dec 2023 20:03:51 -0500 From: Tom Lane To: Jerry Brenner cc: pgsql-performance@lists.postgresql.org, Jim Sinkovic , Danny Lam Subject: Re: Question about semantics of $ variables in json explain plans in 13 In-reply-to: References: Comments: In-reply-to Jerry Brenner message dated "Fri, 08 Dec 2023 15:09:52 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1568642.1702083831.1@sss.pgh.pa.us> Date: Fri, 08 Dec 2023 20:03:51 -0500 Message-ID: <1568643.1702083831@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jerry Brenner writes: > Is there any documentation on the semantics of $ variables in json explain > plans for both InitPlans and SubPlans in 13? I don't think there's anything much in the user-facing docs, which is somewhat unfortunate because it's confusing: the notation is overloaded. $N could be a parameter supplied from outside the query (as in your $1, $2 and $3 in the source text), but it could also be a parameter supplied from an outer query level to a subplan, or it could be the result value of an InitPlan. The numbering of outside-the-query parameters is disjoint from that of the other kind. > - It looks like $0 represents the value from the outer query block when > the correlated subquery is evaluated > - It looks like $1 represents the result of the subquery evaluation Yeah, I think you're right here. $0 evidently corresponds to qRoot.contactID from the outer plan, and the plan label itself shows that $1 carries the sub-select's value back out. This $1 is unrelated to the $1 you wrote in the query text. (It looks like this is a custom plan in which "67" was explicitly substituted for your $3. Presumably $1 and $2 were replaced as well; we don't do half-custom plans.) regards, tom lane