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 1raKpq-009HZS-Cj for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Feb 2024 19:22:22 +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 1raKpo-008LM6-O7 for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Feb 2024 19:22:20 +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.94.2) (envelope-from ) id 1raKpo-008LLy-A9 for pgsql-hackers@lists.postgresql.org; Wed, 14 Feb 2024 19:22:20 +0000 Received: from mail-vk1-xa2a.google.com ([2607:f8b0:4864:20::a2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1raKpl-007Cb7-RI for pgsql-hackers@lists.postgresql.org; Wed, 14 Feb 2024 19:22:19 +0000 Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-4c02478c8efso31492e0c.0 for ; Wed, 14 Feb 2024 11:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20230601.gappssmtp.com; s=20230601; t=1707938536; x=1708543336; 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=0EazzmvEPlSJByZtp4Z8YPZ3juCCJiiJ0HxjbVXWrfI=; b=w3QqoL7nqBELlKZhU8gQmAJz1qZBE35xHZJEbUOIRRvXHuAWckCCj4B9Qcapl3kz8d 3onaUpqoeireC1JEt48RKKmW2ovVWV+e9z7XYHS+xG1rcRvyU+qfaTfe+iEK229wnL+o lN6DKIXwDYQvnezeu8AaDIwJHN0D772cBQYjl8bSfRVGiJH5Dro7LQUE71yfq1ybfTWZ Iu4q+iNlpEvzySNujk1+0PCjfe/7TOv9nV6ZpLT2gML3Wne6Jx9aghzxVD8xz06WyBDn rBG/Y84OyijRJfuEGZECzqOhSOSMN9FlUwF/f0RU/o7xg2a9/1ATp/qaMHI7Gx2sy2qn TC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707938536; x=1708543336; 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=0EazzmvEPlSJByZtp4Z8YPZ3juCCJiiJ0HxjbVXWrfI=; b=KhB15W6r47UUNeej3vJXjS/Ks2esQ1QOO2ct68W3Bhqlouy7YmfA+5OpdtAGJ+9ZKB z3r1xUpq+ZZNR1fpQ3q672IJq0RtMX6ni0Vi8iOKBqpTkSYJspCajyIbEjF3UkxFXBaW Auty63FYVLftfibWXkbfMLTaOjsJnnEQpGJH/WTetiHkkED8/85zQkQQbz6Ywl3WQ9Bj HQYOFblTx/B20LOAxM350O2Cm6UgiAZZlVB5kg/h+P0qYjsuPMFkZvRVXxeBZtpdaaIC GlflaqmzTteKZw8830G6lpbi59ihwrLCBA+HIW8fUuFHR0aMbEJemjRyROJJSz6osEdc XMUg== X-Forwarded-Encrypted: i=1; AJvYcCVbeVsABUsxXQxjnTTUhQh+YhuMFYxzS3vree+9RLKpNFkgEH1tPgY4scWXW+ERLYB8+z49JKGmVY8g84Alp7niqJoZCJd1wYi6XBdLDPGcF7iG X-Gm-Message-State: AOJu0YzyRhRgQnf+MBVdriwurFqIlPMIQs0IkddGUxV2WTt949MaD1J+ YwUQyj84K8XjGV8C3XEL+iUdpQpm7f3k6QzGJX276rd2kbb3gWhkRfe47zTxwQLGAoAXZAl/cM0 sIk8vkG7+4NGTTS0VBmdaxoeE1LQlBCdXtYUvWw== X-Google-Smtp-Source: AGHT+IEXrhz2lKH6FcR/aBtEfFXe61sZQPUeVXkzHQfHAXJXqCZ9KJ6VMH4lr74akHQGg2cvndZG+YerOHYDuVTe+J0= X-Received: by 2002:a1f:e0c3:0:b0:4c0:2158:cca with SMTP id x186-20020a1fe0c3000000b004c021580ccamr3437237vkg.2.1707938535995; Wed, 14 Feb 2024 11:22:15 -0800 (PST) MIME-Version: 1.0 References: <8ec36f51-b863-60e3-20e2-b9c981c5ce5e@enterprisedb.com> <280dc83c-a16f-4424-1319-95e7e3f798bd@enterprisedb.com> <98ba4b25-fae8-c1f4-1597-8093375a1986@enterprisedb.com> <20231221134314.wf2rs62d37u62j7t@alap3.anarazel.de> <20231221154352.ijtg6wloa3nowivh@alap3.anarazel.de> <482ec3ff-52ad-415d-96fd-f3832a894023@enterprisedb.com> <56176b8d-956c-487e-ab09-310db4581c07@enterprisedb.com> <4867452a-b853-4813-a6da-9bb06a336f8b@enterprisedb.com> <4f5f16ef-df1e-4e09-9b3f-2e0961ab5117@enterprisedb.com> In-Reply-To: From: Peter Geoghegan Date: Wed, 14 Feb 2024 14:21:49 -0500 Message-ID: Subject: Re: index prefetching To: Melanie Plageman Cc: Tomas Vondra , Robert Haas , Andres Freund , PostgreSQL Hackers , Georgios , Thomas Munro , 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 Wed, Feb 14, 2024 at 11:40=E2=80=AFAM Melanie Plageman wrote: > I wasn't quite sure how we could use > index_compute_xid_horizon_for_tuples() for inspiration -- per Peter's > suggestion. But, I'd like to understand. The point I was trying to make with that example was: a highly generic mechanism can sometimes work across disparate index AMs (that all at least support plain index scans) when it just so happens that these AMs don't actually differ in a way that could possibly matter to that mechanism. While it's true that (say) nbtree and hash are very different at a high level, it's nevertheless also true that the way things work at the level of individual index pages is much more similar than different. With index deletion, we know that we're differences between each supported index AM either don't matter at all (which is what obviates the need for index_compute_xid_horizon_for_tuples() to be directly aware of which index AM the page it is passed comes from), or matter only in small, incidental ways (e.g., nbtree stores posting lists in its tuples, despite using IndexTuple structs). With prefetching, it seems reasonable to suppose that an index-AM specific approach would end up needing very little truly custom code. This is pretty strongly suggested by the fact that the rules around buffer pins (as an interlock against concurrent TID recycling by VACUUM) are standardized by the index AM API itself. Those rules might be slightly more natural with nbtree, but that's kinda beside the point. While the basic organizing principle for where each index tuple goes can vary enormously, it doesn't necessarily matter at all -- in the end, you're really just reading each index page (that has TIDs to read) exactly once per scan, in some fixed order, with interlaced inline heap accesses (that go fetch heap tuples for each individual TID read from each index page). In general I don't accept that we need to do things outside the index AM, because software architecture encapsulation something something. I suspect that we'll need to share some limited information across different layers of abstraction, because that's just fundamentally what's required by the constraints we're operating under. Can't really prove it, though. --=20 Peter Geoghegan