Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHJqm-0000Jv-7l for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jul 2023 07:56:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHJql-00029L-1S for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jul 2023 07:56:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHJqk-000299-On for pgsql-hackers@lists.postgresql.org; Thu, 06 Jul 2023 07:56:26 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qHJqh-002Jj1-Bv for pgsql-hackers@lists.postgresql.org; Thu, 06 Jul 2023 07:56:25 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id 90E472F9A42D for ; Thu, 6 Jul 2023 09:56:19 +0200 (CEST) Received: from s981.loopia.se (unknown [172.22.191.6]) by s807.loopia.se (Postfix) with ESMTP id 81A982E27E90; Thu, 6 Jul 2023 09:56:19 +0200 (CEST) Received: from s476.loopia.se (unknown [172.22.191.5]) by s981.loopia.se (Postfix) with ESMTP id 7F62522B1696; Thu, 6 Jul 2023 09:56:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1 X-Spam-Level: X-Spam-Status: No, score=-1 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1] autolearn=disabled Received: from s899.loopia.se ([172.22.191.5]) by s476.loopia.se (s476.loopia.se [172.22.190.16]) (amavisd-new, port 10024) with LMTP id X8zbAilrPpJA; Thu, 6 Jul 2023 09:56:18 +0200 (CEST) X-Loopia-Auth: user X-Loopia-User: daniel@yesql.se X-Loopia-Originating-IP: 89.255.232.193 Received: from smtpclient.apple (customer-89-255-232-193.stosn.net [89.255.232.193]) (Authenticated sender: daniel@yesql.se) by s899.loopia.se (Postfix) with ESMTPSA id CDF7B2C8BA64; Thu, 6 Jul 2023 09:56:18 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.3\)) Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment From: Daniel Gustafsson In-Reply-To: Date: Thu, 6 Jul 2023 09:56:18 +0200 Cc: PostgreSQL Hackers , David Rowley Content-Transfer-Encoding: quoted-printable Message-Id: <51A15CD7-E31B-483D-B911-D0EB9F5FF952@yesql.se> References: To: Lukas Fittl X-Mailer: Apple Mail (2.3696.120.41.1.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 7 Mar 2023, at 10:51, David Rowley wrote: >=20 > On Sun, 5 Mar 2023 at 13:21, Lukas Fittl wrote: >> Alternatively (or in addition) we could consider showing the = "ndistinct" value that is calculated in cost_memoize_rescan - since = that's the most significant contributor to the cache hit ratio (and you = can influence that directly by improving the ndistinct statistics). >=20 > I think the ndistinct estimate plus the est_entries together would be > useful. I think showing just the hit ratio number might often just > raise too many questions about how that's calculated. To calculate the > hit ratio we need to estimate the number of entries that can be kept > in the cache at once and also the number of input rows and the number > of distinct values. We can see the input rows by looking at the outer > side of the join in EXPLAIN, but we've no idea about the ndistinct or > how many items the planner thought could be kept in the cache at once. >=20 > The plan node already has est_entries, so it should just be a matter > of storing the ndistinct estimate in the Path and putting it into the > Plan node so the executor has access to it during EXPLAIN. Lukas: do you have an updated patch for this commitfest to address = David's comments? -- Daniel Gustafsson