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 1twSgO-00EnJp-W1 for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Mar 2025 21:16:37 +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 1twSgN-005jdz-C7 for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Mar 2025 21:16:35 +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 1twSgN-005jdn-2U for pgsql-hackers@lists.postgresql.org; Sun, 23 Mar 2025 21:16:35 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1twSgL-000jsA-1l for pgsql-hackers@lists.postgresql.org; Sun, 23 Mar 2025 21:16:34 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-549b12ad16eso4003096e87.0 for ; Sun, 23 Mar 2025 14:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742764592; x=1743369392; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=GOpMLYWwGS0B5sjUzCGQpCqBlBz5jg2quXwDEMK1af4=; b=gi+pTiiH0DWcreGACOHLFFxQgVVCZtS7PzGWNdtyM0n2OV3yICL8QPL2QE1M8NQfg4 OJz1tYtqq0uY4db/rWQ7O9dj4VWI3nFtR11tou/khmpLLIwSlpGx9EQsAtR/9JxgvLic vUETjW2puE0R/6AXQN1X6U1sbhBgjGUwEJJhs9cR5FpnYPzNYGiLXOXJ8AKG90xDCSbf Oc3BNXzy6U0uXWqqbJzt7K06T4Ppb/tInlafA9K//gdEfnm6UX2DV5ohtImNE1iUCq8B Zq8fyGWx0Q9J1HGIaSgf+jlQ7DQCuXS4lWY2X5SgxB6IE/m1uPn1aPq/bFWnJOecBCka Q/OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742764592; x=1743369392; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GOpMLYWwGS0B5sjUzCGQpCqBlBz5jg2quXwDEMK1af4=; b=mjK0uDWWBdNkmGI57FlOBlSgnXUwQST489RjofaS6FWbYlx0HtIre3AiPeiNN5XeED mYxGDGZYZCAuU82qBTpSbHGjwJqkoLfFgT6hATYlFYAtt39A0LU8gbJjCVDdMk3txZi1 m6lglYdSFXybRzcWk8InFmLzjBdLMC+V/62GkpIzuxgOdb3OGgpuNHyfIJlJdQ5HCA66 KREV1JnNHhSmULYWd4Fgs78U6Xk9z0TfZuqkrHmsbCgvpc+aBFK7qci7Sm6PhdvIYed0 furxpm53gKIedum/TaCRItjA6fNwiRIGzDMt376yKDLW32+UNbViQoILML6DNj1IRLsD oidg== X-Forwarded-Encrypted: i=1; AJvYcCUU14AcdVVzbLRasHF+4DqZFnTbAkkTpYTXSrnNnz/0m2pNx5ZKe6pNMSZDUaeXUF4WkbaSfZVqn+PR6QA+@lists.postgresql.org X-Gm-Message-State: AOJu0YwyllCg09Pf8pB3a7L87UB0T49kGlM/m6ex9sq2HNfDFT8staD7 3Sx9GYVYwxM4Dagb+eFzVYwyb1W6FJbTN63/yIVKEc2TPqepf2d8aQLndcpZj9wBnbiY99iyXVo 1TatRuJuBb6iDNyH24q2QvqXhVjM= X-Gm-Gg: ASbGncuHkn2mWnx0YDmdVy3HtFeFBK47z+niHXyiAsqp/tpXRvmS5aV0reFtA3+f/pw Uk7pBlsXLuCHa57uqDHja3FBXL0iaxzLaygK97Ip+ZoyQ8Q1xwyX9rFqzKDBavytnSrApeJ9L73 ImtdYqE5VHlXyp3dR4t3RpF4wTcQ== X-Google-Smtp-Source: AGHT+IEnvdJyIIe5Y1ed+CRbsVSyk1dwpmS+jhS+XB7tvcC1W3aCMVHq2vN0vb7VojuOR2xpJHP4rcLKbBYLvAVKVdg= X-Received: by 2002:a05:6512:6c7:b0:54a:cc11:b55f with SMTP id 2adb3069b0e04-54ad649cb0bmr3110440e87.22.1742764591244; Sun, 23 Mar 2025 14:16:31 -0700 (PDT) MIME-Version: 1.0 References: <51A15CD7-E31B-483D-B911-D0EB9F5FF952@yesql.se> <44229379-3901-4cb0-8812-b354ef70d5e2@gmail.com> <8e12aa55-39eb-4e03-a8f7-077fe02309c3@gmail.com> In-Reply-To: From: David Rowley Date: Mon, 24 Mar 2025 10:16:18 +1300 X-Gm-Features: AQ5f1JoMA65ZahA4uAiHFhcqnY1Sqv040GhiXoVe7bOfs3ie0jKXSONB6Vx_HPA Message-ID: Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment To: Andrei Lepikhov Cc: Ilia Evdokimov , Lukas Fittl , Daniel Gustafsson , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 21 Mar 2025 at 22:02, Andrei Lepikhov wrote: > In cases > I have seen before, the main question is how effective was (or maybe) a > Memoize node == how often the incoming key fits the cache. In that case, > the hit ratio fraction is more understandable for a broad audience. > That's why according to my experience in case of a good cache > reusability factor, users are usually okay with increasing the cache > size to the necessary numbers and avoiding evictions at all costs. So, > the predicted evict_ratio also tells us about incrementing work_mem to > enhance the chances of Memoisation. 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. 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. > Having written the last sentence I came back to the point why work_mem > is so universal and is used at each node as a criteria of memory > allocation size? But it is a different story, I think. We have to set the limit somehow. We could have done this by having a GUC per node type that uses memory, but it looks like something more universal was decided, perhaps to save on GUCs. I don't know the exact history, but once upon a time, sort_mem existed. Perhaps that disappeared because we grew more node types that needed to allocate large, otherwise unbounded amounts of memory. We did more recently grow a hash_mem_multiplier GUC, so it's not true to say that work_mem solely controls the limits of each node's memory allocation sizes. David