Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZTyu-0000Oc-UP for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Mar 2023 09:51:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pZTyt-00048K-Qk for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Mar 2023 09:51:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZTyt-00048B-Gj for pgsql-hackers@lists.postgresql.org; Tue, 07 Mar 2023 09:51:39 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pZTyr-0003Lg-9Z for pgsql-hackers@lists.postgresql.org; Tue, 07 Mar 2023 09:51:39 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-17638494edbso14456648fac.10 for ; Tue, 07 Mar 2023 01:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678182696; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9v2OOO8LYiY/s2a96uSXNQnj/xTsrKklAFEhE54hxXc=; b=QMqD4TbmN76IbbcSqbxmKxy/DLJqw/hAYLxTWkzvHKIOsBMOmnfCpgMTXGbtDJLnem EZxm1NgFKPkCbcwTWd2rBHcVFKmEWcxCHaMhRzqE9FRWyWx6r2W7YkdLfZbpVsteC/Ih H8OqnN2nnbvZqBTQmjOZiMJ+Wiri28tZAvKUoDnt/o3+E8ptS/iB2VoQl8u8m3behLdT 8zQp52IM9sXlb+K0bL5FzXy+vXiIDAXzuE5oVCEapaxuJ8acl12CiWpgAHEy92BFDaKx k1VV6kXxZmpKzPv9sF3y5o86N+UYy/ZhAOqyfqsQ7smjnCici/soGc5NHK0SB8NP6aWo BksA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678182696; h=content-transfer-encoding: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=9v2OOO8LYiY/s2a96uSXNQnj/xTsrKklAFEhE54hxXc=; b=z87r10FxH0+5XXBoHLIFv7uTFt4LWPQyAgUXrnKy48vlTTiErnyGTC20DlPRk6yj3z GbJU0LvFbYQu/oze3rwvSUth3xxESHPQsu2gFCJHCTnMQ9ip3rnRpAIb0qaWRGt1tA52 +DVBYtykLcFah4R6X5lAAWjpcmsm9PSkaofCgoaqG0L7k81qjVyncAKYVsJeZG3LvbXw ocrdvAqgOtPFKTmlby/YSF21SUtKOZU+JQwTkW6z7lSZAPy8FgjsoPWkoTQFZ8WUEOst XOmx8yAZXzCYXGGDYmz333QyM+7/P/HZloxkhDDUOJXrAwrDY8tUKzr6qd/0nVmII0VU EuXg== X-Gm-Message-State: AO0yUKX0YxR1IFDh3t6g3AkHYThI0P5J0CBn9L8TDWnSjV/5tXx9+7UG Y4Hire94rHeaZim/8atYFOLkcFGoD7ttVQVYrHCa7ZKbkLQ= X-Google-Smtp-Source: AK7set81Z70h9qVKOF4gTEQVeINsm9nYSCHZuSNCHM2lUNPWy6FBo8x6RMMiUfbJ9s+xouwnWqwxGwBqW5/OUuOdwDY= X-Received: by 2002:a05:6871:6ba2:b0:16e:29f3:df9b with SMTP id zh34-20020a0568716ba200b0016e29f3df9bmr4908961oab.0.1678182695955; Tue, 07 Mar 2023 01:51:35 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Tue, 7 Mar 2023 22:51:20 +1300 Message-ID: Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment To: Lukas Fittl Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 5 Mar 2023 at 13:21, Lukas Fittl wrote: > Alternatively (or in addition) we could consider showing the "ndistinct" = value that is calculated in cost_memoize_rescan - since that's the most sig= nificant contributor to the cache hit ratio (and you can influence that dir= ectly by improving the ndistinct statistics). I think the ndistinct estimate plus the est_entries together would be useful. I think showing just the hit ratio number might often just raise too many questions about how that's calculated. To calculate the hit ratio we need to estimate the number of entries that can be kept in the cache at once and also the number of input rows and the number of distinct values. We can see the input rows by looking at the outer side of the join in EXPLAIN, but we've no idea about the ndistinct or how many items the planner thought could be kept in the cache at once. The plan node already has est_entries, so it should just be a matter of storing the ndistinct estimate in the Path and putting it into the Plan node so the executor has access to it during EXPLAIN. David