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 1udkPR-00CYLv-0A for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jul 2025 06:54:01 +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 1udkPP-00EUXZ-MW for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jul 2025 06:53:59 +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 1udkPP-00EUXR-DC for pgsql-hackers@lists.postgresql.org; Mon, 21 Jul 2025 06:53:59 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1udkPN-008OSM-1I for pgsql-hackers@lists.postgresql.org; Mon, 21 Jul 2025 06:53:58 +0000 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-311e2cc157bso3333572a91.2 for ; Sun, 20 Jul 2025 23:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753080836; x=1753685636; 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=h1OgbDrNSk7jql+yoYqMv6gSjHE7xI7BAcvSs4AezL0=; b=hdTPx2mVmrGJhKXpSwTLOgTBFu/pF+r7b3Zm8ZiQ6e7+VdhsOAIveMvu6Tb+NZ+WYM yPUTSAnsIniN2U7Mi/62JDOxMZ+82cDojODTDEiOrRGcPyGH3MR2dxJ92VY0Fak4ZhwM 172JHMLcTqtFKUWy2EHnCd5wtWJ1t3iMdsMMAB9WzgV9RQooZOEC4gKtxIAK9nrodRYr CBmbsPy2qoOPoeXdrW1dMYQJ91i42ag3Bv0Hbgi/BnbnD2ulM3oc24EVzpgF00O3BykH 4YaKtUOa7Fp0eQPfv8hFHSaUms2xVvYEiXi26rvOJlW6c6qNRTtHbDI4A3wTVsA8isGm frJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753080836; x=1753685636; 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=h1OgbDrNSk7jql+yoYqMv6gSjHE7xI7BAcvSs4AezL0=; b=ndYzMV1PoIVEtG5QEd77WwluZ4/MHGizpjTJhT+cNYeljthBx20fImkwZiaFlWr9+y Rpl52kVqKntiQjeFXsHAtgxvK9913UXQQpNkqIorIaBfodWc5dbrGDcXZlMvMZGVYN7s Rh5Ubb2EG5Yss1aaEqnewFh75MD/LlVEZ4Z6fvMQy97KwUmJYz+z4++hzA/lY48SHSIW m8hfw0+AEazi6ZfbXsxNi8lhcuP6Qc6Dnk7UhJZsfomJNgV7t4OdI5S82heH/j5fqRKR m5I1r4vo8dTNHLt6c/4XTLDWRQXY4s/pumRG0enY/c7xo9qzOIF+zyfzjJ7GX83uNwAj gtnA== X-Forwarded-Encrypted: i=1; AJvYcCUknzBBNAJnxS1xig3YrMXLCt+h1S7YSKXPxIloMKhDkYnumfwGOx78RNchiE8m1T52K1WVJe9GB7F1W/Mo@lists.postgresql.org X-Gm-Message-State: AOJu0YzE5hjM3QN2B1Pr72SB42Qi2SOBwJHXofqUSr+mGRkh/zWTqIET Y54lSF7WbZl0XlYdF0loxnNyAzF9vfEl230zzNkV7fWvxMeSsL7GWnooqTvJX5cgKC1CaESiCtR 0PoqnUzbXdpUPQmRZzg6slYsYivOED+k= X-Gm-Gg: ASbGncspZxJU++IsrL3WjHfP5Ria6Zp4c7efIKGQDUJ6iO+E2QyZ8tVgJnzkWSmVqhr reSRGtyL9dFMOCQ2CJmns1+a4Qr55vDu8LJ9BW1bKpNz8Fg0HPSVoRvOhKiUEAlGpEtmqiyekdQ /2t9ZIwGYBCkeq9qS3sZD/fZQe9cfFmOs2h69p6MDUdOm+Y39nzzW5FlG7KRLlKJ99mgy1rzLdE aDDbqnVqXdRVAdv4Y63 X-Google-Smtp-Source: AGHT+IFEBAQUtjej2NSxjz9ncCKZhtJHn80i3RDU8XWrrZ4ynTpxRp5RjGNj21MY0eVbWzxhtkLxToH+8Jq9pOkIJx4= X-Received: by 2002:a17:90b:3d8c:b0:316:3972:b9d0 with SMTP id 98e67ed59e1d1-31c9e5fcacfmr28998322a91.0.1753080836480; Sun, 20 Jul 2025 23:53:56 -0700 (PDT) MIME-Version: 1.0 References: <57d0e292-73d5-4ab9-9855-110ee9cbd90a@vondra.me> <32c15a30-6e25-4f6d-9191-76a19482c556@vondra.me> <64c8b824-6203-46a3-b045-5e95b796feee@vondra.me> <03dcc1a9-c5d0-4965-889c-684dc0a7580c@vondra.me> <23f490f4-8325-408c-91a0-a6757ab2441c@vondra.me> In-Reply-To: From: Nazir Bilal Yavuz Date: Mon, 21 Jul 2025 09:53:45 +0300 X-Gm-Features: Ac12FXwRBMNUIMHDRSG9TfRpGsBSdgUjAp9zCLeQPht5kTOmG1PGLWfAVcC4HLg Message-ID: Subject: Re: index prefetching To: Thomas Munro Cc: Tomas Vondra , Peter Geoghegan , Andres Freund , Robert Haas , Melanie Plageman , PostgreSQL Hackers , Georgios , Konstantin Knizhnik , Dilip Kumar 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 Hi, On Mon, 21 Jul 2025 at 03:59, Thomas Munro wrote: > > On Sun, Jul 20, 2025 at 1:07=E2=80=AFAM Thomas Munro wrote: > > On Sat, Jul 19, 2025 at 11:23=E2=80=AFPM Tomas Vondra = wrote: > > > The thing that however concerns me is that what I observed was not th= e > > > distance getting reset to 1, and then ramping up. Which should happen > > > pretty quickly, thanks to the doubling. In my experiments it *never* > > > ramped up again, it stayed at 1. I still don't quite understand why. > > > > Huh. Will look into that on Monday. > > I suspect that it might be working as designed, but suffering from a > bit of a weakness in the distance control algorithm, which I described > in another thread[1]. In short, the simple minded algorithm that > doubles on miss and subtracts one on hit can get stuck alternating > between 1 and 2 if you hit certain patterns. Bilal pinged me off-list > to say that he'd repro'd something like your test case and that's what > seemed to be happening, anyway? I will dig out my experimental > patches that tried different adjustments to escape from that state.... I used Tomas Vondra's test [1]. I tracked how many times StartReadBuffersImpl() functions return true (IO is needed) and false (IO is not needed, cache hit). It returns true ~%6 times on both simple and complex patches (~116000 times true, ~1900000 times false on both patches). A complex patch ramps up to ~250 distance at the start of the stream and %6 is enough to stay at distance. Actually, it is enough to ramp up more but it seems the max distance is about ~270 so it stays there. On the other hand, a simple patch doesn't ramp up at the start of the stream and %6 is not enough to ramp up. It is always like distance is 1 and IO needed, so multiplying the distance by 2 -> distance =3D 2 but then the next block is cached, so decreasing the distance by 1 and distance is 1 again. [1] https://www.postgresql.org/message-id/aa46af80-5219-47e6-a7d0-762810696= 5a6%40vondra.me --=20 Regards, Nazir Bilal Yavuz Microsoft