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 1uex7l-00H4N6-C5 for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 14:40:46 +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 1uex7k-008UGN-7S for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 14:40:44 +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 1uex7j-008UGE-Oy for pgsql-hackers@lists.postgresql.org; Thu, 24 Jul 2025 14:40:44 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uex7h-000ZGs-28 for pgsql-hackers@lists.postgresql.org; Thu, 24 Jul 2025 14:40:43 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-451d3f72391so10647595e9.3 for ; Thu, 24 Jul 2025 07:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20230601.gappssmtp.com; s=20230601; t=1753368040; x=1753972840; 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=P0DAwEHBn/BsIiAh49EKv+ZgOjZJgpv0GvRQOEbiOTs=; b=W0FqmNV7gOCi1I+Eeyc+s83L249Jzhqwho2Ss4up+7mpIJz0RpU2bZ1wk2D5thJf/m nIwWzTnxTvJdyCa6W/cYiLa7g9mqZl4XQR72oEXeSFvCPERTxH3bKZCzaqMlQbL/qkzt +Qn5HUbDJtmiCPlBStjWCO97HPsfRVvHCSlnPTaedKr52BLrUG7/Th1gdzqHMct8EvPn CYPn3zn9qxd+v7yFHCkhi5Kgv9S391IVTfsnpdKZpMiEeRdoFsVa3CxFeu0fn3kFrvM0 gcZK8N39la0G5MTLeCw9VVJz3fTjaoJXvLCPtSx77UARyNHGVKoyXefubvp8c4IWG8Vo gTrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753368040; x=1753972840; 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=P0DAwEHBn/BsIiAh49EKv+ZgOjZJgpv0GvRQOEbiOTs=; b=dfj2aa4jj9QuXOMTKP6hPGk48rzX8ZF3RdRwMuhAc9a/n6zq9pkR83OHcTEAWPM/7f So1Mphi33WVYwYFfXe6ioQSMLvqhNrk+13PiLoZZ1u/cknBlTFSu3J/EBmH4k7xaHJ++ rMj+JrD7OZLgstVdjAsAy+RiOjLg2iV0vcf3nTXQwhMvEec1NfW5YxS/49SYuipvuKZW LoUbs3QqL83UaXOdNri8uK6+NXFir7qGTrA0Mt0s07tnPmy85EoJi18FOniMCx/KvVfd UJ/nbg7CGI91mtq3ToIpti0mlXG7QsJlmp9zv4OOLrPCSOl+QWMBxHs/csFFtg98apEV mNGA== X-Forwarded-Encrypted: i=1; AJvYcCVl9hD2ChmIvRq7fIWk14HAN6n45rVJU1ydl6aq+GnQ424xwRKqaaAsH1YGXw5DCSs/Sx4i6chpmpJkKj8w@lists.postgresql.org X-Gm-Message-State: AOJu0YxagXBT711RitJ2slAV//DO8r+GpVsSukNcKFpEvaVaT2K9+pmR lgM3+ut0IUeuMsyL/fp30E3XWSZAZ3m+x9R8SoNhiDrG376j5Vbd67+ACbbtt5MxTRGl/TvseOY 7tvwlaRJ1f6rtutGakwtAWHfl4tWH9eCA3bfGYOlMBA== X-Gm-Gg: ASbGncvORtZSBVoHcgQO8qmsVqM4r1dYIc3QzgmFCwd66dGqTW455IcRIoGEwlGi9i4 /TN6L/7M6pjoNMwHn2Q3c3Kbmqohi/QG6FRkkE/Qk+joXN3Ic7JKxpz3qhykpu+qZbufACfSyH7 gkbrUTFYxWioC7N3J/Kxb839iAhxF2Oh9y5J26dfXgp7wxZ1wa0CvaM7A8LcW4aWcQFp9/9RQiR U4OzEM= X-Google-Smtp-Source: AGHT+IG4Oe9XyYqhNP4Evw5R0NzB0R1ETknR2Stw9INPi/sUiWMaN9m//6osRhVpnagDgAiVJhGveWV98ePUoc9LGHA= X-Received: by 2002:a05:6000:40da:b0:3a5:1240:6802 with SMTP id ffacd0b85a97d-3b768f164d6mr5598705f8f.57.1753368039549; Thu, 24 Jul 2025 07:40:39 -0700 (PDT) MIME-Version: 1.0 References: <64c8b824-6203-46a3-b045-5e95b796feee@vondra.me> <03dcc1a9-c5d0-4965-889c-684dc0a7580c@vondra.me> <23f490f4-8325-408c-91a0-a6757ab2441c@vondra.me> <1bebfd1b-aea5-4d41-80a6-eae64b8f9eaf@vondra.me> <8ed1d326-5c6e-476e-b3fd-30d3da210546@vondra.me> <38b865bd-2ae9-4a94-a788-6e3dc99ccd70@vondra.me> In-Reply-To: <38b865bd-2ae9-4a94-a788-6e3dc99ccd70@vondra.me> From: Peter Geoghegan Date: Thu, 24 Jul 2025 10:40:12 -0400 X-Gm-Features: Ac12FXygKoC9qMUxAIr3ezLahegQ3vYZf1ToLl6_RhXgX0PdKAAlxXrfSaxX_S8 Message-ID: Subject: Re: index prefetching To: Tomas Vondra Cc: Nazir Bilal Yavuz , Thomas Munro , 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 On Thu, Jul 24, 2025 at 7:19=E2=80=AFAM Tomas Vondra wrot= e: > I got a bit bored yesterday, so I gave this a try and whipped up a patch > that adds two pgstattuple functins that I think could be useful for > analyzing index metrics that matter for prefetching. This seems quite useful. I notice that you're not accounting for posting lists. That'll lead to miscounts of the number of heap blocks in many cases. I think that that's worth fixing, even given that this patch is experimental. > It's trivial to summarize this into a per-index statistic (of course, > there may be some inaccuracies when the run spans multiple ranges), but > it also seems useful to be able to look at parts of the index. FWIW in my experience, the per-leaf-page "nhtids:nhblks" tends to be fairly consistent across all leaf pages from a given index. There are no doubt some exceptions, but they're probably pretty rare. > Second, the index is walked sequentially in physical order, from block 0 > to the last block. But that's not really what the index prefetch sees. > To make it "more accurate" it'd be better to just scan the leaf pages as > if during a "full index scan". Why not just do it that way to begin with? It wouldn't be complicated to make the function follow a chain of right sibling links. I suggest an interface that takes a block number, and an nblocks int8 argument that must be >=3D 1. The function would start from the block number arg leaf page. If it's not a non-ignorable leaf page, throw an error. Otherwise, count the number of distinct heap blocks on the leaf page, and count the number of heap blocks on each additional leaf page to the right -- until we've counted the heap blocks from nblocks-many leaf pages (or until we reach the rightmost leaf page). I suggest that a P_IGNORE() page shouldn't have its heap blocks counted, and shouldn't count towards our nblocks tally of leaf pages whose heap blocks are to be counted. Upon encountering a P_IGNORE() page, just move to the right without doing anything. Note that the rightmost page cannot be P_IGNORE(). This scheme will always succeed, no matter the nblocks argument, provided the initial leaf page is a valid leaf page (and provided the nblocks arg is >=3D 1). I get that this is just a prototype that might not go anywhere, but the scheme I've described requires few changes. --=20 Peter Geoghegan