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 1u4nEJ-007OTF-KB for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Apr 2025 20:50: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 1u4nEH-00GnLF-IT for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Apr 2025 20:50:02 +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 1u4nEH-00GnL7-7Q for pgsql-hackers@lists.postgresql.org; Tue, 15 Apr 2025 20:50:02 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u4nEG-000Fpq-02 for pgsql-hackers@lists.postgresql.org; Tue, 15 Apr 2025 20:50:01 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-54b0d638e86so7002094e87.1 for ; Tue, 15 Apr 2025 13:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744750199; x=1745354999; darn=lists.postgresql.org; 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=4XcmZgU1+RSpB04IDJVOUKXYvlM0RVGrEaTnNiXblzk=; b=EJIi/YHXPvuE2a30U8IVedouzAjOe1HPE5LO1vOZC8hqgXS4ElpICQ9y54GQcWVLnL X8pEedPaFHItKFFONXSg2Vax98d82rZJPprP9agpbuVp5FWRzkxzIM0yGmbfLjuAQhUh 8nnH37P6ISsRhCnW1EFN776lrkDAdv09LpnNj5ST/AU+mCc5fVn0n0uVWtGxU0RfqwAn tVjwtoMEDxc5cEpmEI4+mhvtwAX44StWIHG3ujFloeCf5aQufDqD67m2nW69pge0EFBV emVz5fXSzfz8zbBJYb8i0ImegSmj29I72zrsoUz8eo7/u2Yu8LcGXy2CsgBIN8rDKHmP Q4QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744750199; x=1745354999; 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=4XcmZgU1+RSpB04IDJVOUKXYvlM0RVGrEaTnNiXblzk=; b=NZljJXV7yHXiMXiJbrb+Bo5HUabiVm232BjGVhX4wTFby6QTFdrpAZoq6yBGuRp8hc VUzU5Um5CHJ/dcsDg37i8a0XVJBGBrge6EbaguoofR+xQpju3SJ/8dg+p3C8jATOyQtA 5Y2unT9hgOQQwE+ue2N7VIZSQHlA008GKlZRVuD14cVpzM6sTHu6SKIdI6LbtBAFOA/T qDhnKxYyp8u3mDEasGUbyWI8LhHgyohnUAgpJPXR8HQ77KOEBAGpqGL670hJmMmdBB0A 0R2vwGscsuaVlJVg98GXCBFt20beVCKv/+iSbs25JkdzJ0VzyK/e/QWANPh9XUyNab84 RC+g== X-Forwarded-Encrypted: i=1; AJvYcCUHedSdspLDXZNbdG+bkY+cskLEqME1H8euZbdF5iR1owmmNyeW7qHpx0qURFzJLbtKKvGF5cWefcmh1v//@lists.postgresql.org X-Gm-Message-State: AOJu0YwHiFpkEkRCRQWGdUsSAV+ATamvHJy4ct0MlkRyw5JTOIzNK8jF a+HnbgFaxvMUvyBpRDOaIZuZwa/7dlN4rY2GiacuEHZZ86O0+e8IzEdPdCHndnk4hxHbZUuWHEZ LITzWcMaHyx2h2LP8EsCF5N3cb+0= X-Gm-Gg: ASbGncvvxLqevicErzXqCcQBsuPVhbrwS69K49PXo24Q3iIko7wSLVZO2zP4Fr1G765 EsS85yGMhbPVIwSGxJPADWuW2oPmdv9bgjD8hNXB6Gl5LphsGk1LdbWQrxS+5V7gNk7rTIIQZwj BM5Qik0O6tcQIdgIsio+et+/jylNwIKPeTK0gh3lire9RL1iQ7TvdUfFqL X-Google-Smtp-Source: AGHT+IF6qki3rOzyvG8vK34S8mWHFnMQKgPdyHg9fY2jT6lEdciGWe/dK2R4E7vRyokxBNjP8vaQhrVXi6DP3X3jBTw= X-Received: by 2002:a05:6512:2305:b0:545:6fa:bf60 with SMTP id 2adb3069b0e04-54d604e37d1mr119299e87.19.1744750198502; Tue, 15 Apr 2025 13:49:58 -0700 (PDT) MIME-Version: 1.0 References: <11c709e1-9b17-4c00-9ead-93609a09b9db@gmail.com> <1161645.1742854534@sss.pgh.pa.us> <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> In-Reply-To: From: David Rowley Date: Wed, 16 Apr 2025 08:49:46 +1200 X-Gm-Features: ATxdqUE2QcFeGfDR0PrZzs7sBEYwJ75Ul0GnG4ing1cSbmfCixXf2fk5SBHA99U Message-ID: Subject: Re: Add estimated hit ratio to Memoize in EXPLAIN to explain cost adjustment To: Robert Haas Cc: Ilia Evdokimov , Tom Lane , Lukas Fittl , Daniel Gustafsson , PostgreSQL Hackers , Nikolay Samokhvalov , Andrei Lepikhov 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 Wed, 16 Apr 2025 at 04:25, Robert Haas wrote: > > On Mon, Apr 14, 2025 at 8:23=E2=80=AFPM David Rowley wrote: > > "Estimates: capacity=3DN distinct keys=3DN lookups=3DN hit ratio=3DN.N%= " > > Is lookups=3DN here the estimated number of lookups i.e. what we think > nloops will end up being? Yes. The estimate is the "calls" variable in cost_memoize_rescan(), which is fairly critical in the hit ratio estimate calculation. Technically this is just the Nested Loop's outer_path->rows. There was an argument earlier in the thread for putting this in along with the other fields to make things easier to read. I did argue that it was redundant due to the fact that the reader can look at the row estimate for the outer side of the Nest Loop, but maybe it's small enough to go in using the above format. David