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 1txkED-00E3BD-8p for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Mar 2025 10:12:49 +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 1txkEB-003OSj-MV for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Mar 2025 10:12:47 +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 1txkEB-003OSD-5m for pgsql-hackers@lists.postgresql.org; Thu, 27 Mar 2025 10:12:47 +0000 Received: from forward501b.mail.yandex.net ([178.154.239.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1txkE8-001UiJ-0E for pgsql-hackers@lists.postgresql.org; Thu, 27 Mar 2025 10:12:46 +0000 Received: from mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:bb95:0:640:3bde:0]) by forward501b.mail.yandex.net (Yandex) with ESMTPS id D0C5B617BD; Thu, 27 Mar 2025 13:12:42 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id cCOw7r6Lha60-vPYzZejj; Thu, 27 Mar 2025 13:12:41 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tantorlabs.com; s=mail; t=1743070362; bh=Cc0jFes2EGw28ylWgSJnGHIM4i6ydCO9DbfPyfRk2K4=; h=In-Reply-To:Cc:Date:References:To:Subject:Message-ID:From; b=aBxBceKrrYjPR0GjXUl+BJKWsslSDSKhD+nPYG+B4klI4CyB5om+HxLlLrSFIzrxF QBKZPh+Io9Jr58ZLePzO921n82zygMJ4tTWyI+g8cuxF5FJ5Tx/7ZVdKCr/RpUYSOP SbIUc+plPMTZV0GAVCw/wiJyEqa66WRzXDPZsHQI= Authentication-Results: mail-nwsmtp-smtp-production-main-85.iva.yp-c.yandex.net; dkim=pass header.i=@tantorlabs.com Content-Type: multipart/alternative; boundary="------------d6LPkMVx280kVySqMgBoRUOF" Message-ID: <3ba16aa7-3cb2-4289-b773-522ae2f03a77@tantorlabs.com> Date: Thu, 27 Mar 2025 13:12:38 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment To: Robert Haas , Tom Lane Cc: Lukas Fittl , David Rowley , Andrei Lepikhov , Daniel Gustafsson , PostgreSQL Hackers , Nikolay Samokhvalov References: <51A15CD7-E31B-483D-B911-D0EB9F5FF952@yesql.se> <44229379-3901-4cb0-8812-b354ef70d5e2@gmail.com> <8e12aa55-39eb-4e03-a8f7-077fe02309c3@gmail.com> <11c709e1-9b17-4c00-9ead-93609a09b9db@gmail.com> <1161645.1742854534@sss.pgh.pa.us> <1164845.1742856354@sss.pgh.pa.us> 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. --------------d6LPkMVx280kVySqMgBoRUOF Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 26.03.2025 22:37, Robert Haas wrote: > I also don't think that we should be too concerned about bloating the > EXPLAIN output in the context of a patch that only affects Memoize. > Memoize nodes are not incredibly common in the query plans that I see, > so even if we added another line or three to the output for each one, > I don't think that would create major problems. On the other hand, > maybe there's an argument that what this patch touches is only the tip > of the iceberg, and that we're eventually going to want the same kinds > of things for Nested Loop and Hash Joins and Merge Joins, and maybe > even more detail that can be displayed in say 3 lines. In that case, > there's a double concern. On the one hand, that really would make the > output a whole lot more verbose, and on the other hand, it might > generate a fair amount of work to maintain it across future planner > changes. I can see deciding to reject changes of that sort on the > grounds that we're not prepared to maintain it, or deciding to gate it > behind a new option on the grounds that it is so verbose that even > people who say EXPLAIN VERBOSE are going to be sad if they get all > that crap by default. I'm not saying that we SHOULD make those > decisions -- I think exposing more detail here could be pretty useful > to people trying to solve query plan problems, including me, so I hope > we don't just kick that idea straight to the curb without due thought > -- but I would understand them. > > The part I'm least sure about with respect to the proposed patch is > the actual stuff being displayed. I don't have the experience to know > whether it's useful for tracking down issues. If it's not, then I > agree we shouldn't display it. If it is, then I'm tentatively in favor > of showing it in standard EXPLAIN, possibly only with VERBOSE, with > the caveats from the previous paragraph: if more-common node types are > also going to have a bunch of stuff like this, then we need to think > more carefully. If Memoize is exceptional in needing additional > information displayed, then I think it's fine. > > -- > Robert Haas > EDB:http://www.enterprisedb.com I understand the concerns raised about the risk of opening the door to more diagnostic detail across various plan nodes. However, in Hash Join, Merge Join, and Nested Loop, EXPLAIN typically reveals at least some of the planner’s expectations. For example, Hash Join shows the number of batches and originally expected buckets, giving insight into whether the hash table fit in memory. Merge Join shows unexpected Sort nodes when presorted inputs were assumed. Nested Loop reflects planner assumptions via loops and row estimates. In other words, these nodes expose at least some information about what the planner thought would happen. Memoize is unique in that it shows runtime statistics (hits, misses, evictions), but reveals nothing about the planner’s expectations. We don’t see how many distinct keys were estimated or how many entries the planner thought would fit in memory. This makes it very difficult to understand whether Memoize was a good choice or not, or how to fix it when it performs poorly. -- Best regards, Ilia Evdokimov, Tantor Labs LLC. --------------d6LPkMVx280kVySqMgBoRUOF Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 26.03.2025 22:37, Robert Haas wrote:
I also don't think that we should be too concerned about bloating the
EXPLAIN output in the context of a patch that only affects Memoize.
Memoize nodes are not incredibly common in the query plans that I see,
so even if we added another line or three to the output for each one,
I don't think that would create major problems. On the other hand,
maybe there's an argument that what this patch touches is only the tip
of the iceberg, and that we're eventually going to want the same kinds
of things for Nested Loop and Hash Joins and Merge Joins, and maybe
even more detail that can be displayed in say 3 lines. In that case,
there's a double concern. On the one hand, that really would make the
output a whole lot more verbose, and on the other hand, it might
generate a fair amount of work to maintain it across future planner
changes. I can see deciding to reject changes of that sort on the
grounds that we're not prepared to maintain it, or deciding to gate it
behind a new option on the grounds that it is so verbose that even
people who say EXPLAIN VERBOSE are going to be sad if they get all
that crap by default. I'm not saying that we SHOULD make those
decisions -- I think exposing more detail here could be pretty useful
to people trying to solve query plan problems, including me, so I hope
we don't just kick that idea straight to the curb without due thought
-- but I would understand them.

The part I'm least sure about with respect to the proposed patch is
the actual stuff being displayed. I don't have the experience to know
whether it's useful for tracking down issues. If it's not, then I
agree we shouldn't display it. If it is, then I'm tentatively in favor
of showing it in standard EXPLAIN, possibly only with VERBOSE, with
the caveats from the previous paragraph: if more-common node types are
also going to have a bunch of stuff like this, then we need to think
more carefully. If Memoize is exceptional in needing additional
information displayed, then I think it's fine.

--
Robert Haas
EDB: http://www.enterprisedb.com


I understand the concerns raised about the risk of opening the door to more diagnostic detail across various plan nodes. However, in Hash Join, Merge Join, and Nested Loop, EXPLAIN typically reveals at least some of the planner’s expectations. For example, Hash Join shows the number of batches and originally expected buckets, giving insight into whether the hash table fit in memory. Merge Join shows unexpected Sort nodes when presorted inputs were assumed. Nested Loop reflects planner assumptions via loops and row estimates. In other words, these nodes expose at least some information about what the planner thought would happen.

Memoize is unique in that it shows runtime statistics (hits, misses, evictions), but reveals nothing about the planner’s expectations. We don’t see how many distinct keys were estimated or how many entries the planner thought would fit in memory. This makes it very difficult to understand whether Memoize was a good choice or not, or how to fix it when it performs poorly.

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

--------------d6LPkMVx280kVySqMgBoRUOF--