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 1tvEdo-002dkZ-LZ for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 12:04:52 +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 1tvEdn-0008QP-9k for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 12:04:51 +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 1tvEdm-0008QE-QO for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 12:04:50 +0000 Received: from forward501a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:d501]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tvEdk-0007yK-12 for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 12:04:50 +0000 Received: from mail-nwsmtp-smtp-production-main-67.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-67.vla.yp-c.yandex.net [IPv6:2a02:6b8:c0d:4d14:0:640:55f0:0]) by forward501a.mail.yandex.net (Yandex) with ESMTPS id 3860F6124E; Thu, 20 Mar 2025 15:04:46 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-67.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id h4JR921LhOs0-xtu0vGjq; Thu, 20 Mar 2025 15:04:45 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tantorlabs.com; s=mail; t=1742472285; bh=NJiwdbWYhi2vLNrhefyZZccN9It8+Dl15p9SekX8Ez8=; h=In-Reply-To:Cc:Date:References:To:Subject:Message-ID:From; b=r1Qy5u2Gi79Bi6QeJ206OR62NLv3cwO5SnfxeFzpRUC68LJ7eXHzFNYT3YrZapiti N0wjzRCM5Qsj85e+1XZy9TVhSM+ihezCDptp2NCP0TIk0JpUNsPKc5PgOjk2zK2ekI gFPIAkPwlMShxFLN2gK0zDp5vLuy/WuOjXMyCTtA= Authentication-Results: mail-nwsmtp-smtp-production-main-67.vla.yp-c.yandex.net; dkim=pass header.i=@tantorlabs.com Content-Type: multipart/alternative; boundary="------------9KLaFY4bPPBBBlzeaAIO0C6d" Message-ID: Date: Thu, 20 Mar 2025 15:04:43 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment To: David Rowley Cc: Lukas Fittl , Daniel Gustafsson , PostgreSQL Hackers References: <51A15CD7-E31B-483D-B911-D0EB9F5FF952@yesql.se> Content-Language: en-US From: Ilia Evdokimov In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------9KLaFY4bPPBBBlzeaAIO0C6d Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 20.03.2025 13:37, David Rowley wrote: > est_entries is a uint32, so %u is the correct format character for that type. > > I don't think you need to prefix all these properties with "Cache" > just because the other two properties have that prefix. I also don't > think the names you've chosen really reflect the meaning. How about > something like: "Estimated Distinct Lookup Keys: 721 Estimated > Capacity: 655", in that order. I think maybe having that as one line > for format=text is better than 2 lines. The EXPLAIN output is already > often taking up more lines in v18 than in v17, would be good to not > make that even worse unnecessarily. LGTM > I see the existing code there could use ExplainPropertyText rather > than have a special case for text and non-text formats. That's likely > my fault. If we're touching this code, then we should probably tidy > that up. Do you want to create a precursor fixup patch for that? I fully agree with this suggestion. Then I'll begin with this on another new thread. > + double ndistinct; /* Estimated number of distinct memoization keys, > + * used for cache size evaluation. Kept for EXPLAIN */ > > Maybe this field in MemoizePath needs a better name. How about > "est_unique_keys"? and also do the rename in struct Memoize. LGTM > I'm also slightly concerned about making struct Memoize bigger. I had > issues with a performance regression [1] for 908a96861 when increasing > the WindowAgg struct size last year and the only way I found to make > it go away was to shuffle the fields around so that the struct size > didn't increase. I think we'll need to see a benchmark of a query that > hits Memoize quite hard with a small cache size to see if the > performance decreases as a result of adding the ndistinct field. It's > unfortunate that we'll not have the luxury of squeezing this double > into padding if we do see a slowdown. I tried rearranging the fields in the structure with 'ndistinct' field, but unfortunately, sizeof(Memoize) did not remain the same. Therefore, benchmarking Memoize is definitely necessary. Thanks for the information! -- Best regards, Ilia Evdokimov, Tantor Labs LLC. --------------9KLaFY4bPPBBBlzeaAIO0C6d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit


On 20.03.2025 13:37, David Rowley wrote:
est_entries is a uint32, so %u is the correct format character for that type.

I don't think you need to prefix all these properties with "Cache"
just because the other two properties have that prefix. I also don't
think the names you've chosen really reflect the meaning. How about
something like: "Estimated Distinct Lookup Keys: 721  Estimated
Capacity: 655", in that order. I think maybe having that as one line
for format=text is better than 2 lines. The EXPLAIN output is already
often taking up more lines in v18 than in v17, would be good to not
make that even worse unnecessarily.


LGTM

I see the existing code there could use ExplainPropertyText rather
than have a special case for text and non-text formats. That's likely
my fault. If we're touching this code, then we should probably tidy
that up. Do you want to create a precursor fixup patch for that?


I fully agree with this suggestion. Then I'll begin with this on another new thread.

+ double ndistinct; /* Estimated number of distinct memoization keys,
+ * used for cache size evaluation. Kept for EXPLAIN */

Maybe this field in MemoizePath needs a better name. How about
"est_unique_keys"? and also do the rename in struct Memoize.


LGTM

I'm also slightly concerned about making struct Memoize bigger. I had
issues with a performance regression [1] for 908a96861 when increasing
the WindowAgg struct size last year and the only way I found to make
it go away was to shuffle the fields around so that the struct size
didn't increase. I think we'll need to see a benchmark of a query that
hits Memoize quite hard with a small cache size to see if the
performance decreases as a result of adding the ndistinct field. It's
unfortunate that we'll not have the luxury of squeezing this double
into padding if we do see a slowdown.


I tried rearranging the fields in the structure with 'ndistinct' field, but unfortunately, sizeof(Memoize) did not remain the same. Therefore, benchmarking Memoize is definitely necessary. Thanks for the information!

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

--------------9KLaFY4bPPBBBlzeaAIO0C6d--