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 1twpGX-000SdH-He for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Mar 2025 21:23:25 +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 1twpGW-00AM0Y-0S for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Mar 2025 21:23:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1twpGV-00ALxo-MZ for pgsql-hackers@lists.postgresql.org; Mon, 24 Mar 2025 21:23:23 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1twpGU-000ver-02 for pgsql-hackers@lists.postgresql.org; Mon, 24 Mar 2025 21:23:22 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43cebe06e9eso36717145e9.3 for ; Mon, 24 Mar 2025 14:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742851400; x=1743456200; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=uB2tO6O8EZjv8DaDId9tgvouOsh4WvnUD3M/6kZKlHU=; b=O+TKxqngkIOXuru9n+qv4FbPKY0DgRTcqFrNBtp+yhx7sIaVPjuV6FlTfXq4NVZaGz 3mf7Se1dvaU6VXw7nCk7HmVZ6yh6gkJNWbDivxZkbEUByyplneLkaladp6aGp6QBVPij gVcJCEWg1Whav7ujmrcfsCXP6sVPau4JMXQ9nNIGG/JfOjXc9Bxfd1Jxfxm+gneLAbK4 5/hGj3JSCwMXSrgI7yJX/+F44/fljEMmflY/jAAcgdw4rpLjkhY9pThdDOAyDrVkRp3U T6IOElkQlaYZH8WcJhLDtUWg+ESRwnxPmfcZmemDofFkbu0dwD7Wga5rogzh/b/0n+Ix tVyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742851400; x=1743456200; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uB2tO6O8EZjv8DaDId9tgvouOsh4WvnUD3M/6kZKlHU=; b=P1MbGrfkCSe3Oh4+Zxe5rPyE3atc/huyhXfHaLNp6Zh8b9lB27w8XEyboSsuvgkTL3 zdBfocfkx3gaMQybhB7SYUBbeU4Ra0k5C23INS9kbCTlV0n6kN7t5qKPaNz7fcex/0s4 GZ2Qq/gmSdH7Al9YDXVAlPTwj5OJDS8/QyopePkGQhTHnaMuiO/Az7yCLu+x0oO8KN84 V5Q2CW3ji8D+HM/N3J/w9TA/BzL5+JkSnZ4orJ3fQHitkIH2Gb6zEZHQiN4SxhrKNwtW 5WV9eQ4UAPq8wKRufxFNbyKHIhIc3Sya6lqsNfbCGixKBRFXla/154VoWiF0L2heRzEH pXBw== X-Forwarded-Encrypted: i=1; AJvYcCXAtI0yYLbAgIZ7WTRqE0L8P/b0TbBzJHbjyWsN5aun1XKkZVIkfj4+DiaXO/7IpMfZFd3/4YgAcWotPP8U@lists.postgresql.org X-Gm-Message-State: AOJu0YwLBKuJqG4dXUa4qVTB/MadKqjFCJtqCg7NJoJ3ZSqETDZTdw2z uH37UHZkApJLpu/RUGgiRu+vXPgw6Wrk1INc4WcEjpjl2r9mcxE8 X-Gm-Gg: ASbGncv2Ep2nr+5zEl85rWoRduiYZXXngJTvlirl58tVsHUacPWwDPc4UWW/Y7dvJoV zoQfJP8zp9ADEvfd7mjKgAUs144gLMkbht6S+RZhzPNwB00f0S7HD7ZvhEp5liPOCqoaY+n9x61 BELEbEPKS1K3J+WUVytwATTAeFMJvASkkA/IpR3qGIL/T46+Mr8L8BqfdGCUUHGfA7iR/b3732T 0xbLtgHUUOSr5edZjnRLBbTzDqh6u8TQ06KCY4rdoYcEmJViDKuo1k4gyuaQe8SfcLik3Cbz+Mh iCKRRcwVwxM5+2Qc7gEY7Y6ZUl9tAAEvIYQLT0kypMVjAAtZlyFVsrXWu2/SPj8URyjqC2HMEsq s2Cc= X-Google-Smtp-Source: AGHT+IEGlUm5bErWXeKZ08TNJ9cTB80+KYBmSLNV9ff+JkrsIzrFLqZSiy+Vm1lpqX9VJoRzZ4dQ7w== X-Received: by 2002:a05:600c:35ca:b0:43c:fae1:5151 with SMTP id 5b1f17b1804b1-43d50a4adabmr121251095e9.25.1742851400021; Mon, 24 Mar 2025 14:23:20 -0700 (PDT) Received: from [192.168.0.89] (84.123.232.230.dyn.user.ono.com. [84.123.232.230]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d43fdeba1sm182154865e9.32.2025.03.24.14.23.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Mar 2025 14:23:19 -0700 (PDT) Message-ID: <11c709e1-9b17-4c00-9ead-93609a09b9db@gmail.com> Date: Mon, 24 Mar 2025 22:23:18 +0100 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: Ilia Evdokimov , Lukas Fittl , 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> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/23/25 22:16, David Rowley wrote: > On Fri, 21 Mar 2025 at 22:02, Andrei Lepikhov wrote: > Can you explain why "Estimated Capacity" and "Estimated Distinct > Lookup Keys" don't answer that? If there are more distinct lookup > keys than there is capacity to store them, then some will be evicted. I wouldn't say these parameters don't answer. I try to debate how usable they are. To be more practical, let me demonstrate the example: EXPLAIN (COSTS OFF) SELECT * FROM t1,t2 WHERE t1.x=t2.x; Nested Loop (cost=0.44..7312.65 rows=211330 width=33) -> Seq Scan on t1 (cost=0.00..492.00 rows=30000 width=22) -> Memoize (cost=0.44..3.82 rows=7 width=11) Cache Key: t1.x Cache Mode: logical Estimated Capacity: 1001 Estimated Distinct Lookup Keys: 1001 -> Index Scan using t2_x_idx2 on t2 (cost=0.43..3.81 rows=7) Index Cond: (x = t1.x) At first, I began to look for documentation because it was unclear what both new parameters specifically meant. Okay, there was no documentation but trivial code, and after a short discovery, I realised the meaning. The first fact I see from this EXPLAIN is that Postgres estimates it has enough memory to fit all the entries. Okay, but what does it give me? I may just increase work_mem and provide the query with more memory if needed. My main concern is how frequently this cache is planned to be used. Doing some mental effort, I found the line "rows=30000." Calculating a bit more, I may suppose it means that we have a 95% chance to reuse the cache. Okay, I got it. Now, see: 1. I needed to discover the meaning of the new parameters because they were different from the earlier "hit" and "miss." 2. I need to find a common JOIN for keys of this node. Imagine a typical 200-row EXPLAIN with 2-3 Memoization keys from different tables. 3. I need to make calculations On the opposite, the hit ratio, written instead, already known by analogy, already provides me with necessary cache efficacy data; no need to watch outside the node; it may be easily compared with the actual value. Am I wrong? Both approaches provide the data, but each one is more usable? I think we may ask more people, for example, Nikolay Samokhvalov, who, as I heard, works hard with explains. > > Once again, I'm not necessarily objecting to hit and evict ratios > being shown, I just want to know they're actually useful enough to > show and don't just bloat the EXPLAIN output needlessly. So far your > arguments aren't convincing me that they are. I'm -1 for this redundancy. -- regards, Andrei Lepikhov