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 1rOKmO-003JtS-JL for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2024 16:53:13 +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 1rOKmN-003bpe-86 for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2024 16:53:11 +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 1rOKmM-003bpW-VF for pgsql-hackers@lists.postgresql.org; Fri, 12 Jan 2024 16:53:10 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rOKmK-001Dca-AD for pgsql-hackers@lists.postgresql.org; Fri, 12 Jan 2024 16:53:10 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33677fb38a3so6061933f8f.0 for ; Fri, 12 Jan 2024 08:53:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705078386; x=1705683186; 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=U8HhcYjaP3MVO9gM6ss0eUn3/eFfSDZ8zJWUCI5euZw=; b=PTy+jp2YQJYxxEpdX0fN+IwwHWO/9ISjoybMYEt+lelx+xWvGlgTUyUzL387Dx9gIG NvOLHwOSj21wHAE8Ivth4VXwztWZ1xHVei3C6kDJptOeLL5wp0ZvzuoKXkpu8jGiDnJR EKd/FbOxr+TafR/W+T3IxR68IpSTSf875LxSBtBzpdDG78tFdLdetAZiZc04Ad1M56Jc RftpFyLpvpRQRWNKBpZcN4OoX1twMqeVNT3OiOCLI7V3nGM08/vLZLkqqAoqW09ghQYr mK9Qi+/N1S5Gv1JU06vUN5t7dCnoOkBsVkD1NQm6bmqxX8TC3lAPNw9Ns65hRpN0GVTw Y98g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705078386; x=1705683186; 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=U8HhcYjaP3MVO9gM6ss0eUn3/eFfSDZ8zJWUCI5euZw=; b=WEnWfWulxQ6iy4+e6R1gvIHh4qFpNH2sh3HgDtxIcZLjfdFerPUUx2/Hz7NZOjsPJa 0zNktse7ngmkUrdOej2aihCzeD/KyFizJq8k588GUEALl8xsWj5KnGgvTCvxOyq4akT6 9B7iflTCqCT5cH1HgospyQo8RhA9gi+0jsDDvmwBjsQ6Rw2r+r+BVayjY+Uh6Vufi6Pd GLFt8bY3U7VSNuL59yi/sgUPMFmjYJ2sSNl5C++0Q5/xjODlFChV65b5qIPh96nXASeD a8ghLwehzhot/Nof+6C4GEedk/maLx+5w2m/ncjcajnMcZrfp+CNLZHq9lpf8O7e/tTe 1pZQ== X-Gm-Message-State: AOJu0Yz9WrFOrujzDsKNguGXNATVZid3kZqKXYL8BTg3ib+vXIF9Mqs3 DFbPiTZ74ch7O7wRy4BQI9T42wmwZ8Xt74uUeP4= X-Google-Smtp-Source: AGHT+IGs3aQJGavGPVJ9oweLyajCr9s1ACpnqsH+HLSMJ5dhLLLA7BL62dPyBTTyuXTDy4agTgXZ0Mnhb8uFGNoksPc= X-Received: by 2002:a05:600c:1d2a:b0:40e:4d1e:2d42 with SMTP id l42-20020a05600c1d2a00b0040e4d1e2d42mr882202wms.170.1705078385909; Fri, 12 Jan 2024 08:53:05 -0800 (PST) MIME-Version: 1.0 References: <8ec36f51-b863-60e3-20e2-b9c981c5ce5e@enterprisedb.com> <06bb7d02-2c44-3062-731e-a735ba13da7e@enterprisedb.com> <367160ea-b1ed-4481-e804-bca509128878@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> In-Reply-To: <482ec3ff-52ad-415d-96fd-f3832a894023@enterprisedb.com> From: Robert Haas Date: Fri, 12 Jan 2024 11:52:53 -0500 Message-ID: Subject: Re: index prefetching To: Tomas Vondra Cc: Andres Freund , PostgreSQL Hackers , Georgios 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 Not a full response, but just to address a few points: On Fri, Jan 12, 2024 at 11:42=E2=80=AFAM Tomas Vondra wrote: > Thinking about this, I think it should be possible to make prefetching > work even for plans with execute_once=3Dfalse. In particular, when the > plan changes direction it should be possible to simply "walk back" the > prefetch queue, to get to the "correct" place in in the scan. But I'm > not sure it's worth it, because plans that change direction often can't > really benefit from prefetches anyway - they'll often visit stuff they > accessed shortly before anyway. For plans that don't change direction > but may pause, we don't know if the plan pauses long enough for the > prefetched pages to get evicted or something. So I think it's OK that > execute_once=3Dfalse means no prefetching. +1. > > + * XXX We do add the cache size to the request in order no= t to > > + * have issues with uint64 underflows. > > > > I don't know what this means. > > > > There's a check that does this: > > (x + PREFETCH_CACHE_SIZE) >=3D y > > it might also be done as "mathematically equivalent" > > x >=3D (y - PREFETCH_CACHE_SIZE) > > but if the "y" is an uint64, and the value is smaller than the constant, > this would underflow. It'd eventually disappear, once the "y" gets large > enough, ofc. The problem is, I think, that there's no particular reason that someone reading the existing code should imagine that it might have been done in that "mathematically equivalent" fashion. I imagined that you were trying to make a point about adding the cache size to the request vs. adding nothing, whereas in reality you were trying to make a point about adding from one side vs. subtracting from the other. > > + * We reach here if the index only scan is not parallel, or if we'= re > > + * serially executing an index only scan that was planned to be > > + * parallel. > > > > Well, this seems sad. > > Stale comment, I believe. However, I didn't see much benefits with > parallel index scan during testing. Having I/O from multiple workers > generally had the same effect, I think. Fair point, likely worth mentioning explicitly in the comment. > Yeah. I renamed all the structs and functions to IndexPrefetchSomething, > to keep it consistent. And then the constants are all capital, ofc. It'd still be nice to get table or heap in there, IMHO, but maybe we can't, and consistency is certainly a good thing regardless of the details, so thanks for that. --=20 Robert Haas EDB: http://www.enterprisedb.com