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.96) (envelope-from ) id 1vsW6f-0052yx-36 for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Feb 2026 01:11:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsW6d-00DRku-2J for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Feb 2026 01:11:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsW6d-00DRkm-0q for pgsql-hackers@lists.postgresql.org; Wed, 18 Feb 2026 01:11:55 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vsW6b-00000001Hjo-0ovu for pgsql-hackers@lists.postgresql.org; Wed, 18 Feb 2026 01:11:55 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-436234ef0f0so3404551f8f.1 for ; Tue, 17 Feb 2026 17:11:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771377110; cv=none; d=google.com; s=arc-20240605; b=XJQtb/cW420wygP5er2S294vzi3yMu9ozTRb+XqIrUXLikPRtf0o5cp4Bh6zzSvuOy UPANICOQpZOkohZniRQeitEIBWLP4dhJkSJYkZNhD5TJVUnznDfnBIXdBqa+3L+PUZ5/ 0MTg1hv3uz3UsIWP6weHhAXGIVkXnOhqFOzN1o5o4AEdlS42Kiw+9qbqRvYr2VNUEnWl NzhBQWh4VrnpI9LIEDYnvgV2f2MdDsiFLPFPmL/iAIGRDBXEun0D96rQnSjFBm63ZLh5 uS8JJeozb2JICTDin8ViISUJu9QN01sMnKkC3NRcTBhgFt/FDSRanLTUql3rV6b8qJcm K4jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=U1eRv9evxyUYc7riuIklndonD9CURmZilU6FwhE8aKQ=; fh=jIjwF125Cq9MBo5k6be6ufkvewUGbBLwaHOBjERGil0=; b=Z0S4WL1YYUWQyFzfh8JUBglQjCEmSyR3VocCmbbKhIBujEemXV/mJx7T6XXF0S5Rnc IdrxstyKKaymcnkYe03zhvHQPhHd85h8FkZQz1aNlJQPK2uLtwEAfAGMHM0DRxdQXHfV eBWQcNOqrI3b4/gkCRk7K2uz+tUy15pHYopTYcYP4XC6HzW2sjYwn9mOWPfqEtVHTQNv pvt0Z9E7eivVEDTNgjCRO3O60x5mqbF385JRII8glX81EghenMEprPWtUhwrbZCrgrVM d9hGT8RbQLwiOl1J6IcB7E/8sLvERFf9WiRwmS1aS5z6gBJ/keWo9xZbiyrl2Dijpz4s jMKw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20230601.gappssmtp.com; s=20230601; t=1771377110; x=1771981910; 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=U1eRv9evxyUYc7riuIklndonD9CURmZilU6FwhE8aKQ=; b=Zh4v2oNqduKNVgrNEjkVyp2ocE9le00SjBqeeAfB3Hombt7ueyzqld7rYjuuIQtgrA KO8rHGYdvc0/plpDHi9qBw1ha3CtiEczUr+whGRHGehIvGpSSlINynCpv5Fnyj2Yqsnw L6rxjlr3DC2A52uzUy7MM0sOqhrsiMHt+508AS7aB0t88jlX1sisSgPASpdVSB2alJRm m1KlrKI+4ZjzyMlbkSOSgU2fWBtGeTLW5Ndf0j8ghQYMdi8HVAW6ybwA0+6htR+4Fo/8 mKpNNJkO1I+MgDtRbVCwor+JngQPlNCBKjqyA1bcZbQR4B+tcP0nucU0SuY7lkCdGF73 dudg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771377110; x=1771981910; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=U1eRv9evxyUYc7riuIklndonD9CURmZilU6FwhE8aKQ=; b=FAzYl06juE4c29ozITjRRpUWeRY07UzHNLoNbcF7vokRdxu0+PaGydUU6XO2m6XUIY 8h5Yz/9xLwtipHHSuDmnCj8H19meshx/k8pkrvitS4tPz9Gvb79lh4rpkwDe+ubPOioU wOtOu5Wu84509ha97bHN8kvCmzQa7aoT8Ug34qjFMPf86Z8KtchbsjcKsO8FDF3geBpB 2VpEJk2vY/lQ1eZ2+w/OhbaVXHNTfoCCxX+AX/6Ew0Cej2AZNazep2dvFMNAztb9nTq5 3iYQ0ZCTQMdHTEpXw5h0QZN4bRzQy7YG6LQK4lQuHWoZ+QDsc0svB93dvs6+Y60kg3yz +Sug== X-Forwarded-Encrypted: i=1; AJvYcCXKBjZB/VuYicb6hfMQLY+9N9dGuZeBgbV/Lh22+0JRVK+DMxsfh0FjaFAKQaINg9syw6htvzvDqGIeXber@lists.postgresql.org X-Gm-Message-State: AOJu0Yzs5CKAZO46Ok2isf4/fGIcTXr82yCbem4iLRWKZD3OrV/MsTCy m+/8MUr5wonpCgIM+z+j1P/Sdgj1MHz+1kvnmmhARsM88MEWb02kHVO5dI8+n7Z1IaYvvX6n/05 qRUhnG0lqrW18GQaXXsggxdCmy5/urQu2fne4XQyL9Q== X-Gm-Gg: AZuq6aJ5EzxBuWIgY4PZc+h3DE2x9d780ZPhWNwklsmQ14g/RedIaPI0jNd92Ae7VoS Fpv3VpUkl+Tw8Y3e6uey7pbZgcv0gsiiAO8pcMIu8Uk+zuRFVa0sJKHnpdwM315c36KxCIAYE4d wKuJNjMYtBJ6IkYNenSksbTmYwqjnx9S3vJuOfMFmBPf/jtDGIpVgGM0/nRQTzWwyh1kV3RicTh dlpHWqoOBLIAl1bMEsBxZxghCyXCXaXcJFT2TwdhmoOBjD8B2xDDGtJ8eeqWtSdV9IAk8FdVO3u LKmUtdo= X-Received: by 2002:a5d:5f53:0:b0:436:3536:f694 with SMTP id ffacd0b85a97d-43958e0e72amr274251f8f.22.1771377110504; Tue, 17 Feb 2026 17:11:50 -0800 (PST) MIME-Version: 1.0 References: <64a2re223ajj4popowsyu4xekbuvvyfwkrihn5yzyrkwsmsuvp@2lls3tpww5dl> <52512325-b1f2-4fff-819e-f68122b2e427@vondra.me> <64mfcfv7iihc4pmqlxarii4esnmqry52ckz5m7lmwylnfnuxuz@oxh4ioxkjtep> In-Reply-To: From: Peter Geoghegan Date: Tue, 17 Feb 2026 20:11:24 -0500 X-Gm-Features: AaiRm50n3oIdDDcGSFIGA66bn-eBRjxApWC9szaB0KLCWpnR8LXMwr4b6BPRxoE Message-ID: Subject: Re: index prefetching To: Andres Freund Cc: Tomas Vondra , Alexandre Felipe , Thomas Munro , Nazir Bilal Yavuz , 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 On Tue, Feb 17, 2026 at 7:31=E2=80=AFPM Andres Freund = wrote: > Interestingly, I can't reproduce a regression compared to index prefetchi= ng > being disabled. > > If I evict just prefetch_customers between runs, I see prefetch + no-yiel= d > being the fastest by a good amount. > > If I evict prefetch_customers as well as prefetch_customers_pkey, yieldin= g > wins, but only just about. Which I guess makes sense, the index reads are > synchronous random reads, and we do more of those if we prefetch too > aggressively. That can't have been a factor when I ran the query (which is pretty obvious from the EXPLAIN ANALYZE output). > I ran the queries both with pgbench (in a script that evicts the buffers,= but > then just looks at the per-statement time for the SELECT, 30 iterations) = and > separately interactively with EXPLAIN ANALYZE to get IO stats. > > > This is with debug_io_direct=3Ddata, were you measuring this without DIO?= If so, > was the data in the page cache or did you evict it from there? I rarely use debug_io_direct=3Ddata for any of my testing. The standard for me is to use buffered IO + io_uring, while prewarming all indexes and evicting all heap relations. And by evicting the OS filesystem cache before each run. FWIW, the version of the patch you're using is slightly different to the one I have here. Since I worked on unrelated issues with things like the cost of rescans with nestloop joins. Another difference is that the memory allocation for the VM cache is now combined with the main batch alloc, which seems to be more cache efficient. And saves us memory for plain index scans. > We really should add a function to pg_prewarm (or pg_buffercache, or ...)= that > evicts pages in a targeted way from the kernel page cache... Flushing the > entire kernel pagecache leads to undesirable noise, because it also evict= s > filesystem metadata (on somefilesystems at least) etc. Yeah, having to flush the kernel page cache has been really inconvenient. > FWIW, I got a crash in a mark-restore query. I think I see the problem: > > /* > * Release all currently loaded batches, being sure to avoid free= ing > * markBatch (unless called with complete, where we're supposed t= o) > */ > for (uint8 i =3D batchringbuf->headBatch; i !=3D batchringbuf->ne= xtBatch; i++) > { > IndexScanBatch batch =3D index_scan_batch(scan, i); > > if (complete || batch !=3D markBatch) > { > markBatchFreed =3D (batch =3D=3D markBatch); > tableam_util_free_batch(scan, batch); > } > } > > if (complete && markBatch !=3D NULL && !markBatchFreed) > { > /* > * We didn't free markBatch because it was no longer load= ed in ring > * buffer. Do so now instead. > */ > tableam_util_free_batch(scan, markBatch); > } > > If, in the loop, there's a batch after the markBatch in the ring, it'll r= eset > markBatchFreed to false. Which then leads to the batch being freed a seco= nd > time. Oops. --=20 Peter Geoghegan