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 1u989W-00FnnZ-5i for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Apr 2025 19:59:03 +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 1u989T-00AUti-Rz for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Apr 2025 19:59:00 +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 1u989T-00AUtZ-0j for pgsql-hackers@lists.postgresql.org; Sun, 27 Apr 2025 19:59:00 +0000 Received: from forward502d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:d502]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u989Q-002NL4-16 for pgsql-hackers@lists.postgresql.org; Sun, 27 Apr 2025 19:58:59 +0000 Received: from mail-nwsmtp-smtp-production-main-94.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-94.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:e2ca:0:640:d17d:0]) by forward502d.mail.yandex.net (Yandex) with ESMTPS id 5BA0160E28; Sun, 27 Apr 2025 22:58:55 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-94.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id qwZMeZaLdSw0-5wO6Hrs7; Sun, 27 Apr 2025 22:58:54 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tantorlabs.com; s=mail; t=1745783934; bh=7sueJ6I9zOuQpNQNDi8CuGc3WtBCtD0NsvnTj6L/iSI=; h=In-Reply-To:Cc:Date:References:To:Subject:Message-ID:From; b=y690h2A7iJcB1LsMZn2KUhequke9wU9oQwaV8DBKSdjUzmItMmjjF0x6y1S+kzeQj y5w4YxODF5fUl+ExfEIronQDy+jWOESrCp+TsjnwplHAEEz/Z5d0mwjtMsVF1EIQWC 3Ji1+CpksMef4319zM2E9PBNu+WGsokt/B6H9FG0= Authentication-Results: mail-nwsmtp-smtp-production-main-94.klg.yp-c.yandex.net; dkim=pass header.i=@tantorlabs.com Content-Type: multipart/alternative; boundary="------------nzmYHhivehr40JZ7DBcoZu0F" Message-ID: <06840539-e321-4930-9f89-cfc783c5b80a@tantorlabs.com> Date: Sun, 27 Apr 2025 22:58:52 +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: Robert Haas , Tom Lane , Lukas Fittl , Daniel Gustafsson , PostgreSQL Hackers , Nikolay Samokhvalov , Andrei Lepikhov References: <1164845.1742856354@sss.pgh.pa.us> <3ba16aa7-3cb2-4289-b773-522ae2f03a77@tantorlabs.com> <81ef0f5a-b6a1-4417-ae3a-2bae9b8d419e@gmail.com> <67b5c84a-dedd-4103-af7e-0117046102fe@tantorlabs.com> <580fe72c-85be-45a8-9e00-6b5417690557@tantorlabs.com> <3ea66a50-e4b0-4f20-ae0c-4d9cbaf81cfb@tantorlabs.com> <0e8dc4fa-3655-4e9f-9424-9b32a15e6acd@tantorlabs.com> <7e995158-157e-4ec6-a7c8-266c1a6f7b43@tantorlabs.com> 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. --------------nzmYHhivehr40JZ7DBcoZu0F Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sorry for the delayed reply. On 18.04.2025 00:29, David Rowley wrote: > I know I did suggest that the hit_ratio should be a percent and it > should be multiplied by 100.0. This seems fine for the text format as > you can have the % unit there. However, looking at > ExplainPropertyFloat(), we don't print the unit for non-text formats. > I wonder if printing a number between 0 and 100 there will be > confusing. I don't believe we have anything else in EXPLAIN that shows > a percentage. I don't quite know what to do about this. One thought I > had was to only * 100 for text format, but that might be more > confusing. I agree that displaying the percentage instead of the fraction is a better choice, because it is much more convenient for analysis. If this value were intended to be passed into some API for further computations, it would make sense to keep it as a fraction to avoid unnecessary multiplications and divisions by 100. However, such use cases seem extremely unlikely. Therefore, I think it is better to report percentages directly. Since non-text EXPLAIN formats do not display units, I propose to rename the field to "hit_percent" in all formats, including the text format. This way, the meaning of the value remains clear without needing additional context. What do you think about this approach? > > Aside from that, I'd prefer the new fields in struct Memoize to be > prefixed with "est_" the same as the existing "est_entries" field. I'm > unsure why MemoizePath.calls becomes Memoize.lookups. Seems > unnecessary and just means more brain space being used to maintain a > mental model. Agree. -- Best regards, Ilia Evdokimov, Tantor Labs LLC. --------------nzmYHhivehr40JZ7DBcoZu0F Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Sorry for the delayed reply.


On 18.04.2025 00:29, David Rowley wrote:
I know I did suggest that the hit_ratio should be a percent and it
should be multiplied by 100.0.  This seems fine for the text format as
you can have the % unit there. However, looking at
ExplainPropertyFloat(), we don't print the unit for non-text formats.
I wonder if printing a number between 0 and 100 there will be
confusing. I don't believe we have anything else in EXPLAIN that shows
a percentage. I don't quite know what to do about this. One thought I
had was to only * 100 for text format, but that might be more
confusing.


I agree that displaying the percentage instead of the fraction is a better choice, because it is much more convenient for analysis. If this value were intended to be passed into some API for further computations, it would make sense to keep it as a fraction to avoid unnecessary multiplications and divisions by 100. However, such use cases seem extremely unlikely.

Therefore, I think it is better to report percentages directly. Since non-text EXPLAIN formats do not display units, I propose to rename the field to "hit_percent" in all formats, including the text format. This way, the meaning of the value remains clear without needing additional context. What do you think about this approach?



Aside from that, I'd prefer the new fields in struct Memoize to be
prefixed with "est_" the same as the existing "est_entries" field. I'm
unsure why MemoizePath.calls becomes Memoize.lookups. Seems
unnecessary and just means more brain space being used to maintain a
mental model.


Agree.

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

--------------nzmYHhivehr40JZ7DBcoZu0F--